MessageHandler.c 1.1 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948
  1. #include "Module_OcppBackend20.h"
  2. #include "define.h"
  3. static char *APNAuthenticationEnumTypeStr[] = {
  4. MACROSTR(CHAP),
  5. MACROSTR(NONE),
  6. MACROSTR(PAP),
  7. MACROSTR(AUTO)
  8. };
  9. static char *AttributeEnumTypeStr[] = {
  10. MACROSTR(Actual),
  11. MACROSTR(Target),
  12. MACROSTR(MinSet),
  13. MACROSTR(MaxSet)
  14. };
  15. static char *AuthorizationStatusEnumTypeStr[] = {
  16. MACROSTR(Accepted),
  17. MACROSTR(Blocked),
  18. MACROSTR(ConcurrentTx),
  19. MACROSTR(Expired),
  20. MACROSTR(Invalid),
  21. MACROSTR(NoCredit),
  22. MACROSTR(NotAllowedTypeEVSE),
  23. MACROSTR(NotAtThisLocation),
  24. MACROSTR(NotAtThisTime),
  25. MACROSTR(Unknown)
  26. };
  27. #if 0
  28. static char *AuthorizeCertificateStatusEnumTypeStr[] = {
  29. MACROSTR(Accepted),
  30. MACROSTR(SignatureError),
  31. MACROSTR(CertificateExpired),
  32. MACROSTR(CertificateRevoked),
  33. MACROSTR(NoCertificateAvailable),
  34. MACROSTR(CertChainError),
  35. MACROSTR(ContractCancelled)
  36. };
  37. #endif
  38. static char *BootReasonEnumTypeStr[] = {
  39. MACROSTR(ApplicationReset),
  40. MACROSTR(FirmwareUpdate),
  41. MACROSTR(LocalReset),
  42. MACROSTR(PowerUp),
  43. MACROSTR(RemoteReset),
  44. MACROSTR(ScheduledReset),
  45. MACROSTR(Triggered),
  46. MACROSTR(Unknown),
  47. MACROSTR(Watchdog)
  48. };
  49. static char *SecurityEventEnumTypeStr[] = {
  50. MACROSTR(FirmwareUpdated),
  51. MACROSTR(FailedToAuthenticateAtCsms),
  52. MACROSTR(CsmsFailedToAuthenticate),
  53. MACROSTR(SettingSystemTime),
  54. MACROSTR(StartupOfTheDevice),
  55. MACROSTR(ResetOrReboot),
  56. MACROSTR(SecurityLogWasCleared),
  57. MACROSTR(ReconfigurationOfSecurityParameters),
  58. MACROSTR(MemoryExhaustion),
  59. MACROSTR(InvalidMessages),
  60. MACROSTR(AttemptedReplayAttacks),
  61. MACROSTR(TamperDetectionActivated),
  62. MACROSTR(InvalidFirmwareSignature),
  63. MACROSTR(InvalidFirmwareSigningCertificate),
  64. MACROSTR(InvalidCsmsCertificate),
  65. MACROSTR(InvalidChargingStationCertificate),
  66. MACROSTR(InvalidTLSVersion),
  67. MACROSTR(InvalidTLSCipherSuite)
  68. };
  69. static char *CancelReservationStatusEnumTypeStr[] = {
  70. MACROSTR(Accepted),
  71. MACROSTR(Rejected)
  72. };
  73. static char *CertificateActionEnumTypeStr[] = {
  74. MACROSTR(Install),
  75. MACROSTR(Update)
  76. };
  77. static char *CertificateSignedStatusEnumTypeStr[] = {
  78. MACROSTR(Accepted),
  79. MACROSTR(Rejected)
  80. };
  81. static char *CertificateSigningUseEnumTypeStr[] = {
  82. MACROSTR(ChargingStationCertificate),
  83. MACROSTR(V2GCertificate)
  84. };
  85. static char *ChangeAvailabilityStatusEnumTypeStr[] = {
  86. MACROSTR(Accepted),
  87. MACROSTR(Rejected),
  88. MACROSTR(Scheduled)
  89. };
  90. #if 0
  91. static char *ChargingLimitSourceEnumTypeStr[] = {
  92. MACROSTR(EMS),
  93. MACROSTR(Other),
  94. MACROSTR(SO),
  95. MACROSTR(CSO)
  96. };
  97. #endif
  98. static char *ChargingProfileKindEnumTypeStr[] = {
  99. MACROSTR(Absolute),
  100. MACROSTR(Recurring),
  101. MACROSTR(Relative)
  102. };
  103. static char *ChargingProfilePurposeEnumTypeStr[] = {
  104. MACROSTR(ChargingStationExternalConstraints),
  105. MACROSTR(ChargingStationMaxProfile),
  106. MACROSTR(TxDefaultProfile),
  107. MACROSTR(TxProfile)
  108. };
  109. static char *ChargingProfileStatusEnumTypeStr[] = {
  110. MACROSTR(Accepted),
  111. MACROSTR(Rejected)
  112. };
  113. static char *ChargingRateUnitEnumTypeStr[] = {
  114. MACROSTR(W),
  115. MACROSTR(A)
  116. };
  117. static char *ChargingStateEnumTypeStr[] = {
  118. MACROSTR(Charging),
  119. MACROSTR(EVConnected),
  120. MACROSTR(SuspendedEV),
  121. MACROSTR(SuspendedEVSE),
  122. MACROSTR(Idle)
  123. };
  124. static char *ClearCacheStatusEnumTypeStr[] = {
  125. MACROSTR(Accepted),
  126. MACROSTR(Rejected)
  127. };
  128. static char *ClearChargingProfileStatusEnumTypeStr[] = {
  129. MACROSTR(Accepted),
  130. MACROSTR(Unknown)
  131. };
  132. static char *ClearMessageStatusEnumTypeStr[] = {
  133. MACROSTR(Accepted),
  134. MACROSTR(Unknown)
  135. };
  136. static char *ClearMonitoringStatusEnumTypeStr[] = {
  137. MACROSTR(Accepted),
  138. MACROSTR(Rejected),
  139. MACROSTR(NotFound)
  140. };
  141. static char *ComponentCriterionEnumTypeStr[] = {
  142. MACROSTR(Active),
  143. MACROSTR(Available),
  144. MACROSTR(Enabled),
  145. MACROSTR(Problem)
  146. };
  147. #if 0
  148. static char *ConnectorEnumTypeStr[] = {
  149. MACROSTR(cCCS1),
  150. MACROSTR(cCCS2),
  151. MACROSTR(cG105),
  152. MACROSTR(cTesla),
  153. MACROSTR(cType1),
  154. MACROSTR(cType2),
  155. MACROSTR(s309-1P-16A),
  156. MACROSTR(s309-1P-32A),
  157. MACROSTR(s309-3P-16A),
  158. MACROSTR(s309-3P-32A),
  159. MACROSTR(sBS1361),
  160. MACROSTR(sCEE-7-7),
  161. MACROSTR(sType2),
  162. MACROSTR(sType3),
  163. MACROSTR(Other1PhMax16A),
  164. MACROSTR(Other1PhOver16A),
  165. MACROSTR(Other3Ph),
  166. MACROSTR(Pan),
  167. MACROSTR(wInductive),
  168. MACROSTR(wResonant),
  169. MACROSTR(Undetermined),
  170. MACROSTR(Unknown)
  171. };
  172. #endif
  173. static char *ConnectorStatusEnumTypeStr[] = {
  174. MACROSTR(Available),
  175. MACROSTR(Occupied),
  176. MACROSTR(Reserved),
  177. MACROSTR(Unavailable),
  178. MACROSTR(Faulted)
  179. };
  180. #if 0
  181. static char *CostKindEnumTypeStr[] = {
  182. MACROSTR(CarbonDioxideEmission),
  183. MACROSTR(RelativePricePercentage),
  184. MACROSTR(RenewableGenerationPercentage)
  185. };
  186. #endif
  187. static char *CustomerInformationStatusEnumTypeStr[] = {
  188. MACROSTR(Accepted),
  189. MACROSTR(Rejected),
  190. MACROSTR(Invalid)
  191. };
  192. static char *DataEnumTypeStr[] = {
  193. MACROSTR(string),
  194. MACROSTR(decimal),
  195. MACROSTR(integer),
  196. MACROSTR(dateTime),
  197. MACROSTR(boolean),
  198. MACROSTR(OptionList),
  199. MACROSTR(SequenceList),
  200. MACROSTR(MemberList)
  201. };
  202. static char *DataTransferStatusEnumTypeStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Rejected),
  205. MACROSTR(UnknownMessageId),
  206. MACROSTR(UnknownVendorId)
  207. };
  208. static char *DeleteCertificateStatusEnumTypeStr[] = {
  209. MACROSTR(Accepted),
  210. MACROSTR(Failed),
  211. MACROSTR(NotFound)
  212. };
  213. static char *DisplayMessageStatusEnumTypeStr[] = {
  214. MACROSTR(Accepted),
  215. MACROSTR(NotSupportedMessageFormat),
  216. MACROSTR(Rejected),
  217. MACROSTR(NotSupportedPriority),
  218. MACROSTR(NotSupportedState),
  219. MACROSTR(UnknownTransaction)
  220. };
  221. #if 0
  222. static char *EnergyTransferModeEnumTypeStr[] = {
  223. MACROSTR(DC),
  224. MACROSTR(AC_single_phase),
  225. MACROSTR(AC_two_phase),
  226. MACROSTR(AC_three_phase)
  227. };
  228. #endif
  229. static char *EventNotificationEnumTypeStr[] = {
  230. MACROSTR(HardWiredNotification),
  231. MACROSTR(HardWiredMonitor),
  232. MACROSTR(PreconfiguredMonitor),
  233. MACROSTR(CustomMonitor)
  234. };
  235. static char *EventTriggerEnumTypeStr[] = {
  236. MACROSTR(Alerting),
  237. MACROSTR(Delta),
  238. MACROSTR(Periodic)
  239. };
  240. static char *FirmwareStatusEnumTypeStr[] = {
  241. MACROSTR(Downloaded),
  242. MACROSTR(DownloadFailed),
  243. MACROSTR(Downloading),
  244. MACROSTR(DownloadScheduled),
  245. MACROSTR(DownloadPaused),
  246. MACROSTR(Idle),
  247. MACROSTR(InstallationFailed),
  248. MACROSTR(Installing),
  249. MACROSTR(Installed),
  250. MACROSTR(InstallRebooting),
  251. MACROSTR(InstallScheduled),
  252. MACROSTR(InstallVerificationFailed),
  253. MACROSTR(InvalidSignature),
  254. MACROSTR(SignatureVerified)
  255. };
  256. static char *GenericDeviceModelStatusEnumTypeStr[] = {
  257. MACROSTR(Accepted),
  258. MACROSTR(Rejected),
  259. MACROSTR(NotSupported),
  260. MACROSTR(EmptyResultSet)
  261. };
  262. static char *GenericStatusEnumTypeStr[] = {
  263. MACROSTR(Accepted),
  264. MACROSTR(Rejected)
  265. };
  266. static char *GetCertificateIdUseEnumTypeStr[] = {
  267. MACROSTR(V2GRootCertificate),
  268. MACROSTR(MORootCertificate),
  269. MACROSTR(CSMSRootCertificate),
  270. MACROSTR(V2GCertificateChain),
  271. MACROSTR(ManufacturerRootCertificate)
  272. };
  273. static char *GetCertificateStatusEnumTypeStr[] = {
  274. MACROSTR(Accepted),
  275. MACROSTR(Failed)
  276. };
  277. static char *GetChargingProfileStatusEnumTypeStr[] = {
  278. MACROSTR(Accepted),
  279. MACROSTR(NoProfiles)
  280. };
  281. static char *GetDisplayMessagesStatusEnumTypeStr[] = {
  282. MACROSTR(Accepted),
  283. MACROSTR(Unknown)
  284. };
  285. static char *GetInstalledCertificateStatusEnumTypeStr[] = {
  286. MACROSTR(Accepted),
  287. MACROSTR(NotFound)
  288. };
  289. static char *GetVariableStatusEnumTypeStr[] = {
  290. MACROSTR(Accepted),
  291. MACROSTR(Rejected),
  292. MACROSTR(UnknownComponent),
  293. MACROSTR(UnknownVariable),
  294. MACROSTR(NotSupportedAttributeType)
  295. };
  296. static char *HashAlgorithmEnumTypeStr[] = {
  297. MACROSTR(SHA256),
  298. MACROSTR(SHA384),
  299. MACROSTR(SHA512)
  300. };
  301. static char *IdTokenEnumTypeStr[] = {
  302. MACROSTR(Central),
  303. MACROSTR(eMAID),
  304. MACROSTR(ISO14443),
  305. MACROSTR(ISO15693),
  306. MACROSTR(KeyCode),
  307. MACROSTR(Local),
  308. MACROSTR(MacAddress),
  309. MACROSTR(NoAuthorization),
  310. };
  311. static char *InstallCertificateUseEnumTypeStr[] = {
  312. MACROSTR(V2GRootCertificate),
  313. MACROSTR(MORootCertificate),
  314. MACROSTR(CSMSRootCertificate),
  315. MACROSTR(ManufacturerRootCertificate)
  316. };
  317. static char *InstallCertificateStatusEnumTypeStr[]={
  318. MACROSTR(Accepted),
  319. MACROSTR(Failed),
  320. MACROSTR(Rejected)
  321. };
  322. static char *Iso15118EVCertificateStatusEnumTypeStr[] = {
  323. MACROSTR(Accepted),
  324. MACROSTR(Failed)
  325. };
  326. static char *LocationEnumTypeStr[] = {
  327. MACROSTR(Body),
  328. MACROSTR(Cable),
  329. MACROSTR(EV),
  330. MACROSTR(Inlet),
  331. MACROSTR(Outlet)
  332. };
  333. static char *LogEnumTypeStr[] = {
  334. MACROSTR(DiagnosticsLog),
  335. MACROSTR(SecurityLog)
  336. };
  337. static char *LogStatusEnumTypeStr[] = {
  338. MACROSTR(Accepted),
  339. MACROSTR(Rejected),
  340. MACROSTR(AcceptedCanceled)
  341. };
  342. static char *MeasurandEnumTypeStr[] = {
  343. MACROSTR(Current.Export),
  344. MACROSTR(Current.Import),
  345. MACROSTR(Current.Offered),
  346. MACROSTR(Energy.Active.Export.Register),
  347. MACROSTR(Energy.Active.Import.Register),
  348. MACROSTR(Energy.Reactive.Export.Register),
  349. MACROSTR(Energy.Reactive.Import.Register),
  350. MACROSTR(Energy.Active.Export.Interval),
  351. MACROSTR(Energy.Active.Import.Interval),
  352. MACROSTR(Energy.Active.Net),
  353. MACROSTR(Energy.Reactive.Export.Interval),
  354. MACROSTR(Energy.Reactive.Import.Interval),
  355. MACROSTR(Energy.Reactive.Net),
  356. MACROSTR(Energy.Apparent.Net),
  357. MACROSTR(Energy.Apparent.Import),
  358. MACROSTR(Energy.Apparent.Export),
  359. MACROSTR(Frequency),
  360. MACROSTR(Power.Active.Export),
  361. MACROSTR(Power.Active.Import),
  362. MACROSTR(Power.Factor),
  363. MACROSTR(Power.Offered),
  364. MACROSTR(Power.Reactive.Export),
  365. MACROSTR(Power.Reactive.Import),
  366. MACROSTR(SoC),
  367. MACROSTR(Voltage)
  368. };
  369. static char *MessageFormatEnumTypeStr[] = {
  370. MACROSTR(ASCII),
  371. MACROSTR(HTML),
  372. MACROSTR(URI),
  373. MACROSTR(UTF8)
  374. };
  375. static char *MessagePriorityEnumTypeStr[] = {
  376. MACROSTR(AlwaysFront),
  377. MACROSTR(InFront),
  378. MACROSTR(NormalCycle)
  379. };
  380. static char *MessageStateEnumTypeStr[] = {
  381. MACROSTR(Charging),
  382. MACROSTR(Faulted),
  383. MACROSTR(Idle),
  384. MACROSTR(Unavailable)
  385. };
  386. static char *MessageTriggerEnumTypeStr[] = {
  387. MACROSTR(BootNotification),
  388. MACROSTR(LogStatusNotification),
  389. MACROSTR(FirmwareStatusNotification),
  390. MACROSTR(Heartbeat),
  391. MACROSTR(MeterValues),
  392. MACROSTR(SignChargingStationCertificate),
  393. MACROSTR(SignV2GCertificate),
  394. MACROSTR(StatusNotification),
  395. MACROSTR(TransactionEvent),
  396. MACROSTR(SignCombinedCertificate),
  397. MACROSTR(PublishFirmwareStatusNotification)
  398. };
  399. static char *MonitorEnumTypeStr[] = {
  400. MACROSTR(UpperThreshold),
  401. MACROSTR(LowerThreshold),
  402. MACROSTR(Delta),
  403. MACROSTR(Periodic),
  404. MACROSTR(PeriodicClockAligned)
  405. };
  406. static char *MonitoringBaseEnumTypeStr[] = {
  407. MACROSTR(All),
  408. MACROSTR(FactoryDefault),
  409. MACROSTR(HardWiredOnly)
  410. };
  411. static char *MonitoringCriterionEnumTypeStr[] = {
  412. MACROSTR(ThresholdMonitoring),
  413. MACROSTR(DeltaMonitoring),
  414. MACROSTR(PeriodicMonitoring)
  415. };
  416. static char *MutabilityEnumTypeStr[] = {
  417. MACROSTR(ReadOnly),
  418. MACROSTR(WriteOnly),
  419. MACROSTR(ReadWrite)
  420. };
  421. static char *NotifyEVChargingNeedsStatusEnumTypeStr[] = {
  422. MACROSTR(Accepted),
  423. MACROSTR(Rejected),
  424. MACROSTR(Processing)
  425. };
  426. static char *OCPPInterfaceEnumTypeStr[] = {
  427. MACROSTR(Wired0),
  428. MACROSTR(Wired1),
  429. MACROSTR(Wired2),
  430. MACROSTR(Wired3),
  431. MACROSTR(Wireless0),
  432. MACROSTR(Wireless1),
  433. MACROSTR(Wireless2),
  434. MACROSTR(Wireless3)
  435. };
  436. static char *OCPPTransportEnumTypeStr[] = {
  437. MACROSTR(JSON),
  438. MACROSTR(SOAP)
  439. };
  440. static char *OCPPVersionEnumTypeStr[] = {
  441. MACROSTR(OCPP12),
  442. MACROSTR(OCPP15),
  443. MACROSTR(OCPP16),
  444. MACROSTR(OCPP20)
  445. };
  446. static char *OperationalStatusEnumTypeStr[] = {
  447. MACROSTR(Inoperative),
  448. MACROSTR(Operative)
  449. };
  450. static char *PhaseEnumTypeStr[] = {
  451. MACROSTR(L1),
  452. MACROSTR(L2),
  453. MACROSTR(L3),
  454. MACROSTR(N),
  455. MACROSTR(L1-N),
  456. MACROSTR(L2-N),
  457. MACROSTR(L3-N),
  458. MACROSTR(L1-L2),
  459. MACROSTR(L2-L3),
  460. MACROSTR(L3-L1)
  461. };
  462. static char *PublishFirmwareStatusEnumTypeStr[] = {
  463. MACROSTR(Downloaded),
  464. MACROSTR(DownloadFailed),
  465. MACROSTR(Downloading),
  466. MACROSTR(DownloadScheduled),
  467. MACROSTR(DownloadPaused),
  468. MACROSTR(PublishFailed),
  469. MACROSTR(Published),
  470. MACROSTR(InvalidChecksum),
  471. MACROSTR(ChecksumVerified)
  472. };
  473. static char *ReadingContextEnumTypeStr[] = {
  474. MACROSTR(Interruption.Begin),
  475. MACROSTR(Interruption.End),
  476. MACROSTR(Other),
  477. MACROSTR(Sample.Clock),
  478. MACROSTR(Sample.Periodic),
  479. MACROSTR(Transaction.Begin),
  480. MACROSTR(Transaction.End),
  481. MACROSTR(Trigger)
  482. };
  483. #if 0
  484. static char *ReasonEnumTypeStr[] = {
  485. MACROSTR(DeAuthorized),
  486. MACROSTR(EmergencyStop),
  487. MACROSTR(EnergyLimitReached),
  488. MACROSTR(EVDisconnected),
  489. MACROSTR(GroundFault),
  490. MACROSTR(ImmediateReset),
  491. MACROSTR(Local),
  492. MACROSTR(LocalOutOfCredit),
  493. MACROSTR(MasterPass),
  494. MACROSTR(Other),
  495. MACROSTR(OvercurrentFault),
  496. MACROSTR(PowerLoss),
  497. MACROSTR(PowerQuality),
  498. MACROSTR(Reboot),
  499. MACROSTR(Remote),
  500. MACROSTR(SOCLimitReached),
  501. MACROSTR(StoppedByEV),
  502. MACROSTR(TimeLimitReached),
  503. MACROSTR(TimeLimitReached)
  504. };
  505. #endif
  506. static char *RecurrencyKindEnumTypeStr[] = {
  507. MACROSTR(Daily),
  508. MACROSTR(Weekly)
  509. };
  510. static char *RegistrationStatusEnumTypeStr[] = {
  511. MACROSTR(Accepted),
  512. MACROSTR(Pending),
  513. MACROSTR(Rejected)
  514. };
  515. static char *ReportBaseEnumTypeStr[] = {
  516. MACROSTR(ConfigurationInventory),
  517. MACROSTR(FullInventory),
  518. MACROSTR(SummaryInventory)
  519. };
  520. static char *RequestStartStopStatusEnumTypeStr[] = {
  521. MACROSTR(Accepted),
  522. MACROSTR(Rejected)
  523. };
  524. static char *ReservationUpdateStatusEnumTypeStr[] = {
  525. MACROSTR(Expired),
  526. MACROSTR(Removed)
  527. };
  528. static char *ReserveNowStatusEnumTypeStr[] = {
  529. MACROSTR(Accepted),
  530. MACROSTR(Faulted),
  531. MACROSTR(Occupied),
  532. MACROSTR(Rejected),
  533. MACROSTR(Unavailable)
  534. };
  535. static char *ResetEnumTypeStr[] = {
  536. MACROSTR(Immediate),
  537. MACROSTR(OnIdle)
  538. };
  539. static char *ResetStatusEnumTypeStr[] = {
  540. MACROSTR(Accepted),
  541. MACROSTR(Rejected),
  542. MACROSTR(Scheduled)
  543. };
  544. static char *SetMonitoringStatusEnumTypeStr[] = {
  545. MACROSTR(Accepted),
  546. MACROSTR(UnknownComponent),
  547. MACROSTR(UnknownVariable),
  548. MACROSTR(UnsupportedMonitorType),
  549. MACROSTR(Rejected),
  550. MACROSTR(OutOfRange),
  551. MACROSTR(Duplicate)
  552. };
  553. static char *SetNetworkProfileStatusEnumTypeStr[] = {
  554. MACROSTR(Accepted),
  555. MACROSTR(Rejected),
  556. MACROSTR(Failed)
  557. };
  558. static char *SetVariableStatusEnumTypeStr[] = {
  559. MACROSTR(Accepted),
  560. MACROSTR(Rejected),
  561. MACROSTR(InvalidValue),
  562. MACROSTR(UnknownComponent),
  563. MACROSTR(UnknownVariable),
  564. MACROSTR(NotSupportedAttributeType),
  565. MACROSTR(OutOfRange),
  566. MACROSTR(RebootRequired)
  567. };
  568. static char *TransactionEventEnumTypeStr[] = {
  569. MACROSTR(Ended),
  570. MACROSTR(Started),
  571. MACROSTR(Updated)
  572. };
  573. static char *TriggerMessageStatusEnumTypeStr[] = {
  574. MACROSTR(Accepted),
  575. MACROSTR(Rejected),
  576. MACROSTR(NotImplemented)
  577. };
  578. static char *TriggerReasonEnumTypeStr[] = {
  579. MACROSTR(Authorized),
  580. MACROSTR(CablePluggedIn),
  581. MACROSTR(ChargingRateChanged),
  582. MACROSTR(ChargingStateChanged),
  583. MACROSTR(Deauthorized),
  584. MACROSTR(EnergyLimitReached),
  585. MACROSTR(EVCommunicationLost),
  586. MACROSTR(EVConnectTimeout),
  587. MACROSTR(MeterValueClock),
  588. MACROSTR(MeterValuePeriodic),
  589. MACROSTR(TimeLimitReached),
  590. MACROSTR(Trigger),
  591. MACROSTR(UnlockCommand),
  592. MACROSTR(StopAuthorized),
  593. MACROSTR(EVDeparted),
  594. MACROSTR(EVDetected),
  595. MACROSTR(RemoteStop),
  596. MACROSTR(RemoteStart),
  597. MACROSTR(AbnormalCondition),
  598. MACROSTR(SignedDataReceived),
  599. MACROSTR(ResetCommand)
  600. };
  601. static char *UnlockStatusEnumTypeStr[] = {
  602. MACROSTR(Unlocked),
  603. MACROSTR(UnlockFailed),
  604. MACROSTR(OngoingAuthorizedTransaction),
  605. MACROSTR(UnknownConnector)
  606. };
  607. static char *UnpublishFirmwareStatusEnumTypeStr[] = {
  608. MACROSTR(DownloadOngoing),
  609. MACROSTR(NoFirmware),
  610. MACROSTR(Unpublished)
  611. };
  612. static char *UpdateEnumTypeStr[] = {
  613. MACROSTR(Differential),
  614. MACROSTR(Full)
  615. };
  616. static char *UpdateFirmwareStatusEnumTypeStr[] = {
  617. MACROSTR(Accepted),
  618. MACROSTR(Rejected),
  619. MACROSTR(AcceptedCanceled),
  620. MACROSTR(InvalidCertificate),
  621. MACROSTR(RevokedCertificate)
  622. };
  623. static char *UpdateStatusEnumTypeStr[] = {
  624. MACROSTR(Accepted),
  625. MACROSTR(Failed),
  626. MACROSTR(VersionMismatch)
  627. };
  628. static char *UploadLogStatusEnumTypeStr[] = {
  629. MACROSTR(BadMessage),
  630. MACROSTR(Idle),
  631. MACROSTR(NotSupportedOperation),
  632. MACROSTR(PermissionDenied),
  633. MACROSTR(Uploaded),
  634. MACROSTR(UploadFailure),
  635. MACROSTR(Uploading),
  636. MACROSTR(AcceptedCanceled)
  637. };
  638. static char *VPNEnumTypeStr[] = {
  639. MACROSTR(IKEv2),
  640. MACROSTR(IPSec),
  641. MACROSTR(L2TP),
  642. MACROSTR(PPTP)
  643. };
  644. #if 0
  645. static char *ChargePointErrorCodeEnumTypeStr[] = {
  646. MACROSTR(ConnectorLockFailure),
  647. MACROSTR(EVCommunicationError),
  648. MACROSTR(GroundFailure),
  649. MACROSTR(HighTemperature),
  650. MACROSTR(InternalError),
  651. MACROSTR(LocalListConflict),
  652. MACROSTR(NoError),
  653. MACROSTR(OtherError),
  654. MACROSTR(OverCurrentFailure),
  655. MACROSTR(OverVoltage),
  656. MACROSTR(PowerMeterFailure),
  657. MACROSTR(PowerSwitchFailure),
  658. MACROSTR(ReaderFailure),
  659. MACROSTR(ResetFailure),
  660. MACROSTR(UnderVoltage),
  661. MACROSTR(WeakSignal)
  662. };
  663. #endif
  664. static char *GetCompositeScheduleStatusEnumTypeStr[] = {
  665. MACROSTR(Accepted),
  666. MACROSTR(Rejected)
  667. };
  668. static char *RemoteStartStopStatusEnumTypeStr[] = {
  669. MACROSTR(Accepted),
  670. MACROSTR(Rejected)
  671. };
  672. #if 0
  673. static char * StopTransactionReasonEnumTypeStr[] = {
  674. MACROSTR(EmergencyStop),
  675. MACROSTR(EVDisconnected),
  676. MACROSTR(HardReset),
  677. MACROSTR(Local),
  678. MACROSTR(Other),
  679. MACROSTR(PowerLoss),
  680. MACROSTR(Reboot),
  681. MACROSTR(Remote),
  682. MACROSTR(SoftReset),
  683. MACROSTR(UnlockCommand),
  684. MACROSTR(DeAuthorized)
  685. };
  686. #endif
  687. //ChargePointMaxProfile
  688. #define ChargingStationMaxProfile_JSON "/Storage/OCPP/ChargingStationMaxProfile_OCPP20.json"
  689. //TxDefaultProfile
  690. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0_OCPP20.json"
  691. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  692. struct StatusCodeData *ShmStatusCodeData;
  693. struct PsuData *ShmPsuData ;
  694. struct OCPP20Data *ShmOCPP20Data;
  695. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  696. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  697. //===============================
  698. // Gun Total Numbers
  699. //===============================
  700. static ParsingRatedCur modelnameInfo = {0};
  701. static int gunTotalNumber = 0;
  702. static uint8_t gunType[4] = {0};
  703. //===============================
  704. // Local List Version
  705. //===============================
  706. static int localversion=0;
  707. //===============================
  708. // Variable Version
  709. //===============================
  710. static int variableVersion=10;
  711. //===============================
  712. // OCPP sign variable
  713. //===============================
  714. static int server_sign = FALSE;
  715. int server_pending = FALSE;
  716. static int BootNotificationInterval = 10;
  717. //===============================
  718. // OCPP auth variable
  719. //===============================
  720. static int authorizeRetryTimes = 0; //number of Retry times
  721. //===============================
  722. // OCPP other variables
  723. //===============================
  724. static int HeartBeatWaitTime = 10;
  725. static int FirstHeartBeat = 0;
  726. static int FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle; // Idle
  727. static int LogStatusNotificationStatus = UploadLogStatusEnumType_Idle; // Idle
  728. static char CurrentChargingProfileScheduleStr[30] = {0};
  729. static int isCancelUploadLog = FALSE;
  730. pthread_t th_GetLog;
  731. //========================================
  732. // OCPP status/previous related variables
  733. //========================================
  734. static int GunStatusInterval = 10;
  735. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  736. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  737. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  738. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  739. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  740. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  741. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  742. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  743. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  744. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  745. static int TransactionMessageAttemptsValue = 0;
  746. static int TransactionMessageRetryIntervalValue = 0;
  747. static struct AuthorizationData idTagQuery;
  748. static float periousPeriodicPowerConsumption[CONNECTOR_QUANTITY] = {0};
  749. static float periousClockPowerConsumption[CONNECTOR_QUANTITY] = {0};
  750. //=============================================
  751. // OCPP HeartBeat Response Not Receive Counts
  752. //============================================
  753. static int HeartBeatWithNOResponse = 0;
  754. static int HeartBeatCountPerHour = 0;
  755. sqlite3 *db;
  756. int TransactionMessageAttemptsGet(void);
  757. int TransactionMessageRetryIntervalGet(void);
  758. int GetOcppConnStatus(void);
  759. void SetOcppConnStatus(uint8_t status);
  760. int setKeyValue(char *key, char *value);
  761. void OCPP_get_TableAuthlocalAllData(void);
  762. void processUnkownKey(void);
  763. struct InterLock
  764. {
  765. unsigned char isGetLogGoing:1;
  766. unsigned char isUpdateFirmwareGoing:1;
  767. }interLock;
  768. struct ClientTime
  769. {
  770. struct timespec Heartbeat;
  771. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  772. struct timespec StartTransaction;
  773. struct timespec StopTransaction;
  774. struct timespec MeterValues[CONNECTOR_QUANTITY];
  775. struct timespec SampledDataTxEnded[CONNECTOR_QUANTITY];
  776. struct timespec RemoteStartWait;
  777. struct timespec CharingProfileRefresh[CONNECTOR_QUANTITY];
  778. }clientTime;
  779. typedef union
  780. {
  781. //Operations Initiated by Central System
  782. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  783. struct
  784. {
  785. //CsMsgValue[0]
  786. unsigned char StatusNotificationReq:1; //bit 0,
  787. unsigned char StatusNotificationConf:1; //bit 1,
  788. unsigned char TriggerMeterValueReq:1; //bit 2,
  789. unsigned char SampleMeterReq:1; //bit 3,
  790. unsigned char ClockAlignMeterReq:1; //bit 4,
  791. unsigned char TriggerStatusNotificationReq:1; //bit 5,
  792. unsigned char isOnCharging:1; //bit 6,
  793. unsigned char TriggerTransactionEventReq:1; //bit 7
  794. }bits[CONNECTOR_QUANTITY];
  795. }CpinitiateMsg;
  796. CpinitiateMsg cpinitateMsg;
  797. //=========================================
  798. // Meter buffer process
  799. //=========================================
  800. int meterValueBufferDataQuantity(uint8_t gun_index, ReadingContextEnumType dataType)
  801. {
  802. uint32_t result = 0;
  803. char sqlCmd[8192];
  804. char zErrMsg[200];
  805. int rows, cols;
  806. char **resultData;
  807. sprintf(sqlCmd, "select count(idx) as dataQuantity from meterValuesBuffer where gun_index='%d' and ReadingContext='%d' order by ReadingContext, idx", gun_index, (dataType==ReadingContextEnumType_Sample_Periodic?0:1));
  808. if( sqlite3_get_table(db, sqlCmd, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  809. {
  810. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  811. }
  812. else
  813. {
  814. if(rows >= 1)
  815. {
  816. result = atoi(resultData[1]);
  817. }
  818. }
  819. return result;
  820. }
  821. int meterValueBufferClear(uint8_t gun_index)
  822. {
  823. int result = PASS;
  824. char sqlCmd[512];
  825. char *errMsg = 0;
  826. sprintf(sqlCmd, "delete from meterValuesBuffer where gun_index=%d", gun_index);
  827. if (sqlite3_exec(db, sqlCmd, 0, 0, &errMsg) != SQLITE_OK)
  828. {
  829. DEBUG_INFO("SQL error: %s\n",errMsg);
  830. result = FAIL;
  831. }
  832. return result;
  833. }
  834. int meterValueBufferInsert(uint8_t gun_index, ReadingContextEnumType dataType, char * transactionId, char *meterValue)
  835. {
  836. int result = PASS;
  837. char sqlCmd[8192];
  838. char *errMsg = 0;
  839. sprintf(sqlCmd, "insert into meterValuesBuffer(occurDatetime, gun_index, transactionId, ReadingContext, meterValue) values(CURRENT_TIMESTAMP, '%d', '%s','%d','%s')", gun_index
  840. , transactionId
  841. , (dataType==ReadingContextEnumType_Sample_Periodic?0:1)
  842. , meterValue);
  843. if (sqlite3_exec(db, sqlCmd, 0, 0, &errMsg) != SQLITE_OK)
  844. {
  845. result = FAIL;
  846. DEBUG_WARN( "Insert meter value record error message: %s\n", errMsg);
  847. }
  848. return result;
  849. }
  850. int meterValueBufferReplace(int bufferIdx, uint8_t gun_index, ReadingContextEnumType dataType, char * transactionId, char *meterValue)
  851. {
  852. int result = PASS;
  853. char sqlCmd[8192];
  854. char *errMsg = 0;
  855. sprintf(sqlCmd, "replace into meterValuesBuffer(idx, occurDatetime, gun_index, transactionId, ReadingContext, meterValue) values('%d', CURRENT_TIMESTAMP, '%d', '%s','%d','%s')", bufferIdx
  856. , gun_index
  857. , transactionId
  858. , (dataType==ReadingContextEnumType_Sample_Periodic?0:1)
  859. , meterValue);
  860. if (sqlite3_exec(db, sqlCmd, 0, 0, &errMsg) != SQLITE_OK)
  861. {
  862. result = FAIL;
  863. DEBUG_WARN( "Insert meter value record error message: %s\n", errMsg);
  864. }
  865. return result;
  866. }
  867. int meterValueBufferQuery(uint8_t gun_index, json_object *MeterValues)
  868. {
  869. int result = PASS;
  870. char sqlCmd[8192];
  871. char zErrMsg[200];
  872. int rows, cols;
  873. char **resultData;
  874. sprintf(sqlCmd, "select * from meterValuesBuffer where gun_index='%d' order by ReadingContext, idx", gun_index);
  875. if( sqlite3_get_table(db, sqlCmd, &resultData, &rows, &cols, (char **)&zErrMsg) != SQLITE_OK)
  876. {
  877. DEBUG_WARN("SQL error: %s\n", zErrMsg);
  878. result = FAIL;
  879. }
  880. else
  881. {
  882. for(uint32_t idxRow=1;idxRow<=rows;idxRow++)
  883. {
  884. json_object *MeterValue = json_tokener_parse(resultData[(idxRow*cols)+5]);
  885. json_object_array_add(MeterValues, MeterValue);
  886. }
  887. }
  888. return result;
  889. }
  890. //=========================================
  891. // Certificate related routine
  892. //=========================================
  893. int certVerify(char *privateKey, char *cert)
  894. {
  895. int result = PASS;
  896. SSL_CTX *ctx = SSL_CTX_new(TLS_method());
  897. // Load certificate file
  898. if(SSL_CTX_use_certificate_file(ctx, cert, SSL_FILETYPE_PEM) <= 0)
  899. {
  900. DEBUG_ERROR("Load certificate error!\n");
  901. result = FAIL;
  902. }
  903. // Load private key file
  904. if(SSL_CTX_use_PrivateKey_file(ctx, privateKey, SSL_FILETYPE_PEM) <= 0)
  905. {
  906. DEBUG_ERROR("Load private key error!\n");
  907. result = FAIL;
  908. }
  909. if(!SSL_CTX_check_private_key(ctx))
  910. {
  911. result = FAIL;
  912. }
  913. SSL_CTX_free(ctx);
  914. return result;
  915. }
  916. //==========================================
  917. // Parse certificate content
  918. //==========================================
  919. int parseCertInfo(char *certPath, int parseType, char *data)
  920. {
  921. int result = FAIL;
  922. int count = 0;
  923. int showupLine = 0;
  924. memset(data, 0, ARRAY_SIZE(data));
  925. if(access(certPath,F_OK) != -1)
  926. {
  927. char temp[512] = {0};
  928. char capturedData[256] = {0};
  929. char hashType[10] = "SHA256";
  930. FILE *fp;
  931. // Need to get hash type first
  932. sprintf(temp ,"openssl x509 -noout -text -in %s", certPath);
  933. fp = popen(temp, "r");
  934. if(fp)
  935. {
  936. while(fgets(temp, sizeof(temp), fp) != NULL)
  937. {
  938. if(strstr(temp, "Signature Algorithm:") != NULL)
  939. {
  940. result = PASS;
  941. if(strstr(temp, "sha256") != NULL || strstr(temp, "SHA256") != NULL)
  942. sprintf((char*)hashType, "SHA256");
  943. else if(strstr(temp, "sha384") != NULL || strstr(temp, "SHA384") != NULL)
  944. sprintf((char*)hashType, "SHA384");
  945. else if(strstr(temp, "sha512") != NULL || strstr(temp, "SHA512") != NULL)
  946. sprintf((char*)hashType, "SHA512");
  947. else
  948. {
  949. DEBUG_INFO("Error: hashAlgorithm is illegal or missing.\n");
  950. result = FAIL;
  951. }
  952. break;
  953. }
  954. }
  955. }
  956. switch(parseType)
  957. {
  958. case CERT_PARSE_HashAlgorithm:
  959. sprintf((char*)data, hashType);
  960. DEBUG_INFO("hashAlgorithm: %s\n", hashType);
  961. break;
  962. case CERT_PARSE_SerialNumber:
  963. sprintf(temp ,"openssl x509 -noout -serial -in %s", certPath);
  964. fp = popen(temp, "r");
  965. if(fp)
  966. {
  967. while(fgets(temp, sizeof(temp), fp) != NULL)
  968. {
  969. if(strstr(temp, "serial=") != NULL)
  970. {
  971. sscanf(temp, "%*[^=]=%s", capturedData);
  972. result = PASS;
  973. break;
  974. }
  975. }
  976. DEBUG_INFO("serialNumber: %s\n", capturedData);
  977. sprintf((char*)data, capturedData);
  978. }
  979. break;
  980. case CERT_PARSE_IssuerNameHash:
  981. sprintf(temp ,"openssl asn1parse -i < %s", certPath);
  982. fp = popen(temp, "r");
  983. if(fp)
  984. {
  985. while(fgets(temp, sizeof(temp), fp) != NULL)
  986. {
  987. if(strstr(temp, "SEQUENCE") != NULL)
  988. {
  989. count++;
  990. if(count==4)
  991. {
  992. sscanf(temp, "%[^:]", capturedData);
  993. showupLine = atoi(capturedData);
  994. break;
  995. }
  996. }
  997. }
  998. }
  999. if(showupLine > 0)
  1000. {
  1001. sprintf(temp ,"openssl asn1parse -i < %s -strparse %d -out /Storage/OCPP/IssuerNameHash", certPath, showupLine);
  1002. system(temp);
  1003. }
  1004. else
  1005. {
  1006. break;
  1007. }
  1008. if(access("/Storage/OCPP/IssuerNameHash",F_OK) != -1)
  1009. {
  1010. sprintf(temp ,"openssl %s < /Storage/OCPP/IssuerNameHash", (char*)hashType);
  1011. fp = popen(temp, "r");
  1012. if(fp)
  1013. {
  1014. while(fgets(temp, sizeof(temp), fp) != NULL)
  1015. {
  1016. if(strstr(temp, "(stdin)=") != NULL)
  1017. {
  1018. sscanf(temp, "%*[^=]=%s", capturedData);
  1019. result = PASS;
  1020. break;
  1021. }
  1022. }
  1023. stringtrimspace(capturedData);
  1024. DEBUG_INFO("issuerNameHash: %s\n", capturedData);
  1025. sprintf((char*)data, capturedData);
  1026. }
  1027. }
  1028. break;
  1029. case CERT_PARSE_IssuerKeyHash:
  1030. sprintf(temp ,"openssl asn1parse -i < %s", certPath);
  1031. fp = popen(temp, "r");
  1032. if(fp)
  1033. {
  1034. while(fgets(temp, sizeof(temp), fp) != NULL)
  1035. {
  1036. if(strstr(temp, "BIT STRING") != NULL)
  1037. {
  1038. sscanf(temp, "%[^:]", capturedData);
  1039. showupLine = atoi(capturedData);
  1040. break;
  1041. }
  1042. }
  1043. }
  1044. if(showupLine > 0)
  1045. {
  1046. sprintf(temp ,"openssl asn1parse -i < %s -strparse %d -out /Storage/OCPP/IssuerKeyHash", certPath, showupLine);
  1047. system(temp);
  1048. }
  1049. else
  1050. {
  1051. break;
  1052. }
  1053. if(access("/Storage/OCPP/IssuerKeyHash",F_OK) != -1)
  1054. {
  1055. sprintf(temp ,"openssl %s < /Storage/OCPP/IssuerKeyHash", (char*)hashType);
  1056. fp = popen(temp, "r");
  1057. if(fp)
  1058. {
  1059. while(fgets(temp, sizeof(temp), fp) != NULL)
  1060. {
  1061. if(strstr(temp, "(stdin)=") != NULL)
  1062. {
  1063. sscanf(temp, "%*[^=]=%s", capturedData);
  1064. result = PASS;
  1065. break;
  1066. }
  1067. }
  1068. stringtrimspace(capturedData);
  1069. DEBUG_INFO("issuerNameHash: %s\n", capturedData);
  1070. sprintf((char*)data, capturedData);
  1071. }
  1072. }
  1073. break;
  1074. case CERT_PARSE_OcspUrl:
  1075. //sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", certPath);
  1076. sprintf(temp ,"openssl crl2pkcs7 -nocrl -certfile %s | openssl pkcs7 -print_certs -text -noout", certPath);
  1077. fp = popen(temp, "r");
  1078. if(fp)
  1079. {
  1080. while(fgets(temp, sizeof(temp), fp) != NULL)
  1081. {
  1082. if(strstr(temp, "OCSP - URI:") != NULL)
  1083. {
  1084. //strcpy((char*)data, temp);
  1085. sscanf(temp, "%*[^:]:%s", capturedData);
  1086. sprintf((char*)data, capturedData);
  1087. DEBUG_INFO("OCSP_URI: %s\n", data);
  1088. result = PASS;
  1089. break;
  1090. }
  1091. }
  1092. }
  1093. break;
  1094. default:
  1095. DEBUG_INFO("Parse type is invalid.\n");
  1096. break;
  1097. }
  1098. pclose(fp);
  1099. }
  1100. return result;
  1101. }
  1102. //=========================================
  1103. // Get connector charging info
  1104. //=========================================
  1105. struct ChargingInfoData *getTargetChargingInfoData(uint8_t gun_index)
  1106. {
  1107. struct ChargingInfoData *targetChargingInfoData;
  1108. uint8_t tempIndex;
  1109. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  1110. {
  1111. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1112. {
  1113. tempIndex = ((gun_index==2) ? 1: 0);
  1114. }
  1115. else
  1116. {
  1117. tempIndex = gun_index;
  1118. }
  1119. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  1120. {
  1121. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  1122. {
  1123. targetChargingInfoData = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
  1124. break;
  1125. }
  1126. }
  1127. }
  1128. else if(gunType[gun_index] == GUN_TYPE_CCS)
  1129. {
  1130. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1131. {
  1132. tempIndex = ((gun_index==2) ? 1: 0);
  1133. }
  1134. else
  1135. {
  1136. tempIndex = gun_index;
  1137. }
  1138. for (int index = 0; index < CCS_QUANTITY; index++)
  1139. {
  1140. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  1141. {
  1142. targetChargingInfoData = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
  1143. break;
  1144. }
  1145. }
  1146. }
  1147. else if(gunType[gun_index] == GUN_TYPE_GBT)
  1148. {
  1149. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  1150. {
  1151. tempIndex = ((gun_index==2) ? 1: 0);
  1152. }
  1153. else
  1154. {
  1155. tempIndex = gun_index;
  1156. }
  1157. for (int index = 0; index < GB_QUANTITY; index++)
  1158. {
  1159. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  1160. {
  1161. targetChargingInfoData = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
  1162. break;
  1163. }
  1164. }
  1165. }
  1166. else if(gunType[gun_index] == GUN_TYPE_DO)
  1167. {
  1168. tempIndex = gun_index;
  1169. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  1170. {
  1171. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  1172. {
  1173. targetChargingInfoData = &ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData;
  1174. break;
  1175. }
  1176. }
  1177. }
  1178. else
  1179. {
  1180. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1181. {
  1182. tempIndex = 2;
  1183. }
  1184. else
  1185. {
  1186. tempIndex = gun_index;
  1187. }
  1188. for (int index = 0; index < AC_QUANTITY; index++)
  1189. {
  1190. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  1191. {
  1192. targetChargingInfoData = &ShmSysConfigAndInfo->SysInfo.AcChargingData[index];
  1193. break;
  1194. }
  1195. }
  1196. }
  1197. return targetChargingInfoData;
  1198. }
  1199. //=========================================
  1200. // Save configuration
  1201. //=========================================
  1202. int runShellCmd(const char*cmd)
  1203. {
  1204. int result = FAIL;
  1205. char buf[256];
  1206. FILE *fp;
  1207. fp = popen(cmd, "r");
  1208. if(fp != NULL)
  1209. {
  1210. while(fgets(buf, sizeof(buf), fp) != NULL)
  1211. {
  1212. DEBUG_INFO("%s\n", buf);
  1213. }
  1214. result = PASS;
  1215. }
  1216. pclose(fp);
  1217. return result;
  1218. }
  1219. int StoreUsrConfigData(struct SysConfigData *UsrData)
  1220. {
  1221. int result = PASS;
  1222. int fd,wrd;
  1223. unsigned int i,Chk;
  1224. unsigned char *ptr, *BufTmp;
  1225. int MtdBlockSize = 0x300000;
  1226. Chk=0;
  1227. ptr=(unsigned char *)UsrData;
  1228. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  1229. {
  1230. memset(BufTmp,0,MtdBlockSize);
  1231. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  1232. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  1233. Chk+=*(BufTmp+i);
  1234. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  1235. // Output configuration to file.
  1236. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  1237. if (fd < 0)
  1238. {
  1239. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  1240. free(BufTmp);
  1241. return 0;
  1242. }
  1243. wrd=write(fd, BufTmp, MtdBlockSize);
  1244. close(fd);
  1245. if(wrd<MtdBlockSize)
  1246. {
  1247. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  1248. free(BufTmp);
  1249. return 0;
  1250. }
  1251. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  1252. DEBUG_INFO("Erase /dev/mtd10.\n");
  1253. runShellCmd("flash_erase /dev/mtd10 0 0");
  1254. DEBUG_INFO("Write /dev/mtd10.\n");
  1255. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  1256. DEBUG_INFO("Erase /dev/mtd11.\n");
  1257. runShellCmd("flash_erase /dev/mtd11 0 0");
  1258. DEBUG_INFO("Write /dev/mtd11.\n");
  1259. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  1260. system("rm -f /mnt/EvseConfig.bin");
  1261. DEBUG_INFO("EvseConfig write to flash OK\n");
  1262. }
  1263. else
  1264. {
  1265. DEBUG_ERROR("alloc BlockSize NG\r\n");
  1266. result = FAIL;
  1267. }
  1268. if(BufTmp!=NULL)
  1269. free(BufTmp);
  1270. return result;
  1271. }
  1272. //=========================================
  1273. // Date time related function
  1274. //=========================================
  1275. void getNowDatetime(uint8_t *data)
  1276. {
  1277. time_t t = time(NULL);
  1278. struct tm tm = *localtime(&t);
  1279. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  1280. }
  1281. //=========================================
  1282. // Sqlite3 related function
  1283. //=========================================
  1284. int DB_Initial()
  1285. {
  1286. int result = PASS;
  1287. char* errMsg = NULL;
  1288. char *sqlOcppAuthCache = "create table if not exists ocpp20_auth_cache (idx integer primary key,"
  1289. "idToken text UNIQUE,"
  1290. "type text,"
  1291. "status text,"
  1292. "cacheExpiryDateTime text,"
  1293. "chargingPriority integer,"
  1294. "language1 text,"
  1295. "evseId text,"
  1296. "language2 text,"
  1297. "groupIdToken_idToken text,"
  1298. "groupIdToken_type text,"
  1299. "personalMessage text);";
  1300. char *sqlOcppAuthLocal = "create table if not exists ocpp20_auth_local (idx integer primary key,"
  1301. "idToken text UNIQUE,"
  1302. "type text,"
  1303. "status text,"
  1304. "cacheExpiryDateTime text,"
  1305. "chargingPriority integer,"
  1306. "language1 text,"
  1307. "evseId text,"
  1308. "language2 text,"
  1309. "groupIdToken_idToken text,"
  1310. "groupIdToken_type text,"
  1311. "personalMessage text,"
  1312. "version text);";
  1313. char *sqlOcppVariable = "create table if not exists ocpp20_variable (idx integer primary key,"
  1314. "componentName text NOT NULL ,"
  1315. "componentInstance text, "
  1316. "variableName text NOT NULL, "
  1317. "variableInstance text, "
  1318. "variableCharacteristicsDataType integer, "
  1319. "variableCharacteristicsUnit text, "
  1320. "variableCharacteristicsMaxLimit real,"
  1321. "variableAttributesType text, "
  1322. "variableAttributesTypeMutability text, "
  1323. "variableAttributesTypeValue text, "
  1324. "variableCharacteristicsMinLimit real,"
  1325. "unique(componentName, componentInstance,variableName, variableInstance) on conflict replace);";
  1326. char *sqlVariableMonitoring = "create table if not exists ocpp20_variable_monitoring (idx integer primary key,"
  1327. "id integer ,"
  1328. "transaction text, "
  1329. "value text , "
  1330. "type text, "
  1331. "severity integer, "
  1332. "component_name text, "
  1333. "component_instance text,"
  1334. "component_evse_id integer, "
  1335. "component_evse_connectorId integer, "
  1336. "variable_name text, "
  1337. "variable_instance text);";
  1338. char *sqlBootType = "create table if not exists ocpp20_boot_type (idx integer primary key,"
  1339. "type text);";
  1340. char *sqlSecurityEventType = "create table if not exists ocpp20_securityevent_type (idx integer primary key,"
  1341. "type text);";
  1342. char *sqlNetworkProfile = "create table if not exists ocpp20_networkprofile (idx integer primary key,"
  1343. "slot integer UNIQUE, connectionData text);";
  1344. char *sqlTransaction = "create table if not exists ocpp20_transaction_record (idx integer primary key,"
  1345. "occurDatetime text,"
  1346. "message_type text,"
  1347. "message_content text)";
  1348. char *sqlMeterValueBuffer = "create table if not exists meterValuesBuffer( idx integer primary key,"
  1349. "occurDatetime text,"
  1350. "gun_index text,"
  1351. "transactionId text,"
  1352. "ReadingContext text,"
  1353. "meterValue text);";
  1354. //sqlite3_config(SQLITE_CONFIG_URI, 1);
  1355. if(sqlite3_open(OCPP_LOCAL_DB_FILE, &db))
  1356. {
  1357. result = FAIL;
  1358. DEBUG_ERROR( "Can't open database: %s\n", sqlite3_errmsg(db));
  1359. sqlite3_close(db);
  1360. }
  1361. else
  1362. {
  1363. DEBUG_INFO( "OCPP local database open successfully.\n");
  1364. if (sqlite3_exec(db, sqlOcppAuthCache, 0, 0, &errMsg) != SQLITE_OK)
  1365. {
  1366. result = FAIL;
  1367. DEBUG_ERROR( "Create OCPP 2.0 auth cache table error message: %s\n", errMsg);
  1368. }
  1369. else
  1370. {
  1371. DEBUG_INFO( "Create OCPP 2.0 auth cache table table successfully\n");
  1372. }
  1373. if (sqlite3_exec(db, sqlOcppAuthLocal, 0, 0, &errMsg) != SQLITE_OK)
  1374. {
  1375. result = FAIL;
  1376. DEBUG_ERROR( "Create OCPP 2.0 auth list table error message: %s\n", errMsg);
  1377. }
  1378. else
  1379. {
  1380. DEBUG_INFO( "Create OCPP 2.0 auth list table successfully\n");
  1381. }
  1382. if (sqlite3_exec(db, sqlOcppVariable, 0, 0, &errMsg) != SQLITE_OK)
  1383. {
  1384. result = FAIL;
  1385. DEBUG_ERROR( "Create OCPP 2.0 variable table error message: %s\n", errMsg);
  1386. }
  1387. else
  1388. {
  1389. DEBUG_INFO( "Create OCPP 2.0 variable table successfully\n");
  1390. }
  1391. if (sqlite3_exec(db, sqlVariableMonitoring, 0, 0, &errMsg) != SQLITE_OK)
  1392. {
  1393. result = FAIL;
  1394. DEBUG_ERROR( "Create OCPP 2.0 variable monitoring table error message: %s\n", errMsg);
  1395. }
  1396. else
  1397. {
  1398. DEBUG_INFO( "Create OCPP 2.0 variable monitoring table successfully\n");
  1399. }
  1400. if (sqlite3_exec(db, sqlBootType, 0, 0, &errMsg) != SQLITE_OK)
  1401. {
  1402. result = FAIL;
  1403. DEBUG_ERROR( "Create OCPP 2.0 boot_type table error message: %s\n", errMsg);
  1404. }
  1405. else
  1406. {
  1407. DEBUG_INFO( "Create OCPP 2.0 boot_type table successfully\n");
  1408. }
  1409. if (sqlite3_exec(db, sqlSecurityEventType, 0, 0, &errMsg) != SQLITE_OK)
  1410. {
  1411. result = FAIL;
  1412. DEBUG_ERROR( "Create OCPP 2.0 securityevent_type table error message: %s\n", errMsg);
  1413. }
  1414. else
  1415. {
  1416. DEBUG_INFO( "Create OCPP 2.0 securityevent_type table successfully\n");
  1417. }
  1418. if (sqlite3_exec(db, sqlNetworkProfile, 0, 0, &errMsg) != SQLITE_OK)
  1419. {
  1420. result = FAIL;
  1421. DEBUG_ERROR( "Create OCPP 2.0 ocpp20_networkprofile table error message: %s\n", errMsg);
  1422. }
  1423. else
  1424. {
  1425. DEBUG_INFO( "Create OCPP 2.0 ocpp20_networkprofile table successfully\n");
  1426. }
  1427. if (sqlite3_exec(db, sqlTransaction, 0, 0, &errMsg) != SQLITE_OK)
  1428. {
  1429. result = FAIL;
  1430. DEBUG_ERROR( "Create OCPP 2.0 ocpp20_transaction_record table error message: %s\n", errMsg);
  1431. }
  1432. else
  1433. {
  1434. DEBUG_INFO( "Create OCPP 2.0 ocpp20_transaction_record table successfully\n");
  1435. }
  1436. // Create meter values buffer table
  1437. if(sqlite3_exec(db, sqlMeterValueBuffer, 0, 0, &errMsg) != SQLITE_OK)
  1438. {
  1439. DEBUG_INFO( "Create Table meterValuesBuffer error %s\n",errMsg);
  1440. return 0;
  1441. }
  1442. else
  1443. {
  1444. DEBUG_INFO( "Opened meterValuesBuffer table successfully\n");
  1445. }
  1446. //sqlite3_close(db);
  1447. }
  1448. return result;
  1449. }
  1450. int DB_cbGetVersion(void *para, int columnCount, char **columnValue, char **columnName)
  1451. {
  1452. localversion = columnValue[12] ? atoi(columnValue[12]) : 0;
  1453. return 0;
  1454. }
  1455. void DB_getListVerion()
  1456. {
  1457. char sql[256];
  1458. char* errMsg = NULL;
  1459. strcpy(sql, "select * from ocpp20_auth_local order by version desc, idx desc limit 1");
  1460. /* Execute SQL statement */
  1461. if( sqlite3_exec(db, sql, DB_cbGetVersion, 0, &errMsg) != SQLITE_OK )
  1462. {
  1463. DEBUG_INFO("SQL error: %s", errMsg);
  1464. }
  1465. }
  1466. int DB_cbGetIdTag(void *para, int columnCount, char **columnValue, char **columnName)
  1467. {
  1468. sprintf((char*)idTagQuery.idToken.idToken,"%s", columnValue[1] ? columnValue[1] : "NULL");
  1469. sprintf((char*)idTagQuery.idToken.type,"%s", columnValue[2] ? columnValue[2] : "NULL");
  1470. sprintf((char*)idTagQuery.idTokenInfo.status,"%s", columnValue[3] ? columnValue[3] : "NULL");
  1471. sprintf((char*)idTagQuery.idTokenInfo.cacheExpiryDateTime,"%s", columnValue[4] ? columnValue[4] : "NULL");
  1472. idTagQuery.idTokenInfo.chargingPriority = columnValue[5] ? atoi(columnValue[5]) : -1;
  1473. sprintf((char*)idTagQuery.idTokenInfo.language1,"%s", columnValue[6] ? columnValue[6] : "NULL");
  1474. sprintf((char*)idTagQuery.idTokenInfo.language2,"%s", columnValue[8] ? columnValue[8] : "NULL");
  1475. sprintf((char*)idTagQuery.idTokenInfo.groupIdToken.idToken,"%s", columnValue[9] ? columnValue[9] : "NULL");
  1476. sprintf((char*)idTagQuery.idTokenInfo.groupIdToken.type,"%s", columnValue[10] ? columnValue[10] : "NULL");
  1477. return 0;
  1478. }
  1479. void DB_getIdTag(char idTag[], uint8_t isQueryFromCache)
  1480. {
  1481. char sql[256];
  1482. char* errMsg = NULL;
  1483. memset(&idTagQuery, 0, sizeof(idTagQuery));
  1484. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  1485. if(isQueryFromCache)
  1486. sprintf(sql,"select * from ocpp20_auth_cache where idToken='%s'", idTag);
  1487. else
  1488. sprintf(sql,"select * from ocpp20_auth_local where idToken='%s'", idTag);
  1489. /* Execute SQL statement */
  1490. if(sqlite3_exec(db, sql, DB_cbGetIdTag, 0, &errMsg) != SQLITE_OK )
  1491. {
  1492. DEBUG_INFO("SQL error: %s", errMsg);
  1493. }
  1494. }
  1495. int DB_cbTableAuthlocalAllData(void *para, int columnCount, char **columnValue, char **columnName)
  1496. {
  1497. for (int i = 0; i < columnCount; i++)
  1498. {
  1499. DEBUG_INFO("%s = %s, ", columnName[i], columnValue[i]);
  1500. }
  1501. return 0;
  1502. }
  1503. void DB_get_TableAuthlocalAllData(void)
  1504. {
  1505. char sql[256];
  1506. char* errMsg = NULL;
  1507. sprintf(sql,"select * from ocpp20_auth_local;");
  1508. /* Execute SQL statement */
  1509. if(sqlite3_exec(db, sql, DB_cbTableAuthlocalAllData, 0,&errMsg) != SQLITE_OK)
  1510. {
  1511. DEBUG_INFO("SQL error: %s", errMsg);
  1512. }
  1513. }
  1514. int DB_cbAddLocalListCache(void *para, int columnCount, char **columnValue, char **columnName)
  1515. {
  1516. for(int i = 0; i<columnCount; i++)
  1517. {
  1518. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1519. }
  1520. return 0;
  1521. }
  1522. int DB_addLocalList(int listVersion, struct AuthorizationData *data)
  1523. {
  1524. int result = PASS;
  1525. char sql[512];
  1526. char* errMsg = NULL;
  1527. sprintf(sql,"insert or replace into ocpp20_auth_local (idToken, type, status, cacheExpiryDateTime, chargingPriority, language1, language2, groupIdToken_idToken, groupIdToken_type, version) VALUES('%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', %d ); SELECT * from ocpp20_auth_local;",
  1528. data->idToken.idToken,
  1529. data->idToken.type,
  1530. data->idTokenInfo.status,
  1531. data->idTokenInfo.cacheExpiryDateTime,
  1532. data->idTokenInfo.chargingPriority,
  1533. data->idTokenInfo.language1,
  1534. data->idTokenInfo.language2,
  1535. data->idTokenInfo.groupIdToken.idToken,
  1536. data->idTokenInfo.groupIdToken.type,
  1537. listVersion);
  1538. //* Execute SQL statement */
  1539. if(sqlite3_exec(db, sql, DB_cbAddLocalListCache, 0, &errMsg) != SQLITE_OK)
  1540. {
  1541. DEBUG_INFO("SQL error: %s\n", errMsg);
  1542. result = FAIL;
  1543. }
  1544. else
  1545. {
  1546. memset(sql, 0, ARRAY_SIZE(sql));
  1547. sprintf(sql, "UPDATE ocpp20_auth_local SET version=%d",listVersion);
  1548. if( sqlite3_exec(db, sql, NULL, NULL, &errMsg) != SQLITE_OK )
  1549. {
  1550. DEBUG_INFO("SQL error: %s\n", errMsg);
  1551. result = FAIL;
  1552. }
  1553. }
  1554. return result;
  1555. }
  1556. int DB_addLocalCache(struct IdTokenType *idToken, struct IdTokenInfoType *idTokenInfo)
  1557. {
  1558. int result = PASS;
  1559. char sql[512];
  1560. char* errMsg = NULL;
  1561. sprintf(sql,"insert or replace into ocpp20_auth_cache (idToken, type, status, cacheExpiryDateTime, chargingPriority, language1, language2, groupIdToken_idToken, groupIdToken_type) VALUES('%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s'); SELECT * from ocpp20_auth_cache;",
  1562. idToken->idToken,
  1563. idToken->type,
  1564. idTokenInfo->status,
  1565. idTokenInfo->cacheExpiryDateTime,
  1566. idTokenInfo->chargingPriority,
  1567. idTokenInfo->language1,
  1568. idTokenInfo->language2,
  1569. idTokenInfo->groupIdToken.idToken,
  1570. idTokenInfo->groupIdToken.type);
  1571. //* Execute SQL statement */
  1572. if(sqlite3_exec(db, sql, DB_cbAddLocalListCache, 0, &errMsg) != SQLITE_OK)
  1573. {
  1574. DEBUG_INFO("SQL error: %s\n", errMsg);
  1575. result = FAIL;
  1576. }
  1577. return result;
  1578. }
  1579. int deleteIdTagcallback(void *para, int columnCount, char **columnValue, char **columnName)
  1580. {
  1581. // localversion = argv[5] ? atoi(columnValue[5]) : 0;
  1582. // printf("localversion=%d\n", localversion);
  1583. return 0;
  1584. }
  1585. void DB_deleteIdTag(char idTag[])
  1586. {
  1587. char sql[512];
  1588. char* errMsg = NULL;
  1589. sprintf(sql,"DELETE from ocpp20_auth_local where idToken='%s'; SELECT * from ocpp20_auth_local;", idTag);
  1590. //* Execute SQL statement */
  1591. if( sqlite3_exec(db, sql, deleteIdTagcallback, 0, &errMsg) != SQLITE_OK )
  1592. {
  1593. DEBUG_INFO("SQL error: %s", errMsg);
  1594. }
  1595. }
  1596. int DB_cleanLocalList()
  1597. {
  1598. int result = PASS;
  1599. char * sqlcleanLocalList = "delete from ocpp20_auth_local";
  1600. char *errMsg = 0;
  1601. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1602. {
  1603. DEBUG_INFO("%s\n", errMsg);
  1604. result = FAIL;
  1605. }
  1606. return result;
  1607. }
  1608. int DB_cleanLocalCache()
  1609. {
  1610. int result = PASS;
  1611. char * sqlcleanLocalList = "delete from ocpp20_auth_cache";
  1612. char *errMsg = 0;
  1613. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1614. {
  1615. DEBUG_INFO("%s\n", errMsg);
  1616. result = FAIL;
  1617. }
  1618. return result;
  1619. }
  1620. int BootTypecallback(void *para, int columnCount, char **columnValue, char **columnName)
  1621. {
  1622. sprintf((char*)ShmOCPP20Data->BootNotification.reason,"%s", columnValue[1] ? columnValue[1] : BootReasonEnumTypeStr[BootReasonEnumType_PowerUp]);
  1623. return 0;
  1624. }
  1625. void DB_getBooType()
  1626. {
  1627. char sql[256];
  1628. char* errMsg = NULL;
  1629. sprintf(sql,"select * from ocpp20_boot_type;");
  1630. /* Execute SQL statement */
  1631. if(sqlite3_exec(db, sql, BootTypecallback, 0, &errMsg) != SQLITE_OK )
  1632. {
  1633. DEBUG_INFO("SQL error: %s\n", errMsg);
  1634. }
  1635. }
  1636. int DB_cbUpdateBootType(void *para, int columnCount, char **columnValue, char **columnName)
  1637. {
  1638. for(int i = 0; i<columnCount; i++)
  1639. {
  1640. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1641. }
  1642. return 0;
  1643. }
  1644. int DB_updateBootType(BootReasonEnumType reason)
  1645. {
  1646. int result = PASS;
  1647. char sql[512];
  1648. char* errMsg = NULL;
  1649. sprintf(sql,"insert or replace into ocpp20_boot_type (idx, type) VALUES(1, '%s');", BootReasonEnumTypeStr[reason>BootReasonEnumType_Watchdog?BootReasonEnumType_PowerUp:reason]);
  1650. //* Execute SQL statement */
  1651. if(sqlite3_exec(db, sql, DB_cbUpdateBootType, 0, &errMsg) != SQLITE_OK)
  1652. {
  1653. DEBUG_INFO("SQL error: %s\n", errMsg);
  1654. result = FAIL;
  1655. }
  1656. return result;
  1657. }
  1658. int SecurityEventTypecallback(void *para, int columnCount, char **columnValue, char **columnName)
  1659. {
  1660. sprintf((char*)ShmOCPP20Data->SecurityEventNotification.type,"%s", columnValue[1] ? columnValue[1] : SecurityEventEnumTypeStr[SecurityEventEnumType_ResetOrReboot]);
  1661. return 0;
  1662. }
  1663. void DB_getSecurityEventType()
  1664. {
  1665. char sql[256];
  1666. char* errMsg = NULL;
  1667. sprintf(sql,"select * from ocpp20_securityevent_type;");
  1668. /* Execute SQL statement */
  1669. if(sqlite3_exec(db, sql, SecurityEventTypecallback, 0, &errMsg) != SQLITE_OK )
  1670. {
  1671. DEBUG_INFO("SQL error: %s\n", errMsg);
  1672. }
  1673. }
  1674. int DB_cbUpdateSecurityEventType(void *para, int columnCount, char **columnValue, char **columnName)
  1675. {
  1676. for(int i = 0; i<columnCount; i++)
  1677. {
  1678. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1679. }
  1680. return 0;
  1681. }
  1682. int DB_updateSecurityEventType(SecurityEventEnumType reason)
  1683. {
  1684. int result = PASS;
  1685. char sql[512];
  1686. char* errMsg = NULL;
  1687. sprintf(sql,"insert or replace into ocpp20_securityevent_type (idx, type) VALUES(1, '%s');", SecurityEventEnumTypeStr[reason]);
  1688. //* Execute SQL statement */
  1689. if(sqlite3_exec(db, sql, DB_cbUpdateSecurityEventType, 0, &errMsg) != SQLITE_OK)
  1690. {
  1691. DEBUG_INFO("SQL error: %s\n", errMsg);
  1692. result = FAIL;
  1693. }
  1694. return result;
  1695. }
  1696. int DB_variableClear()
  1697. {
  1698. int result = PASS;
  1699. char * sqlclearVariable = "delete from ocpp20_variable";
  1700. char *errMsg = 0;
  1701. if (sqlite3_exec(db, sqlclearVariable, 0, 0, &errMsg) != SQLITE_OK)
  1702. {
  1703. DEBUG_INFO("%s\n", errMsg);
  1704. result = FAIL;
  1705. }
  1706. return result;
  1707. }
  1708. int DB_cbVariableSaveToDb(void *para, int columnCount, char **columnValue, char **columnName)
  1709. {
  1710. for(int i = 0; i<columnCount; i++)
  1711. {
  1712. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1713. }
  1714. return 0;
  1715. }
  1716. int DB_variableSaveToDb(struct ReportDataType *variable)
  1717. {
  1718. int result = FAIL;
  1719. char sql[4096];
  1720. char* errMsg = NULL;
  1721. sprintf(sql,"insert or replace into ocpp20_variable (componentName, componentInstance, variableName, variableInstance, variableCharacteristicsDataType, variableCharacteristicsUnit, variableCharacteristicsMaxLimit, variableAttributesType, variableAttributesTypeMutability, variableAttributesTypeValue, variableCharacteristicsMinLimit) VALUES('%s', '%s', '%s', '%s', '%s', '%s', %f, '%s', '%s', '%s', '%f'); SELECT * from ocpp20_variable;",
  1722. variable->component.name,
  1723. variable->component.instance,
  1724. variable->variable.name,
  1725. variable->variable.instance,
  1726. variable->variableCharacteristics.dataType,
  1727. variable->variableCharacteristics.unit,
  1728. variable->variableCharacteristics.maxLimit,
  1729. variable->variableAttribute[0].type,
  1730. variable->variableAttribute[0].mutability,
  1731. variable->variableAttribute[0].value,
  1732. variable->variableCharacteristics.minLimit);
  1733. //* Execute SQL statement */
  1734. if(sqlite3_exec(db, sql, DB_cbVariableSaveToDb, 0, &errMsg) != SQLITE_OK)
  1735. {
  1736. DEBUG_INFO("SQL error: %s\n", errMsg);
  1737. result = FAIL;
  1738. }
  1739. return result;
  1740. }
  1741. int DB_cbVariableIsCreate(void *para, int columnCount, char **columnValue, char **columnName)
  1742. {
  1743. memset(&ShmOCPP20Data->ControllerComponentVariable[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable));
  1744. if(atoi(columnValue[0]) == 0)
  1745. {
  1746. DB_updateBootType(BootReasonEnumType_PowerUp);
  1747. // Create variable table content
  1748. /* AlignedDataCtrlr Required item */
  1749. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].component.name, "AlignedDataCtrlr");
  1750. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variable.name, "Enabled");
  1751. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1752. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1753. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1754. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].value, "false");
  1755. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled]);
  1756. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].component.name, "AlignedDataCtrlr");
  1757. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variable.name, "Available");
  1758. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1759. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1760. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1761. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].value, "true");
  1762. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available]);
  1763. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].component.name, "AlignedDataCtrlr");
  1764. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variable.name, "Measurands");
  1765. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1766. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableCharacteristics.maxLimit = 20;
  1767. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1768. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1769. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1770. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, "Current.Import,"
  1771. "Energy.Active.Import.Register,"
  1772. "Energy.Active.Import.Interval,"
  1773. "Power.Active.Import,"
  1774. "Voltage,"
  1775. "SoC,"
  1776. "Current.Offered,"
  1777. "Power.Offered");
  1778. else
  1779. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, "Current.Import,"
  1780. "Energy.Active.Import.Register,"
  1781. "Energy.Active.Import.Interval,"
  1782. "Power.Active.Import,"
  1783. "Voltage,"
  1784. "Current.Offered");
  1785. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands]);
  1786. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].component.name, "AlignedDataCtrlr");
  1787. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variable.name, "Interval");
  1788. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.unit, "Seconds");
  1789. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1790. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.minLimit = 5;
  1791. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1792. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1793. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value, "0");
  1794. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval]);
  1795. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].component.name, "AlignedDataCtrlr");
  1796. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variable.name, "SendDuringIdle");
  1797. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1798. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1799. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1800. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].value, "true");
  1801. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle]);
  1802. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].component.name, "AlignedDataCtrlr");
  1803. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variable.name, "SignReadings");
  1804. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1805. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1806. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1807. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].value, "false");
  1808. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings]);
  1809. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].component.name, "AlignedDataCtrlr");
  1810. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  1811. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1812. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableCharacteristics.maxLimit = 10;
  1813. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1814. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1815. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1816. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  1817. "Energy.Active.Import.Register,"
  1818. "Energy.Active.Import.Interval,"
  1819. "Power.Active.Import,"
  1820. "Voltage,"
  1821. "SoC");
  1822. else
  1823. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  1824. "Energy.Active.Import.Register,"
  1825. "Energy.Active.Import.Interval,"
  1826. "Power.Active.Import,"
  1827. "Voltage");
  1828. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands]);
  1829. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].component.name, "AlignedDataCtrlr");
  1830. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  1831. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableCharacteristics.unit, "Seconds");
  1832. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1833. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1834. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1835. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].value, "0");
  1836. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval]);
  1837. /* AuthCtrlrVariable Required item */
  1838. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].component.name, "AuthCtrlr");
  1839. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variable.name, "Enabled");
  1840. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1841. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1842. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1843. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].value, ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE?"true":"false");
  1844. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled]);
  1845. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].component.name, "AuthCtrlr");
  1846. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variable.name, "AdditionalInfoItemsPerMessage");
  1847. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1848. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1849. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1850. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].value, "0");
  1851. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage]);
  1852. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].component.name, "AuthCtrlr");
  1853. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variable.name, "OfflineTxForUnknownIdEnabled");
  1854. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1855. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1856. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1857. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].value, "false");
  1858. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled]);
  1859. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].component.name, "AuthCtrlr");
  1860. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variable.name, "AuthorizeRemoteStart");
  1861. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1862. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1863. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1864. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].value, "false");
  1865. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart]);
  1866. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].component.name, "AuthCtrlr");
  1867. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variable.name, "LocalAuthorizeOffline");
  1868. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1869. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1870. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1871. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "true");
  1872. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline]);
  1873. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].component.name, "AuthCtrlr");
  1874. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variable.name, "LocalPreAuthorize");
  1875. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1876. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1877. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1878. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].value, "true");
  1879. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize]);
  1880. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].component.name, "AuthCtrlr");
  1881. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variable.name, "MasterPassGroupId");
  1882. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1883. ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableCharacteristics.maxLimit = 36;
  1884. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1885. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1886. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].value, " ");
  1887. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId]);
  1888. /* AuthCacheCtrlr Variable Required item*/
  1889. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].component.name, "AuthCacheCtrlr");
  1890. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variable.name, "Enabled");
  1891. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1892. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1893. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1894. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].value, "false");
  1895. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled]);
  1896. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].component.name, "AuthCacheCtrlr");
  1897. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variable.name, "Available");
  1898. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1899. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1900. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1901. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].value, "true");
  1902. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available]);
  1903. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].component.name, "AuthCacheCtrlr");
  1904. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variable.name, "LifeTime");
  1905. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableCharacteristics.unit, "Seconds");
  1906. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1907. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1908. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1909. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].value, "true");
  1910. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime]);
  1911. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].component.name, "AuthCacheCtrlr");
  1912. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variable.name, "Storage");
  1913. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1914. ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableCharacteristics.maxLimit = (1024*10);
  1915. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1916. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1917. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].value, "true");
  1918. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage]);
  1919. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].component.name, "AuthCacheCtrlr");
  1920. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variable.name, "Policy");
  1921. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1922. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1923. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1924. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].value, "LRU,LFU");
  1925. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy]);
  1926. /* ClockCtrlr Variable Required item */
  1927. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].component.name, "ClockCtrlr");
  1928. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variable.name, "DateTime");
  1929. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_dateTime]);
  1930. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1931. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1932. getNowDatetime(ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].value);
  1933. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime]);
  1934. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].component.name, "ClockCtrlr");
  1935. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variable.name, "NtpSource");
  1936. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1937. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1938. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1939. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].value, "DHCP, manual");
  1940. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource]);
  1941. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].component.name, "ClockCtrlr");
  1942. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.name, "NtpServerUri");
  1943. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.instance, "1");
  1944. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1945. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1946. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1947. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].value, " ");
  1948. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri]);
  1949. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].component.name, "ClockCtrlr");
  1950. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variable.name, "TimeOffset");
  1951. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1952. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1953. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1954. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].value, "+00:00");
  1955. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset]);
  1956. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].component.name, "ClockCtrlr");
  1957. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variable.name, "NextTimeOffsetTransitionDateTime");
  1958. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_dateTime]);
  1959. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1960. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1961. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].value, " ");
  1962. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime]);
  1963. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].component.name, "ClockCtrlr");
  1964. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.name, "TimeOffset");
  1965. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.instance, "NextTransition");
  1966. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1967. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1968. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1969. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].value, "+00:00");
  1970. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset]);
  1971. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].component.name, "ClockCtrlr");
  1972. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variable.name, "TimeSource");
  1973. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_SequenceList]);
  1974. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1975. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1976. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].value, "Heartbeat,RealTimeClock");
  1977. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource]);
  1978. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].component.name, "ClockCtrlr");
  1979. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variable.name, "TimeZone");
  1980. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1981. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1982. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1983. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].value, "UTC");
  1984. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone]);
  1985. /* ChargingStation Required item */
  1986. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].component.name, "ChargingStation");
  1987. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variable.name, "Available");
  1988. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1989. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1990. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1991. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].value, "false");
  1992. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available]);
  1993. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].component.name, "ChargingStation");
  1994. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variable.name, "AvailabilityState");
  1995. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1996. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1997. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1998. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].value, "Available,Occupied,Reserved,Unavailable,Faulted");
  1999. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState]);
  2000. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].component.name, "ChargingStation");
  2001. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variable.name, "SupplyPhases");
  2002. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2003. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2004. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2005. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].value, "3");
  2006. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases]);
  2007. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].component.name, "ChargingStation");
  2008. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variable.name, "SystemUptimeSec");
  2009. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2010. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2011. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2012. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableAttribute[0].value, "0");
  2013. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec]);
  2014. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].component.name, "ChargingStation");
  2015. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variable.name, "FreeVend");
  2016. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2017. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2018. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2019. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableAttribute[0].value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"true":"false"));
  2020. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend]);
  2021. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].component.name, "ChargingStation");
  2022. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variable.name, "FreeVendIdtag");
  2023. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2024. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2025. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2026. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableAttribute[0].value, "FreeVendIdtag");
  2027. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag]);
  2028. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].component.name, "ChargingStation");
  2029. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variable.name, "OffLineMaxChargingPower");
  2030. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2031. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2032. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2033. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variableAttribute[0].value, "0");
  2034. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower]);
  2035. /* Connector Required item */
  2036. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].component.name, "Connector");
  2037. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variable.name, "Available");
  2038. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2039. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2040. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2041. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].value, "false");
  2042. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_Available]);
  2043. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].component.name, "Connector");
  2044. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variable.name, "ConnectorType");
  2045. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2046. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2047. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2048. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].value, " ");
  2049. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType]);
  2050. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].component.name, "Connector");
  2051. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variable.name, "SupplyPhases");
  2052. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2053. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2054. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2055. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].value, "3");
  2056. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases]);
  2057. /* CustomizationCtrlr Required item */
  2058. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].component.name, "CustomizationCtrlr");
  2059. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variable.name, "CustomImplementationEnabled");
  2060. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2061. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2062. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2063. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].value, "false");
  2064. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled]);
  2065. /* DeviceDataCtrlr Required item */
  2066. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2067. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.instance, "GetReport");
  2068. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2069. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2070. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2071. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2072. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].value, "10");
  2073. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage]);
  2074. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2075. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.instance, "GetVariables");
  2076. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2077. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2078. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2079. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2080. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].value, "10");
  2081. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage]);
  2082. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2083. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.instance, "GetReport");
  2084. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.name, "BytesPerMessage");
  2085. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2086. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2087. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2088. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].value, "2048");
  2089. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage]);
  2090. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2091. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.instance, "GetVariables");
  2092. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2093. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2094. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2095. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2096. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].value, "2048");
  2097. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage]);
  2098. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].component.name, "DeviceDataCtrlr");
  2099. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variable.name, "ConfigurationValueSize");
  2100. ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableCharacteristics.maxLimit = 1000;
  2101. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2102. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2103. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2104. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].value, "10");
  2105. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize]);
  2106. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].component.name, "DeviceDataCtrlr");
  2107. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variable.name, "ReportingValueSize");
  2108. ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableCharacteristics.maxLimit = 2500;
  2109. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2110. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2111. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2112. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].value, "10");
  2113. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize]);
  2114. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2115. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.instance, "SetVariables");
  2116. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2117. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2118. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2119. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2120. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].value, "10");
  2121. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage]);
  2122. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2123. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.instance, "SetVariables");
  2124. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2125. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2126. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2127. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2128. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].value, "2048");
  2129. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage]);
  2130. /* DisplayMessageCtrlr Required item */
  2131. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].component.name, "DisplayMessageCtrlr");
  2132. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variable.name, "Enabled");
  2133. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2134. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2135. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2136. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].value, "false");
  2137. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled]);
  2138. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].component.name, "DisplayMessageCtrlr");
  2139. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variable.name, "Available");
  2140. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2141. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2142. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2143. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].value, "false");
  2144. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available]);
  2145. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].component.name, "DisplayMessageCtrlr");
  2146. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variable.name, "DisplayMessages");
  2147. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2148. ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableCharacteristics.maxLimit = 1;
  2149. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2150. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2151. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].value, "%s", "1");
  2152. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages]);
  2153. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].component.name, "DisplayMessageCtrlr");
  2154. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variable.name, "SupportedFormats");
  2155. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2156. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2157. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2158. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].value, " ");
  2159. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats]);
  2160. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].component.name, "DisplayMessageCtrlr");
  2161. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variable.name, "SupportedPriorities");
  2162. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2163. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2164. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2165. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].value, " ");
  2166. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities]);
  2167. /* EVSE Required item */
  2168. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].component.name, "EVSE");
  2169. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variable.name, "Available");
  2170. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2171. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2172. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2173. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].value, "false");
  2174. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_Available]);
  2175. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].component.name, "EVSE");
  2176. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variable.name, "AvailabilityState");
  2177. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2178. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2179. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2180. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].value, "Available,Occupied,Reserved,Unavailable,Faulted");
  2181. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState]);
  2182. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].component.name, "EVSE");
  2183. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variable.name, "SupplyPhases");
  2184. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2185. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2186. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2187. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].value, "3");
  2188. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases]);
  2189. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].component.name, "EVSE");
  2190. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variable.name, "Power");
  2191. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_decimal]);
  2192. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2193. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2194. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].value, "7700");
  2195. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_Power]);
  2196. /* LocalAuthListCtrlr Required item */
  2197. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].component.name, "LocalAuthListCtrlr");
  2198. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variable.name, "Enabled");
  2199. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2200. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2201. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2202. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "true");
  2203. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled]);
  2204. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].component.name, "LocalAuthListCtrlr");
  2205. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variable.name, "Entries");
  2206. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2207. ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableCharacteristics.maxLimit = 5000;
  2208. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2209. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2210. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].value, "5000");
  2211. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries]);
  2212. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].component.name, "LocalAuthListCtrlr");
  2213. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variable.name, "Available");
  2214. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2215. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2216. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2217. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].value, "true");
  2218. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available]);
  2219. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].component.name, "LocalAuthListCtrlr");
  2220. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2221. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.instance, "SendLocalList");
  2222. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2223. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2224. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2225. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].value, "500");
  2226. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage]);
  2227. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].component.name, "LocalAuthListCtrlr");
  2228. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.name, "BytesPerMessage");
  2229. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.instance, "SendLocalList");
  2230. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2231. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2232. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2233. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].value, "20480");
  2234. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage]);
  2235. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].component.name, "LocalAuthListCtrlr");
  2236. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variable.name, "Storage");
  2237. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2238. ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableCharacteristics.maxLimit = (1024*10);
  2239. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2240. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2241. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].value, "100000");
  2242. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage]);
  2243. /* MonitoringCtrlr Required item */
  2244. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].component.name, "MonitoringCtrlr");
  2245. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variable.instance, "Enabled");
  2246. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2247. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2248. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2249. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].value, "false");
  2250. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled]);
  2251. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].component.name, "MonitoringCtrlr");
  2252. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variable.instance, "Available");
  2253. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2254. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2255. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2256. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].value, "false");
  2257. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available]);
  2258. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2259. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.instance, "ClearVariableMonitoring");
  2260. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2261. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2262. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2263. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2264. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].value, "1");
  2265. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage]);
  2266. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2267. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.instance, "SetVariableMonitoring");
  2268. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2269. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2270. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2271. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2272. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].value, "1");
  2273. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage]);
  2274. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2275. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.instance, "ClearVariableMonitoring");
  2276. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2277. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2278. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2279. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2280. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].value, "2048");
  2281. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage]);
  2282. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2283. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.instance, "SetVariableMonitoring");
  2284. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2285. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2286. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2287. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2288. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].value, "2048");
  2289. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage]);
  2290. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].component.name, "MonitoringCtrlr");
  2291. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variable.name, "OfflineQueuingSeverity");
  2292. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2293. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2294. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2295. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].value, "2048");
  2296. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity]);
  2297. /* OCPPCommCtrlr Required item */
  2298. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].component.name, "OCPPCommCtrlr");
  2299. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variable.name, "ActiveNetworkProfile");
  2300. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2301. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2302. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2303. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].value, "1");
  2304. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile]);
  2305. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].component.name, "OCPPCommCtrlr");
  2306. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.instance, "Default");
  2307. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.name, "MessageTimeout");
  2308. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableCharacteristics.unit, "Seconds");
  2309. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2310. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2311. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2312. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].value, "30");
  2313. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout]);
  2314. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].component.name, "OCPPCommCtrlr");
  2315. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variable.name, "FileTransferProtocols");
  2316. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2317. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2318. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2319. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].value, "FTP,FTPS,HTTP,HTTPS");
  2320. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols]);
  2321. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].component.name, "OCPPCommCtrlr");
  2322. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variable.name, "HeartbeatInterval");
  2323. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.unit, "Seconds");
  2324. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.minLimit = 10;
  2325. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2326. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2327. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2328. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value, "30");
  2329. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval]);
  2330. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].component.name, "OCPPCommCtrlr");
  2331. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variable.name, "NetworkConfigurationPriority");
  2332. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_SequenceList]);
  2333. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2334. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2335. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value, "[0]");
  2336. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority]);
  2337. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].component.name, "OCPPCommCtrlr");
  2338. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variable.name, "NetworkProfileConnectionAttempts");
  2339. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2340. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2341. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2342. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].value, "3");
  2343. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts]);
  2344. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].component.name, "OCPPCommCtrlr");
  2345. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variable.name, "OfflineThreshold");
  2346. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableCharacteristics.unit, "Seconds");
  2347. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2348. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2349. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2350. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].value, "30");
  2351. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold]);
  2352. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].component.name, "OCPPCommCtrlr");
  2353. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variable.name, "QueueAllMessages");
  2354. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2355. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2356. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2357. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].value, "false");
  2358. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages]);
  2359. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].component.name, "OCPPCommCtrlr");
  2360. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.instance, "TransactionEvent");
  2361. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.name, "MessageAttempts");
  2362. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableCharacteristics.unit, "Seconds");
  2363. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2364. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2365. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2366. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].value, "3");
  2367. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts]);
  2368. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].component.name, "OCPPCommCtrlr");
  2369. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.instance, "TransactionEvent");
  2370. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.name, "MessageAttemptInterval");
  2371. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableCharacteristics.unit, "Seconds");
  2372. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2373. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2374. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2375. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].value, "30");
  2376. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval]);
  2377. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].component.name, "OCPPCommCtrlr");
  2378. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variable.name, "UnlockOnEVSideDisconnect");
  2379. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2380. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2381. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2382. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].value, "true");
  2383. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect]);
  2384. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].component.name, "OCPPCommCtrlr");
  2385. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variable.name, "WebSocketPingInterval");
  2386. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.unit, "Seconds");
  2387. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.minLimit = 10;
  2388. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2389. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2390. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2391. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].value, "30");
  2392. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval]);
  2393. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].component.name, "OCPPCommCtrlr");
  2394. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variable.name, "ResetRetries");
  2395. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2396. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2397. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2398. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].value, "3");
  2399. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries]);
  2400. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].component.name, "OCPPCommCtrlr");
  2401. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variable.name, "PublicKeyWithSignedMeterValue");
  2402. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2403. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2404. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2405. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].value, "Never,OncePerTransaction,EveryMeterValue");
  2406. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue]);
  2407. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].component.name, "OCPPCommCtrlr");
  2408. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variable.name, "VariableVersion");
  2409. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2410. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2411. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2412. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].value, "%d", variableVersion);
  2413. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion]);
  2414. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].component.name, "OCPPCommCtrlr");
  2415. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variable.name, "StatusNotificationPeriodically");
  2416. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2417. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2418. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2419. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].value, "false");
  2420. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically]);
  2421. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].component.name, "OCPPCommCtrlr");
  2422. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variable.name, "StatusNotificationInterval");
  2423. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableCharacteristics.unit, "Seconds");
  2424. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableCharacteristics.minLimit = 10;
  2425. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2426. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2427. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2428. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].value, "120");
  2429. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval]);
  2430. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].component.name, "OCPPCommCtrlr");
  2431. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variable.name, "CharingProfileRefreshInterval");
  2432. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableCharacteristics.unit, "Seconds");
  2433. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableCharacteristics.minLimit = 5;
  2434. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2435. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2436. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2437. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variableAttribute[0].value, "30");
  2438. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval]);
  2439. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_RfidEndianType].component.name, "OCPPCommCtrlr");
  2440. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_RfidEndianType].variable.name, "RfidEndianType");
  2441. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_RfidEndianType].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2442. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_RfidEndianType].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2443. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_RfidEndianType].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2444. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_RfidEndianType].variableAttribute[0].value, ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian==1?"big":"little");
  2445. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_RfidEndianType]);
  2446. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].component.name, "OCPPCommCtrlr");
  2447. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].variable.name, "AuthorizeTimeout");
  2448. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].variableCharacteristics.unit, "Seconds");
  2449. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].variableCharacteristics.minLimit = 10;
  2450. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].variableCharacteristics.maxLimit = 300;
  2451. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2452. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2453. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2454. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].variableAttribute[0].value, "15");
  2455. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout]);
  2456. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_EnableAcCcs].component.name, "OCPPCommCtrlr");
  2457. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_EnableAcCcs].variable.name, "EnableAcCcs");
  2458. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_EnableAcCcs].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2459. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_EnableAcCcs].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2460. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_EnableAcCcs].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2461. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_EnableAcCcs].variableAttribute[0].value, "false");
  2462. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_EnableAcCcs]);
  2463. /* ReservationCtrlr Required item */
  2464. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].component.name, "ReservationCtrlr");
  2465. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variable.name, "Enabled");
  2466. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2467. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2468. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2469. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].value, "true");
  2470. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled]);
  2471. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].component.name, "ReservationCtrlr");
  2472. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variable.name, "Available");
  2473. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2474. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2475. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2476. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].value, "true");
  2477. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available]);
  2478. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].component.name, "ReservationCtrlr");
  2479. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variable.name, "NonEvseSpecific");
  2480. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2481. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2482. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2483. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].value, "false");
  2484. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific]);
  2485. /* SampledDataCtrlr Required item */
  2486. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].component.name, "SampledDataCtrlr");
  2487. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variable.name, "Enabled");
  2488. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2489. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2490. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2491. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].value, "true");
  2492. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled]);
  2493. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].component.name, "SampledDataCtrlr");
  2494. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variable.name, "Available");
  2495. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2496. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2497. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2498. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].value, "true");
  2499. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available]);
  2500. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].component.name, "SampledDataCtrlr");
  2501. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variable.name, "SignReadings");
  2502. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2503. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2504. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2505. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].value, "false");
  2506. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings]);
  2507. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].component.name, "SampledDataCtrlr");
  2508. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2509. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2510. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableCharacteristics.maxLimit = 10;
  2511. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2512. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2513. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2514. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  2515. "Energy.Active.Import.Register,"
  2516. "Energy.Active.Import.Interval,"
  2517. "Power.Active.Import,"
  2518. "Voltage,"
  2519. "SoC");
  2520. else
  2521. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  2522. "Energy.Active.Import.Register,"
  2523. "Energy.Active.Import.Interval,"
  2524. "Power.Active.Import,"
  2525. "Voltage");
  2526. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands]);
  2527. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].component.name, "SampledDataCtrlr");
  2528. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2529. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableCharacteristics.unit, "Seconds");
  2530. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2531. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2532. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2533. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].value, "0");
  2534. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval]);
  2535. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].component.name, "SampledDataCtrlr");
  2536. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variable.name, "TxStartedMeasurands");
  2537. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2538. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableCharacteristics.maxLimit = 10;
  2539. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2540. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2541. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].value, " ");
  2542. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands]);
  2543. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].component.name, "SampledDataCtrlr");
  2544. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variable.name, "TxUpdatedMeasurands");
  2545. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2546. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableCharacteristics.maxLimit = 10;
  2547. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2548. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2549. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2550. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, "Current.Import,"
  2551. "Energy.Active.Import.Register,"
  2552. "Energy.Active.Import.Interval,"
  2553. "Power.Active.Import,"
  2554. "Voltage,"
  2555. "SoC,"
  2556. "Current.Offered,"
  2557. "Power.Offered");
  2558. else
  2559. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, "Current.Import,"
  2560. "Energy.Active.Import.Register,"
  2561. "Energy.Active.Import.Interval,"
  2562. "Power.Active.Import,"
  2563. "Voltage,"
  2564. "Current.Offered");
  2565. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands]);
  2566. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].component.name, "SampledDataCtrlr");
  2567. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variable.name, "TxUpdatedInterval");
  2568. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.unit, "Seconds");
  2569. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2570. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.minLimit = 3;
  2571. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2572. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2573. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value, "30");
  2574. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval]);
  2575. /* SecurityCtrlr Required item */
  2576. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].component.name, "SecurityCtrlr");
  2577. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variable.name, "BasicAuthPassword");
  2578. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2579. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableCharacteristics.maxLimit = 40;
  2580. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2581. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_WriteOnly]);
  2582. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].value, "%s", (strlen((char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword)>0?(char*)ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword:"00000000"));
  2583. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword]);
  2584. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].component.name, "SecurityCtrlr");
  2585. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variable.name, "Identity");
  2586. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2587. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableCharacteristics.maxLimit = 48;
  2588. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2589. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2590. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].value, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  2591. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity]);
  2592. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].component.name, "SecurityCtrlr");
  2593. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variable.name, "OrganizationName");
  2594. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2595. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2596. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2597. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].value, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2598. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName]);
  2599. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].component.name, "SecurityCtrlr");
  2600. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variable.name, "CertificateEntries");
  2601. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2602. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableCharacteristics.maxLimit = 1;
  2603. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2604. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2605. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].value, "1");
  2606. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries]);
  2607. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].component.name, "SecurityCtrlr");
  2608. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variable.name, "SecurityProfile");
  2609. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2610. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2611. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2612. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].value, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  2613. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile]);
  2614. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].component.name, "SecurityCtrlr");
  2615. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variable.name, "AdditionalRootCertificateCheck");
  2616. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2617. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2618. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2619. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].value, "false");
  2620. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck]);
  2621. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].component.name, "SecurityCtrlr");
  2622. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variable.name, "MaxCertificateChainSize");
  2623. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2624. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableCharacteristics.maxLimit = 10000;
  2625. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2626. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2627. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].value, "10000");
  2628. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize]);
  2629. /* SmartChargingCtrlr Required item */
  2630. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].component.name, "SmartChargingCtrlr");
  2631. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variable.name, "Enabled");
  2632. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2633. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2634. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2635. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].value, "true");
  2636. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled]);
  2637. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].component.name, "SmartChargingCtrlr");
  2638. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variable.name, "Available");
  2639. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2640. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2641. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2642. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].value, "true");
  2643. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available]);
  2644. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].component.name, "SmartChargingCtrlr");
  2645. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variable.name, "ACPhaseSwitchingSupported");
  2646. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2647. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2648. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2649. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].value, "false");
  2650. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported]);
  2651. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].component.name, "SmartChargingCtrlr");
  2652. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variable.name, "ProfileStackLevel");
  2653. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2654. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2655. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2656. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value, "3");
  2657. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel]);
  2658. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].component.name, "SmartChargingCtrlr");
  2659. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variable.name, "RateUnit");
  2660. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2661. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2662. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2663. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].value, "A,W");
  2664. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit]);
  2665. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].component.name, "SmartChargingCtrlr");
  2666. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variable.name, "PeriodsPerSchedule");
  2667. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2668. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2669. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2670. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].value, "10");
  2671. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule]);
  2672. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].component.name, "SmartChargingCtrlr");
  2673. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variable.name, "ExternalControlSignalsEnabled");
  2674. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2675. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2676. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2677. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].value, "false");
  2678. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled]);
  2679. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].component.name, "SmartChargingCtrlr");
  2680. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variable.name, "NotifyChargingLimitWithSchedules");
  2681. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2682. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2683. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2684. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].value, "false");
  2685. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules]);
  2686. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].component.name, "SmartChargingCtrlr");
  2687. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variable.name, "Phases3to1");
  2688. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2689. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2690. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2691. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].value, "false");
  2692. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1]);
  2693. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].component.name, "SmartChargingCtrlr");
  2694. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variable.name, "Entries");
  2695. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2696. ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableCharacteristics.maxLimit = 10;
  2697. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2698. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2699. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value, "10");
  2700. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries]);
  2701. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].component.name, "SmartChargingCtrlr");
  2702. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variable.name, "LimitChangeSignificance");
  2703. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_decimal]);
  2704. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2705. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2706. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].value, "1");
  2707. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance]);
  2708. /* TariffCostCtrlr Required item */
  2709. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].component.name, "TariffCostCtrlr");
  2710. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.instance, "Tariff");
  2711. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.name, "Enabled");
  2712. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2713. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2714. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2715. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].value, "false");
  2716. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled]);
  2717. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].component.name, "TariffCostCtrlr");
  2718. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.instance, "Tariff");
  2719. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.name, "Available");
  2720. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2721. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2722. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2723. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].value, "false");
  2724. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_Available]);
  2725. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].component.name, "TariffCostCtrlr");
  2726. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variable.name, "TariffFallbackMessage");
  2727. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2728. ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableCharacteristics.maxLimit = 255;
  2729. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2730. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2731. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].value, " ");
  2732. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage]);
  2733. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].component.name, "TariffCostCtrlr");
  2734. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.instance, "Cost");
  2735. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.name, "Enabled");
  2736. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2737. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2738. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2739. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].value, "false");
  2740. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled]);
  2741. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].component.name, "TariffCostCtrlr");
  2742. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.instance, "Cost");
  2743. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.name, "Available");
  2744. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2745. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2746. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2747. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].value, "false");
  2748. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Available]);
  2749. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].component.name, "TariffCostCtrlr");
  2750. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variable.name, "TotalCostFallbackMessage");
  2751. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2752. ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableCharacteristics.maxLimit = 255;
  2753. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2754. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2755. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].value, " ");
  2756. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage]);
  2757. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].component.name, "TariffCostCtrlr");
  2758. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variable.name, "Currency");
  2759. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2760. ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableCharacteristics.maxLimit = 3;
  2761. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2762. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2763. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].value, "NTD");
  2764. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Currency]);
  2765. /* TxCtrlr Required item */
  2766. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2767. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variable.name, "ChargingBeforeAcceptedEnabled");
  2768. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2769. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2770. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2771. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].value, "false");
  2772. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled]);
  2773. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].component.name, "TxCtrlr");
  2774. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variable.name, "EVConnectionTimeOut");
  2775. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableCharacteristics.unit, "Seconds");
  2776. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2777. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2778. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2779. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value, "180");
  2780. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut]);
  2781. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].component.name, "TxCtrlr");
  2782. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variable.name, "StopTxOnEVSideDisconnect");
  2783. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2784. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2785. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2786. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].value, "true");
  2787. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect]);
  2788. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2789. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variable.name, "TxBeforeAcceptedEnabled");
  2790. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2791. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2792. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2793. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].value, "false");
  2794. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled]);
  2795. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].component.name, "TxCtrlr");
  2796. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variable.name, "TxStartPoint");
  2797. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2798. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2799. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2800. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].value, "PowerPathClosed");
  2801. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint]);
  2802. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].component.name, "TxCtrlr");
  2803. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variable.name, "TxStopPoint");
  2804. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2805. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2806. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2807. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].value, "PowerPathClosed");
  2808. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint]);
  2809. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].component.name, "TxCtrlr");
  2810. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variable.name, "MaxEnergyOnInvalidId");
  2811. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2812. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableCharacteristics.unit, "Wh");
  2813. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2814. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2815. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].value, "0");
  2816. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId]);
  2817. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].component.name, "TxCtrlr");
  2818. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variable.name, "StopTxOnInvalidId");
  2819. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2820. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  2821. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2822. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].value, "false");
  2823. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId]);
  2824. }
  2825. else
  2826. {
  2827. // Variable name init
  2828. /* AlignedDataCtrlr Required item */
  2829. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].component.name, "AlignedDataCtrlr");
  2830. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variable.name, "Enabled");
  2831. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].component.name, "AlignedDataCtrlr");
  2832. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variable.name, "Available");
  2833. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].component.name, "AlignedDataCtrlr");
  2834. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variable.name, "Measurands");
  2835. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].component.name, "AlignedDataCtrlr");
  2836. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variable.name, "Interval");
  2837. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].component.name, "AlignedDataCtrlr");
  2838. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variable.name, "SendDuringIdle");
  2839. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].component.name, "AlignedDataCtrlr");
  2840. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variable.name, "SignReadings");
  2841. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].component.name, "AlignedDataCtrlr");
  2842. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2843. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].component.name, "AlignedDataCtrlr");
  2844. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2845. /* AuthCtrlrVariable Required item */
  2846. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].component.name, "AuthCtrlr");
  2847. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variable.name, "Enabled");
  2848. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].component.name, "AlignedDataCtrlr");
  2849. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variable.name, "AdditionalInfoItemsPerMessage");
  2850. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].component.name, "AuthCtrlr");
  2851. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variable.name, "OfflineTxForUnknownIdEnabled");
  2852. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].component.name, "AuthCtrlr");
  2853. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variable.name, "AuthorizeRemoteStart");
  2854. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].component.name, "AuthCtrlr");
  2855. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variable.name, "LocalAuthorizeOffline");
  2856. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].component.name, "AuthCtrlr");
  2857. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variable.name, "LocalPreAuthorize");
  2858. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].component.name, "AuthCtrlr");
  2859. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variable.name, "MasterPassGroupId");
  2860. /* AuthCacheCtrlr Variable Required item */
  2861. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].component.name, "AuthCacheCtrlr");
  2862. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variable.name, "Enabled");
  2863. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].component.name, "AuthCacheCtrlr");
  2864. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variable.name, "Available");
  2865. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].component.name, "AuthCacheCtrlr");
  2866. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variable.name, "LifeTime");
  2867. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].component.name, "AuthCacheCtrlr");
  2868. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variable.name, "Storage");
  2869. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].component.name, "AuthCacheCtrlr");
  2870. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variable.name, "Policy");
  2871. /* ClockCtrlr Variable Required item */
  2872. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].component.name, "ClockCtrlr");
  2873. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variable.name, "DateTime");
  2874. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].component.name, "ClockCtrlr");
  2875. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variable.name, "NtpSource");
  2876. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].component.name, "ClockCtrlr");
  2877. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.name, "NtpServerUri");
  2878. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.instance, "1");
  2879. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].component.name, "ClockCtrlr");
  2880. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variable.name, "TimeOffset");
  2881. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].component.name, "ClockCtrlr");
  2882. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variable.name, "NextTimeOffsetTransitionDateTime");
  2883. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].component.name, "ClockCtrlr");
  2884. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.name, "TimeOffset");
  2885. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.instance, "NextTransition");
  2886. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].component.name, "ClockCtrlr");
  2887. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variable.name, "TimeSource");
  2888. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].component.name, "ClockCtrlr");
  2889. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variable.name, "TimeZone");
  2890. /* ChargingStation Required item */
  2891. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].component.name, "ChargingStation");
  2892. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variable.name, "Available");
  2893. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].component.name, "ChargingStation");
  2894. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variable.name, "AvailabilityState");
  2895. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].component.name, "ChargingStation");
  2896. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variable.name, "SupplyPhases");
  2897. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].component.name, "ChargingStation");
  2898. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variable.name, "SystemUptimeSec");
  2899. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].component.name, "ChargingStation");
  2900. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variable.name, "FreeVend");
  2901. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].component.name, "ChargingStation");
  2902. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variable.name, "FreeVendIdtag");
  2903. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].component.name, "ChargingStation");
  2904. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_OffLineMaxChargingPower].variable.name, "OffLineMaxChargingPower");
  2905. /* Connector Required item */
  2906. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].component.name, "Connector");
  2907. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variable.name, "Available");
  2908. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].component.name, "Connector");
  2909. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variable.name, "ConnectorType");
  2910. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].component.name, "Connector");
  2911. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variable.name, "SupplyPhases");
  2912. /* CustomizationCtrlr Required item */
  2913. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].component.name, "CustomizationCtrlr");
  2914. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variable.name, "CustomImplementationEnabled");
  2915. /* DeviceDataCtrlr Required item */
  2916. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2917. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.instance, "GetReport");
  2918. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2919. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2920. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.instance, "GetVariables");
  2921. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2922. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2923. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.instance, "GetReport");
  2924. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.name, "BytesPerMessage");
  2925. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2926. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.instance, "GetVariables");
  2927. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2928. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].component.name, "DeviceDataCtrlr");
  2929. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variable.name, "ConfigurationValueSize");
  2930. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].component.name, "DeviceDataCtrlr");
  2931. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variable.name, "ReportingValueSize");
  2932. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2933. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.instance, "SetVariables");
  2934. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2935. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2936. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.instance, "SetVariables");
  2937. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2938. /* DisplayMessageCtrlr Required item */
  2939. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].component.name, "DisplayMessageCtrlr");
  2940. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variable.name, "Enabled");
  2941. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].component.name, "DisplayMessageCtrlr");
  2942. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variable.name, "Available");
  2943. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].component.name, "DisplayMessageCtrlr");
  2944. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variable.name, "DisplayMessages");
  2945. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].component.name, "DisplayMessageCtrlr");
  2946. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variable.name, "SupportedFormats");
  2947. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].component.name, "DisplayMessageCtrlr");
  2948. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variable.name, "SupportedPriorities");
  2949. /* EVSE Required item */
  2950. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].component.name, "EVSE");
  2951. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variable.name, "Available");
  2952. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].component.name, "EVSE");
  2953. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variable.name, "AvailabilityState");
  2954. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].component.name, "EVSE");
  2955. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variable.name, "SupplyPhases");
  2956. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].component.name, "EVSE");
  2957. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variable.name, "Power");
  2958. /* LocalAuthListCtrlr Required item */
  2959. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].component.name, "LocalAuthListCtrlr");
  2960. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variable.name, "Enabled");
  2961. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].component.name, "LocalAuthListCtrlr");
  2962. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variable.name, "Entries");
  2963. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].component.name, "LocalAuthListCtrlr");
  2964. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variable.name, "Available");
  2965. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].component.name, "LocalAuthListCtrlr");
  2966. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2967. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.instance, "SendLocalList");
  2968. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].component.name, "LocalAuthListCtrlr");
  2969. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.name, "BytesPerMessage");
  2970. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.instance, "SendLocalList");
  2971. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].component.name, "LocalAuthListCtrlr");
  2972. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variable.name, "Storage");
  2973. /* MonitoringCtrlr Required item */
  2974. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].component.name, "MonitoringCtrlr");
  2975. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variable.instance, "Enabled");
  2976. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].component.name, "MonitoringCtrlr");
  2977. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variable.instance, "Available");
  2978. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2979. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.instance, "ClearVariableMonitoring");
  2980. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2981. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2982. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.instance, "SetVariableMonitoring");
  2983. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2984. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2985. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.instance, "ClearVariableMonitoring");
  2986. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2987. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2988. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.instance, "SetVariableMonitoring");
  2989. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2990. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].component.name, "MonitoringCtrlr");
  2991. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variable.name, "OfflineQueuingSeverity");
  2992. /* OCPPCommCtrlr Required item */
  2993. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].component.name, "OCPPCommCtrlr");
  2994. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variable.name, "ActiveNetworkProfile");
  2995. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].component.name, "OCPPCommCtrlr");
  2996. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.instance, "Default");
  2997. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.name, "MessageTimeout");
  2998. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].component.name, "OCPPCommCtrlr");
  2999. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variable.name, "FileTransferProtocols");
  3000. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].component.name, "OCPPCommCtrlr");
  3001. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variable.name, "HeartbeatInterval");
  3002. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].component.name, "OCPPCommCtrlr");
  3003. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variable.name, "NetworkConfigurationPriority");
  3004. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].component.name, "OCPPCommCtrlr");
  3005. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variable.name, "NetworkProfileConnectionAttempts");
  3006. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].component.name, "OCPPCommCtrlr");
  3007. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variable.name, "OfflineThreshold");
  3008. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].component.name, "OCPPCommCtrlr");
  3009. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variable.name, "QueueAllMessages");
  3010. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].component.name, "OCPPCommCtrlr");
  3011. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.instance, "TransactionEvent");
  3012. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.name, "MessageAttempts");
  3013. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].component.name, "OCPPCommCtrlr");
  3014. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.instance, "TransactionEvent");
  3015. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.name, "MessageAttemptInterval");
  3016. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].component.name, "OCPPCommCtrlr");
  3017. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variable.name, "UnlockOnEVSideDisconnect");
  3018. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].component.name, "OCPPCommCtrlr");
  3019. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variable.name, "WebSocketPingInterval");
  3020. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].component.name, "OCPPCommCtrlr");
  3021. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variable.name, "ResetRetries");
  3022. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].component.name, "OCPPCommCtrlr");
  3023. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variable.name, "PublicKeyWithSignedMeterValue");
  3024. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].component.name, "OCPPCommCtrlr");
  3025. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variable.name, "VariableVersion");
  3026. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].component.name, "OCPPCommCtrlr");
  3027. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variable.name, "StatusNotificationPeriodically");
  3028. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].component.name, "OCPPCommCtrlr");
  3029. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variable.name, "StatusNotificationInterval");
  3030. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].component.name, "OCPPCommCtrlr");
  3031. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_CharingProfileRefreshInterval].variable.name, "CharingProfileRefreshInterval");
  3032. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_RfidEndianType].component.name, "OCPPCommCtrlr");
  3033. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_RfidEndianType].variable.name, "RfidEndianType");
  3034. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].component.name, "OCPPCommCtrlr");
  3035. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_AuthorizeTimeout].variable.name, "AuthorizeTimeout");
  3036. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_EnableAcCcs].component.name, "OCPPCommCtrlr");
  3037. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_EnableAcCcs].variable.name, "EnableAcCcs");
  3038. /* ReservationCtrlr Required item */
  3039. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].component.name, "ReservationCtrlr");
  3040. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variable.name, "Enabled");
  3041. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].component.name, "ReservationCtrlr");
  3042. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variable.name, "Available");
  3043. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].component.name, "ReservationCtrlr");
  3044. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variable.name, "NonEvseSpecific");
  3045. /* SampledDataCtrlr Required item */
  3046. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].component.name, "SampledDataCtrlr");
  3047. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variable.name, "Enabled");
  3048. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].component.name, "SampledDataCtrlr");
  3049. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variable.name, "Available");
  3050. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].component.name, "SampledDataCtrlr");
  3051. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variable.name, "SignReadings");
  3052. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].component.name, "SampledDataCtrlr");
  3053. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  3054. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].component.name, "SampledDataCtrlr");
  3055. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  3056. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].component.name, "SampledDataCtrlr");
  3057. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variable.name, "TxStartedMeasurands");
  3058. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].component.name, "SampledDataCtrlr");
  3059. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variable.name, "TxUpdatedMeasurands");
  3060. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].component.name, "SampledDataCtrlr");
  3061. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variable.name, "TxUpdatedInterval");
  3062. /* SecurityCtrlr Required item */
  3063. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].component.name, "SecurityCtrlr");
  3064. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variable.name, "BasicAuthPassword");
  3065. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].component.name, "SecurityCtrlr");
  3066. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variable.name, "Identity");
  3067. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].component.name, "SecurityCtrlr");
  3068. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variable.name, "OrganizationName");
  3069. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].component.name, "SecurityCtrlr");
  3070. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variable.name, "CertificateEntries");
  3071. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].component.name, "SecurityCtrlr");
  3072. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variable.name, "SecurityProfile");
  3073. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].component.name, "SecurityCtrlr");
  3074. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variable.name, "AdditionalRootCertificateCheck");
  3075. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].component.name, "SecurityCtrlr");
  3076. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variable.name, "MaxCertificateChainSize");
  3077. /* SmartChargingCtrlr Required item */
  3078. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].component.name, "SmartChargingCtrlr");
  3079. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variable.name, "Enabled");
  3080. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].component.name, "SmartChargingCtrlr");
  3081. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variable.name, "Available");
  3082. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].component.name, "SmartChargingCtrlr");
  3083. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variable.name, "ACPhaseSwitchingSupported");
  3084. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].component.name, "SmartChargingCtrlr");
  3085. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variable.name, "ProfileStackLevel");
  3086. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].component.name, "SmartChargingCtrlr");
  3087. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variable.name, "RateUnit");
  3088. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].component.name, "SmartChargingCtrlr");
  3089. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variable.name, "PeriodsPerSchedule");
  3090. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].component.name, "SmartChargingCtrlr");
  3091. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variable.name, "ExternalControlSignalsEnabled");
  3092. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].component.name, "SmartChargingCtrlr");
  3093. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variable.name, "NotifyChargingLimitWithSchedules");
  3094. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].component.name, "SmartChargingCtrlr");
  3095. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variable.name, "Phases3to1");
  3096. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].component.name, "SmartChargingCtrlr");
  3097. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variable.name, "Entries");
  3098. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].component.name, "SmartChargingCtrlr");
  3099. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variable.name, "LimitChangeSignificance");
  3100. /* TariffCostCtrlr Required item */
  3101. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].component.name, "TariffCostCtrlr");
  3102. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.instance, "Tariff");
  3103. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.name, "Enabled");
  3104. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].component.name, "TariffCostCtrlr");
  3105. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.instance, "Tariff");
  3106. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.name, "Available");
  3107. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].component.name, "TariffCostCtrlr");
  3108. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variable.name, "TariffFallbackMessage");
  3109. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].component.name, "TariffCostCtrlr");
  3110. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.instance, "Cost");
  3111. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.name, "Enabled");
  3112. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].component.name, "TariffCostCtrlr");
  3113. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.instance, "Cost");
  3114. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.name, "Available");
  3115. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].component.name, "TariffCostCtrlr");
  3116. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variable.name, "TotalCostFallbackMessage");
  3117. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].component.name, "TariffCostCtrlr");
  3118. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variable.name, "Currency");
  3119. /* TxCtrlr Required item */
  3120. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].component.name, "TxCtrlr");
  3121. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variable.name, "ChargingBeforeAcceptedEnabled");
  3122. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].component.name, "TxCtrlr");
  3123. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variable.name, "EVConnectionTimeOut");
  3124. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].component.name, "TxCtrlr");
  3125. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variable.name, "StopTxOnEVSideDisconnect");
  3126. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].component.name, "TxCtrlr");
  3127. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variable.name, "TxBeforeAcceptedEnabled");
  3128. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].component.name, "TxCtrlr");
  3129. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variable.name, "TxStartPoint");
  3130. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].component.name, "TxCtrlr");
  3131. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variable.name, "TxStopPoint");
  3132. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].component.name, "TxCtrlr");
  3133. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variable.name, "MaxEnergyOnInvalidId");
  3134. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].component.name, "TxCtrlr");
  3135. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variable.name, "StopTxOnInvalidId");
  3136. }
  3137. return 0;
  3138. }
  3139. void DB_variableIsCreate()
  3140. {
  3141. char sql[512];
  3142. char* errMsg = NULL;
  3143. sprintf(sql,"select count(idx) as quantity from ocpp20_variable;");
  3144. /* Execute SQL statement */
  3145. if(sqlite3_exec(db, sql, DB_cbVariableIsCreate, 0, &errMsg) != SQLITE_OK )
  3146. {
  3147. DEBUG_INFO("SQL error: %s\n", errMsg);
  3148. }
  3149. }
  3150. int DB_cbVariableLoadFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  3151. {
  3152. for(int idx=0;idx<CtrlrVariable_CNT;idx++)
  3153. {
  3154. if((strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].component.name, columnValue[1]) == 0) &&
  3155. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].component.instance, columnValue[2]) == 0) &&
  3156. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variable.name, columnValue[3]) == 0) &&
  3157. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variable.instance, columnValue[4]) == 0))
  3158. {
  3159. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.dataType, "%s", columnValue[5]);
  3160. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.unit, "%s", columnValue[6]);
  3161. ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.maxLimit = strlen(columnValue[7])>0?atoi(columnValue[7]):255;
  3162. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].type, "%s", columnValue[8]);
  3163. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].mutability, "%s", columnValue[9]);
  3164. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].value, "%s", columnValue[10]);
  3165. ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.minLimit = strlen(columnValue[11])>=0?atoi(columnValue[11]):0;
  3166. }
  3167. }
  3168. return 0;
  3169. }
  3170. void DB_variableLoadFromDb()
  3171. {
  3172. char sql[512];
  3173. char* errMsg = NULL;
  3174. sprintf(sql,"select * from ocpp20_variable order by idx;");
  3175. /* Execute SQL statement */
  3176. if(sqlite3_exec(db, sql, DB_cbVariableLoadFromDb, 0, &errMsg) != SQLITE_OK )
  3177. {
  3178. DEBUG_INFO("SQL error: %s\n", errMsg);
  3179. }
  3180. }
  3181. //==============================
  3182. // Variable Monitoring
  3183. //==============================
  3184. int DB_variableMonitoringClear()
  3185. {
  3186. int result = PASS;
  3187. char * sqlclearVariableMonitoring = "delete from ocpp20_variable_monitoring";
  3188. char *errMsg = 0;
  3189. if (sqlite3_exec(db, sqlclearVariableMonitoring, 0, 0, &errMsg) != SQLITE_OK)
  3190. {
  3191. DEBUG_INFO("%s\n", errMsg);
  3192. result = FAIL;
  3193. }
  3194. return result;
  3195. }
  3196. int DB_cbVariableMonitoringSaveToDb(void *para, int columnCount, char **columnValue, char **columnName)
  3197. {
  3198. for(int i = 0; i<columnCount; i++)
  3199. {
  3200. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  3201. }
  3202. return 0;
  3203. }
  3204. int DB_variableMonitoringSaveToDb(struct SetMonitoringDataType *variableMonitoring)
  3205. {
  3206. int result = FAIL;
  3207. char sql[4096];
  3208. char* errMsg = NULL;
  3209. sprintf(sql,"insert or replace into ocpp20_variable_monitoring "
  3210. "(id, transaction, value, type, severity, component_name, component_instance, component_evse_id, component_evse_connectorId, variable_name, variable_instance) "
  3211. "VALUES('%d', '%d', '%.2f', '%s', '%d', '%s', %s, '%d', '%d', '%s', '%s'); SELECT * from ocpp20_variable_monitoring;",
  3212. variableMonitoring->id,
  3213. variableMonitoring->transaction,
  3214. variableMonitoring->value,
  3215. variableMonitoring->type,
  3216. variableMonitoring->severity,
  3217. variableMonitoring->component.name,
  3218. variableMonitoring->component.instance,
  3219. variableMonitoring->component.evse.id,
  3220. variableMonitoring->component.evse.connectorId,
  3221. variableMonitoring->variable.name,
  3222. variableMonitoring->variable.instance
  3223. );
  3224. //* Execute SQL statement */
  3225. if(sqlite3_exec(db, sql, DB_cbVariableMonitoringSaveToDb, 0, &errMsg) != SQLITE_OK)
  3226. {
  3227. DEBUG_INFO("SQL error: %s\n", errMsg);
  3228. result = FAIL;
  3229. }
  3230. return result;
  3231. }
  3232. int DB_cbVariableMonitoringLoadFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  3233. {
  3234. for(int idx=0;idx<10;idx++)
  3235. {
  3236. if((strlen((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].component.name) == 0) &&
  3237. (strlen((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].variable.name) == 0))
  3238. {
  3239. ShmOCPP20Data->MonitoringComponentVariable[idx].id = strlen(columnValue[1])>=0?atoi(columnValue[1]):-1;
  3240. ShmOCPP20Data->MonitoringComponentVariable[idx].transaction = strlen(columnValue[2])>=0?atoi(columnValue[2]):0;
  3241. ShmOCPP20Data->MonitoringComponentVariable[idx].value = strlen(columnValue[3])>=0?atof(columnValue[3]):0;
  3242. sprintf((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type, "%s", columnValue[4]);
  3243. ShmOCPP20Data->MonitoringComponentVariable[idx].severity = strlen(columnValue[5])>0?atoi(columnValue[5]):9;
  3244. sprintf((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].component.name, "%s", columnValue[6]);
  3245. sprintf((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].component.instance, "%s", columnValue[7]);
  3246. ShmOCPP20Data->MonitoringComponentVariable[idx].component.evse.id = strlen(columnValue[8])>0?atoi(columnValue[8]):-1;
  3247. ShmOCPP20Data->MonitoringComponentVariable[idx].component.evse.connectorId = strlen(columnValue[9])>0?atoi(columnValue[9]):-1;
  3248. sprintf((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].variable.name, "%s", columnValue[10]);
  3249. sprintf((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].variable.instance, "%s", columnValue[11]);
  3250. break;
  3251. }
  3252. }
  3253. return 0;
  3254. }
  3255. void DB_variableMonitoringLoadFromDb()
  3256. {
  3257. char sql[512];
  3258. char* errMsg = NULL;
  3259. sprintf(sql,"select * from ocpp20_variable_monitoring order by idx;");
  3260. /* Execute SQL statement */
  3261. if(sqlite3_exec(db, sql, DB_cbVariableMonitoringLoadFromDb, 0, &errMsg) != SQLITE_OK )
  3262. {
  3263. DEBUG_INFO("SQL error: %s\n", errMsg);
  3264. }
  3265. }
  3266. int DB_cbGetNetworkProfileFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  3267. {
  3268. memset(&ShmOCPP20Data->NetworkConnectionProfile[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile));
  3269. if(columnCount > 0)
  3270. {
  3271. for(int idx=0;idx<columnCount;idx++)
  3272. {
  3273. json_object *SetNetworkProfile;
  3274. SetNetworkProfile = json_tokener_parse(columnValue[2]);
  3275. if(!is_error(SetNetworkProfile))
  3276. {
  3277. // Required data
  3278. if(json_object_object_get(SetNetworkProfile, "ocppVersion") != NULL)
  3279. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppVersion, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppVersion")));
  3280. if(json_object_object_get(SetNetworkProfile, "ocppTransport") != NULL)
  3281. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppTransport")));
  3282. if(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl") != NULL)
  3283. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl")));
  3284. if(json_object_object_get(SetNetworkProfile, "messageTimeout") != NULL)
  3285. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.messageTimeout = json_object_get_int(json_object_object_get(SetNetworkProfile, "messageTimeout"));
  3286. if(json_object_object_get(SetNetworkProfile, "ocppInterface") != NULL)
  3287. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppInterface, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppInterface")));
  3288. if(json_object_object_get(SetNetworkProfile, "vpn") != NULL)
  3289. {
  3290. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server") != NULL)
  3291. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.server, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server")));
  3292. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user") != NULL)
  3293. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.user, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user")));
  3294. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group") != NULL)
  3295. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.group, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group")));
  3296. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password") != NULL)
  3297. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.password, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password")));
  3298. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key") != NULL)
  3299. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.key, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key")));
  3300. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type") != NULL)
  3301. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type")));
  3302. }
  3303. if(json_object_object_get(SetNetworkProfile, "apn") != NULL)
  3304. {
  3305. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn") != NULL)
  3306. {
  3307. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn));
  3308. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn")));
  3309. }
  3310. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName") != NULL)
  3311. {
  3312. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName));
  3313. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName")));
  3314. }
  3315. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword") != NULL)
  3316. {
  3317. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword));
  3318. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword")));
  3319. }
  3320. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin") != NULL)
  3321. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.simPin = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin"));
  3322. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork") != NULL)
  3323. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.preferredNetwork, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork")));
  3324. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork") != NULL)
  3325. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.useOnlyPreferredNetwork = json_object_get_boolean(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork"));
  3326. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication") != NULL)
  3327. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnAuthentication, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication")));
  3328. }
  3329. }
  3330. json_object_put(SetNetworkProfile);
  3331. ShmOCPP20Data->NetworkConnectionProfile[idx].slot = atoi(columnValue[1]);
  3332. }
  3333. }
  3334. return 0;
  3335. }
  3336. void DB_getNetworkProfileFromDb()
  3337. {
  3338. char sql[512];
  3339. char* errMsg = NULL;
  3340. sprintf(sql,"select * from ocpp20_networkprofile order by slot;");
  3341. /* Execute SQL statement */
  3342. if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
  3343. {
  3344. DEBUG_INFO("SQL error: %s\n", errMsg);
  3345. }
  3346. }
  3347. int DB_addNetworkProfile(int slot, char *data)
  3348. {
  3349. int result = PASS;
  3350. char sql[512];
  3351. char* errMsg = NULL;
  3352. sprintf(sql,"insert or replace into ocpp20_networkprofile (slot, connectionData) VALUES('%d', '%s'); SELECT * from ocpp20_networkprofile order by slot;",
  3353. slot,
  3354. data);
  3355. //* Execute SQL statement */
  3356. if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK)
  3357. {
  3358. DEBUG_INFO("SQL error: %s\n", errMsg);
  3359. result = FAIL;
  3360. }
  3361. return result;
  3362. }
  3363. int DB_deleteNetworkProfile(int slot)
  3364. {
  3365. int result = PASS;
  3366. char sql[512];
  3367. char* errMsg = NULL;
  3368. sprintf(sql,"DELETE from ocpp20_networkprofile where slot=%d; SELECT * from ocpp20_networkprofile order by slot;", slot);
  3369. //* Execute SQL statement */
  3370. if( sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
  3371. {
  3372. DEBUG_INFO("SQL error: %s", errMsg);
  3373. result = FAIL;
  3374. }
  3375. return result;
  3376. }
  3377. int isNumber(uint8_t *string, uint8_t isFloat)
  3378. {
  3379. int result = NO;
  3380. int cntDecimal = 0;
  3381. float i;
  3382. for(int idx=0; idx<strlen((char*)string); idx++)
  3383. {
  3384. if((isdigit(string[idx])==0) && (string[idx] != '.'))
  3385. {
  3386. return result;
  3387. }
  3388. else if(string[idx] == '.')
  3389. cntDecimal++;
  3390. if(cntDecimal>1)
  3391. return result;
  3392. }
  3393. if((isFloat==FALSE) && (strstr((char*)string, ".") != NULL))
  3394. {
  3395. //DEBUG_INFO("%s is not pure integer!!\n", string);
  3396. }
  3397. else if((isFloat==TRUE) && (strstr((char*)string, ".") == NULL))
  3398. {
  3399. //DEBUG_INFO("%s is not float format!!\n", string);
  3400. }
  3401. else if(sscanf((char*)string, "%f", &i) != 0)
  3402. {
  3403. result = YES;
  3404. }
  3405. return result;
  3406. }
  3407. int isMatchTimeFormat(uint8_t *time)
  3408. {
  3409. int result = NO;
  3410. struct ParsingResult
  3411. {
  3412. int result;
  3413. int scanedElement;
  3414. int year;
  3415. int month;
  3416. int mday;
  3417. int hour;
  3418. int min;
  3419. int sec;
  3420. int tz_hour;
  3421. int tz_min;
  3422. float minSec;
  3423. }parsingResult;
  3424. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  3425. if(strstr((char*)time, ".") != NULL)
  3426. {
  3427. // Original data with mini second
  3428. if(strstr((char*)time, "Z") != NULL)
  3429. {
  3430. // Original data with Z
  3431. parsingResult.scanedElement = sscanf((char*)time, "%d-%d-%dT%d:%d:%d.%fZ",
  3432. &parsingResult.year,
  3433. &parsingResult.month,
  3434. &parsingResult.mday,
  3435. &parsingResult.hour,
  3436. &parsingResult.min,
  3437. &parsingResult.sec,
  3438. &parsingResult.minSec);
  3439. }
  3440. else
  3441. {
  3442. // Original data without Z
  3443. parsingResult.scanedElement = sscanf((char*)time, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3444. &parsingResult.year,
  3445. &parsingResult.month,
  3446. &parsingResult.mday,
  3447. &parsingResult.hour,
  3448. &parsingResult.min,
  3449. &parsingResult.sec,
  3450. &parsingResult.minSec,
  3451. &parsingResult.tz_hour,
  3452. &parsingResult.tz_min);
  3453. }
  3454. }
  3455. else
  3456. {
  3457. // Original data without mini second
  3458. if(strstr((char*)time, "Z") != NULL)
  3459. {
  3460. // Original data with Z
  3461. parsingResult.scanedElement = sscanf((char*)time, "%d-%d-%dT%d:%d:%dZ",
  3462. &parsingResult.year,
  3463. &parsingResult.month,
  3464. &parsingResult.mday,
  3465. &parsingResult.hour,
  3466. &parsingResult.min,
  3467. &parsingResult.sec);
  3468. }
  3469. else
  3470. {
  3471. // Original data without Z
  3472. parsingResult.scanedElement = sscanf((char*)time, "%d-%d-%dT%d:%d:%d%d:%d",
  3473. &parsingResult.year,
  3474. &parsingResult.month,
  3475. &parsingResult.mday,
  3476. &parsingResult.hour,
  3477. &parsingResult.min,
  3478. &parsingResult.sec,
  3479. &parsingResult.tz_hour,
  3480. &parsingResult.tz_min);
  3481. }
  3482. }
  3483. if(parsingResult.scanedElement >= 6)
  3484. {
  3485. result = YES;
  3486. }
  3487. return result;
  3488. }
  3489. int getCurrentYear()
  3490. {
  3491. int result = 0;
  3492. time_t CurrentTime;
  3493. struct tm *tm;
  3494. CurrentTime = time(NULL);
  3495. tm=localtime(&CurrentTime);
  3496. result = (tm->tm_year + 1900);
  3497. return result;
  3498. }
  3499. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  3500. {
  3501. int result = PASS;
  3502. char* errMsg = NULL;
  3503. char sqlStr[WEBSOCKET_BUFFER_SIZE];
  3504. sprintf(sqlStr, "insert into ocpp20_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  3505. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  3506. {
  3507. result = FAIL;
  3508. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  3509. }
  3510. 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));
  3511. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  3512. {
  3513. result = FAIL;
  3514. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  3515. }
  3516. return result;
  3517. }
  3518. //==========================================
  3519. // Check time passed since today
  3520. //==========================================
  3521. long long DiffTimebWithNow(struct timeb ST)
  3522. {
  3523. //return milli-second
  3524. struct timeb ET;
  3525. long long StartTime,StopTime;
  3526. ftime(&ET);
  3527. StartTime=(long long)ST.time;
  3528. StopTime=(long long)ET.time;
  3529. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  3530. }
  3531. int getTimePassSinceToday(uint8_t gun_index)
  3532. {
  3533. int result = -1;
  3534. static time_t lastTime[4];
  3535. time_t t;
  3536. struct tm *tmStartToday;
  3537. struct timeb tbStartToday;
  3538. t=time(NULL);
  3539. if(difftime(t, lastTime[gun_index])>0)
  3540. {
  3541. tmStartToday=localtime(&t);
  3542. tmStartToday->tm_hour = 0;
  3543. tmStartToday->tm_min = 0;
  3544. tmStartToday->tm_sec = 0;
  3545. tbStartToday.time = mktime(tmStartToday);
  3546. tbStartToday.millitm = 0;
  3547. result = DiffTimebWithNow(tbStartToday)/1000;
  3548. lastTime[gun_index] = t;
  3549. }
  3550. return result;
  3551. }
  3552. int syncDateTimeRTC(uint8_t *data)
  3553. {
  3554. struct ParsingResult
  3555. {
  3556. int result;
  3557. int scanedElement;
  3558. int year;
  3559. int month;
  3560. int mday;
  3561. int hour;
  3562. int min;
  3563. int sec;
  3564. int tz_hour;
  3565. int tz_min;
  3566. float minSec;
  3567. }result;
  3568. struct tm tmOrg;
  3569. struct tm *tmTarget;
  3570. struct timeb tbTarget;
  3571. char buf[128];
  3572. memset(&result, 0x00, sizeof(struct ParsingResult));
  3573. result.result = PASS;
  3574. if(strstr((char*)data, ".") != NULL)
  3575. {
  3576. // Original data with mini second
  3577. if(strstr((char*)data, "Z") != NULL)
  3578. {
  3579. // Original data with Z
  3580. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  3581. &result.year,
  3582. &result.month,
  3583. &result.mday,
  3584. &result.hour,
  3585. &result.min,
  3586. &result.sec,
  3587. &result.minSec);
  3588. }
  3589. else
  3590. {
  3591. // Original data without Z
  3592. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3593. &result.year,
  3594. &result.month,
  3595. &result.mday,
  3596. &result.hour,
  3597. &result.min,
  3598. &result.sec,
  3599. &result.minSec,
  3600. &result.tz_hour,
  3601. &result.tz_min);
  3602. }
  3603. }
  3604. else
  3605. {
  3606. // Original data without mini second
  3607. if(strstr((char*)data, "Z") != NULL)
  3608. {
  3609. // Original data with Z
  3610. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  3611. &result.year,
  3612. &result.month,
  3613. &result.mday,
  3614. &result.hour,
  3615. &result.min,
  3616. &result.sec);
  3617. }
  3618. else
  3619. {
  3620. // Original data without Z
  3621. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  3622. &result.year,
  3623. &result.month,
  3624. &result.mday,
  3625. &result.hour,
  3626. &result.min,
  3627. &result.sec,
  3628. &result.tz_hour,
  3629. &result.tz_min);
  3630. }
  3631. }
  3632. tmOrg.tm_year = result.year - 1900;
  3633. tmOrg.tm_mon = result.month - 1;
  3634. tmOrg.tm_mday = result.mday;
  3635. tmOrg.tm_hour = result.hour;
  3636. tmOrg.tm_min = result.min;
  3637. tmOrg.tm_sec = result.sec;
  3638. tmOrg.tm_gmtoff = 0;
  3639. tbTarget.time = mktime(&tmOrg);
  3640. tbTarget.timezone = 0;
  3641. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  3642. tmTarget = gmtime(&tbTarget.time);
  3643. 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);
  3644. //DEBUG_INFO(" org date time: %s\n", data);
  3645. //DEBUG_INFO("parse date time: %s\n", buf);
  3646. system(buf);
  3647. system("/sbin/hwclock -w --systohc");
  3648. if(result.scanedElement < 6)
  3649. result.result = FAIL;
  3650. return result.result;
  3651. }
  3652. //==========================================
  3653. // GetCompositeSchedule logic related function
  3654. //==========================================
  3655. int DiffTimebSec(struct timeb ST, struct timeb ET)
  3656. {
  3657. //return milli-second
  3658. unsigned int StartTime,StopTime;
  3659. StartTime=(unsigned int)ST.time;
  3660. StopTime=(unsigned int)ET.time;
  3661. return (StopTime-StartTime);
  3662. }
  3663. int DiffTimebWithNowSec(struct timeb ST)
  3664. {
  3665. //return milli-second
  3666. struct timeb ET;
  3667. unsigned int StartTime,StopTime;
  3668. ftime(&ET);
  3669. StartTime=(unsigned int)ST.time;
  3670. StopTime=(unsigned int)ET.time;
  3671. return (StopTime-StartTime);
  3672. }
  3673. int getStartStop(uint8_t *start, uint8_t *stop)
  3674. {
  3675. struct ParsingResult
  3676. {
  3677. int result;
  3678. int scanedElement;
  3679. int year;
  3680. int month;
  3681. int mday;
  3682. int hour;
  3683. int min;
  3684. int sec;
  3685. int tz_hour;
  3686. int tz_min;
  3687. float minSec;
  3688. };
  3689. struct ParsingResult parseStart;
  3690. struct ParsingResult parseStop;
  3691. int result = -1;
  3692. struct tm tmStart;
  3693. struct timeb tbStart;
  3694. struct tm tmStop;
  3695. struct timeb tbStop;
  3696. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  3697. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  3698. // Scan start & stop date time
  3699. if(strstr((char*)start, ".") != NULL)
  3700. {
  3701. // Original data with mini second
  3702. if(strstr((char*)start, "Z") != NULL)
  3703. {
  3704. // Original data with Z
  3705. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  3706. &parseStart.year,
  3707. &parseStart.month,
  3708. &parseStart.mday,
  3709. &parseStart.hour,
  3710. &parseStart.min,
  3711. &parseStart.sec,
  3712. &parseStart.minSec);
  3713. }
  3714. else
  3715. {
  3716. // Original data without Z
  3717. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3718. &parseStart.year,
  3719. &parseStart.month,
  3720. &parseStart.mday,
  3721. &parseStart.hour,
  3722. &parseStart.min,
  3723. &parseStart.sec,
  3724. &parseStart.minSec,
  3725. &parseStart.tz_hour,
  3726. &parseStart.tz_min);
  3727. }
  3728. }
  3729. else
  3730. {
  3731. // Original data without mini second
  3732. if(strstr((char*)start, "Z") != NULL)
  3733. {
  3734. // Original data with Z
  3735. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  3736. &parseStart.year,
  3737. &parseStart.month,
  3738. &parseStart.mday,
  3739. &parseStart.hour,
  3740. &parseStart.min,
  3741. &parseStart.sec);
  3742. }
  3743. else
  3744. {
  3745. // Original data without Z
  3746. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  3747. &parseStart.year,
  3748. &parseStart.month,
  3749. &parseStart.mday,
  3750. &parseStart.hour,
  3751. &parseStart.min,
  3752. &parseStart.sec,
  3753. &parseStart.tz_hour,
  3754. &parseStart.tz_min);
  3755. }
  3756. }
  3757. if(strstr((char*)stop, ".") != NULL)
  3758. {
  3759. // Original data with mini second
  3760. if(strstr((char*)stop, "Z") != NULL)
  3761. {
  3762. // Original data with Z
  3763. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  3764. &parseStop.year,
  3765. &parseStop.month,
  3766. &parseStop.mday,
  3767. &parseStop.hour,
  3768. &parseStop.min,
  3769. &parseStop.sec,
  3770. &parseStop.minSec);
  3771. }
  3772. else
  3773. {
  3774. // Original data without Z
  3775. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3776. &parseStop.year,
  3777. &parseStop.month,
  3778. &parseStop.mday,
  3779. &parseStop.hour,
  3780. &parseStop.min,
  3781. &parseStop.sec,
  3782. &parseStop.minSec,
  3783. &parseStop.tz_hour,
  3784. &parseStop.tz_min);
  3785. }
  3786. }
  3787. else
  3788. {
  3789. // Original data without mini second
  3790. if(strstr((char*)stop, "Z") != NULL)
  3791. {
  3792. // Original data with Z
  3793. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  3794. &parseStop.year,
  3795. &parseStop.month,
  3796. &parseStop.mday,
  3797. &parseStop.hour,
  3798. &parseStop.min,
  3799. &parseStop.sec);
  3800. }
  3801. else
  3802. {
  3803. // Original data without Z
  3804. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  3805. &parseStop.year,
  3806. &parseStop.month,
  3807. &parseStop.mday,
  3808. &parseStop.hour,
  3809. &parseStop.min,
  3810. &parseStop.sec,
  3811. &parseStop.tz_hour,
  3812. &parseStop.tz_min);
  3813. }
  3814. }
  3815. // Calculate date time difference
  3816. if((parseStart.scanedElement >=6) &&
  3817. (parseStop.scanedElement >=6))
  3818. {
  3819. //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);
  3820. //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);
  3821. tmStart.tm_year = parseStart.year - 1900;
  3822. tmStart.tm_mon = parseStart.month - 1;
  3823. tmStart.tm_mday = parseStart.mday;
  3824. tmStart.tm_hour = parseStart.hour;
  3825. tmStart.tm_min = parseStart.min;
  3826. tmStart.tm_sec = parseStart.sec;
  3827. tmStart.tm_gmtoff = 0;
  3828. tbStart.time = mktime(&tmStart);
  3829. tbStart.timezone = 0;
  3830. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  3831. tmStop.tm_year = parseStop.year - 1900;
  3832. tmStop.tm_mon = parseStop.month - 1;
  3833. tmStop.tm_mday = parseStop.mday;
  3834. tmStop.tm_hour = parseStop.hour;
  3835. tmStop.tm_min = parseStop.min;
  3836. tmStop.tm_sec = parseStop.sec;
  3837. tmStop.tm_gmtoff = 0;
  3838. tbStop.time = mktime(&tmStop);
  3839. tbStop.timezone = 0;
  3840. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  3841. result = DiffTimebSec(tbStart, tbStop);
  3842. //DEBUG_INFO("getStartStop(): %d\n", result);
  3843. }
  3844. else
  3845. {
  3846. DEBUG_WARN("Start or stop date parsing error.\r\n");
  3847. }
  3848. return result;
  3849. }
  3850. int isOvertNow(uint8_t *start)
  3851. {
  3852. int result = NO;
  3853. struct ParsingResult
  3854. {
  3855. int result;
  3856. int scanedElement;
  3857. int year;
  3858. int month;
  3859. int mday;
  3860. int hour;
  3861. int min;
  3862. int sec;
  3863. int tz_hour;
  3864. int tz_min;
  3865. float minSec;
  3866. }parsingResult;
  3867. struct tm tmStart;
  3868. struct timeb tbStart;
  3869. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  3870. if(strstr((char*)start, ".") != NULL)
  3871. {
  3872. // Original data with mini second
  3873. if(strstr((char*)start, "Z") != NULL)
  3874. {
  3875. // Original data with Z
  3876. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  3877. &parsingResult.year,
  3878. &parsingResult.month,
  3879. &parsingResult.mday,
  3880. &parsingResult.hour,
  3881. &parsingResult.min,
  3882. &parsingResult.sec,
  3883. &parsingResult.minSec);
  3884. }
  3885. else
  3886. {
  3887. // Original data without Z
  3888. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3889. &parsingResult.year,
  3890. &parsingResult.month,
  3891. &parsingResult.mday,
  3892. &parsingResult.hour,
  3893. &parsingResult.min,
  3894. &parsingResult.sec,
  3895. &parsingResult.minSec,
  3896. &parsingResult.tz_hour,
  3897. &parsingResult.tz_min);
  3898. }
  3899. }
  3900. else
  3901. {
  3902. // Original data without mini second
  3903. if(strstr((char*)start, "Z") != NULL)
  3904. {
  3905. // Original data with Z
  3906. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  3907. &parsingResult.year,
  3908. &parsingResult.month,
  3909. &parsingResult.mday,
  3910. &parsingResult.hour,
  3911. &parsingResult.min,
  3912. &parsingResult.sec);
  3913. }
  3914. else
  3915. {
  3916. // Original data without Z
  3917. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  3918. &parsingResult.year,
  3919. &parsingResult.month,
  3920. &parsingResult.mday,
  3921. &parsingResult.hour,
  3922. &parsingResult.min,
  3923. &parsingResult.sec,
  3924. &parsingResult.tz_hour,
  3925. &parsingResult.tz_min);
  3926. }
  3927. }
  3928. if(parsingResult.scanedElement >= 6)
  3929. {
  3930. tmStart.tm_year = parsingResult.year - 1900;
  3931. tmStart.tm_mon = parsingResult.month - 1;
  3932. tmStart.tm_mday = parsingResult.mday;
  3933. tmStart.tm_hour = parsingResult.hour;
  3934. tmStart.tm_min = parsingResult.min;
  3935. tmStart.tm_sec = parsingResult.sec;
  3936. tmStart.tm_gmtoff = 0;
  3937. tbStart.time = mktime(&tmStart);
  3938. tbStart.timezone = 0;
  3939. tbStart.millitm = 0;
  3940. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  3941. if(DiffTimebWithNowSec(tbStart) <= 0)
  3942. result = NO;
  3943. else
  3944. result = YES;
  3945. }
  3946. else
  3947. {
  3948. DEBUG_WARN("Start date parsing error.\n");
  3949. }
  3950. return result;
  3951. }
  3952. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  3953. {
  3954. struct ParsingResult
  3955. {
  3956. int result;
  3957. int scanedElement;
  3958. int year;
  3959. int month;
  3960. int mday;
  3961. int hour;
  3962. int min;
  3963. int sec;
  3964. int tz_hour;
  3965. int tz_min;
  3966. float minSec;
  3967. };
  3968. struct ParsingResult parseStart;
  3969. struct ParsingResult parseStop;
  3970. int result = -1;
  3971. struct tm tmStart;
  3972. struct timeb tbStart;
  3973. struct tm tmStop;
  3974. struct timeb tbStop;
  3975. memset(&parseStart, 0x00, sizeof(struct ParsingResult));
  3976. memset(&parseStop, 0x00, sizeof(struct ParsingResult));
  3977. // Scan start & stop date time
  3978. if(strstr((char*)start, ".") != NULL)
  3979. {
  3980. // Original data with mini second
  3981. if(strstr((char*)start, "Z") != NULL)
  3982. {
  3983. // Original data with Z
  3984. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  3985. &parseStart.year,
  3986. &parseStart.month,
  3987. &parseStart.mday,
  3988. &parseStart.hour,
  3989. &parseStart.min,
  3990. &parseStart.sec,
  3991. &parseStart.minSec);
  3992. }
  3993. else
  3994. {
  3995. // Original data without Z
  3996. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  3997. &parseStart.year,
  3998. &parseStart.month,
  3999. &parseStart.mday,
  4000. &parseStart.hour,
  4001. &parseStart.min,
  4002. &parseStart.sec,
  4003. &parseStart.minSec,
  4004. &parseStart.tz_hour,
  4005. &parseStart.tz_min);
  4006. }
  4007. }
  4008. else
  4009. {
  4010. // Original data without mini second
  4011. if(strstr((char*)start, "Z") != NULL)
  4012. {
  4013. // Original data with Z
  4014. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  4015. &parseStart.year,
  4016. &parseStart.month,
  4017. &parseStart.mday,
  4018. &parseStart.hour,
  4019. &parseStart.min,
  4020. &parseStart.sec);
  4021. }
  4022. else
  4023. {
  4024. // Original data without Z
  4025. parseStart.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  4026. &parseStart.year,
  4027. &parseStart.month,
  4028. &parseStart.mday,
  4029. &parseStart.hour,
  4030. &parseStart.min,
  4031. &parseStart.sec,
  4032. &parseStart.tz_hour,
  4033. &parseStart.tz_min);
  4034. }
  4035. }
  4036. if(strstr((char*)stop, ".") != NULL)
  4037. {
  4038. // Original data with mini second
  4039. if(strstr((char*)stop, "Z") != NULL)
  4040. {
  4041. // Original data with Z
  4042. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%fZ",
  4043. &parseStop.year,
  4044. &parseStop.month,
  4045. &parseStop.mday,
  4046. &parseStop.hour,
  4047. &parseStop.min,
  4048. &parseStop.sec,
  4049. &parseStop.minSec);
  4050. }
  4051. else
  4052. {
  4053. // Original data without Z
  4054. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  4055. &parseStop.year,
  4056. &parseStop.month,
  4057. &parseStop.mday,
  4058. &parseStop.hour,
  4059. &parseStop.min,
  4060. &parseStop.sec,
  4061. &parseStop.minSec,
  4062. &parseStop.tz_hour,
  4063. &parseStop.tz_min);
  4064. }
  4065. }
  4066. else
  4067. {
  4068. // Original data without mini second
  4069. if(strstr((char*)stop, "Z") != NULL)
  4070. {
  4071. // Original data with Z
  4072. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%dZ",
  4073. &parseStop.year,
  4074. &parseStop.month,
  4075. &parseStop.mday,
  4076. &parseStop.hour,
  4077. &parseStop.min,
  4078. &parseStop.sec);
  4079. }
  4080. else
  4081. {
  4082. // Original data without Z
  4083. parseStop.scanedElement = sscanf((char*)stop, "%d-%d-%dT%d:%d:%d%d:%d",
  4084. &parseStop.year,
  4085. &parseStop.month,
  4086. &parseStop.mday,
  4087. &parseStop.hour,
  4088. &parseStop.min,
  4089. &parseStop.sec,
  4090. &parseStop.tz_hour,
  4091. &parseStop.tz_min);
  4092. }
  4093. }
  4094. // Calculate date time difference
  4095. if((parseStart.scanedElement >=6) &&
  4096. (parseStop.scanedElement >=6))
  4097. {
  4098. //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);
  4099. //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);
  4100. tmStart.tm_year = parseStart.year - 1900;
  4101. tmStart.tm_mon = parseStart.month - 1;
  4102. tmStart.tm_mday = parseStart.mday;
  4103. tmStart.tm_hour = parseStart.hour;
  4104. tmStart.tm_min = parseStart.min;
  4105. tmStart.tm_sec = parseStart.sec;
  4106. tmStart.tm_gmtoff = 0;
  4107. tbStart.time = mktime(&tmStart);
  4108. tbStart.timezone = 0;
  4109. tbStart.time -= (parseStart.tz_hour*3600) + (parseStart.tz_min*60*(parseStart.tz_hour>=0?1:-1));
  4110. tmStop.tm_year = parseStop.year - 1900;
  4111. tmStop.tm_mon = parseStop.month - 1;
  4112. tmStop.tm_mday = parseStop.mday;
  4113. tmStop.tm_hour = parseStop.hour;
  4114. tmStop.tm_min = parseStop.min;
  4115. tmStop.tm_sec = parseStop.sec;
  4116. tmStop.tm_gmtoff = 0;
  4117. tbStop.time = mktime(&tmStop);
  4118. tbStop.timezone = 0;
  4119. tbStop.time -= (parseStop.tz_hour*3600) + (parseStop.tz_min*60*(parseStop.tz_hour>=0?1:-1));
  4120. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  4121. //DEBUG_INFO("getStartStop(): %d\n", result);
  4122. }
  4123. else
  4124. {
  4125. DEBUG_WARN("Start or stop date parsing error.\r\n");
  4126. }
  4127. return result;
  4128. }
  4129. void checkChargingStationMaxProfile(uint32_t durationReq, struct ChargingProfileType *targetCompositeProfile, uint8_t idxSchedule, uint8_t isUnitA)
  4130. {
  4131. FILE *fp;
  4132. char profileFileName[128];
  4133. char *line = NULL;
  4134. size_t len = 0;
  4135. time_t CurrentTime;
  4136. struct tm *tmComposite;
  4137. struct ChargingProfileType maxProfile;
  4138. struct ChargingProfileType compositeProfile;
  4139. uint8_t limitMax=0;
  4140. int compositePeriodIdx = 0;
  4141. CurrentTime = time(NULL);
  4142. tmComposite=localtime(&CurrentTime);
  4143. 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);
  4144. if(isUnitA)
  4145. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4146. else
  4147. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4148. compositeProfile.chargingSchedule[idxSchedule].duration = durationReq;
  4149. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4150. {
  4151. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4152. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4153. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4154. }
  4155. compositeProfile.id = 0;
  4156. compositeProfile.stackLevel = 99 ;
  4157. sprintf((char*)compositeProfile.chargingProfileKind ,"Absolute");
  4158. maxProfile.id = -1;
  4159. maxProfile.chargingSchedule[idxSchedule].duration = -1;
  4160. system("rm -f /tmp/*.json");
  4161. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  4162. // Search max profile
  4163. sprintf(profileFileName, "/tmp/ChargingStationMaxProfile_OCPP20.json");
  4164. if((access(profileFileName, F_OK))!=-1)
  4165. {
  4166. fp = fopen(profileFileName, "r");
  4167. while(getline(&line, &len, fp) != -1)
  4168. {
  4169. json_object *obj = NULL;
  4170. obj = json_tokener_parse(line);
  4171. if(is_error(obj))
  4172. {
  4173. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  4174. }
  4175. else
  4176. {
  4177. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != maxProfile.id) &&
  4178. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= maxProfile.stackLevel)
  4179. )
  4180. {
  4181. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  4182. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4183. )
  4184. {
  4185. struct tm tmFrom, tmTo;
  4186. struct timeb tbFrom, tbTo;
  4187. 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) &&
  4188. (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))
  4189. {
  4190. tmFrom.tm_year -= 1900;
  4191. tmFrom.tm_mon -= 1;
  4192. tbFrom.time = mktime(&tmFrom);
  4193. tmTo.tm_year -= 1900;
  4194. tmTo.tm_mon -= 1;
  4195. tbTo.time = mktime(&tmTo);
  4196. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  4197. {
  4198. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4199. {
  4200. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4201. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4202. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4203. }
  4204. if(maxProfile.id == -1)
  4205. DEBUG_INFO("MaxProfile found.\n");
  4206. else
  4207. DEBUG_INFO("MaxProfile updated.\n");
  4208. // Required item
  4209. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4210. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4211. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4212. if(isUnitA)
  4213. {
  4214. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4215. 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++)
  4216. {
  4217. 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"));
  4218. 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"));
  4219. /*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)
  4220. {
  4221. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4222. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4223. else
  4224. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4225. }
  4226. else
  4227. {
  4228. 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"));
  4229. }*/
  4230. 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")));
  4231. }
  4232. }
  4233. else
  4234. {
  4235. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4236. 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++)
  4237. {
  4238. 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"));
  4239. 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"));
  4240. /*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)
  4241. {
  4242. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4243. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4244. else
  4245. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4246. }
  4247. else
  4248. {
  4249. 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"));
  4250. }*/
  4251. 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));
  4252. }
  4253. }
  4254. // Optional item
  4255. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4256. {
  4257. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4258. }
  4259. else
  4260. {
  4261. sprintf((char*)maxProfile.validFrom, " ");
  4262. }
  4263. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4264. {
  4265. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4266. }
  4267. else
  4268. {
  4269. sprintf((char*)maxProfile.validTo, " ");
  4270. }
  4271. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4272. {
  4273. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4274. }
  4275. else
  4276. {
  4277. sprintf((char*)maxProfile.recurrencyKind, " ");
  4278. }
  4279. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4280. {
  4281. sprintf((char*)maxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4282. }
  4283. else
  4284. {
  4285. sprintf((char*)maxProfile.transactionId, " ");
  4286. }
  4287. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4288. {
  4289. 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"));
  4290. }
  4291. else
  4292. {
  4293. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4294. }
  4295. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4296. {
  4297. 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")));
  4298. }
  4299. else
  4300. {
  4301. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  4302. }
  4303. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4304. {
  4305. 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"));
  4306. }
  4307. else
  4308. {
  4309. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4310. }
  4311. }
  4312. }
  4313. }
  4314. else
  4315. {
  4316. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4317. {
  4318. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4319. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4320. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4321. }
  4322. if(maxProfile.id == -1)
  4323. DEBUG_INFO("MaxProfile found.\n");
  4324. else
  4325. DEBUG_INFO("MaxProfile updated.\n");
  4326. // Required item
  4327. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4328. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4329. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4330. if(isUnitA)
  4331. {
  4332. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4333. 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++)
  4334. {
  4335. 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"));
  4336. 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"));
  4337. /*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)
  4338. {
  4339. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4340. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4341. else
  4342. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4343. }
  4344. else
  4345. {
  4346. 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"));
  4347. }*/
  4348. 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")));
  4349. }
  4350. }
  4351. else
  4352. {
  4353. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4354. 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++)
  4355. {
  4356. 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"));
  4357. 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"));
  4358. /*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)
  4359. {
  4360. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4361. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4362. else
  4363. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4364. }
  4365. else
  4366. {
  4367. 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"));
  4368. }*/
  4369. 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));
  4370. }
  4371. }
  4372. // Optional item
  4373. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4374. {
  4375. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4376. }
  4377. else
  4378. {
  4379. sprintf((char*)maxProfile.validFrom, " ");
  4380. }
  4381. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4382. {
  4383. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4384. }
  4385. else
  4386. {
  4387. sprintf((char*)maxProfile.validTo, " ");
  4388. }
  4389. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4390. {
  4391. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4392. }
  4393. else
  4394. {
  4395. sprintf((char*)maxProfile.recurrencyKind, " ");
  4396. }
  4397. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4398. {
  4399. sprintf((char*)maxProfile.transactionId,"%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4400. }
  4401. else
  4402. {
  4403. sprintf((char*)maxProfile.transactionId, " ");
  4404. }
  4405. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4406. {
  4407. 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"));
  4408. }
  4409. else
  4410. {
  4411. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4412. }
  4413. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4414. {
  4415. 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")));
  4416. }
  4417. else
  4418. {
  4419. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  4420. }
  4421. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4422. {
  4423. 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"));
  4424. }
  4425. else
  4426. {
  4427. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4428. }
  4429. }
  4430. }
  4431. }
  4432. json_object_put(obj);
  4433. }
  4434. fclose(fp);
  4435. /*
  4436. if(maxProfile.id !=-1)
  4437. {
  4438. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  4439. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  4440. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  4441. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  4442. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  4443. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  4444. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  4445. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.chargingSchedule[idxSchedule].StartSchedule);
  4446. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  4447. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4448. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4449. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4450. {
  4451. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4452. {
  4453. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4454. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4455. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4456. }
  4457. }
  4458. }
  4459. else
  4460. DEBUG_INFO("MaxProfile not found.\n");
  4461. DEBUG_INFO("------------------------------------\n");*/
  4462. }
  4463. if(maxProfile.id != -1)
  4464. {
  4465. if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  4466. {
  4467. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4468. {
  4469. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  4470. 0:
  4471. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  4472. }
  4473. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4474. {
  4475. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4476. {
  4477. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  4478. 0:
  4479. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  4480. if(idxPeriod > 0)
  4481. {
  4482. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4483. {
  4484. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4485. }
  4486. }
  4487. }
  4488. }
  4489. }
  4490. else if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  4491. {
  4492. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4493. {
  4494. maxProfile.chargingSchedule[idxSchedule].duration = maxProfile.chargingSchedule[idxSchedule].duration;
  4495. }
  4496. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4497. {
  4498. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4499. {
  4500. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod;
  4501. if(idxPeriod > 0)
  4502. {
  4503. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4504. {
  4505. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4506. }
  4507. }
  4508. }
  4509. }
  4510. }
  4511. else
  4512. {
  4513. if(strstr((char*)maxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  4514. {
  4515. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4516. {
  4517. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4518. 0:
  4519. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4520. }
  4521. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4522. {
  4523. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4524. {
  4525. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4526. 0:
  4527. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4528. if(idxPeriod > 0)
  4529. {
  4530. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4531. {
  4532. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4533. }
  4534. }
  4535. }
  4536. }
  4537. }
  4538. else
  4539. {
  4540. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4541. {
  4542. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4543. 0:
  4544. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4545. }
  4546. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4547. {
  4548. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4549. {
  4550. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4551. 0:
  4552. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4553. if(idxPeriod > 0)
  4554. {
  4555. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4556. {
  4557. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4558. }
  4559. }
  4560. }
  4561. }
  4562. }
  4563. }
  4564. /*
  4565. DEBUG_INFO("MaxProfile after align.\n");
  4566. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  4567. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  4568. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  4569. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  4570. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  4571. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  4572. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  4573. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  4574. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  4575. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4576. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4577. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4578. {
  4579. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4580. {
  4581. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4582. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4583. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4584. }
  4585. }
  4586. DEBUG_INFO("------------------------------------\n");*/
  4587. }
  4588. // Find each profile period quantity
  4589. for(int idx=0;idx<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  4590. {
  4591. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  4592. limitMax = idx+1;
  4593. }
  4594. if(maxProfile.id != -1)
  4595. {
  4596. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4597. {
  4598. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  4599. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  4600. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  4601. {
  4602. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4603. {
  4604. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct ChargingSchedulePeriodType));
  4605. compositePeriodIdx++;
  4606. }
  4607. else
  4608. {
  4609. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct ChargingSchedulePeriodType));
  4610. }
  4611. }
  4612. }
  4613. }
  4614. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  4615. DEBUG_INFO("Schedule start: %s\n", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  4616. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.chargingSchedule[idxSchedule].duration);
  4617. DEBUG_INFO("Rate unit: %s\n", compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit);
  4618. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4619. {
  4620. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod >= 0)
  4621. {
  4622. compositeProfile.id = 1;
  4623. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  4624. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit);
  4625. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases);
  4626. }
  4627. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit == -1)
  4628. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit =0;
  4629. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod == -1)
  4630. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod =0;
  4631. }
  4632. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  4633. if(line)
  4634. free(line);
  4635. }
  4636. void checkCompositeSchedule(uint8_t evseId, uint32_t durationReq, struct ChargingProfileType *targetCompositeProfile, uint8_t idxSchedule, uint8_t isUnitA)
  4637. {
  4638. FILE *fp;
  4639. char profileFileName[128];
  4640. char *line = NULL;
  4641. size_t len = 0;
  4642. time_t CurrentTime;
  4643. struct tm *tmComposite;
  4644. struct ChargingProfileType maxProfile;
  4645. struct ChargingProfileType defaultTxProfile;
  4646. struct ChargingProfileType txProfile;
  4647. struct ChargingProfileType compositeProfile;
  4648. struct ChargingSchedulePeriodType tmpPeriod;
  4649. uint8_t limitMax=0;
  4650. uint8_t limitDef=0;
  4651. uint8_t limitTx=0;
  4652. int compositePeriodIdx = 0;
  4653. CurrentTime = time(NULL);
  4654. tmComposite=localtime(&CurrentTime);
  4655. 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);
  4656. if(isUnitA)
  4657. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4658. else
  4659. sprintf((char*)compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4660. compositeProfile.chargingSchedule[idxSchedule].duration = durationReq;
  4661. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4662. {
  4663. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4664. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4665. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4666. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4667. }
  4668. compositeProfile.id = 0;
  4669. compositeProfile.stackLevel = 99 ;
  4670. sprintf((char*)compositeProfile.chargingProfileKind ,ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]);
  4671. maxProfile.id = -1;
  4672. defaultTxProfile.id = -1;
  4673. txProfile.id = -1;
  4674. maxProfile.chargingSchedule[idxSchedule].duration = -1;
  4675. defaultTxProfile.chargingSchedule[idxSchedule].duration = -1;
  4676. txProfile.chargingSchedule[idxSchedule].duration = -1;
  4677. system("rm -f /tmp/*.json");
  4678. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  4679. /*
  4680. * Search valid charging profile
  4681. */
  4682. //DEBUG_INFO("====================================\n");
  4683. // Search tx profile
  4684. sprintf(profileFileName, "/tmp/TxProfile_%d_OCPP20.json", evseId);
  4685. if((access(profileFileName, F_OK))!=-1)
  4686. {
  4687. fp = fopen(profileFileName, "r");
  4688. while(getline(&line, &len, fp) != -1)
  4689. {
  4690. json_object *obj = NULL;
  4691. obj = json_tokener_parse(line);
  4692. if(is_error(obj))
  4693. {
  4694. DEBUG_ERROR("Parse txProfile from file error.\n");
  4695. }
  4696. else
  4697. {
  4698. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != txProfile.id) &&
  4699. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= txProfile.stackLevel)
  4700. )
  4701. {
  4702. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  4703. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4704. )
  4705. {
  4706. struct tm tmFrom, tmTo;
  4707. struct timeb tbFrom, tbTo;
  4708. 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) &&
  4709. (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))
  4710. {
  4711. tmFrom.tm_year -= 1900;
  4712. tmFrom.tm_mon -= 1;
  4713. tbFrom.time = mktime(&tmFrom);
  4714. tmTo.tm_year -= 1900;
  4715. tmTo.tm_mon -= 1;
  4716. tbTo.time = mktime(&tmTo);
  4717. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  4718. {
  4719. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4720. {
  4721. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4722. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4723. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4724. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4725. }
  4726. if(txProfile.id == -1)
  4727. DEBUG_INFO("TxProfile found.\n");
  4728. else
  4729. DEBUG_INFO("TxProfile updated.\n");
  4730. // Required item
  4731. txProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4732. txProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4733. sprintf((char*)txProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4734. if(isUnitA)
  4735. {
  4736. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4737. 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++)
  4738. {
  4739. 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"));
  4740. 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"));
  4741. /*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)
  4742. {
  4743. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4744. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4745. else
  4746. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4747. }
  4748. else
  4749. {
  4750. 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"));
  4751. }*/
  4752. 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")));
  4753. }
  4754. }
  4755. else
  4756. {
  4757. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4758. 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++)
  4759. {
  4760. 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"));
  4761. 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"));
  4762. /*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)
  4763. {
  4764. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4765. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4766. else
  4767. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4768. }
  4769. else
  4770. {
  4771. 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"));
  4772. }*/
  4773. 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));
  4774. }
  4775. }
  4776. // Optional item
  4777. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4778. {
  4779. sprintf((char*)txProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4780. }
  4781. else
  4782. {
  4783. sprintf((char*)txProfile.validFrom, " ");
  4784. }
  4785. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4786. {
  4787. sprintf((char*)txProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4788. }
  4789. else
  4790. {
  4791. sprintf((char*)txProfile.validTo, " ");
  4792. }
  4793. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4794. {
  4795. sprintf((char*)txProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4796. }
  4797. else
  4798. {
  4799. sprintf((char*)txProfile.recurrencyKind, " ");
  4800. }
  4801. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4802. {
  4803. sprintf((char*)txProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4804. }
  4805. else
  4806. {
  4807. sprintf((char*)txProfile.transactionId, " ");
  4808. }
  4809. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4810. {
  4811. 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"));
  4812. }
  4813. else
  4814. {
  4815. txProfile.chargingSchedule[idxSchedule].duration = 86400;
  4816. }
  4817. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4818. {
  4819. 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")));
  4820. }
  4821. else
  4822. {
  4823. sprintf((char*)txProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging ? compositeProfile.chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp));
  4824. }
  4825. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4826. {
  4827. 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"));
  4828. }
  4829. else
  4830. {
  4831. txProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4832. }
  4833. }
  4834. }
  4835. }
  4836. else
  4837. {
  4838. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4839. {
  4840. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4841. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4842. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4843. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4844. }
  4845. if(txProfile.id == -1)
  4846. DEBUG_INFO("TxProfile found.\n");
  4847. else
  4848. DEBUG_INFO("TxProfile updated.\n");
  4849. // Required item
  4850. txProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4851. txProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4852. sprintf((char*)txProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4853. if(isUnitA)
  4854. {
  4855. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4856. 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++)
  4857. {
  4858. 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"));
  4859. 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"));
  4860. /*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)
  4861. {
  4862. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4863. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4864. else
  4865. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4866. }
  4867. else
  4868. {
  4869. 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"));
  4870. }*/
  4871. 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")));
  4872. }
  4873. }
  4874. else
  4875. {
  4876. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4877. 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++)
  4878. {
  4879. 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"));
  4880. 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"));
  4881. /*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)
  4882. {
  4883. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  4884. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  4885. else
  4886. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  4887. }
  4888. else
  4889. {
  4890. 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"));
  4891. }*/
  4892. 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));
  4893. }
  4894. }
  4895. // Optional item
  4896. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4897. {
  4898. sprintf((char*)txProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4899. }
  4900. else
  4901. {
  4902. sprintf((char*)txProfile.validFrom, " ");
  4903. }
  4904. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4905. {
  4906. sprintf((char*)txProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4907. }
  4908. else
  4909. {
  4910. sprintf((char*)txProfile.validTo, " ");
  4911. }
  4912. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4913. {
  4914. sprintf((char*)txProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4915. }
  4916. else
  4917. {
  4918. sprintf((char*)txProfile.recurrencyKind, " ");
  4919. }
  4920. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4921. {
  4922. sprintf((char*)txProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4923. }
  4924. else
  4925. {
  4926. sprintf((char*)txProfile.transactionId, " ");
  4927. }
  4928. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  4929. {
  4930. 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"));
  4931. }
  4932. else
  4933. {
  4934. txProfile.chargingSchedule[idxSchedule].duration = 86400;
  4935. }
  4936. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  4937. {
  4938. 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")));
  4939. }
  4940. else
  4941. {
  4942. sprintf((char*)txProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging ? compositeProfile.chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp));
  4943. }
  4944. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  4945. {
  4946. 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"));
  4947. }
  4948. else
  4949. {
  4950. txProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4951. }
  4952. }
  4953. }
  4954. }
  4955. json_object_put(obj);
  4956. }
  4957. fclose(fp);
  4958. /*
  4959. if(txProfile.id != -1)
  4960. {
  4961. DEBUG_INFO("Profile ID: %d\n", txProfile.id);
  4962. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  4963. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  4964. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  4965. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  4966. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  4967. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.recurrencyKind);
  4968. DEBUG_INFO("Profile start schedule: %s\n", txProfile.chargingSchedule[idxSchedule].StartSchedule);
  4969. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.chargingSchedule[idxSchedule].Duration);
  4970. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4971. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4972. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4973. {
  4974. if(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4975. {
  4976. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4977. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4978. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4979. }
  4980. }
  4981. }
  4982. else
  4983. DEBUG_INFO("TxProfile not found.\n");*/
  4984. }
  4985. // Search default tx profile
  4986. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d_OCPP20.json", evseId);
  4987. if((access(profileFileName, F_OK))==-1)
  4988. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  4989. if((access(profileFileName, F_OK))!=-1)
  4990. {
  4991. fp = fopen(profileFileName, "r");
  4992. while(getline(&line, &len, fp) != -1)
  4993. {
  4994. json_object *obj = NULL;
  4995. obj = json_tokener_parse(line);
  4996. if(is_error(obj))
  4997. {
  4998. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  4999. }
  5000. else
  5001. {
  5002. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != defaultTxProfile.id) &&
  5003. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= defaultTxProfile.stackLevel)
  5004. )
  5005. {
  5006. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  5007. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  5008. )
  5009. {
  5010. struct tm tmFrom, tmTo;
  5011. struct timeb tbFrom, tbTo;
  5012. 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) &&
  5013. (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))
  5014. {
  5015. tmFrom.tm_year -= 1900;
  5016. tmFrom.tm_mon -= 1;
  5017. tbFrom.time = mktime(&tmFrom);
  5018. tmTo.tm_year -= 1900;
  5019. tmTo.tm_mon -= 1;
  5020. tbTo.time = mktime(&tmTo);
  5021. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  5022. {
  5023. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5024. {
  5025. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  5026. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  5027. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  5028. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  5029. }
  5030. if(defaultTxProfile.id == -1)
  5031. DEBUG_INFO("TxDefaultProfile found.\n");
  5032. else
  5033. DEBUG_INFO("TxDefaultProfile updated.\n");
  5034. // Required item
  5035. defaultTxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  5036. defaultTxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  5037. sprintf((char*)defaultTxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  5038. if(isUnitA)
  5039. {
  5040. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  5041. 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++)
  5042. {
  5043. 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"));
  5044. 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"));
  5045. /*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)
  5046. {
  5047. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5048. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5049. else
  5050. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5051. }
  5052. else
  5053. {
  5054. 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"));
  5055. }*/
  5056. 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")));
  5057. }
  5058. }
  5059. else
  5060. {
  5061. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  5062. 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++)
  5063. {
  5064. 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"));
  5065. 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"));
  5066. /*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)
  5067. {
  5068. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5069. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5070. else
  5071. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5072. }
  5073. else
  5074. {
  5075. 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"));
  5076. }*/
  5077. 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));
  5078. }
  5079. }
  5080. // Optional item
  5081. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  5082. {
  5083. sprintf((char*)defaultTxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  5084. }
  5085. else
  5086. {
  5087. sprintf((char*)defaultTxProfile.validFrom, " ");
  5088. }
  5089. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  5090. {
  5091. sprintf((char*)defaultTxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  5092. }
  5093. else
  5094. {
  5095. sprintf((char*)defaultTxProfile.validTo, " ");
  5096. }
  5097. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  5098. {
  5099. sprintf((char*)defaultTxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  5100. }
  5101. else
  5102. {
  5103. sprintf((char*)defaultTxProfile.recurrencyKind, " ");
  5104. }
  5105. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  5106. {
  5107. sprintf((char*)defaultTxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  5108. }
  5109. else
  5110. {
  5111. sprintf((char*)defaultTxProfile.transactionId, " ");
  5112. }
  5113. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  5114. {
  5115. 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"));
  5116. }
  5117. else
  5118. {
  5119. defaultTxProfile.chargingSchedule[idxSchedule].duration = 86400;
  5120. }
  5121. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  5122. {
  5123. 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")));
  5124. }
  5125. else
  5126. {
  5127. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging ? compositeProfile.chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp));
  5128. }
  5129. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  5130. {
  5131. 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"));
  5132. }
  5133. else
  5134. {
  5135. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  5136. }
  5137. }
  5138. }
  5139. }
  5140. else
  5141. {
  5142. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5143. {
  5144. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  5145. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  5146. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  5147. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  5148. }
  5149. if(defaultTxProfile.id == -1)
  5150. DEBUG_INFO("TxDefaultProfile found.\n");
  5151. else
  5152. DEBUG_INFO("TxDefaultProfile updated.\n");
  5153. // Required item
  5154. defaultTxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  5155. defaultTxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  5156. sprintf((char*)defaultTxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  5157. if(isUnitA)
  5158. {
  5159. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  5160. 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++)
  5161. {
  5162. 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"));
  5163. 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"));
  5164. /*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)
  5165. {
  5166. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5167. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5168. else
  5169. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5170. }
  5171. else
  5172. {
  5173. 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"));
  5174. }*/
  5175. 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")));
  5176. }
  5177. }
  5178. else
  5179. {
  5180. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  5181. 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++)
  5182. {
  5183. 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"));
  5184. 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"));
  5185. /*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)
  5186. {
  5187. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5188. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5189. else
  5190. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5191. }
  5192. else
  5193. {
  5194. 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"));
  5195. }*/
  5196. 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));
  5197. }
  5198. }
  5199. // Optional item
  5200. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  5201. {
  5202. sprintf((char*)defaultTxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  5203. }
  5204. else
  5205. {
  5206. sprintf((char*)defaultTxProfile.validFrom, " ");
  5207. }
  5208. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  5209. {
  5210. sprintf((char*)defaultTxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  5211. }
  5212. else
  5213. {
  5214. sprintf((char*)defaultTxProfile.validTo, " ");
  5215. }
  5216. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  5217. {
  5218. sprintf((char*)defaultTxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  5219. }
  5220. else
  5221. {
  5222. sprintf((char*)defaultTxProfile.recurrencyKind, " ");
  5223. }
  5224. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  5225. {
  5226. sprintf((char*)defaultTxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  5227. }
  5228. else
  5229. {
  5230. sprintf((char*)defaultTxProfile.transactionId, " ");
  5231. }
  5232. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  5233. {
  5234. 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"));
  5235. }
  5236. else
  5237. {
  5238. defaultTxProfile.chargingSchedule[idxSchedule].duration = 86400;
  5239. }
  5240. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  5241. {
  5242. 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")));
  5243. }
  5244. else
  5245. {
  5246. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging ? compositeProfile.chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp));
  5247. }
  5248. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  5249. {
  5250. 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"));
  5251. }
  5252. else
  5253. {
  5254. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  5255. }
  5256. }
  5257. }
  5258. }
  5259. json_object_put(obj);
  5260. }
  5261. fclose(fp);
  5262. /*
  5263. if(defaultTxProfile.id != -1)
  5264. {
  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", defaultTxProfile.chargingSchedule[idxSchedule].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. }
  5286. else
  5287. DEBUG_INFO("TxDefaultProfile not found.\n");
  5288. DEBUG_INFO("------------------------------------\n");*/
  5289. }
  5290. // Search max profile
  5291. sprintf(profileFileName, "/tmp/ChargingStationMaxProfile_OCPP20.json");
  5292. if((access(profileFileName, F_OK))!=-1)
  5293. {
  5294. fp = fopen(profileFileName, "r");
  5295. while(getline(&line, &len, fp) != -1)
  5296. {
  5297. json_object *obj = NULL;
  5298. obj = json_tokener_parse(line);
  5299. if(is_error(obj))
  5300. {
  5301. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  5302. }
  5303. else
  5304. {
  5305. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != maxProfile.id) &&
  5306. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= maxProfile.stackLevel)
  5307. )
  5308. {
  5309. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  5310. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  5311. )
  5312. {
  5313. struct tm tmFrom, tmTo;
  5314. struct timeb tbFrom, tbTo;
  5315. 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) &&
  5316. (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))
  5317. {
  5318. tmFrom.tm_year -= 1900;
  5319. tmFrom.tm_mon -= 1;
  5320. tbFrom.time = mktime(&tmFrom);
  5321. tmTo.tm_year -= 1900;
  5322. tmTo.tm_mon -= 1;
  5323. tbTo.time = mktime(&tmTo);
  5324. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  5325. {
  5326. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5327. {
  5328. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  5329. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  5330. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  5331. }
  5332. if(maxProfile.id == -1)
  5333. DEBUG_INFO("MaxProfile found.\n");
  5334. else
  5335. DEBUG_INFO("MaxProfile updated.\n");
  5336. // Required item
  5337. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  5338. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  5339. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  5340. if(isUnitA)
  5341. {
  5342. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  5343. 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++)
  5344. {
  5345. 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"));
  5346. 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"));
  5347. /*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)
  5348. {
  5349. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5350. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5351. else
  5352. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5353. }
  5354. else
  5355. {
  5356. 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"));
  5357. }*/
  5358. 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")));
  5359. }
  5360. }
  5361. else
  5362. {
  5363. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  5364. 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++)
  5365. {
  5366. 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"));
  5367. 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"));
  5368. /*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)
  5369. {
  5370. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5371. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5372. else
  5373. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5374. }
  5375. else
  5376. {
  5377. 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"));
  5378. }*/
  5379. 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));
  5380. }
  5381. }
  5382. // Optional item
  5383. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  5384. {
  5385. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  5386. }
  5387. else
  5388. {
  5389. sprintf((char*)maxProfile.validFrom, " ");
  5390. }
  5391. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  5392. {
  5393. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  5394. }
  5395. else
  5396. {
  5397. sprintf((char*)maxProfile.validTo, " ");
  5398. }
  5399. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  5400. {
  5401. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  5402. }
  5403. else
  5404. {
  5405. sprintf((char*)maxProfile.recurrencyKind, " ");
  5406. }
  5407. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  5408. {
  5409. sprintf((char*)maxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  5410. }
  5411. else
  5412. {
  5413. sprintf((char*)maxProfile.transactionId, " ");
  5414. }
  5415. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  5416. {
  5417. 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"));
  5418. }
  5419. else
  5420. {
  5421. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  5422. }
  5423. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  5424. {
  5425. 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")));
  5426. }
  5427. else
  5428. {
  5429. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging ? compositeProfile.chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp));
  5430. }
  5431. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  5432. {
  5433. 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"));
  5434. }
  5435. else
  5436. {
  5437. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  5438. }
  5439. }
  5440. }
  5441. }
  5442. else
  5443. {
  5444. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5445. {
  5446. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  5447. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  5448. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  5449. }
  5450. if(maxProfile.id == -1)
  5451. DEBUG_INFO("MaxProfile found.\n");
  5452. else
  5453. DEBUG_INFO("MaxProfile updated.\n");
  5454. // Required item
  5455. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  5456. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  5457. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  5458. if(isUnitA)
  5459. {
  5460. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  5461. 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++)
  5462. {
  5463. 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"));
  5464. 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"));
  5465. /*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)
  5466. {
  5467. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5468. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5469. else
  5470. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5471. }
  5472. else
  5473. {
  5474. 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"));
  5475. }*/
  5476. 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")));
  5477. }
  5478. }
  5479. else
  5480. {
  5481. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  5482. 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++)
  5483. {
  5484. 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"));
  5485. 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"));
  5486. /*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)
  5487. {
  5488. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A')
  5489. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='D') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')?3:1);
  5490. else
  5491. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 1;
  5492. }
  5493. else
  5494. {
  5495. 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"));
  5496. }*/
  5497. 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));
  5498. }
  5499. }
  5500. // Optional item
  5501. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  5502. {
  5503. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  5504. }
  5505. else
  5506. {
  5507. sprintf((char*)maxProfile.validFrom, " ");
  5508. }
  5509. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  5510. {
  5511. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  5512. }
  5513. else
  5514. {
  5515. sprintf((char*)maxProfile.validTo, " ");
  5516. }
  5517. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  5518. {
  5519. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  5520. }
  5521. else
  5522. {
  5523. sprintf((char*)maxProfile.recurrencyKind, " ");
  5524. }
  5525. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  5526. {
  5527. sprintf((char*)maxProfile.transactionId,"%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  5528. }
  5529. else
  5530. {
  5531. sprintf((char*)maxProfile.transactionId, " ");
  5532. }
  5533. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "duration") != NULL)
  5534. {
  5535. 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"));
  5536. }
  5537. else
  5538. {
  5539. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  5540. }
  5541. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "startSchedule") != NULL)
  5542. {
  5543. 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")));
  5544. }
  5545. else
  5546. {
  5547. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging ? compositeProfile.chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp));
  5548. }
  5549. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), 0), "minChargingRate") != NULL)
  5550. {
  5551. 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"));
  5552. }
  5553. else
  5554. {
  5555. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  5556. }
  5557. }
  5558. }
  5559. }
  5560. json_object_put(obj);
  5561. }
  5562. fclose(fp);
  5563. /*
  5564. if(maxProfile.id !=-1)
  5565. {
  5566. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  5567. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  5568. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  5569. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  5570. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  5571. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  5572. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  5573. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.chargingSchedule[idxSchedule].StartSchedule);
  5574. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  5575. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5576. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5577. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5578. {
  5579. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5580. {
  5581. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5582. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5583. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5584. }
  5585. }
  5586. }
  5587. else
  5588. DEBUG_INFO("MaxProfile not found.\n");
  5589. DEBUG_INFO("------------------------------------\n");*/
  5590. }
  5591. /*
  5592. * Align found profile start schedule & periods
  5593. */
  5594. //DEBUG_INFO("====================================\n");
  5595. /*
  5596. // For local test usage, force modify found profile start schedule info
  5597. 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);
  5598. 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);
  5599. 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);
  5600. */
  5601. if(txProfile.id != -1)
  5602. {
  5603. if(strstr((char*)txProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  5604. {
  5605. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  5606. {
  5607. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5608. 0:
  5609. (txProfile.chargingSchedule[idxSchedule].duration-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5610. }
  5611. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5612. {
  5613. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5614. {
  5615. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5616. 0:
  5617. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5618. if(idxPeriod > 0)
  5619. {
  5620. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5621. {
  5622. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5623. }
  5624. }
  5625. }
  5626. }
  5627. }
  5628. else if(strstr((char*)txProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  5629. {
  5630. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  5631. {
  5632. txProfile.chargingSchedule[idxSchedule].duration = !cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging?txProfile.chargingSchedule[idxSchedule].duration:((txProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5633. 0:
  5634. (txProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5635. }
  5636. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5637. {
  5638. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5639. {
  5640. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = !cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging?txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod:((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5641. 0:
  5642. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5643. if(idxPeriod > 0)
  5644. {
  5645. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5646. {
  5647. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5648. }
  5649. }
  5650. }
  5651. }
  5652. }
  5653. else
  5654. {
  5655. if(strstr((char*)txProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  5656. {
  5657. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  5658. {
  5659. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5660. 0:
  5661. (txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5662. }
  5663. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5664. {
  5665. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5666. {
  5667. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5668. 0:
  5669. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5670. if(idxPeriod > 0)
  5671. {
  5672. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5673. {
  5674. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5675. }
  5676. }
  5677. }
  5678. }
  5679. }
  5680. else
  5681. {
  5682. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  5683. {
  5684. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5685. 0:
  5686. (txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5687. }
  5688. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5689. {
  5690. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5691. {
  5692. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5693. 0:
  5694. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5695. if(idxPeriod > 0)
  5696. {
  5697. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5698. {
  5699. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5700. }
  5701. }
  5702. }
  5703. }
  5704. }
  5705. }
  5706. /*
  5707. DEBUG_INFO("txProfile after align.\n");
  5708. DEBUG_INFO("Profile ID: %d\n", txProfile.id);
  5709. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  5710. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  5711. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  5712. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  5713. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  5714. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.recurrencyKind);
  5715. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  5716. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.chargingSchedule[idxSchedule].Duration);
  5717. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5718. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5719. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5720. {
  5721. if(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5722. {
  5723. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5724. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5725. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5726. }
  5727. }*/
  5728. }
  5729. if(defaultTxProfile.id != -1)
  5730. {
  5731. if(strstr((char*)defaultTxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  5732. {
  5733. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  5734. {
  5735. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5736. 0:
  5737. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5738. }
  5739. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5740. {
  5741. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5742. {
  5743. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5744. 0:
  5745. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5746. if(idxPeriod > 0)
  5747. {
  5748. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5749. {
  5750. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5751. }
  5752. }
  5753. }
  5754. }
  5755. }
  5756. else if(strstr((char*)defaultTxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  5757. {
  5758. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  5759. {
  5760. defaultTxProfile.chargingSchedule[idxSchedule].duration = !cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging?defaultTxProfile.chargingSchedule[idxSchedule].duration:((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5761. 0:
  5762. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5763. }
  5764. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5765. {
  5766. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5767. {
  5768. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = !cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging?defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod:((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5769. 0:
  5770. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5771. if(idxPeriod > 0)
  5772. {
  5773. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5774. {
  5775. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5776. }
  5777. }
  5778. }
  5779. }
  5780. }
  5781. else
  5782. {
  5783. if(strstr((char*)defaultTxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  5784. {
  5785. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  5786. {
  5787. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5788. 0:
  5789. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5790. }
  5791. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5792. {
  5793. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5794. {
  5795. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5796. 0:
  5797. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5798. if(idxPeriod > 0)
  5799. {
  5800. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5801. {
  5802. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5803. }
  5804. }
  5805. }
  5806. }
  5807. }
  5808. else
  5809. {
  5810. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  5811. {
  5812. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5813. 0:
  5814. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5815. }
  5816. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5817. {
  5818. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5819. {
  5820. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5821. 0:
  5822. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5823. if(idxPeriod > 0)
  5824. {
  5825. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5826. {
  5827. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5828. }
  5829. }
  5830. }
  5831. }
  5832. }
  5833. }
  5834. /*
  5835. DEBUG_INFO("defaultTxProfile after align.\n");
  5836. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.id);
  5837. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  5838. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  5839. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  5840. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  5841. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  5842. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.recurrencyKind);
  5843. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  5844. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.chargingSchedule[idxSchedule].Duration);
  5845. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5846. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5847. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5848. {
  5849. if(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5850. {
  5851. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5852. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5853. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5854. }
  5855. }
  5856. DEBUG_INFO("------------------------------------\n");*/
  5857. }
  5858. if(maxProfile.id != -1)
  5859. {
  5860. if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  5861. {
  5862. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5863. {
  5864. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5865. 0:
  5866. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5867. }
  5868. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5869. {
  5870. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5871. {
  5872. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5873. 0:
  5874. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5875. if(idxPeriod > 0)
  5876. {
  5877. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5878. {
  5879. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5880. }
  5881. }
  5882. }
  5883. }
  5884. }
  5885. else if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  5886. {
  5887. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5888. {
  5889. maxProfile.chargingSchedule[idxSchedule].duration = !cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging?maxProfile.chargingSchedule[idxSchedule].duration:((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5890. 0:
  5891. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[9].startSchedule)));
  5892. }
  5893. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5894. {
  5895. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5896. {
  5897. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = !cpinitateMsg.bits[(evseId==0?0:evseId-1)].isOnCharging?maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod:((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule))<0?
  5898. 0:
  5899. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(evseId==0?0:evseId-1)].timestamp, compositeProfile.chargingSchedule[idxSchedule].startSchedule)));
  5900. if(idxPeriod > 0)
  5901. {
  5902. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5903. {
  5904. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5905. }
  5906. }
  5907. }
  5908. }
  5909. }
  5910. else
  5911. {
  5912. if(strstr((char*)maxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  5913. {
  5914. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5915. {
  5916. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5917. 0:
  5918. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5919. }
  5920. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5921. {
  5922. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5923. {
  5924. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  5925. 0:
  5926. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, FALSE)));
  5927. if(idxPeriod > 0)
  5928. {
  5929. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5930. {
  5931. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5932. }
  5933. }
  5934. }
  5935. }
  5936. }
  5937. else
  5938. {
  5939. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  5940. {
  5941. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5942. 0:
  5943. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5944. }
  5945. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5946. {
  5947. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  5948. {
  5949. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  5950. 0:
  5951. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile.chargingSchedule[idxSchedule].startSchedule, TRUE)));
  5952. if(idxPeriod > 0)
  5953. {
  5954. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  5955. {
  5956. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  5957. }
  5958. }
  5959. }
  5960. }
  5961. }
  5962. }
  5963. /*
  5964. DEBUG_INFO("MaxProfile after align.\n");
  5965. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  5966. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  5967. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  5968. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  5969. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  5970. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  5971. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  5972. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile.ChargingSchedule.StartSchedule);
  5973. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  5974. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  5975. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  5976. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  5977. {
  5978. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  5979. {
  5980. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  5981. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  5982. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  5983. }
  5984. }
  5985. DEBUG_INFO("------------------------------------\n");*/
  5986. }
  5987. /*
  5988. * Merge to conposite schedule
  5989. */
  5990. //DEBUG_INFO("====================================\n");
  5991. // Find each profile period quantity
  5992. for(int idx=0;idx<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  5993. {
  5994. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  5995. limitMax = idx+1;
  5996. }
  5997. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  5998. {
  5999. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  6000. limitDef = idx+1;
  6001. }
  6002. for(int idx=0;idx<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  6003. {
  6004. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  6005. limitTx = idx+1;
  6006. }
  6007. // TxProfile found, composite schedule based on it
  6008. if(txProfile.id != -1)
  6009. {
  6010. compositeProfile.chargingSchedule[idxSchedule].duration = txProfile.chargingSchedule[idxSchedule].duration;
  6011. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  6012. {
  6013. if((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit != -1) &&
  6014. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod < durationReq) &&
  6015. (txProfile.chargingSchedule[idxSchedule].duration > 0))
  6016. {
  6017. if(maxProfile.id != -1)
  6018. {
  6019. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  6020. {
  6021. if((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod))
  6022. {
  6023. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  6024. {
  6025. tmpPeriod.startPeriod = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod;
  6026. tmpPeriod.numberPhases = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].numberPhases;
  6027. 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);
  6028. }
  6029. else
  6030. {
  6031. tmpPeriod.startPeriod = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod;
  6032. tmpPeriod.numberPhases = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].numberPhases;
  6033. tmpPeriod.limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit;
  6034. }
  6035. }
  6036. if(idxMaxPeriod == (limitMax-1))
  6037. {
  6038. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  6039. {
  6040. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6041. {
  6042. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6043. compositePeriodIdx++;
  6044. }
  6045. else
  6046. {
  6047. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6048. }
  6049. }
  6050. }
  6051. }
  6052. }
  6053. else
  6054. {
  6055. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6056. {
  6057. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod],sizeof(struct ChargingSchedulePeriodType));
  6058. compositePeriodIdx++;
  6059. }
  6060. else
  6061. {
  6062. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod],sizeof(struct ChargingSchedulePeriodType));
  6063. }
  6064. }
  6065. }
  6066. if(idxTxPeriod == (limitTx-1))
  6067. {
  6068. if(defaultTxProfile.id != -1)
  6069. {
  6070. compositeProfile.chargingSchedule[idxSchedule].duration = (defaultTxProfile.chargingSchedule[idxSchedule].duration>compositeProfile.chargingSchedule[idxSchedule].duration)?defaultTxProfile.chargingSchedule[idxSchedule].duration:compositeProfile.chargingSchedule[idxSchedule].duration;
  6071. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  6072. {
  6073. if((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod + (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod))) &&
  6074. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod < durationReq) &&
  6075. (defaultTxProfile.chargingSchedule[idxSchedule].duration>0))
  6076. {
  6077. if(maxProfile.id != -1)
  6078. {
  6079. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  6080. {
  6081. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod)
  6082. {
  6083. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  6084. {
  6085. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  6086. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  6087. 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);
  6088. }
  6089. else
  6090. {
  6091. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  6092. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  6093. tmpPeriod.limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit;
  6094. }
  6095. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  6096. {
  6097. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6098. {
  6099. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6100. compositePeriodIdx++;
  6101. }
  6102. else
  6103. {
  6104. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6105. }
  6106. }
  6107. // Delete duplicate period
  6108. if(compositePeriodIdx > 1)
  6109. {
  6110. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  6111. {
  6112. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  6113. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  6114. compositePeriodIdx -= 1;
  6115. }
  6116. }
  6117. }
  6118. else
  6119. {
  6120. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6121. {
  6122. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6123. compositePeriodIdx++;
  6124. }
  6125. else
  6126. {
  6127. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6128. }
  6129. break;
  6130. }
  6131. }
  6132. }
  6133. else
  6134. {
  6135. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6136. {
  6137. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6138. compositePeriodIdx++;
  6139. }
  6140. else
  6141. {
  6142. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6143. }
  6144. }
  6145. }
  6146. }
  6147. }
  6148. }
  6149. }
  6150. }
  6151. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  6152. else if(defaultTxProfile.id != -1)
  6153. {
  6154. compositeProfile.chargingSchedule[idxSchedule].duration = defaultTxProfile.chargingSchedule[idxSchedule].duration;
  6155. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  6156. {
  6157. if((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit != -1) &&
  6158. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod < durationReq) &&
  6159. (defaultTxProfile.chargingSchedule[idxSchedule].duration > 0))
  6160. {
  6161. if(maxProfile.id != -1)
  6162. {
  6163. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  6164. {
  6165. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod)
  6166. {
  6167. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  6168. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  6169. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  6170. {
  6171. 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);
  6172. }
  6173. else
  6174. {
  6175. tmpPeriod.limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit;
  6176. }
  6177. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  6178. {
  6179. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6180. {
  6181. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6182. compositePeriodIdx++;
  6183. }
  6184. else
  6185. {
  6186. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6187. }
  6188. }
  6189. // Delete duplicate period
  6190. if(compositePeriodIdx > 1)
  6191. {
  6192. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  6193. {
  6194. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  6195. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  6196. compositePeriodIdx -= 1;
  6197. }
  6198. }
  6199. }
  6200. else
  6201. {
  6202. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6203. {
  6204. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6205. compositePeriodIdx++;
  6206. }
  6207. else
  6208. {
  6209. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6210. }
  6211. break;
  6212. }
  6213. }
  6214. }
  6215. else
  6216. {
  6217. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6218. {
  6219. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6220. compositePeriodIdx++;
  6221. }
  6222. else
  6223. {
  6224. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  6225. }
  6226. }
  6227. }
  6228. }
  6229. }
  6230. // Fill other period by MaxProfile
  6231. if(maxProfile.id != -1)
  6232. {
  6233. if(compositePeriodIdx==0)
  6234. {
  6235. compositeProfile.chargingSchedule[idxSchedule].duration = maxProfile.chargingSchedule[idxSchedule].duration;
  6236. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  6237. {
  6238. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  6239. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  6240. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  6241. {
  6242. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  6243. {
  6244. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  6245. compositePeriodIdx++;
  6246. }
  6247. else
  6248. {
  6249. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  6250. }
  6251. }
  6252. }
  6253. }
  6254. else
  6255. {
  6256. int lastCompositePeriodIdx = compositePeriodIdx;
  6257. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  6258. {
  6259. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  6260. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  6261. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  6262. {
  6263. if((maxProfile.chargingSchedule[idxSchedule].duration >= compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod))
  6264. {
  6265. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit > compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[lastCompositePeriodIdx-1].limit)
  6266. {
  6267. tmpPeriod.startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod;
  6268. tmpPeriod.numberPhases = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].numberPhases;
  6269. tmpPeriod.limit = compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[lastCompositePeriodIdx-1].limit;
  6270. }
  6271. else
  6272. {
  6273. tmpPeriod.startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod;
  6274. tmpPeriod.numberPhases = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].numberPhases;
  6275. tmpPeriod.limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit;
  6276. }
  6277. }
  6278. if(tmpPeriod.limit != -1)
  6279. {
  6280. if(tmpPeriod.limit != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx-1)].limit)
  6281. {
  6282. if(tmpPeriod.startPeriod != compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx-1)].startPeriod)
  6283. {
  6284. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6285. compositePeriodIdx++;
  6286. }
  6287. else
  6288. {
  6289. memcpy(&compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  6290. }
  6291. }
  6292. // Delete duplicate period
  6293. if(compositePeriodIdx > 1)
  6294. {
  6295. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  6296. {
  6297. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  6298. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  6299. compositePeriodIdx -= 1;
  6300. }
  6301. }
  6302. }
  6303. }
  6304. }
  6305. }
  6306. }
  6307. if(compositeProfile.chargingSchedule[idxSchedule].duration < durationReq)
  6308. {
  6309. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  6310. {
  6311. if((idxPeriod >= 0) && (compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod == -1))
  6312. {
  6313. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = compositeProfile.chargingSchedule[idxSchedule].duration;
  6314. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (isUnitA==TRUE)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:modelnameInfo.ratedPower;
  6315. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].numberPhases;
  6316. DEBUG_INFO(">>> Adding startPeriod because the duration of the final schedule is shorter than requested duration.\n");
  6317. DEBUG_INFO("Add Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  6318. DEBUG_INFO("Add Period-%02d limit: %f\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit);
  6319. DEBUG_INFO("Add Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases);
  6320. DEBUG_INFO("------------------------------------------------\n");
  6321. break;
  6322. }
  6323. }
  6324. }
  6325. compositeProfile.chargingSchedule[idxSchedule].duration = durationReq;
  6326. DEBUG_INFO("Connector-%d composite schedule ready.\n", evseId);
  6327. DEBUG_INFO("Schedule start: %s\n", compositeProfile.chargingSchedule[idxSchedule].startSchedule);
  6328. DEBUG_INFO("Schedule duration: %d\n", compositeProfile.chargingSchedule[idxSchedule].duration);
  6329. DEBUG_INFO("Rate unit: %s\n", compositeProfile.chargingSchedule[idxSchedule].chargingRateUnit);
  6330. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  6331. {
  6332. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod >= 0)
  6333. {
  6334. compositeProfile.id = 1;
  6335. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  6336. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit);
  6337. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases);
  6338. }
  6339. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit == -1)
  6340. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit =0;
  6341. if(compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod == -1)
  6342. compositeProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod =0;
  6343. }
  6344. memcpy(targetCompositeProfile, &compositeProfile, sizeof(struct StructChargingProfile));
  6345. if(line)
  6346. free(line);
  6347. ShmOCPP20Data->CSUMsg.bits[(evseId==0?0:evseId-1)].ChargingProfileConf = ON;
  6348. }
  6349. //==========================================
  6350. // Init all share memory
  6351. //==========================================
  6352. int InitShareMemory()
  6353. {
  6354. int result = PASS;
  6355. int MeterSMId;
  6356. //creat ShmSysConfigAndInfo
  6357. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  6358. {
  6359. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  6360. result = FAIL;
  6361. }
  6362. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  6363. {
  6364. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  6365. result = FAIL;
  6366. }
  6367. else
  6368. {}
  6369. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  6370. {
  6371. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  6372. result = FAIL;
  6373. }
  6374. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  6375. {
  6376. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  6377. result = FAIL;
  6378. }
  6379. else
  6380. {}
  6381. //creat ShmPsuData
  6382. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  6383. {
  6384. DEBUG_ERROR("shmget ShmPsuData NG\n");
  6385. result = FAIL;
  6386. }
  6387. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  6388. {
  6389. DEBUG_ERROR("shmat ShmPsuData NG\n");
  6390. result = FAIL;
  6391. }
  6392. else
  6393. {}
  6394. //creat ShmOCPP20Data
  6395. if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), 0777)) < 0)
  6396. {
  6397. DEBUG_ERROR("shmget ShmOCPP20Data NG\n");
  6398. result = FAIL;
  6399. }
  6400. else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  6401. {
  6402. DEBUG_ERROR("shmat ShmOCPP20Data NG\n");
  6403. result = FAIL;
  6404. }
  6405. else
  6406. {}
  6407. /****************************** For Initial Settings************************************************/
  6408. /*
  6409. DEBUG_INFO("Authorize_20 size: %d\n", sizeof(struct Authorize_20));
  6410. DEBUG_INFO("BootNotification_20 size: %d\n", sizeof(struct BootNotification_20));
  6411. DEBUG_INFO("CancelReservation_20 size: %d\n", sizeof(struct CancelReservation_20));
  6412. DEBUG_INFO("CertificateSigned_20 size: %d\n", sizeof(struct CertificateSigned_20));
  6413. DEBUG_INFO("ChangeAvailability_20 size: %d\n", sizeof(struct ChangeAvailability_20));
  6414. DEBUG_INFO("ClearCache_20 size: %d\n", sizeof(struct ClearCache_20));
  6415. DEBUG_INFO("ClearChargingProfile_20 size: %d\n", sizeof(struct ClearChargingProfile_20));
  6416. DEBUG_INFO("ClearDisplayMessage_20 size: %d\n", sizeof(struct ClearDisplayMessage_20));
  6417. DEBUG_INFO("ClearedChargingLimit_20 size: %d\n", sizeof(struct ClearedChargingLimit_20));
  6418. DEBUG_INFO("ClearVariableMonitoring_20 size: %d\n", sizeof(struct ClearVariableMonitoring_20));
  6419. DEBUG_INFO("CostUpdated_20 size: %d\n", sizeof(struct CostUpdated_20));
  6420. DEBUG_INFO("CustomerInformation_20 size: %d\n", sizeof(struct CustomerInformation_20));
  6421. DEBUG_INFO("DeleteCertificate_20 size: %d\n", sizeof(struct DeleteCertificate_20));
  6422. DEBUG_INFO("FirmwareStatusNotification_20 size: %d\n", sizeof(struct FirmwareStatusNotification_20));
  6423. DEBUG_INFO("Get15118EVCertificate_20 size: %d\n", sizeof(struct Get15118EVCertificate_20));
  6424. DEBUG_INFO("GetBaseReport_20 size: %d\n", sizeof(struct GetBaseReport_20));
  6425. DEBUG_INFO("GetCertificateStatus_20 size: %d\n", sizeof(struct GetCertificateStatus_20));
  6426. DEBUG_INFO("GetChargingProfiles_20 size: %d\n", sizeof(struct GetChargingProfiles_20));
  6427. DEBUG_INFO("GetCompositeSchedule_20 size: %d\n", sizeof(struct GetCompositeSchedule_20));
  6428. DEBUG_INFO("GetDisplayMessages_20 size: %d\n", sizeof(struct GetDisplayMessages_20));
  6429. DEBUG_INFO("GetInstalledCertificateIds_20 size: %d\n", sizeof(struct GetInstalledCertificateIds_20));
  6430. DEBUG_INFO("GetLog_20 size: %d\n", sizeof(struct GetLog_20));
  6431. DEBUG_INFO("GetMonitoringReport_20 size: %d\n", sizeof(struct GetMonitoringReport_20));
  6432. DEBUG_INFO("GetReport_20 size: %d\n", sizeof(struct GetReport_20));
  6433. DEBUG_INFO("GetTransactionStatus_20 size: %d\n", sizeof(struct GetTransactionStatus_20));
  6434. DEBUG_INFO("GetVariables_20 size: %d\n", sizeof(struct GetVariables_20));
  6435. DEBUG_INFO("InstallCertificate_20 size: %d\n", sizeof(struct InstallCertificate_20));
  6436. DEBUG_INFO("LogStatusNotification_20 size: %d\n", sizeof(struct LogStatusNotification_20));
  6437. DEBUG_INFO("MeterValues_20 size: %d\n", sizeof(struct MeterValues_20));
  6438. DEBUG_INFO("NotifyChargingLimit_20 size: %d\n", sizeof(struct NotifyChargingLimit_20));
  6439. DEBUG_INFO("NotifyCustomerInformation_20 size: %d\n", sizeof(struct NotifyCustomerInformation_20));
  6440. DEBUG_INFO("NotifyDisplayMessages_20 size: %d\n", sizeof(struct NotifyDisplayMessages_20));
  6441. DEBUG_INFO("NotifyEVChargingNeeds_20 size: %d\n", sizeof(struct NotifyEVChargingNeeds_20));
  6442. DEBUG_INFO("NotifyEVChargingSchedule_20 size: %d\n", sizeof(struct NotifyEVChargingSchedule_20));
  6443. DEBUG_INFO("NotifyEvent_20 size: %d\n", sizeof(struct NotifyEvent_20));
  6444. DEBUG_INFO("NotifyMonitoringReport_20 size: %d\n", sizeof(struct NotifyMonitoringReport_20));
  6445. DEBUG_INFO("NotifyReport_20 size: %d\n", sizeof(struct NotifyReport_20));
  6446. DEBUG_INFO("PublishFirmware_20 size: %d\n", sizeof(struct PublishFirmware_20));
  6447. DEBUG_INFO("PublishFirmwareStatusNotification_20 size: %d\n", sizeof(struct PublishFirmwareStatusNotification_20));
  6448. DEBUG_INFO("ReportChargingProfiles_20 size: %d\n", sizeof(struct ReportChargingProfiles_20));
  6449. DEBUG_INFO("RequestStartTransaction_20 size: %d\n", sizeof(struct RequestStartTransaction_20));
  6450. DEBUG_INFO("RequestStopTransaction_20 size: %d\n", sizeof(struct RequestStopTransaction_20));
  6451. DEBUG_INFO("ReservationStatusUpdate_20 size: %d\n", sizeof(struct ReservationStatusUpdate_20));
  6452. DEBUG_INFO("ReserveNow_20 size: %d\n", sizeof(struct ReserveNow_20));
  6453. DEBUG_INFO("Reset_20 size: %d\n", sizeof(struct Reset_20));
  6454. DEBUG_INFO("SecurityEventNotification_20 size: %d\n", sizeof(struct SecurityEventNotification_20));
  6455. DEBUG_INFO("SendLocalList_20 size: %d\n", sizeof(struct SendLocalList_20));
  6456. DEBUG_INFO("SetChargingProfile_20 size: %d\n", sizeof(struct SetChargingProfile_20));
  6457. DEBUG_INFO("SetDisplayMessage_20 size: %d\n", sizeof(struct SetDisplayMessage_20));
  6458. DEBUG_INFO("SetMonitoringBase_20 size: %d\n", sizeof(struct SetMonitoringBase_20));
  6459. DEBUG_INFO("SetMonitoringLevel_20 size: %d\n", sizeof(struct SetMonitoringLevel_20));
  6460. DEBUG_INFO("SetNetworkProfile_20 size: %d\n", sizeof(struct SetNetworkProfile_20));
  6461. DEBUG_INFO("SetVariableMonitoring_20 size: %d\n", sizeof(struct SetVariableMonitoring_20));
  6462. DEBUG_INFO("SetVariables_20 size: %d\n", sizeof(struct SetVariables_20));
  6463. DEBUG_INFO("SignCertificate_20 size: %d\n", sizeof(struct SignCertificate_20));
  6464. DEBUG_INFO("StatusNotification_20 size: %d\n", sizeof(struct StatusNotification_20));
  6465. DEBUG_INFO("TransactionEvent_20 size: %d\n", sizeof(struct TransactionEvent_20));
  6466. DEBUG_INFO("TriggerMessage_20 size: %d\n", sizeof(struct TriggerMessage_20));
  6467. DEBUG_INFO("UnlockConnector_20 size: %d\n", sizeof(struct UnlockConnector_20));
  6468. DEBUG_INFO("UnpublishFirmware_20 size: %d\n", sizeof(struct UnpublishFirmware_20));
  6469. DEBUG_INFO("UpdateFirmware_20 size: %d\n", sizeof(struct UpdateFirmware_20));
  6470. DEBUG_INFO("ChargingProfileType size: %d\n", sizeof(struct ChargingProfileType));
  6471. */
  6472. return result;
  6473. }
  6474. int ProcessShareMemory()
  6475. {
  6476. int result = PASS;
  6477. if(InitShareMemory() == FAIL)
  6478. {
  6479. DEBUG_ERROR("InitShareMemory NG\n");
  6480. if(ShmStatusCodeData!=NULL)
  6481. {
  6482. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  6483. }
  6484. result = FAIL;
  6485. }
  6486. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  6487. {
  6488. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  6489. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6490. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  6491. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  6492. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  6493. ) // 'D' means DC
  6494. {
  6495. // DO series
  6496. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  6497. {
  6498. gunTotalNumber += 1;
  6499. gunType[gun_index] = GUN_TYPE_DO;
  6500. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6501. {
  6502. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == gun_index)
  6503. {
  6504. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6505. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6506. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption);
  6507. }
  6508. }
  6509. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  6510. {
  6511. case Gun_Type_Chademo:
  6512. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  6513. for(int index = 0; index < CHAdeMO_QUANTITY; index++)
  6514. {
  6515. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == gun_index)
  6516. {
  6517. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6518. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6519. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption);
  6520. }
  6521. }
  6522. break;
  6523. case Gun_Type_CCS_2:
  6524. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  6525. for (int index = 0; index < CCS_QUANTITY; index++)
  6526. {
  6527. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == gun_index)
  6528. {
  6529. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6530. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6531. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption);
  6532. }
  6533. }
  6534. break;
  6535. case Gun_Type_GB:
  6536. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  6537. for (int index = 0; index < GB_QUANTITY; index++)
  6538. {
  6539. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == gun_index)
  6540. {
  6541. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6542. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6543. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption);
  6544. }
  6545. }
  6546. break;
  6547. case Gun_Type_AC:
  6548. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  6549. for (int index = 0; index < AC_QUANTITY; index++)
  6550. {
  6551. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == gun_index)
  6552. {
  6553. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6554. periousClockPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6555. DEBUG_INFO("Gun-%02d PowerConsumption: %.3f\n", gun_index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption);
  6556. }
  6557. }
  6558. break;
  6559. default:
  6560. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  6561. break;
  6562. }
  6563. }
  6564. }
  6565. else
  6566. {
  6567. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  6568. {
  6569. gunTotalNumber += 1;
  6570. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  6571. {
  6572. case Gun_Type_Chademo:
  6573. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  6574. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  6575. break;
  6576. case Gun_Type_CCS_2:
  6577. gunType[gun_index] = GUN_TYPE_CCS;
  6578. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  6579. break;
  6580. case Gun_Type_GB:
  6581. gunType[gun_index] = GUN_TYPE_GBT;
  6582. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  6583. break;
  6584. case Gun_Type_AC:
  6585. gunType[gun_index] = GUN_TYPE_AC;
  6586. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  6587. break;
  6588. default:
  6589. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  6590. break;
  6591. }
  6592. }
  6593. }
  6594. }
  6595. else
  6596. {
  6597. DEBUG_ERROR("Model name parsing fail.\n");
  6598. result = FAIL;
  6599. }
  6600. if(result != PASS)sleep(5);
  6601. return result;
  6602. }
  6603. //---------------------common routine---------------------------//
  6604. void checkNetworkProfile(void)
  6605. {
  6606. memcpy(ShmOCPP20Data->OcppServerURL, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmOCPP20Data->OcppServerURL));
  6607. json_object *priority;
  6608. priority = json_tokener_parse((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value);
  6609. if(!is_error(priority))
  6610. {
  6611. for(uint8_t idxPriority=0;idxPriority<json_object_array_length(priority);idxPriority++)
  6612. {
  6613. for(uint8_t idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile);idx++)
  6614. {
  6615. if((ShmOCPP20Data->NetworkConnectionProfile[idx].slot == json_object_get_int(json_object_array_get_idx(priority, idxPriority))) &&
  6616. (strlen((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl) > 0) &&
  6617. (ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount < 3))
  6618. {
  6619. memcpy(ShmOCPP20Data->OcppServerURL, ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl));
  6620. ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount++;
  6621. break;
  6622. }
  6623. }
  6624. }
  6625. }
  6626. json_object_put(priority);
  6627. DEBUG_INFO("Get network profile URL: %s\n", ShmOCPP20Data->OcppServerURL);
  6628. }
  6629. void checkRemoteStart(uint8_t evseIdx)
  6630. {
  6631. uint8_t tempIndex;
  6632. int isAllowStart = TRUE;
  6633. char cmdBuf[512];
  6634. //check Transaction active
  6635. if(gunType[evseIdx-1] == GUN_TYPE_CHAdeMO)
  6636. {
  6637. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6638. {
  6639. tempIndex = ((evseIdx-1) == 2) ? 1: 0;
  6640. }
  6641. else
  6642. {
  6643. tempIndex = (evseIdx-1);
  6644. }
  6645. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6646. {
  6647. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  6648. {
  6649. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseIdx-1].idToken.idToken) == 0))
  6650. {
  6651. //Reserved
  6652. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  6653. }
  6654. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseIdx-1].idToken.idToken) != 0))
  6655. {
  6656. //Reserved
  6657. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  6658. isAllowStart = FALSE;
  6659. }
  6660. else
  6661. {
  6662. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6663. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6664. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6665. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6666. {
  6667. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  6668. isAllowStart = FALSE;
  6669. }
  6670. }//END FOR ELSE
  6671. }
  6672. }// END FOR CHAdeMO_QUANTITY
  6673. }
  6674. else if(gunType[evseIdx-1] == GUN_TYPE_CCS)
  6675. {
  6676. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6677. {
  6678. tempIndex = ((evseIdx-1) == 2) ? 1: 0;
  6679. }
  6680. else
  6681. {
  6682. tempIndex = (evseIdx-1);
  6683. }
  6684. for (int index = 0; index < CCS_QUANTITY; index++)
  6685. {
  6686. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6687. {
  6688. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseIdx-1].idToken.idToken) == 0))
  6689. {
  6690. //Reserved
  6691. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  6692. }
  6693. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseIdx-1].idToken.idToken) != 0))
  6694. {
  6695. //Reserved
  6696. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  6697. isAllowStart = FALSE;
  6698. }
  6699. else
  6700. {
  6701. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6702. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6703. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6704. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6705. {
  6706. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  6707. isAllowStart = FALSE;
  6708. }
  6709. }// END FOR ELSE
  6710. }
  6711. }// END FOR CCS_QUANTITY
  6712. }
  6713. else if(gunType[evseIdx-1] == GUN_TYPE_GBT)
  6714. {
  6715. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6716. {
  6717. tempIndex = ((evseIdx-1) == 2) ? 1: 0;
  6718. }
  6719. else
  6720. {
  6721. tempIndex = (evseIdx-1);
  6722. }
  6723. for (int index = 0; index < GB_QUANTITY; index++)
  6724. {
  6725. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  6726. {
  6727. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseIdx-1].idToken.idToken) == 0))
  6728. {
  6729. //Reserved
  6730. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  6731. }
  6732. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseIdx-1].idToken.idToken) != 0))
  6733. {
  6734. //Reserved
  6735. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  6736. isAllowStart = FALSE;
  6737. }
  6738. else
  6739. {
  6740. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6741. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6742. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6743. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6744. {
  6745. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  6746. isAllowStart = FALSE;
  6747. }
  6748. }// END FOR ELSE
  6749. }
  6750. } // END FOR GB_QUANTITY
  6751. }
  6752. else if(gunType[evseIdx-1] == GUN_TYPE_DO)
  6753. {
  6754. tempIndex = (evseIdx-1);
  6755. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6756. {
  6757. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  6758. {
  6759. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseIdx-1].idToken.idToken) == 0))
  6760. {
  6761. //Reserved
  6762. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  6763. }
  6764. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseIdx-1].idToken.idToken) != 0))
  6765. {
  6766. //Reserved
  6767. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  6768. isAllowStart = FALSE;
  6769. }
  6770. else
  6771. {
  6772. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6773. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6774. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6775. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6776. {
  6777. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  6778. isAllowStart = FALSE;
  6779. }
  6780. }// END FOR ELSE
  6781. }
  6782. } // END FOR GB_QUANTITY
  6783. }
  6784. else
  6785. {
  6786. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  6787. {
  6788. tempIndex = 2;
  6789. }
  6790. else
  6791. {
  6792. tempIndex = (evseIdx-1);
  6793. }
  6794. for (int index = 0; index < AC_QUANTITY; index++)
  6795. {
  6796. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  6797. {
  6798. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseIdx-1].idToken.idToken) == 0))
  6799. {
  6800. //Reserved
  6801. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  6802. }
  6803. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseIdx-1].idToken.idToken) != 0))
  6804. {
  6805. //Reserved
  6806. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  6807. isAllowStart = FALSE;
  6808. }
  6809. else
  6810. {
  6811. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6812. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  6813. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  6814. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  6815. {
  6816. DEBUG_WARN("AC connector not allow start cause busy.\n");
  6817. isAllowStart = FALSE;
  6818. }
  6819. }//END FOR ELSE
  6820. }
  6821. }// END FOR AC_QUANTITY
  6822. }
  6823. if(isAllowStart == TRUE)
  6824. {
  6825. if(ShmOCPP20Data->RequestStartTransaction[evseIdx -1].chargingProfile.id > 0)
  6826. {
  6827. if((access("/Storage/OCPP/TxProfile_Tmp_OCPP20.json", F_OK))!=-1)
  6828. {
  6829. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp_OCPP20.json /Storage/OCPP/TxProfile_%d_OCPP20.json", evseIdx);
  6830. system(cmdBuf);
  6831. }
  6832. }
  6833. ShmOCPP20Data->CsMsg.bits[evseIdx-1].RequestStartTransactionReq = ON;
  6834. }
  6835. }
  6836. void CheckSystemValue(void)
  6837. {
  6838. char filenmae[100]={0};
  6839. char str[100]={0};
  6840. int tempIndex = 0;
  6841. //===============================
  6842. // EVSE operation check
  6843. //===============================
  6844. //===============================
  6845. // Heartbeat check
  6846. //===============================
  6847. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  6848. {
  6849. //parameter for test
  6850. sendHeartbeatRequest(0);
  6851. //==============================================
  6852. // Reset Waiting Time
  6853. //==============================================
  6854. HeartBeatWithNOResponse += 1;
  6855. }
  6856. //===============================
  6857. // CSU Trigger Authorize Request
  6858. //===============================
  6859. if(isWebsocketSendable &&
  6860. (server_sign == TRUE) &&
  6861. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON) &&
  6862. (authorizeRetryTimes < 3))
  6863. {
  6864. sendAuthorizeRequest(0);
  6865. authorizeRetryTimes = authorizeRetryTimes + 1;
  6866. if(authorizeRetryTimes < 3)
  6867. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  6868. }
  6869. else if((server_sign == TRUE) &&
  6870. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON) &&
  6871. (authorizeRetryTimes >= 3))
  6872. {
  6873. authorizeRetryTimes = 0;
  6874. SetOcppConnStatus(FALSE);
  6875. server_sign = FALSE;
  6876. }
  6877. else if((server_sign == FALSE) &&
  6878. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "true") == 0) &&
  6879. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].value, "true") == 0) &&
  6880. (ShmOCPP20Data->OcppConnStatus == OFF) &&
  6881. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON))
  6882. {
  6883. sendAuthorizeRequest(0);
  6884. }
  6885. //===============================
  6886. // NotifyMonitoringReportRequest
  6887. //===============================
  6888. if(isWebsocketSendable &&
  6889. (server_sign == TRUE) &&
  6890. (ShmOCPP20Data->GetMonitoringReport.requestId > 0))
  6891. {
  6892. for(uint8_t idxCriterion=0;idxCriterion<ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.monitoringCriteria);idxCriterion++)
  6893. {
  6894. if((strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_ThresholdMonitoring]) == 0) ||
  6895. (strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_DeltaMonitoring]) == 0) ||
  6896. (strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_PeriodicMonitoring]) == 0))
  6897. {
  6898. /*for(uint8_t idxVarMonitoring=0; idxVarMonitoring<10; idxVarMonitoring++)
  6899. {
  6900. if(strcmp((char*)ShmOCPP20Data->ControllerVariableMonitoring[idxVarMonitoring].variableMonitoring[idxVarMonitoring].type, (char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion]))
  6901. {
  6902. strcpy(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxVarMonitoring].component, ShmOCPP20Data->ControllerVariableMonitoring[idxVarMonitoring].
  6903. }
  6904. }*/
  6905. }
  6906. if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_ThresholdMonitoring]) == 0)
  6907. {
  6908. /*
  6909. * TODO:
  6910. * 1. Report component that are ThresholdMonitoring
  6911. */
  6912. }
  6913. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_DeltaMonitoring]) == 0)
  6914. {
  6915. /*
  6916. * TODO:
  6917. * 1. Report component that are DeltaMonitoring
  6918. */
  6919. }
  6920. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_PeriodicMonitoring]) == 0)
  6921. {
  6922. /*
  6923. * TODO:
  6924. * 1. Report component that are PeriodicMonitoring
  6925. */
  6926. }
  6927. else
  6928. {
  6929. /*
  6930. * TODO:
  6931. * 1. Process unknown criteria condition
  6932. */
  6933. }
  6934. }
  6935. ShmOCPP20Data->GetMonitoringReport.requestId = 0;
  6936. }
  6937. if(isWebsocketSendable &&
  6938. (server_sign == TRUE) &&
  6939. (ShmOCPP20Data->GetReport.requestId > 0))
  6940. {
  6941. for(uint8_t idxCriterion=0;idxCriterion<ARRAY_SIZE(ShmOCPP20Data->GetReport.componentCriteria);idxCriterion++)
  6942. {
  6943. if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Active]) == 0)
  6944. {
  6945. /*
  6946. * TODO:
  6947. * 1. Report component that are active
  6948. */
  6949. }
  6950. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Available]) == 0)
  6951. {
  6952. /*
  6953. * TODO:
  6954. * 1. Report component that are available
  6955. */
  6956. }
  6957. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Enabled]) == 0)
  6958. {
  6959. /*
  6960. * TODO:
  6961. * 1. Report component that are enable
  6962. */
  6963. }
  6964. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Problem]) == 0)
  6965. {
  6966. /*
  6967. * TODO:
  6968. * 1. Report component that are problem
  6969. */
  6970. }
  6971. else
  6972. {
  6973. /*
  6974. * TODO:
  6975. * 1. Process unknown criteria condition
  6976. */
  6977. }
  6978. }
  6979. ShmOCPP20Data->GetReport.requestId = 0;
  6980. }
  6981. if(isWebsocketSendable &&
  6982. (server_sign == TRUE) &&
  6983. (ShmOCPP20Data->GetBaseReport.requestId > 0))
  6984. {
  6985. uint8_t reportIdx = 0;
  6986. ShmOCPP20Data->NotifyReport.requestId = ShmOCPP20Data->GetBaseReport.requestId;
  6987. if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_ConfigurationInventory]) == 0)
  6988. {
  6989. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  6990. {
  6991. if(reportIdx < ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData))
  6992. {
  6993. 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))
  6994. {
  6995. memcpy(&ShmOCPP20Data->NotifyReport.reportData[reportIdx], &ShmOCPP20Data->ControllerComponentVariable[idx_var], sizeof(struct ReportDataType));
  6996. reportIdx++;
  6997. }
  6998. }
  6999. else
  7000. {
  7001. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  7002. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  7003. ShmOCPP20Data->NotifyReport.seqNo += 1;
  7004. else
  7005. ShmOCPP20Data->NotifyReport.seqNo = 0;
  7006. sendNotifyReportRequest();
  7007. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  7008. reportIdx = 0;
  7009. idx_var--;
  7010. }
  7011. }
  7012. }
  7013. else if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_FullInventory]) == 0)
  7014. {
  7015. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  7016. {
  7017. if(reportIdx < ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData))
  7018. {
  7019. memcpy(&ShmOCPP20Data->NotifyReport.reportData[reportIdx], &ShmOCPP20Data->ControllerComponentVariable[idx_var], sizeof(struct ReportDataType));
  7020. reportIdx++;
  7021. }
  7022. else
  7023. {
  7024. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  7025. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  7026. ShmOCPP20Data->NotifyReport.seqNo += 1;
  7027. else
  7028. ShmOCPP20Data->NotifyReport.seqNo = 0;
  7029. sendNotifyReportRequest();
  7030. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  7031. reportIdx = 0;
  7032. idx_var--;
  7033. }
  7034. }
  7035. }
  7036. else
  7037. {
  7038. /*
  7039. * TODO:
  7040. * 1. Fill out summary inventory to response message, currently not support
  7041. */
  7042. }
  7043. if(reportIdx > 0)
  7044. {
  7045. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  7046. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  7047. ShmOCPP20Data->NotifyReport.seqNo += 1;
  7048. else
  7049. ShmOCPP20Data->NotifyReport.seqNo = 0;
  7050. sendNotifyReportRequest();
  7051. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  7052. reportIdx = 0;
  7053. }
  7054. ShmOCPP20Data->GetBaseReport.requestId = 0;
  7055. }
  7056. if(isWebsocketSendable &&
  7057. (server_sign == TRUE) &&
  7058. ShmOCPP20Data->SpMsg.bits.NotifyEventReq)
  7059. {
  7060. getNowDatetime(ShmOCPP20Data->NotifyEvent.generatedAt);
  7061. ShmOCPP20Data->NotifyEvent.tbc = FALSE;
  7062. if(ShmOCPP20Data->NotifyEvent.seqNo < INT_MAX)
  7063. ShmOCPP20Data->NotifyEvent.seqNo += 1;
  7064. else
  7065. ShmOCPP20Data->NotifyEvent.seqNo = 0;
  7066. sendNotifyEventRequest();
  7067. memset(&ShmOCPP20Data->NotifyEvent.eventData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)* sizeof(struct EventDataType ));
  7068. ShmOCPP20Data->SpMsg.bits.NotifyEventReq = OFF;
  7069. }
  7070. if(isWebsocketSendable &&
  7071. (server_sign == TRUE) &&
  7072. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq)
  7073. {
  7074. if(strcmp((char*)ShmOCPP20Data->Get15118EVCertificate.action, CertificateActionEnumTypeStr[CertificateActionEnumType_Install]) == 0)
  7075. {
  7076. /*
  7077. * TODO:
  7078. * 1.
  7079. */
  7080. }
  7081. else if(strcmp((char*)ShmOCPP20Data->Get15118EVCertificate.action, CertificateActionEnumTypeStr[CertificateActionEnumType_Update]) == 0)
  7082. {
  7083. /*
  7084. * TODO:
  7085. * 1.
  7086. */
  7087. }
  7088. else
  7089. {
  7090. /*
  7091. * TODO:
  7092. * 1.
  7093. */
  7094. }
  7095. sendGet15118EVCertificateRequest();
  7096. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq = OFF;
  7097. }
  7098. if(isWebsocketSendable &&
  7099. (server_sign == TRUE) &&
  7100. (ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq == ON))
  7101. {
  7102. sendSecurityEventNotificationRequest();
  7103. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = OFF;
  7104. }
  7105. if(isWebsocketSendable &&
  7106. (server_sign == TRUE) &&
  7107. (ShmOCPP20Data->SpMsg.bits.NotifyCustomerInformationReq == ON))
  7108. {
  7109. sendNotifyCustomerInformationRequest();
  7110. ShmOCPP20Data->SpMsg.bits.NotifyCustomerInformationReq = OFF;
  7111. }
  7112. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7113. {
  7114. // ClockAlign MeterValue
  7115. 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))
  7116. {
  7117. //check Transaction active
  7118. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7119. {
  7120. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7121. {
  7122. tempIndex = ((gun_index==2) ? 1: 0);
  7123. }
  7124. else
  7125. {
  7126. tempIndex = gun_index;
  7127. }
  7128. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7129. {
  7130. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7131. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7132. {
  7133. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  7134. }
  7135. }// End for CHAdeMO
  7136. }
  7137. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7138. {
  7139. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7140. {
  7141. tempIndex = ((gun_index==2) ? 1: 0);
  7142. }
  7143. else
  7144. {
  7145. tempIndex = gun_index;
  7146. }
  7147. for (int index = 0; index < CCS_QUANTITY; index++)
  7148. {
  7149. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7150. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7151. {
  7152. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  7153. }
  7154. } // End for CCS
  7155. }
  7156. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7157. {
  7158. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7159. {
  7160. tempIndex = ((gun_index==2) ? 1: 0);
  7161. }
  7162. else
  7163. {
  7164. tempIndex = gun_index;
  7165. }
  7166. for (int index = 0; index < GB_QUANTITY; index++)
  7167. {
  7168. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7169. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7170. {
  7171. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  7172. }
  7173. }// End for GB
  7174. }
  7175. else if(gunType[gun_index] == GUN_TYPE_DO)
  7176. {
  7177. tempIndex = gun_index;
  7178. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7179. {
  7180. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7181. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7182. {
  7183. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  7184. }
  7185. }
  7186. }
  7187. else
  7188. {
  7189. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7190. {
  7191. tempIndex = 2;
  7192. }
  7193. else
  7194. {
  7195. tempIndex = gun_index;
  7196. }
  7197. for (int index = 0; index < AC_QUANTITY; index++)
  7198. {
  7199. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7200. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7201. {
  7202. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  7203. }
  7204. }//End for AC
  7205. }
  7206. }
  7207. }
  7208. //===============================
  7209. // Each connector operation check
  7210. //===============================
  7211. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  7212. {
  7213. //==========================================
  7214. // Check remote start without connector id
  7215. //==========================================
  7216. if(ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  7217. {
  7218. int evseIdInt = -1;
  7219. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  7220. {
  7221. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[ConnectorStatusEnumType_Occupied]) != NULL))
  7222. {
  7223. evseIdInt = (gun_index+1);
  7224. DEBUG_INFO("Detect connector of evse-%02d connected ready to start.\n", evseIdInt);
  7225. checkRemoteStart(evseIdInt);
  7226. ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = OFF;
  7227. break;
  7228. }
  7229. }
  7230. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value))
  7231. {
  7232. DEBUG_WARN("Remote start request without evse id wait link over %s seconds.\n", (char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value);
  7233. ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = OFF;
  7234. }
  7235. }
  7236. //==========================================
  7237. // csu trigger DataTransferReq
  7238. //==========================================
  7239. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].DataTransferReq == ON))
  7240. {
  7241. sendDataTransferRequest(gun_index);
  7242. ShmOCPP20Data->CsMsg.bits[gun_index].DataTransferReq = OFF;
  7243. }
  7244. //==============================================
  7245. // Charger status notification & Transaction event report
  7246. //==============================================
  7247. //--- Check Mode Change ---//
  7248. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  7249. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7250. {
  7251. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7252. {
  7253. tempIndex = ((gun_index==2) ? 1: 0);
  7254. }
  7255. else
  7256. {
  7257. tempIndex = gun_index;
  7258. }
  7259. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7260. {
  7261. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7262. {
  7263. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  7264. {
  7265. //if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_AUTHORIZING)
  7266. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  7267. /*if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  7268. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_COMPLETE) &&
  7269. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != AcPreviousSystemStatus[index]))
  7270. {
  7271. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7272. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7273. else
  7274. {
  7275. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) > 0)
  7276. {
  7277. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic); //For synchronizing metervalues
  7278. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7279. }
  7280. }
  7281. }*/
  7282. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  7283. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  7284. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  7285. {
  7286. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  7287. if((access(filenmae,F_OK))!=-1)
  7288. {
  7289. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  7290. sprintf(str,"rm -f %s",filenmae);
  7291. system(str);
  7292. }
  7293. }
  7294. }
  7295. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  7296. #if 1 // for TempStopTransaction
  7297. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  7298. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  7299. {
  7300. checkTempStopTransaction(gun_index);
  7301. }
  7302. #endif
  7303. }
  7304. }
  7305. }
  7306. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7307. {
  7308. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7309. {
  7310. tempIndex = ((gun_index==2) ? 1: 0);
  7311. }
  7312. else
  7313. {
  7314. tempIndex = gun_index;
  7315. }
  7316. for (int index = 0; index < CCS_QUANTITY; index++)
  7317. {
  7318. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7319. {
  7320. 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]*/ )
  7321. {
  7322. //if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_AUTHORIZING)
  7323. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  7324. /*if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  7325. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_COMPLETE) &&
  7326. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != AcPreviousSystemStatus[index]))
  7327. {
  7328. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7329. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7330. else
  7331. {
  7332. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) > 0)
  7333. {
  7334. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic); //For synchronizing metervalues
  7335. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7336. }
  7337. }
  7338. }*/
  7339. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  7340. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  7341. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  7342. {
  7343. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  7344. if((access(filenmae,F_OK))!=-1)
  7345. {
  7346. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  7347. sprintf(str,"rm -f %s",filenmae);
  7348. system(str);
  7349. }
  7350. }
  7351. }
  7352. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  7353. #if 1 // for TempStopTransaction
  7354. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  7355. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  7356. {
  7357. checkTempStopTransaction(gun_index);
  7358. }
  7359. #endif
  7360. }
  7361. }
  7362. }
  7363. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7364. {
  7365. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7366. {
  7367. tempIndex = ((gun_index==2) ? 1: 0);
  7368. }
  7369. else
  7370. {
  7371. tempIndex = gun_index;
  7372. }
  7373. for (int index = 0; index < GB_QUANTITY; index++)
  7374. {
  7375. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7376. {
  7377. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  7378. {
  7379. //if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_AUTHORIZING)
  7380. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  7381. /*if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  7382. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_COMPLETE) &&
  7383. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]))
  7384. {
  7385. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7386. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7387. else
  7388. {
  7389. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) > 0)
  7390. {
  7391. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic); //For synchronizing metervalues
  7392. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7393. }
  7394. }
  7395. }*/
  7396. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  7397. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  7398. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  7399. {
  7400. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  7401. if((access(filenmae,F_OK))!=-1)
  7402. {
  7403. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  7404. sprintf(str,"rm -f %s",filenmae);
  7405. system(str);
  7406. }
  7407. }
  7408. }
  7409. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  7410. #if 1 // for TempStopTransaction
  7411. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  7412. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  7413. {
  7414. checkTempStopTransaction(gun_index);
  7415. }
  7416. #endif
  7417. }
  7418. }
  7419. }
  7420. else if(gunType[gun_index] == GUN_TYPE_DO)
  7421. {
  7422. tempIndex = gun_index;
  7423. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7424. {
  7425. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7426. {
  7427. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  7428. {
  7429. //if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_AUTHORIZING)
  7430. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  7431. /*if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CHARGING) &&
  7432. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_COMPLETE) &&
  7433. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]))
  7434. {
  7435. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  7436. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7437. else
  7438. {
  7439. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) > 0)
  7440. {
  7441. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic); //For synchronizing metervalues
  7442. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7443. }
  7444. }
  7445. }*/
  7446. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  7447. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  7448. 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
  7449. {
  7450. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  7451. if((access(filenmae,F_OK))!=-1)
  7452. {
  7453. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  7454. sprintf(str,"rm -f %s",filenmae);
  7455. system(str);
  7456. }
  7457. }
  7458. }
  7459. 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);
  7460. #if 1 // for TempStopTransaction
  7461. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  7462. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  7463. {
  7464. checkTempStopTransaction(gun_index);
  7465. }
  7466. #endif
  7467. }
  7468. }
  7469. }
  7470. else
  7471. {
  7472. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7473. {
  7474. tempIndex = 2;
  7475. }
  7476. else
  7477. {
  7478. tempIndex = gun_index;
  7479. }
  7480. for (int index = 0; index < AC_QUANTITY; index++)
  7481. {
  7482. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7483. {
  7484. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  7485. {
  7486. //if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_AUTHORIZING)
  7487. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  7488. /*if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  7489. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_COMPLETE) &&
  7490. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) && (AcPreviousSystemStatus[index] != 99))
  7491. {
  7492. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  7493. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7494. else
  7495. {
  7496. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) > 0)
  7497. {
  7498. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic); //For synchronizing metervalues
  7499. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7500. }
  7501. }
  7502. }*/
  7503. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  7504. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  7505. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  7506. {
  7507. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  7508. if((access(filenmae,F_OK))!=-1)
  7509. {
  7510. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  7511. sprintf(str,"rm -f %s",filenmae);
  7512. system(str);
  7513. }
  7514. }
  7515. }
  7516. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  7517. #if 1 // for TempStopTransaction
  7518. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  7519. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  7520. {
  7521. checkTempStopTransaction(gun_index);
  7522. }
  7523. #endif
  7524. }
  7525. }// END
  7526. }
  7527. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) && (ShmOCPP20Data->MsMsg.bits.ResetConf != ON) &&
  7528. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == ON) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == ON) ||
  7529. ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].value, "true") == 0) &&
  7530. (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].value)))))
  7531. {
  7532. sendStatusNotificationRequest(gun_index);
  7533. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  7534. }
  7535. //==============================================
  7536. // CSU Trigger or timer timeout refresh Smart Charging Profile
  7537. //==============================================
  7538. if((ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq == ON) ||
  7539. ((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))))
  7540. {
  7541. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  7542. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP20Data->SmartChargingProfile[gun_index], 0, TRUE);
  7543. ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq = OFF;
  7544. refreshStartTimer(&clientTime.CharingProfileRefresh[gun_index]);
  7545. }
  7546. //==============================================
  7547. // CSU transaction event
  7548. //==============================================
  7549. if(ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == ON || cpinitateMsg.bits[gun_index].TriggerTransactionEventReq == ON)
  7550. {
  7551. sendTransactionEventRequest(gun_index);
  7552. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = OFF;
  7553. cpinitateMsg.bits[gun_index].TriggerTransactionEventReq = OFF;
  7554. //storeTempStopTransaction(gun_index);
  7555. //memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0], 0x00, sizeof(struct MeterValueType));
  7556. }
  7557. //==============================================
  7558. // Meter report
  7559. //==============================================
  7560. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValueReq)
  7561. {
  7562. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Trigger, FALSE);
  7563. cpinitateMsg.bits[gun_index].TriggerMeterValueReq = OFF;
  7564. }
  7565. if(isWebsocketSendable && (cpinitateMsg.bits[gun_index].ClockAlignMeterReq == ON))
  7566. {
  7567. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Clock, FALSE);
  7568. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = OFF;
  7569. }
  7570. // Sample period MeterValue
  7571. if((atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value) > 0) &&
  7572. (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)))
  7573. {
  7574. //check Transaction active
  7575. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7576. {
  7577. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7578. {
  7579. tempIndex = ((gun_index==2) ? 1: 0);
  7580. }
  7581. else
  7582. {
  7583. tempIndex = gun_index;
  7584. }
  7585. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7586. {
  7587. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7588. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7589. {
  7590. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7591. {
  7592. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7593. }
  7594. }
  7595. }// End for CHAdeMO
  7596. }
  7597. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7598. {
  7599. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7600. {
  7601. tempIndex = ((gun_index==2) ? 1: 0);
  7602. }
  7603. else
  7604. {
  7605. tempIndex = gun_index;
  7606. }
  7607. for (int index = 0; index < CCS_QUANTITY; index++)
  7608. {
  7609. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7610. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7611. {
  7612. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7613. {
  7614. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7615. }
  7616. }
  7617. } // End for CCS
  7618. }
  7619. else if(gunType[gun_index] == GUN_TYPE_GBT)
  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 < GB_QUANTITY; index++)
  7630. {
  7631. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7632. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7633. {
  7634. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7635. {
  7636. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7637. }
  7638. }
  7639. }// End for GB
  7640. }
  7641. else if(gunType[gun_index] == GUN_TYPE_DO)
  7642. {
  7643. tempIndex = gun_index;
  7644. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7645. {
  7646. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7647. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7648. {
  7649. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING))
  7650. {
  7651. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7652. }
  7653. }
  7654. }
  7655. }
  7656. else
  7657. {
  7658. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7659. {
  7660. tempIndex = 2;
  7661. }
  7662. else
  7663. {
  7664. tempIndex = gun_index;
  7665. }
  7666. for (int index = 0; index < AC_QUANTITY; index++)
  7667. {
  7668. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7669. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7670. {
  7671. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7672. {
  7673. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7674. }
  7675. }
  7676. }//End for AC
  7677. }
  7678. if(cpinitateMsg.bits[gun_index].SampleMeterReq == ON)
  7679. {
  7680. if(atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value) > 0)
  7681. {
  7682. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic, FALSE);
  7683. }
  7684. cpinitateMsg.bits[gun_index].SampleMeterReq = OFF;
  7685. }
  7686. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  7687. }
  7688. if((atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].value) > 0) &&
  7689. (getDiffSecNow(clientTime.SampledDataTxEnded[gun_index]) >= ((atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].value)>3)?(atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].value)- 1):3)))
  7690. {
  7691. //check Transaction active
  7692. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7693. {
  7694. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7695. {
  7696. tempIndex = ((gun_index==2) ? 1: 0);
  7697. }
  7698. else
  7699. {
  7700. tempIndex = gun_index;
  7701. }
  7702. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7703. {
  7704. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7705. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7706. {
  7707. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7708. {
  7709. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7710. }
  7711. }
  7712. }// End for CHAdeMO
  7713. }
  7714. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7715. {
  7716. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7717. {
  7718. tempIndex = ((gun_index==2) ? 1: 0);
  7719. }
  7720. else
  7721. {
  7722. tempIndex = gun_index;
  7723. }
  7724. for (int index = 0; index < CCS_QUANTITY; index++)
  7725. {
  7726. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7727. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7728. {
  7729. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7730. {
  7731. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7732. }
  7733. }
  7734. } // End for CCS
  7735. }
  7736. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7737. {
  7738. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7739. {
  7740. tempIndex = ((gun_index==2) ? 1: 0);
  7741. }
  7742. else
  7743. {
  7744. tempIndex = gun_index;
  7745. }
  7746. for (int index = 0; index < GB_QUANTITY; index++)
  7747. {
  7748. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7749. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7750. {
  7751. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7752. {
  7753. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7754. }
  7755. }
  7756. }// End for GB
  7757. }
  7758. else if(gunType[gun_index] == GUN_TYPE_DO)
  7759. {
  7760. tempIndex = gun_index;
  7761. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7762. {
  7763. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7764. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7765. {
  7766. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING))
  7767. {
  7768. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7769. }
  7770. }
  7771. }
  7772. }
  7773. else
  7774. {
  7775. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7776. {
  7777. tempIndex = 2;
  7778. }
  7779. else
  7780. {
  7781. tempIndex = gun_index;
  7782. }
  7783. for (int index = 0; index < AC_QUANTITY; index++)
  7784. {
  7785. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  7786. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7787. {
  7788. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING))
  7789. {
  7790. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  7791. }
  7792. }
  7793. }//End for AC
  7794. }
  7795. if(cpinitateMsg.bits[gun_index].SampleMeterReq == ON)
  7796. {
  7797. if(atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value) > 0)
  7798. {
  7799. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic, TRUE);
  7800. }
  7801. cpinitateMsg.bits[gun_index].SampleMeterReq = OFF;
  7802. }
  7803. refreshStartTimer(&clientTime.SampledDataTxEnded[gun_index]);
  7804. }
  7805. //==============================================
  7806. // Check Connector reserved
  7807. //==============================================
  7808. //===============================
  7809. // Check if Reserve is expired
  7810. //===============================
  7811. if((server_sign == TRUE) && (ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime[0] != 0))
  7812. {
  7813. if(isOvertNow(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime))
  7814. {
  7815. DEBUG_INFO("reserve expired.\n");
  7816. ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationId = ShmOCPP20Data->ReserveNow[gun_index].id;
  7817. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Expired]);
  7818. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = ON;
  7819. memset(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime,0,ARRAY_SIZE(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime));
  7820. }
  7821. }//END OF Check if Reserve is expired
  7822. //==========================================
  7823. // csu trigger FirmwareStatusNotificationReq
  7824. //==========================================
  7825. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq == ON))
  7826. {
  7827. sendFirmwareStatusNotificationRequest((char *)ShmOCPP20Data->FirmwareStatusNotification.status);
  7828. }
  7829. //==========================================
  7830. // csu cleared charging limit request
  7831. //==========================================
  7832. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq == ON))
  7833. {
  7834. sendClearedChargingLimitRequest(gun_index);
  7835. }
  7836. //==========================================
  7837. // csu trigger CancelReservationConf
  7838. //==========================================
  7839. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationConf == ON))
  7840. {
  7841. sendCancelReservationConfirmation((char *)ShmOCPP20Data->CancelReservation[gun_index].guid, gun_index);
  7842. }
  7843. //==========================================
  7844. // csu notify EV charging need request
  7845. //==========================================
  7846. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsReq == ON))
  7847. {
  7848. sendNotifyEVChargingNeedsRequest(gun_index);
  7849. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsReq = OFF;
  7850. }
  7851. //==========================================
  7852. // csu notify EV charging schedule request
  7853. //==========================================
  7854. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingScheduleReq == ON))
  7855. {
  7856. sendNotifyEVChargingScheduleRequest(gun_index);
  7857. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingScheduleReq = OFF;
  7858. }
  7859. //==========================================
  7860. // csu trigger ChangeAvailabilityConf
  7861. //==========================================
  7862. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == ON))
  7863. {
  7864. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP20Data->ChangeAvailability[gun_index].ResponseStatus);
  7865. }
  7866. //==========================================
  7867. // csu trigger UnlockConnectorConf
  7868. //==========================================
  7869. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf == ON))
  7870. {
  7871. sendUnlockConnectorConfirmation((char *)ShmOCPP20Data->UnlockConnector[gun_index].guid, gun_index);
  7872. }
  7873. //==========================================
  7874. // csu trigger ReserveNowConf
  7875. //==========================================
  7876. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf == ON))
  7877. {
  7878. sendReserveNowConfirmation((char *)ShmOCPP20Data->ReserveNow[gun_index].guid, gun_index);
  7879. }
  7880. //==========================================
  7881. // csu trigger ReserveNowConf
  7882. //==========================================
  7883. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq == ON))
  7884. {
  7885. sendReservationStatusUpdateRequest(gun_index);
  7886. }
  7887. //==========================================
  7888. // csu trigger LogStatusNotificationReq
  7889. //==========================================
  7890. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq == ON))
  7891. {
  7892. if(isCancelUploadLog == TRUE)
  7893. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  7894. else
  7895. sendLogStatusNotificationRequest((char *)ShmOCPP20Data->LogStatusNotification.status);
  7896. }
  7897. //==========================================
  7898. // csu trigger SignCertificateReq
  7899. //==========================================
  7900. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.SignCertificateReq == ON))
  7901. {
  7902. if((access("/Storage/OCPP/certCP.csr",F_OK) != -1) &&
  7903. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) == 0) )
  7904. {
  7905. sendSignCertificateRequest(CertificateSignedStatusEnumType_ChargingStationCertificate);
  7906. }
  7907. else if((access("/Storage/OCPP/certV2G.csr",F_OK) != -1) &&
  7908. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0))
  7909. {
  7910. sendSignCertificateRequest(CertificateSignedStatusEnumType_V2GCertificate);
  7911. }
  7912. }
  7913. }
  7914. }
  7915. //==========================================
  7916. // send request routine
  7917. //==========================================
  7918. int sendAuthorizeRequest(int gun_index)
  7919. {
  7920. mtrace();
  7921. int result = FAIL;
  7922. char message[4096]={0};
  7923. char guid[37];
  7924. char tempdata[128]={0};
  7925. json_object *Authorize = json_object_new_object();
  7926. json_object *idToken = json_object_new_object();
  7927. DEBUG_INFO("sendAuthorizeRequest...\n");
  7928. memset(&(ShmOCPP20Data->Authorize.Response_idTokenInfo),0,sizeof(struct IdTokenInfoType));
  7929. //Local Authorize
  7930. if((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].value, "true")==0) && (ShmOCPP20Data->OcppConnStatus == 0))
  7931. {
  7932. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  7933. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "");
  7934. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, "");
  7935. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]);
  7936. result = PASS;
  7937. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  7938. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  7939. authorizeRetryTimes = 0;
  7940. return result;
  7941. }
  7942. 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)) ||
  7943. ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].value, "true") == 0)&&(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "true") == 0)))
  7944. {
  7945. // Query idtag from cache
  7946. DB_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId, TRUE);
  7947. // Query idtag from list
  7948. if((strcmp((char*)idTagQuery.idToken.idToken,"") == 0) || (strstr((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) == NULL))
  7949. DB_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId, FALSE);
  7950. if((strcmp((char*)idTagQuery.idToken.idToken,"") == 0) || (strstr((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) == NULL))
  7951. {
  7952. if(strcmp((char*)idTagQuery.idToken.idToken,"") == 0)
  7953. {
  7954. DEBUG_INFO("Card %s does not find in list or cache\n", ShmSysConfigAndInfo->SysConfig.UserId);
  7955. }
  7956. if(strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0)
  7957. {
  7958. DEBUG_INFO("Card %s does not accepted in list and cache\n", ShmSysConfigAndInfo->SysConfig.UserId);
  7959. }
  7960. // Return authorize result if does not connect to server
  7961. if(!ShmOCPP20Data->OcppConnStatus)
  7962. {
  7963. DEBUG_INFO("Local Authorization Fail.\n");
  7964. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "");
  7965. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  7966. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Invalid]);
  7967. DEBUG_INFO("ShmOCPP20Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
  7968. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  7969. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  7970. authorizeRetryTimes = 0;
  7971. return result;
  7972. }
  7973. }
  7974. else
  7975. {
  7976. DEBUG_INFO("Local Authorization get result.\n");
  7977. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, (char*)idTagQuery.idTokenInfo.cacheExpiryDateTime);
  7978. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
  7979. if(isOvertNow((uint8_t*)&idTagQuery.idTokenInfo.cacheExpiryDateTime[0]))
  7980. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Expired]);
  7981. else
  7982. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, (char*)idTagQuery.idTokenInfo.status);
  7983. DEBUG_INFO("ShmOCPP20Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
  7984. result = PASS;
  7985. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  7986. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  7987. authorizeRetryTimes = 0;
  7988. return result;
  7989. }
  7990. }
  7991. //get data from shared memory
  7992. strcpy((char *)ShmOCPP20Data->Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  7993. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.idToken));
  7994. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.type));
  7995. if(strcmp((char*)ShmOCPP20Data->Authorize.idToken.type, IdTokenEnumTypeStr[IdTokenType_eMAID]) == 0)
  7996. {
  7997. memset(&ShmOCPP20Data->Authorize.Response_idTokenInfo,0,sizeof(struct IdTokenInfoType));
  7998. int parseCertResult = FAIL;
  7999. json_object *iso15118CertificateHashData = json_object_new_array();
  8000. // Read CERTIFICATE_PnCAuth file content
  8001. if(access(CERTIFICATE_PnCAuth,F_OK) != -1)
  8002. {
  8003. memset(ShmOCPP20Data->Authorize.certificate, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.certificate));
  8004. FILE *fp=fopen(CERTIFICATE_PnCAuth,"r");
  8005. char *line = NULL;
  8006. size_t len = 0;
  8007. while(getline(&line, &len, fp) != -1)
  8008. {
  8009. //memcpy(&ShmOCPP16Data->v2g_extend.Authorize.certificate[strlen((char*)ShmOCPP16Data->v2g_extend.Authorize.certificate)], line, (strlen(line)-1));
  8010. strcat((char *)ShmOCPP20Data->Authorize.certificate, line);
  8011. }
  8012. fclose(fp);
  8013. }
  8014. if(strlen((char*)ShmOCPP20Data->Authorize.certificate) > 0)
  8015. json_object_object_add(Authorize, "certificate", json_object_new_string((char*)ShmOCPP20Data->Authorize.certificate));
  8016. char parseData[512] = {0};
  8017. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  8018. sprintf((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[0].hashAlgorithm, parseData);
  8019. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_SerialNumber, parseData) == PASS)
  8020. sprintf((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[0].serialNumber, parseData);
  8021. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  8022. sprintf((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[0].issuerNameHash, parseData);
  8023. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  8024. sprintf((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[0].issuerKeyHash, parseData);
  8025. if(parseCertInfo(CERTIFICATE_PnCAuth, CERT_PARSE_OcspUrl, parseData) == PASS && strlen((char*)parseData) >= 7)
  8026. strcpy((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[0].responderURL, parseData);
  8027. for(int idx=0; idx < 4; idx++)
  8028. {
  8029. if(strlen((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].hashAlgorithm) > 0)
  8030. {
  8031. json_object *OCSPRequestDataType = json_object_new_object();
  8032. json_object_object_add(OCSPRequestDataType, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].hashAlgorithm));
  8033. json_object_object_add(OCSPRequestDataType, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].issuerNameHash));
  8034. json_object_object_add(OCSPRequestDataType, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].issuerKeyHash));
  8035. json_object_object_add(OCSPRequestDataType, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].serialNumber));
  8036. json_object_object_add(OCSPRequestDataType, "responderURL", json_object_new_string((char*)ShmOCPP20Data->Authorize.iso15118CertificateHashData[idx].responderURL));
  8037. json_object_array_add(iso15118CertificateHashData, OCSPRequestDataType);
  8038. parseCertResult = PASS;
  8039. }
  8040. }
  8041. if(parseCertResult == PASS)
  8042. {
  8043. json_object_object_add(Authorize, "iso15118CertificateHashData", iso15118CertificateHashData);
  8044. }
  8045. else
  8046. {
  8047. sprintf((char*)ShmOCPP20Data->Authorize.Response_certificateStatus, "NoCertificateAvailable");
  8048. sprintf((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, "Invalid");
  8049. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON;
  8050. }
  8051. }
  8052. json_object_object_add(Authorize, "idToken", idToken);
  8053. random_uuid(guid);
  8054. sprintf(message,"[%d,\"%s\",\"Authorize\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(Authorize, JSON_C_TO_STRING_PLAIN));
  8055. json_object_put(Authorize);
  8056. LWS_Send(message);
  8057. sprintf(tempdata, "Authorize,%d", gun_index);
  8058. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8059. {
  8060. result = PASS;
  8061. }
  8062. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  8063. return result;
  8064. }
  8065. int sendBootNotificationRequest()
  8066. {
  8067. mtrace();
  8068. int result = FAIL;
  8069. char message[4096]={0};
  8070. char guid[37]={0};
  8071. char tempdata[128]={0};
  8072. json_object *BootNotification = json_object_new_object();
  8073. json_object *chargingStation = json_object_new_object();
  8074. json_object *modem = json_object_new_object();
  8075. DEBUG_INFO("sendBootNotificationRequest...\n");
  8076. // Fill BootNotification fields
  8077. DB_getBooType();
  8078. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.model, "%s", ShmSysConfigAndInfo->SysConfig.ModelName);
  8079. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.vendorName, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  8080. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.serialNumber, "%s", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  8081. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.firmwareVersion, "%s", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  8082. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.modem.iccid, "%s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  8083. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.modem.imsi, "%s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  8084. if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
  8085. {
  8086. json_object_object_add(modem, "iccid", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.modem.iccid));
  8087. json_object_object_add(modem, "imsi", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.modem.imsi));
  8088. json_object_object_add(chargingStation, "modem", modem);
  8089. }
  8090. json_object_object_add(chargingStation, "model", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.model));
  8091. json_object_object_add(chargingStation, "vendorName", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.vendorName));
  8092. json_object_object_add(chargingStation, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.serialNumber));
  8093. json_object_object_add(chargingStation, "firmwareVersion", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.firmwareVersion));
  8094. json_object_object_add(BootNotification, "chargingStation", chargingStation);
  8095. json_object_object_add(BootNotification, "reason", json_object_new_string((char*)ShmOCPP20Data->BootNotification.reason));
  8096. random_uuid(guid);
  8097. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", json_object_to_json_string_ext(BootNotification, JSON_C_TO_STRING_PLAIN));
  8098. json_object_put(BootNotification);
  8099. LWS_Send(message);
  8100. sprintf(tempdata, "BootNotification,0");
  8101. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8102. {
  8103. result = PASS;
  8104. }
  8105. return result;
  8106. }
  8107. int sendClearedChargingLimitRequest(int gun_index)
  8108. {
  8109. mtrace();
  8110. int result = FAIL;
  8111. char message[4096]={0};
  8112. char guid[37]={0};
  8113. char tempdata[128]={0};
  8114. json_object *ClearedChargingLimit = json_object_new_object();
  8115. DEBUG_INFO("sendClearedChargingLimitRequest...\n");
  8116. json_object_object_add(ClearedChargingLimit, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->ClearedChargingLimit[gun_index].chargingLimitSource));
  8117. json_object_object_add(ClearedChargingLimit, "evseId", json_object_new_int(ShmOCPP20Data->ClearedChargingLimit[gun_index].evseId));
  8118. random_uuid(guid);
  8119. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ClearedChargingLimit", json_object_to_json_string_ext(ClearedChargingLimit, JSON_C_TO_STRING_PLAIN));
  8120. json_object_put(ClearedChargingLimit);
  8121. LWS_Send(message);
  8122. sprintf(tempdata, "ClearedChargingLimit,%d", gun_index);
  8123. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8124. {
  8125. result = PASS;
  8126. }
  8127. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq = OFF;
  8128. return result;
  8129. }
  8130. int sendDataTransferRequest(int gun_index)
  8131. {
  8132. mtrace();
  8133. char message[1000]={0};
  8134. char guid[37]={0};
  8135. char tempdata[65]={0};
  8136. int result = FAIL;
  8137. DEBUG_INFO("sendDataTransferRequest...\n");
  8138. random_uuid(guid);
  8139. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  8140. MESSAGE_TYPE_CALL,
  8141. guid,
  8142. ShmOCPP20Data->DataTransfer[gun_index].vendorId,
  8143. ShmOCPP20Data->DataTransfer[gun_index].messageId,
  8144. ShmOCPP20Data->DataTransfer[gun_index].data);
  8145. LWS_Send(message);
  8146. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  8147. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8148. {
  8149. result = PASS;
  8150. }
  8151. return result;
  8152. }
  8153. int sendFirmwareStatusNotificationRequest(char *status)
  8154. {
  8155. mtrace();
  8156. int result = FAIL;
  8157. char message[110]={0};
  8158. char guid[37]={0};
  8159. char tempdata[65]={0};
  8160. json_object *FirmwareStatusNotification = json_object_new_object();
  8161. DEBUG_INFO("sendFirmwareStatusNotificationRequest...\n");
  8162. sprintf((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", (const char *)status);
  8163. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  8164. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->FirmwareStatusNotification.status));
  8165. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->FirmwareStatusNotification.requestId));
  8166. random_uuid(guid);
  8167. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  8168. json_object_put(FirmwareStatusNotification);
  8169. LWS_SendNow(message);
  8170. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  8171. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8172. {
  8173. result = PASS;
  8174. }
  8175. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = OFF;
  8176. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationConf = OFF;
  8177. //record status
  8178. if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded])==0)
  8179. {
  8180. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Downloaded;
  8181. }
  8182. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed])==0)
  8183. {
  8184. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadFailed;
  8185. }
  8186. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading])==0)
  8187. {
  8188. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Downloading;
  8189. }
  8190. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadScheduled])==0)
  8191. {
  8192. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadScheduled;
  8193. }
  8194. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadPaused])==0)
  8195. {
  8196. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadPaused;
  8197. }
  8198. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle])==0)
  8199. {
  8200. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle;
  8201. }
  8202. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallationFailed])==0)
  8203. {
  8204. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallationFailed;
  8205. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  8206. }
  8207. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Installing])==0)
  8208. {
  8209. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Installing;
  8210. }
  8211. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Installed])==0)
  8212. {
  8213. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Installed;
  8214. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  8215. DB_updateSecurityEventType(SecurityEventEnumType_FirmwareUpdated);
  8216. }
  8217. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallRebooting])==0)
  8218. {
  8219. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallRebooting;
  8220. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  8221. DB_updateSecurityEventType(SecurityEventEnumType_FirmwareUpdated);
  8222. }
  8223. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallScheduled])==0)
  8224. {
  8225. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallScheduled;
  8226. }
  8227. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallVerificationFailed])==0)
  8228. {
  8229. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallVerificationFailed;
  8230. }
  8231. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InvalidSignature])==0)
  8232. {
  8233. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InvalidSignature;
  8234. }
  8235. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_SignatureVerified])==0)
  8236. {
  8237. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_SignatureVerified;
  8238. }
  8239. return result;
  8240. }
  8241. int sendGet15118EVCertificateRequest()
  8242. {
  8243. mtrace();
  8244. int result = FAIL;
  8245. char message[4096]={0};
  8246. char guid[37]={0};
  8247. char tempdata[128]={0};
  8248. json_object *Get15118EVCertificate = json_object_new_object();
  8249. DEBUG_INFO("sendGet15118EVCertificateRequest...\n");
  8250. json_object_object_add(Get15118EVCertificate, "iso15118SchemaVersion", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.iso15118SchemaVersion));
  8251. json_object_object_add(Get15118EVCertificate, "action", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.action));
  8252. json_object_object_add(Get15118EVCertificate, "exiRequest", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.exiRequest));
  8253. random_uuid(guid);
  8254. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "Get15118EVCertificate", json_object_to_json_string_ext(Get15118EVCertificate, JSON_C_TO_STRING_PLAIN));
  8255. json_object_put(Get15118EVCertificate);
  8256. LWS_Send(message);
  8257. sprintf(tempdata, "Get15118EVCertificate,0");
  8258. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8259. {
  8260. result = PASS;
  8261. }
  8262. return result;
  8263. }
  8264. int sendGetCertificateStatusRequest()
  8265. {
  8266. mtrace();
  8267. int result = FAIL;
  8268. char message[4096]={0};
  8269. char guid[37]={0};
  8270. char tempdata[128]={0};
  8271. json_object *GetCertificateStatus = json_object_new_object();
  8272. json_object *ocspRequestData = json_object_new_object();
  8273. DEBUG_INFO("sendGetCertificateStatusRequest...\n");
  8274. json_object_object_add(ocspRequestData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.hashAlgorithm));
  8275. json_object_object_add(ocspRequestData, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.issuerNameHash));
  8276. json_object_object_add(ocspRequestData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.issuerKeyHash));
  8277. json_object_object_add(ocspRequestData, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.serialNumber));
  8278. json_object_object_add(ocspRequestData, "responderURL", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.responderURL));
  8279. json_object_object_add(GetCertificateStatus, "ocspRequestData", ocspRequestData);
  8280. random_uuid(guid);
  8281. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "GetCertificateStatus", json_object_to_json_string_ext(GetCertificateStatus, JSON_C_TO_STRING_PLAIN));
  8282. json_object_put(GetCertificateStatus);
  8283. LWS_Send(message);
  8284. sprintf(tempdata, "GetCertificateStatus,0");
  8285. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8286. {
  8287. result = PASS;
  8288. }
  8289. return result;
  8290. }
  8291. int sendHeartbeatRequest()
  8292. {
  8293. mtrace();
  8294. int result = FAIL;
  8295. char message[40096]={0};
  8296. char guid[37]={0};
  8297. char tempdata[128]={0};
  8298. DEBUG_INFO("sendHeartbeatRequest...\n");
  8299. random_uuid(guid);
  8300. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{}]"
  8301. , MESSAGE_TYPE_CALL
  8302. , guid );
  8303. LWS_Send(message);
  8304. sprintf(tempdata, "Heartbeat,%d", 0);
  8305. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8306. {
  8307. result = PASS;
  8308. }
  8309. return result;
  8310. }
  8311. int sendLogStatusNotificationRequest(char *status)
  8312. {
  8313. mtrace();
  8314. int result = FAIL;
  8315. char message[4096]={0};
  8316. char guid[37]={0};
  8317. char tempdata[128]={0};
  8318. json_object *LogStatusNotification = json_object_new_object();
  8319. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  8320. ShmOCPP20Data->LogStatusNotification.requestId = ShmOCPP20Data->GetLog.requestId;
  8321. sprintf((char *)ShmOCPP20Data->LogStatusNotification.status,"%s",(const char *)status);
  8322. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->LogStatusNotification.status));
  8323. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->LogStatusNotification.requestId));
  8324. random_uuid(guid);
  8325. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  8326. json_object_put(LogStatusNotification);
  8327. LWS_SendNow(message);
  8328. sprintf(tempdata, "LogStatusNotification,%d", 0);
  8329. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8330. {
  8331. result = PASS;
  8332. }
  8333. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  8334. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationConf = OFF;
  8335. //record status
  8336. if(strcmp(status,"BadMessage")==0)
  8337. {
  8338. LogStatusNotificationStatus = UploadLogStatusEnumType_BadMessage;
  8339. }
  8340. else if(strcmp(status,"Idle")==0)
  8341. {
  8342. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle;
  8343. }
  8344. else if(strcmp(status,"NotSupportedOperation")==0)
  8345. {
  8346. LogStatusNotificationStatus = UploadLogStatusEnumType_NotSupportedOperation;
  8347. }
  8348. else if(strcmp(status,"PermissionDenied")==0)
  8349. {
  8350. LogStatusNotificationStatus = UploadLogStatusEnumType_PermissionDenied;
  8351. }
  8352. else if(strcmp(status,"Uploaded")==0)
  8353. {
  8354. LogStatusNotificationStatus = UploadLogStatusEnumType_Uploaded;
  8355. }
  8356. else if(strcmp(status,"UploadFailure")==0)
  8357. {
  8358. LogStatusNotificationStatus = UploadLogStatusEnumType_UploadFailure;
  8359. }
  8360. else if(strcmp(status,"Uploading")==0)
  8361. {
  8362. LogStatusNotificationStatus = UploadLogStatusEnumType_Uploading;
  8363. }
  8364. return result;
  8365. }
  8366. int sendMeterValuesRequest(int gun_index, ReadingContextEnumType dataType, uint8_t isSampledDataTxEnd)
  8367. {
  8368. mtrace();
  8369. int result = FAIL;
  8370. char guid[37]={0};
  8371. char tempdata[65]={0};
  8372. int tempIndex = 0;
  8373. DEBUG_INFO("sendMeterValuesRequest...\n");
  8374. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  8375. memset(&ShmOCPP20Data->MeterValues[gun_index], 0, sizeof(struct MeterValues_20));
  8376. //set value
  8377. ShmOCPP20Data->MeterValues[gun_index].evseId = gun_index + 1; // gun start from 1~
  8378. //UTC Date time
  8379. struct timeval tmnow;
  8380. struct tm *tm;
  8381. char buf[28];//, usec_buf[6];
  8382. gettimeofday(&tmnow, NULL);
  8383. time_t t;
  8384. t = time(NULL);
  8385. /*UTC time and date*/
  8386. tm = gmtime(&t);
  8387. if(dataType == ReadingContextEnumType_Sample_Clock)
  8388. {
  8389. struct tm *tmTarget;
  8390. struct timeb tbTarget;
  8391. tbTarget.time = mktime(tm);
  8392. tbTarget.time -= (atoi((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value));
  8393. tmTarget = gmtime(&tbTarget.time);
  8394. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tmTarget);
  8395. }
  8396. else
  8397. {
  8398. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  8399. }
  8400. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].timestamp, buf);
  8401. struct ChargingInfoData *targetChargingInfoData = getTargetChargingInfoData(gun_index);
  8402. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  8403. //idx_sample=0;
  8404. //********************************(1)Current.Import L1************************************************/
  8405. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8406. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8407. (dataType == ReadingContextEnumType_Trigger))
  8408. {
  8409. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8410. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(targetChargingInfoData->PresentChargingCurrent*100))/100.0;
  8411. if(gunType[gun_index] == GUN_TYPE_AC)
  8412. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  8413. else
  8414. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8415. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].context, ReadingContextEnumTypeStr[dataType]);
  8416. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  8417. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8418. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].unitOfMeasure.uint , "A");
  8419. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].unitOfMeasure.multiplier = 0;
  8420. }
  8421. //idx_sample=1;
  8422. //********************************(2)Energy.Active.Import.Register ************************************************/
  8423. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]) != NULL)) ||
  8424. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]) != NULL)) ||
  8425. (dataType == ReadingContextEnumType_Trigger))
  8426. {
  8427. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8428. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(targetChargingInfoData->PowerConsumption*100))/100.0;
  8429. if(gunType[gun_index] == GUN_TYPE_AC)
  8430. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  8431. else
  8432. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8433. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].context, ReadingContextEnumTypeStr[dataType]);
  8434. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]);
  8435. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8436. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].unitOfMeasure.uint , "kWh");
  8437. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.multiplier = 0;
  8438. }
  8439. //idx_sample=2;
  8440. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  8441. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]) != NULL)) ||
  8442. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]) != NULL)) ||
  8443. (dataType == ReadingContextEnumType_Trigger))
  8444. {
  8445. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8446. if(dataType == ReadingContextEnumType_Sample_Clock)
  8447. {
  8448. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (targetChargingInfoData->PowerConsumption - periousClockPowerConsumption[gun_index]);
  8449. periousClockPowerConsumption[gun_index] = targetChargingInfoData->PowerConsumption;
  8450. }
  8451. else if(dataType == ReadingContextEnumType_Sample_Periodic)
  8452. {
  8453. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = (targetChargingInfoData->PowerConsumption - periousPeriodicPowerConsumption[gun_index]);
  8454. periousPeriodicPowerConsumption[gun_index] = targetChargingInfoData->PowerConsumption;
  8455. }
  8456. else
  8457. {
  8458. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = 0;
  8459. }
  8460. if(gunType[gun_index] == GUN_TYPE_AC)
  8461. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  8462. else
  8463. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8464. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].context, ReadingContextEnumTypeStr[dataType]);
  8465. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]);
  8466. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8467. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.uint , "kWh");
  8468. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.multiplier = 0;
  8469. }
  8470. //idx_sample=3;
  8471. //********************************(4)Power.Active.Import************************************************/
  8472. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]) != NULL)) ||
  8473. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]) != NULL)) ||
  8474. (dataType == ReadingContextEnumType_Trigger))
  8475. {
  8476. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8477. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(targetChargingInfoData->PresentChargingPower*100))/100.0;
  8478. if(gunType[gun_index] == GUN_TYPE_AC)
  8479. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  8480. else
  8481. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8482. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].context, ReadingContextEnumTypeStr[dataType]);
  8483. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]);
  8484. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8485. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].unitOfMeasure.uint , "kW");
  8486. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].unitOfMeasure.multiplier = 0;
  8487. }
  8488. //idx_sample=4;
  8489. //***********************************************(5)VOLTAGE L1******************************************************/
  8490. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8491. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8492. (dataType == ReadingContextEnumType_Trigger))
  8493. {
  8494. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8495. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(targetChargingInfoData->PresentChargingVoltage*100))/100.0;
  8496. if(gunType[gun_index] == GUN_TYPE_AC)
  8497. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  8498. else
  8499. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8500. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].context, ReadingContextEnumTypeStr[dataType]);
  8501. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  8502. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8503. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].unitOfMeasure.uint , "V");
  8504. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].unitOfMeasure.multiplier = 0;
  8505. }
  8506. //***********************************************(6)SOC******************************************************/
  8507. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) != NULL)) ||
  8508. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) != NULL)) ||
  8509. (dataType == ReadingContextEnumType_Trigger))
  8510. {
  8511. 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))
  8512. {
  8513. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = targetChargingInfoData->EvBatterySoc;
  8514. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].context, ReadingContextEnumTypeStr[dataType]);
  8515. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].measurand, MeasurandEnumTypeStr[MeasurandEnumType_SoC]);
  8516. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8517. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].location, LocationEnumTypeStr[LocationEnumType_EV]);
  8518. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].unitOfMeasure.uint , "Percent");
  8519. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].unitOfMeasure.multiplier = 0;
  8520. }
  8521. }
  8522. //********************************(7)Current.Import L2************************************************/
  8523. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8524. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8525. (dataType == ReadingContextEnumType_Trigger))
  8526. {
  8527. // Only for AC 3 phase
  8528. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8529. {
  8530. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].value = ((uint32_t)(targetChargingInfoData->PresentChargingCurrentL2*100))/100.0;
  8531. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].phase, PhaseEnumTypeStr[PhaseEnumType_L2_N]);
  8532. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].context, ReadingContextEnumTypeStr[dataType]);
  8533. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  8534. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8535. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].unitOfMeasure.uint , "A");
  8536. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].unitOfMeasure.multiplier = 0;
  8537. }
  8538. }
  8539. //********************************(8)Current.Import L3************************************************/
  8540. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8541. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  8542. (dataType == ReadingContextEnumType_Trigger))
  8543. {
  8544. // Only for AC 3 phase
  8545. if( (gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8546. {
  8547. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].value = ((uint32_t)(targetChargingInfoData->PresentChargingCurrentL3*100))/100.0;
  8548. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8549. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].context, ReadingContextEnumTypeStr[dataType]);
  8550. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  8551. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8552. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].unitOfMeasure.uint , "A");
  8553. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].unitOfMeasure.multiplier = 0;
  8554. }
  8555. }
  8556. //***********************************************(9)VOLTAGE L2******************************************************/
  8557. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8558. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8559. (dataType == ReadingContextEnumType_Trigger))
  8560. {
  8561. if( (gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8562. {
  8563. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].value = ((uint32_t)(targetChargingInfoData->PresentChargingVoltageL2*100))/100.0;
  8564. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].phase, PhaseEnumTypeStr[PhaseEnumType_L2_N]);
  8565. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].context, ReadingContextEnumTypeStr[dataType]);
  8566. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  8567. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8568. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].unitOfMeasure.uint , "V");
  8569. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].unitOfMeasure.multiplier = 0;
  8570. }
  8571. }
  8572. //***********************************************(10)VOLTAGE L3******************************************************/
  8573. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8574. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  8575. (dataType == ReadingContextEnumType_Trigger))
  8576. {
  8577. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  8578. {
  8579. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].value = ((uint32_t)(targetChargingInfoData->PresentChargingVoltageL3*100))/100.0;
  8580. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  8581. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].context, ReadingContextEnumTypeStr[dataType]);
  8582. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  8583. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8584. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].unitOfMeasure.uint , "V");
  8585. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].unitOfMeasure.multiplier = 0;
  8586. }
  8587. }
  8588. //***********************************************(11)Current.Offered******************************************************/
  8589. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) != NULL)) ||
  8590. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) != NULL)) ||
  8591. (dataType == ReadingContextEnumType_Trigger))
  8592. {
  8593. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8594. if(gunType[gun_index] == GUN_TYPE_AC)
  8595. {
  8596. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8597. {
  8598. tempIndex = 2;
  8599. }
  8600. else
  8601. {
  8602. tempIndex = gun_index;
  8603. }
  8604. for (int index = 0; index < AC_QUANTITY; index++)
  8605. {
  8606. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8607. {
  8608. uint16_t currentOffer;
  8609. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  8610. {
  8611. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  8612. }
  8613. else
  8614. {
  8615. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  8616. }
  8617. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = currentOffer;
  8618. }
  8619. }
  8620. }
  8621. else
  8622. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = (uint16_t)(targetChargingInfoData->AvailableChargingCurrent/10);
  8623. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].context, ReadingContextEnumTypeStr[dataType]);
  8624. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]);
  8625. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8626. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].unitOfMeasure.uint , "A");
  8627. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].unitOfMeasure.multiplier = 0;
  8628. }
  8629. //***********************************************(12)Power.Offered******************************************************/
  8630. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) != NULL)) ||
  8631. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) != NULL)) ||
  8632. (dataType == ReadingContextEnumType_Trigger))
  8633. {
  8634. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8635. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].value = (uint16_t)(targetChargingInfoData->AvailableChargingPower*100);
  8636. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].context, ReadingContextEnumTypeStr[dataType]);
  8637. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]);
  8638. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  8639. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].unitOfMeasure.uint , "W");
  8640. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].unitOfMeasure.multiplier = 0;
  8641. }
  8642. // Message create ====================================================================================================
  8643. random_uuid(guid);
  8644. json_object *MeterValueReq = json_object_new_object();
  8645. json_object *meterValues = json_object_new_array();
  8646. json_object *sampledValues = json_object_new_array();
  8647. json_object *sampledValuesBuffer = json_object_new_array();
  8648. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->MeterValues[gun_index].meterValue);idxMeter++)
  8649. {
  8650. json_object *meterValue = json_object_new_object();
  8651. json_object *MeterValueBuffer = json_object_new_object();
  8652. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  8653. {
  8654. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  8655. {
  8656. json_object *sampledValue = json_object_new_object();
  8657. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  8658. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  8659. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  8660. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  8661. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  8662. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  8663. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  8664. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  8665. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  8666. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.signedMeterData) > 0)
  8667. {
  8668. json_object *signedMeterValue = json_object_new_object();
  8669. json_object_object_add(signedMeterValue, "signedMeterData", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.signedMeterData));
  8670. json_object_object_add(signedMeterValue, "signingMethod", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.signingMethod));
  8671. json_object_object_add(signedMeterValue, "encodingMethod", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.encodingMethod));
  8672. json_object_object_add(signedMeterValue, "publicKey", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.publicKey));
  8673. json_object_object_add(sampledValue, "signedMeterValue", signedMeterValue);
  8674. }
  8675. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  8676. {
  8677. json_object *unitOfMeasure = json_object_new_object();
  8678. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  8679. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  8680. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  8681. }
  8682. json_object_array_add(sampledValues, sampledValue);
  8683. // For StopTxn data
  8684. if((isSampledDataTxEnd == TRUE) &&
  8685. (((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, (char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand ) != NULL) && (strlen((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value) > 0)) ||
  8686. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, (char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) != NULL) && (strlen((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value) > 0))))
  8687. {
  8688. json_object *sampledValue = json_object_new_object();
  8689. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  8690. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  8691. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  8692. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  8693. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  8694. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  8695. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  8696. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  8697. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  8698. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.signedMeterData) > 0)
  8699. {
  8700. json_object *signedMeterValue = json_object_new_object();
  8701. json_object_object_add(signedMeterValue, "signedMeterData", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.signedMeterData));
  8702. json_object_object_add(signedMeterValue, "signingMethod", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.signingMethod));
  8703. json_object_object_add(signedMeterValue, "encodingMethod", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.encodingMethod));
  8704. json_object_object_add(signedMeterValue, "publicKey", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].signedMeterValue.publicKey));
  8705. json_object_object_add(sampledValue, "signedMeterValue", signedMeterValue);
  8706. }
  8707. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  8708. {
  8709. json_object *unitOfMeasure = json_object_new_object();
  8710. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  8711. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  8712. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  8713. }
  8714. json_object_array_add(sampledValuesBuffer, sampledValue);
  8715. }
  8716. }
  8717. }
  8718. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].timestamp));
  8719. json_object_object_add(meterValue, "sampledValue", sampledValues);
  8720. json_object_array_add(meterValues, meterValue);
  8721. // For StopTxn data
  8722. if((isSampledDataTxEnd == TRUE) && (dataType != ReadingContextEnumType_Trigger) &&
  8723. (json_object_array_length(sampledValuesBuffer) > 0))
  8724. {
  8725. json_object_object_add(MeterValueBuffer, "timestamp", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].timestamp));
  8726. json_object_object_add(MeterValueBuffer, "sampledValue", sampledValuesBuffer);
  8727. if(meterValueBufferDataQuantity(gun_index, dataType) < 200)
  8728. meterValueBufferInsert(gun_index, dataType, (char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)json_object_to_json_string_ext(MeterValueBuffer, JSON_C_TO_STRING_PLAIN));
  8729. else
  8730. meterValueBufferReplace(200, gun_index, dataType, (char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)json_object_to_json_string_ext(MeterValueBuffer, JSON_C_TO_STRING_PLAIN));
  8731. json_object_put(MeterValueBuffer);
  8732. }
  8733. else
  8734. {
  8735. json_object_put(sampledValuesBuffer);
  8736. json_object_put(MeterValueBuffer);
  8737. }
  8738. idxMeter++;
  8739. }
  8740. json_object_object_add(MeterValueReq, "meterValue", meterValues);
  8741. json_object_object_add(MeterValueReq, "evseId", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].evseId));
  8742. sprintf(queuedata,"[%d,\"%s\",\"MeterValues\",%s]"
  8743. ,MESSAGE_TYPE_CALL
  8744. ,guid
  8745. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  8746. json_object_put(MeterValueReq);
  8747. if((dataType != ReadingContextEnumType_Trigger) &&
  8748. (dataType != ReadingContextEnumType_Sample_Clock))
  8749. {
  8750. // Transaction meter value send by TransactionEvent message
  8751. memcpy(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0], &ShmOCPP20Data->MeterValues[gun_index].meterValue[0], sizeof(struct MeterValueType));
  8752. if(isSampledDataTxEnd != TRUE)
  8753. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  8754. result = PASS;
  8755. }
  8756. else
  8757. {
  8758. // Put request guid to hash map
  8759. sprintf(tempdata, "MeterValues,%d", (gun_index));
  8760. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8761. {
  8762. result = PASS;
  8763. }
  8764. if((dataType != ReadingContextEnumType_Trigger) &&
  8765. (dataType != ReadingContextEnumType_Sample_Clock))
  8766. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  8767. else
  8768. {
  8769. if(FirstHeartBeat)
  8770. LWS_Send(queuedata);
  8771. }
  8772. }
  8773. return result;
  8774. }
  8775. int sendNotifyChargingLimitRequest(int gun_index)
  8776. {
  8777. mtrace();
  8778. int result = FAIL;
  8779. char message[4096]={0};
  8780. char guid[37]={0};
  8781. char tempdata[128]={0};
  8782. json_object *NotifyChargingLimit = json_object_new_object();
  8783. json_object *chargingLimit = json_object_new_object();
  8784. DEBUG_INFO("sendNotifyChargingLimitRequest...\n");
  8785. json_object_object_add(NotifyChargingLimit, "evseId", json_object_new_int(ShmOCPP20Data->NotifyChargingLimit[gun_index].evseId));
  8786. json_object_object_add(chargingLimit, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->NotifyChargingLimit[gun_index].chargingLimit.chargingLimitSource));
  8787. json_object_object_add(chargingLimit, "chargingLimitSource", json_object_new_boolean(ShmOCPP20Data->NotifyChargingLimit[gun_index].chargingLimit.isGridCritical));
  8788. json_object_object_add(NotifyChargingLimit, "chargingLimit", NotifyChargingLimit);
  8789. random_uuid(guid);
  8790. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyChargingLimit", json_object_to_json_string_ext(NotifyChargingLimit, JSON_C_TO_STRING_PLAIN));
  8791. json_object_put(NotifyChargingLimit);
  8792. LWS_Send(message);
  8793. sprintf(tempdata, "NotifyChargingLimit,%d", gun_index);
  8794. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8795. {
  8796. result = PASS;
  8797. }
  8798. return result;
  8799. }
  8800. int sendNotifyCustomerInformationRequest()
  8801. {
  8802. mtrace();
  8803. int result = FAIL;
  8804. char message[4096]={0};
  8805. char guid[37]={0};
  8806. char tempdata[128]={0};
  8807. json_object *NotifyCustomerInformation = json_object_new_object();
  8808. DEBUG_INFO("sendNotifyCustomerInformationRequest...\n");
  8809. json_object_object_add(NotifyCustomerInformation, "data", json_object_new_string((char*)ShmOCPP20Data->NotifyCustomerInformation.data));
  8810. json_object_object_add(NotifyCustomerInformation, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyCustomerInformation.tbc));
  8811. json_object_object_add(NotifyCustomerInformation, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyCustomerInformation.seqNo));
  8812. json_object_object_add(NotifyCustomerInformation, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyCustomerInformation.generatedAt));
  8813. json_object_object_add(NotifyCustomerInformation, "requestId", json_object_new_int(ShmOCPP20Data->NotifyCustomerInformation.requestId));
  8814. random_uuid(guid);
  8815. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyCustomerInformation", json_object_to_json_string_ext(NotifyCustomerInformation, JSON_C_TO_STRING_PLAIN));
  8816. json_object_put(NotifyCustomerInformation);
  8817. LWS_Send(message);
  8818. sprintf(tempdata, "NotifyCustomerInformation,0");
  8819. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8820. {
  8821. result = PASS;
  8822. }
  8823. return result;
  8824. }
  8825. int sendNotifyDisplayMessagesRequest()
  8826. {
  8827. mtrace();
  8828. int result = FAIL;
  8829. char message[4096]={0};
  8830. char guid[37]={0};
  8831. char tempdata[128]={0};
  8832. json_object *NotifyDisplayMessages = json_object_new_object();
  8833. json_object *messageInfos = json_object_new_array();
  8834. DEBUG_INFO("sendNotifyDisplayMessagesRequest...\n");
  8835. json_object_object_add(NotifyDisplayMessages, "requestId", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.requestId));
  8836. json_object_object_add(NotifyDisplayMessages, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyDisplayMessages.tbc));
  8837. for(int idxMsg=0;idxMsg<ARRAY_SIZE(ShmOCPP20Data->NotifyDisplayMessages.messageInfo);idxMsg++)
  8838. {
  8839. if(strlen((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.content) > 0)
  8840. {
  8841. json_object *messageInfo = json_object_new_object();
  8842. json_object *message = json_object_new_object();
  8843. json_object *display = json_object_new_object();
  8844. json_object *evse = json_object_new_object();
  8845. json_object_object_add(messageInfo, "id", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].id));
  8846. json_object_object_add(messageInfo, "priority", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].priority));
  8847. json_object_object_add(messageInfo, "state", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].state));
  8848. json_object_object_add(messageInfo, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].startDateTime));
  8849. json_object_object_add(messageInfo, "endDateTime", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].endDateTime));
  8850. json_object_object_add(messageInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].transactionId));
  8851. json_object_object_add(message, "format", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.format));
  8852. json_object_object_add(message, "language", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.language));
  8853. json_object_object_add(message, "content", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.content));
  8854. json_object_object_add(messageInfo, "message", message);
  8855. json_object_object_add(display, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.name));
  8856. json_object_object_add(display, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.instance));
  8857. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.evse.id));
  8858. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.evse.connectorId));
  8859. json_object_object_add(display, "evse",evse);
  8860. json_object_object_add(messageInfo, "evse", display);
  8861. json_object_array_add(messageInfos, messageInfo);
  8862. }
  8863. }
  8864. json_object_object_add(NotifyDisplayMessages, "messageInfo", messageInfos);
  8865. random_uuid(guid);
  8866. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyDisplayMessages", json_object_to_json_string_ext(NotifyDisplayMessages, JSON_C_TO_STRING_PLAIN));
  8867. json_object_put(NotifyDisplayMessages);
  8868. LWS_Send(message);
  8869. sprintf(tempdata, "NotifyDisplayMessages,0");
  8870. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8871. {
  8872. result = PASS;
  8873. }
  8874. return result;
  8875. }
  8876. int sendNotifyEVChargingNeedsRequest(int gun_index)
  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 *NotifyEVChargingNeeds = json_object_new_object();
  8884. json_object *chargingNeeds = json_object_new_object();
  8885. json_object *acChargingParameters = json_object_new_object();
  8886. json_object *dcChargingParameters = json_object_new_object();
  8887. DEBUG_INFO("sendNotifyEVChargingNeedsRequest...\n");
  8888. json_object_object_add(NotifyEVChargingNeeds, "maxScheduleTuples", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].maxScheduleTuples));
  8889. json_object_object_add(NotifyEVChargingNeeds, "evseId", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].evseId));
  8890. json_object_object_add(chargingNeeds, "requestedEnergyTransfer", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.requestedEnergyTransfer));
  8891. json_object_object_add(chargingNeeds, "departureTime", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.departureTime));
  8892. json_object_object_add(acChargingParameters, "energyAmount", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.energyAmount));
  8893. json_object_object_add(acChargingParameters, "evMinCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMinCurrent));
  8894. json_object_object_add(acChargingParameters, "evMaxCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMaxCurrent));
  8895. json_object_object_add(acChargingParameters, "evMaxVoltage", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMaxVoltage));
  8896. json_object_object_add(chargingNeeds, "acChargingParameters", acChargingParameters);
  8897. json_object_object_add(dcChargingParameters, "evMaxCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxCurrent));
  8898. json_object_object_add(dcChargingParameters, "evMaxVoltage", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxVoltage));
  8899. json_object_object_add(dcChargingParameters, "energyAmount", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.energyAmount));
  8900. json_object_object_add(dcChargingParameters, "evMaxPower", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxPower));
  8901. json_object_object_add(dcChargingParameters, "stateOfCharge", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.stateOfCharge));
  8902. json_object_object_add(dcChargingParameters, "evEnergyCapacity", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evEnergyCapacity));
  8903. json_object_object_add(dcChargingParameters, "fullSoC", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.fullSoC));
  8904. json_object_object_add(dcChargingParameters, "bulkSoC", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.bulkSoC));
  8905. json_object_object_add(chargingNeeds, "dcChargingParameters", dcChargingParameters);
  8906. json_object_object_add(NotifyEVChargingNeeds, "chargingNeeds", chargingNeeds);
  8907. random_uuid(guid);
  8908. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEVChargingNeeds", json_object_to_json_string_ext(NotifyEVChargingNeeds, JSON_C_TO_STRING_PLAIN));
  8909. json_object_put(NotifyEVChargingNeeds);
  8910. LWS_Send(message);
  8911. sprintf(tempdata, "NotifyEVChargingNeeds,%d", gun_index);
  8912. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8913. {
  8914. result = PASS;
  8915. }
  8916. return result;
  8917. }
  8918. int sendNotifyEVChargingScheduleRequest(int gun_index)
  8919. {
  8920. mtrace();
  8921. int result = FAIL;
  8922. char message[4096]={0};
  8923. char guid[37]={0};
  8924. char tempdata[128]={0};
  8925. json_object *NotifyEVChargingSchedule = json_object_new_object();
  8926. json_object *chargingSchedule = json_object_new_object();
  8927. json_object *periods = json_object_new_array();
  8928. DEBUG_INFO("sendNotifyEVChargingScheduleRequest...\n");
  8929. json_object_object_add(NotifyEVChargingSchedule, "timeBase", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].timeBase));
  8930. json_object_object_add(NotifyEVChargingSchedule, "evseId", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].evseId));
  8931. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.startSchedule));
  8932. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.duration));
  8933. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingRateUnit));
  8934. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.minChargingRate));
  8935. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.id));
  8936. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  8937. {
  8938. if(((ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  8939. (ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  8940. {
  8941. json_object *Period = json_object_new_object();
  8942. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  8943. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  8944. if(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  8945. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  8946. if(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  8947. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  8948. json_object_array_add(periods, Period);
  8949. }
  8950. }
  8951. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", periods);
  8952. json_object_object_add(NotifyEVChargingSchedule, "chargingSchedule", chargingSchedule);
  8953. random_uuid(guid);
  8954. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEVChargingSchedule", json_object_to_json_string_ext(NotifyEVChargingSchedule, JSON_C_TO_STRING_PLAIN));
  8955. json_object_put(NotifyEVChargingSchedule);
  8956. LWS_Send(message);
  8957. sprintf(tempdata, "NotifyEVChargingSchedule,%d", gun_index);
  8958. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8959. {
  8960. result = PASS;
  8961. }
  8962. return result;
  8963. }
  8964. int sendNotifyEventRequest()
  8965. {
  8966. mtrace();
  8967. int result = FAIL;
  8968. char message[4096]={0};
  8969. char guid[37]={0};
  8970. char tempdata[128]={0};
  8971. json_object *NotifyEvent = json_object_new_object();
  8972. json_object *eventDatas = json_object_new_array();
  8973. DEBUG_INFO("sendNotifyEventRequest...\n");
  8974. json_object_object_add(NotifyEvent, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.generatedAt));
  8975. json_object_object_add(NotifyEvent, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyEvent.tbc));
  8976. json_object_object_add(NotifyEvent, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyEvent.seqNo));
  8977. for(int idxEvent=0;idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData);idxEvent++)
  8978. {
  8979. if(strlen((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp) > 0)
  8980. {
  8981. json_object *eventData = json_object_new_object();
  8982. json_object *component = json_object_new_object();
  8983. json_object *evse = json_object_new_object();
  8984. json_object *variable = json_object_new_object();
  8985. json_object_object_add(eventData, "eventId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId));
  8986. json_object_object_add(eventData, "timestamp", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp));
  8987. json_object_object_add(eventData, "trigger", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger));
  8988. json_object_object_add(eventData, "cause", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cause));
  8989. json_object_object_add(eventData, "actualValue", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue));
  8990. json_object_object_add(eventData, "techCode", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode));
  8991. json_object_object_add(eventData, "techInfo", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo));
  8992. json_object_object_add(eventData, "cleared", json_object_new_boolean(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared));
  8993. json_object_object_add(eventData, "transactionId", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].transactionId));
  8994. json_object_object_add(eventData, "variableMonitoringId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variableMonitoringId));
  8995. json_object_object_add(eventData, "eventNotificationType", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType));
  8996. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name));
  8997. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.instance));
  8998. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.id));
  8999. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId));
  9000. json_object_object_add(component, "evse",evse);
  9001. json_object_object_add(eventData, "component", component);
  9002. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name));
  9003. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.instance));
  9004. json_object_object_add(eventData, "variable", variable);
  9005. json_object_array_add(eventDatas, eventData);
  9006. }
  9007. }
  9008. json_object_object_add(NotifyEvent, "eventData", eventDatas);
  9009. random_uuid(guid);
  9010. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEvent", json_object_to_json_string_ext(NotifyEvent, JSON_C_TO_STRING_PLAIN));
  9011. json_object_put(NotifyEvent);
  9012. LWS_Send(message);
  9013. sprintf(tempdata, "NotifyEvent,0");
  9014. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9015. {
  9016. result = PASS;
  9017. }
  9018. return result;
  9019. }
  9020. int sendNotifyMonitoringReportRequest()
  9021. {
  9022. mtrace();
  9023. int result = FAIL;
  9024. char message[4096]={0};
  9025. char guid[37]={0};
  9026. char tempdata[128]={0};
  9027. json_object *NotifyMonitoringReport = json_object_new_object();
  9028. json_object *monitors = json_object_new_array();
  9029. DEBUG_INFO("sendNotifyMonitoringReportRequest...\n");
  9030. json_object_object_add(NotifyMonitoringReport, "requestId", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.requestId));
  9031. json_object_object_add(NotifyMonitoringReport, "tbc", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.tbc));
  9032. json_object_object_add(NotifyMonitoringReport, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.seqNo));
  9033. json_object_object_add(NotifyMonitoringReport, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.generatedAt));
  9034. for(int idxMonitor=0;idxMonitor<ARRAY_SIZE(ShmOCPP20Data->NotifyMonitoringReport.monitor);idxMonitor++)
  9035. {
  9036. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.name) > 0)
  9037. {
  9038. json_object *monitor = json_object_new_object();
  9039. json_object *component = json_object_new_object();
  9040. json_object *evse = json_object_new_object();
  9041. json_object *variable = json_object_new_object();
  9042. json_object *variableMonitorings = json_object_new_array();
  9043. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.name));
  9044. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.instance));
  9045. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.evse.id));
  9046. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.evse.connectorId));
  9047. json_object_object_add(component, "evse",evse);
  9048. json_object_object_add(monitor, "component", component);
  9049. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variable.name));
  9050. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variable.instance));
  9051. json_object_object_add(monitor, "variable", variable);
  9052. for(int idxVar=0;idxVar<ARRAY_SIZE(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring);idxVar++)
  9053. {
  9054. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].type) > 0)
  9055. {
  9056. json_object *variableMonitoring = json_object_new_object();
  9057. json_object_object_add(variableMonitoring, "id", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].id));
  9058. json_object_object_add(variableMonitoring, "value", json_object_new_double(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].value));
  9059. json_object_object_add(variableMonitoring, "type", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].type));
  9060. json_object_object_add(variableMonitoring, "severity", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].severity));
  9061. json_object_object_add(variableMonitoring, "transaction", json_object_new_boolean(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].transaction));
  9062. json_object_array_add(variableMonitorings, variableMonitoring);
  9063. }
  9064. }
  9065. json_object_object_add(monitor, "variableMonitoring", variableMonitorings);
  9066. json_object_array_add(monitors, monitor);
  9067. }
  9068. }
  9069. json_object_object_add(NotifyMonitoringReport, "monitor", monitors);
  9070. random_uuid(guid);
  9071. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyMonitoringReport", json_object_to_json_string_ext(NotifyMonitoringReport, JSON_C_TO_STRING_PLAIN));
  9072. json_object_put(NotifyMonitoringReport);
  9073. LWS_Send(message);
  9074. sprintf(tempdata, "NotifyMonitoringReport,0");
  9075. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9076. {
  9077. result = PASS;
  9078. }
  9079. return result;
  9080. }
  9081. int sendNotifyReportRequest()
  9082. {
  9083. mtrace();
  9084. int result = FAIL;
  9085. char message[4096]={0};
  9086. char guid[37]={0};
  9087. char tempdata[128]={0};
  9088. json_object *NotifyReport = json_object_new_object();
  9089. json_object *reportDatas = json_object_new_array();
  9090. DEBUG_INFO("sendNotifyReportRequest...\n");
  9091. json_object_object_add(NotifyReport, "requestId", json_object_new_int(ShmOCPP20Data->NotifyReport.requestId));
  9092. json_object_object_add(NotifyReport, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.generatedAt));
  9093. json_object_object_add(NotifyReport, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyReport.tbc));
  9094. json_object_object_add(NotifyReport, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyReport.seqNo));
  9095. for(int idxReport=0;idxReport<ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData);idxReport++)
  9096. {
  9097. if(strlen((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.name) > 0)
  9098. {
  9099. json_object *reportData = json_object_new_object();
  9100. json_object *component = json_object_new_object();
  9101. json_object *evse = json_object_new_object();
  9102. json_object *variable = json_object_new_object();
  9103. json_object *variableAttributes = json_object_new_array();
  9104. json_object *variableCharacteristics = json_object_new_object();
  9105. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.name));
  9106. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.instance));
  9107. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyReport.reportData[idxReport].component.evse.id));
  9108. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyReport.reportData[idxReport].component.evse.connectorId));
  9109. json_object_object_add(component, "evse",evse);
  9110. json_object_object_add(reportData, "component", component);
  9111. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variable.name));
  9112. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variable.instance));
  9113. json_object_object_add(reportData, "variable",variable);
  9114. json_object_object_add(variableCharacteristics, "unit", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.unit));
  9115. json_object_object_add(variableCharacteristics, "dataType", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.dataType));
  9116. json_object_object_add(variableCharacteristics, "minLimit", json_object_new_double(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.minLimit));
  9117. json_object_object_add(variableCharacteristics, "maxLimit", json_object_new_double(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.maxLimit));
  9118. json_object_object_add(variableCharacteristics, "supportsMonitoring", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.supportsMonitoring));
  9119. json_object_object_add(reportData, "variableCharacteristics",variableCharacteristics);
  9120. for(int idxAttr=0;idxAttr<ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute);idxAttr++)
  9121. {
  9122. if(strlen((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].value) > 0)
  9123. {
  9124. json_object *variableAttribute = json_object_new_object();
  9125. json_object_object_add(variableAttribute, "type", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].type));
  9126. json_object_object_add(variableAttribute, "value", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].value));
  9127. json_object_object_add(variableAttribute, "mutability", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].mutability));
  9128. json_object_object_add(variableAttribute, "persistent", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].persistent));
  9129. json_object_object_add(variableAttribute, "constant", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].constant));
  9130. json_object_array_add(variableAttributes, variableAttribute);
  9131. }
  9132. }
  9133. json_object_object_add(reportData, "variableAttribute", variableAttributes);
  9134. json_object_array_add(reportDatas, reportData);
  9135. }
  9136. }
  9137. json_object_object_add(NotifyReport, "reportData", reportDatas);
  9138. random_uuid(guid);
  9139. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyReport", json_object_to_json_string_ext(NotifyReport, JSON_C_TO_STRING_PLAIN));
  9140. json_object_put(NotifyReport);
  9141. LWS_SendNow(message);
  9142. sprintf(tempdata, "NotifyReport,0");
  9143. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9144. {
  9145. result = PASS;
  9146. }
  9147. return result;
  9148. }
  9149. int sendPublishFirmwareStatusNotificationRequest()
  9150. {
  9151. mtrace();
  9152. int result = FAIL;
  9153. char message[4096]={0};
  9154. char guid[37]={0};
  9155. char tempdata[128]={0};
  9156. json_object *PublishFirmwareStatusNotification = json_object_new_object();
  9157. json_object *locations = json_object_new_array();
  9158. DEBUG_INFO("sendPublishFirmwareStatusNotificationRequest...\n");
  9159. json_object_object_add(PublishFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->PublishFirmwareStatusNotificatio.status));
  9160. json_object_object_add(PublishFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->PublishFirmwareStatusNotificatio.requestId));
  9161. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->PublishFirmwareStatusNotificatio.location);idx++)
  9162. {
  9163. json_object_array_add(locations, json_object_new_string((char*)ShmOCPP20Data->PublishFirmwareStatusNotificatio.location[idx]));
  9164. }
  9165. json_object_object_add(PublishFirmwareStatusNotification, "location", locations);
  9166. random_uuid(guid);
  9167. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "PublishFirmwareStatusNotification", json_object_to_json_string_ext(PublishFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  9168. json_object_put(PublishFirmwareStatusNotification);
  9169. LWS_Send(message);
  9170. sprintf(tempdata, "PublishFirmwareStatusNotification,0");
  9171. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9172. {
  9173. result = PASS;
  9174. }
  9175. return result;
  9176. }
  9177. int sendReportChargingProfilesRequest(int gun_index)
  9178. {
  9179. mtrace();
  9180. int result = FAIL;
  9181. char message[4096]={0};
  9182. char guid[37]={0};
  9183. char tempdata[128]={0};
  9184. json_object *ReportChargingProfiles = json_object_new_object();
  9185. json_object *chargingProfiles = json_object_new_array();
  9186. DEBUG_INFO("sendReportChargingProfilesRequest...\n");
  9187. json_object_object_add(ReportChargingProfiles, "requestId", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].requestId));
  9188. json_object_object_add(ReportChargingProfiles, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingLimitSource));
  9189. json_object_object_add(ReportChargingProfiles, "tbc", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].tbc));
  9190. json_object_object_add(ReportChargingProfiles, "evseId", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].evseId));
  9191. for(int idxProfile=0;idxProfile<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile);idxProfile++)
  9192. {
  9193. json_object *chargingProfile = json_object_new_object();
  9194. json_object *chargingSchedules = json_object_new_array();
  9195. json_object_object_add(chargingProfile, "id", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].id));
  9196. json_object_object_add(chargingProfile, "stackLevel", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].stackLevel));
  9197. json_object_object_add(chargingProfile, "chargingProfilePurpose", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingProfilePurpose));
  9198. json_object_object_add(chargingProfile, "chargingProfileKind", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingProfileKind));
  9199. json_object_object_add(chargingProfile, "recurrencyKind", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].recurrencyKind));
  9200. json_object_object_add(chargingProfile, "validFrom", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].validFrom));
  9201. json_object_object_add(chargingProfile, "validTo", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].validTo));
  9202. json_object_object_add(chargingProfile, "transactionId", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].transactionId));
  9203. for(int idxSchedule=0;idxSchedule<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule);idxSchedule++)
  9204. {
  9205. json_object *chargingSchedule = json_object_new_object();
  9206. json_object *chargingSchedulePeriods = json_object_new_array();
  9207. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].startSchedule));
  9208. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].duration));
  9209. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingRateUnit));
  9210. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].minChargingRate));
  9211. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].id));
  9212. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  9213. {
  9214. json_object *chargingSchedulePeriod = json_object_new_object();
  9215. json_object_object_add(chargingSchedulePeriod, "startPeriod", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod));
  9216. json_object_object_add(chargingSchedulePeriod, "limit", json_object_new_double(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit));
  9217. json_object_object_add(chargingSchedulePeriod, "numberPhases", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  9218. json_object_object_add(chargingSchedulePeriod, "phaseToUse", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse));
  9219. json_object_array_add(chargingSchedulePeriods, chargingSchedulePeriod);
  9220. }
  9221. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriods);
  9222. json_object_array_add(chargingSchedules, chargingSchedule);
  9223. }
  9224. json_object_object_add(chargingProfile, "chargingSchedule", chargingSchedules);
  9225. json_object_array_add(chargingProfiles, chargingProfile);
  9226. }
  9227. json_object_object_add(ReportChargingProfiles, "chargingProfile", chargingProfiles);
  9228. random_uuid(guid);
  9229. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ReportChargingProfiles", json_object_to_json_string_ext(ReportChargingProfiles, JSON_C_TO_STRING_PLAIN));
  9230. json_object_put(ReportChargingProfiles);
  9231. LWS_Send(message);
  9232. sprintf(tempdata, "ReportChargingProfiles,%d", gun_index);
  9233. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9234. {
  9235. result = PASS;
  9236. }
  9237. return result;
  9238. }
  9239. int sendReservationStatusUpdateRequest(int gun_index)
  9240. {
  9241. mtrace();
  9242. int result = FAIL;
  9243. char message[4096]={0};
  9244. char guid[37]={0};
  9245. char tempdata[128]={0};
  9246. json_object *ReservationStatusUpdate = json_object_new_object();
  9247. DEBUG_INFO("sendReservationStatusUpdateRequest...\n");
  9248. json_object_object_add(ReservationStatusUpdate, "reservationId", json_object_new_int(ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationId));
  9249. json_object_object_add(ReservationStatusUpdate, "reservationUpdateStatus", json_object_new_string((char*)ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationUpdateStatus));
  9250. random_uuid(guid);
  9251. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ReservationStatusUpdate", json_object_to_json_string_ext(ReservationStatusUpdate, JSON_C_TO_STRING_PLAIN));
  9252. json_object_put(ReservationStatusUpdate);
  9253. LWS_Send(message);
  9254. sprintf(tempdata, "ReservationStatusUpdate,%d", gun_index);
  9255. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9256. {
  9257. result = PASS;
  9258. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = OFF;
  9259. }
  9260. return result;
  9261. }
  9262. int sendSecurityEventNotificationRequest()
  9263. {
  9264. mtrace();
  9265. int result = FAIL;
  9266. char message[4096]={0};
  9267. char guid[37]={0};
  9268. char tempdata[128]={0};
  9269. struct timeval tmnow;
  9270. struct tm *tm;
  9271. char buf[28];//, usec_buf[6];
  9272. json_object *SecurityEventNotification = json_object_new_object();
  9273. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  9274. DB_getSecurityEventType();
  9275. gettimeofday(&tmnow, NULL);
  9276. time_t t;
  9277. t = time(NULL);
  9278. /*UTC time and date*/
  9279. tm = gmtime(&t);
  9280. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  9281. #if 0 // remove temporally
  9282. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  9283. strcat(buf,".");
  9284. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  9285. strcat(buf,usec_buf);
  9286. #endif
  9287. printf("%s",buf);
  9288. strcpy((char *)ShmOCPP20Data->SecurityEventNotification.timestamp, buf);
  9289. if(strlen((char *)ShmOCPP20Data->SecurityEventNotification.techInfo)==0)
  9290. sprintf((char*)ShmOCPP20Data->SecurityEventNotification.type,"%s", SecurityEventEnumTypeStr[SecurityEventEnumType_ResetOrReboot]);
  9291. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.type));
  9292. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.timestamp));
  9293. if(strlen((char *)ShmOCPP20Data->SecurityEventNotification.techInfo)>0)
  9294. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.techInfo));
  9295. random_uuid(guid);
  9296. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  9297. json_object_put(SecurityEventNotification);
  9298. LWS_Send(message);
  9299. sprintf(tempdata, "SecurityEventNotification,0");
  9300. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9301. {
  9302. result = PASS;
  9303. }
  9304. return result;
  9305. }
  9306. int sendSignCertificateRequest(CertificateSigningUseEnumType certType)
  9307. {
  9308. mtrace();
  9309. int result = FAIL;
  9310. char message[4096]={0};
  9311. char guid[37]={0};
  9312. char tempdata[128]={0};
  9313. json_object *SignCertificate = json_object_new_object();
  9314. DEBUG_INFO("sendSignCertificateRequest...\n");
  9315. // Read csr file content
  9316. memset(ShmOCPP20Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP20Data->SignCertificate.csr));
  9317. FILE *fp=fopen(((certType == CertificateSignedStatusEnumType_V2GCertificate)?CSR_V2G:CSR_CP),"r");
  9318. char *line = NULL;
  9319. size_t len = 0;
  9320. while(getline(&line, &len, fp) != -1)
  9321. {
  9322. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  9323. {
  9324. memcpy(&ShmOCPP20Data->SignCertificate.csr[strlen((char*)ShmOCPP20Data->SignCertificate.csr)], line, (strlen(line)-1));
  9325. }
  9326. }
  9327. fclose(fp);
  9328. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP20Data->SignCertificate.csr));
  9329. sprintf((char*)ShmOCPP20Data->SignCertificate.certificateType, CertificateSigningUseEnumTypeStr[certType]);
  9330. json_object_object_add(SignCertificate, "certificateType", json_object_new_string((char*)ShmOCPP20Data->SignCertificate.certificateType));
  9331. random_uuid(guid);
  9332. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  9333. json_object_put(SignCertificate);
  9334. LWS_Send(message);
  9335. sprintf(tempdata, "SignCertificate,0");
  9336. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9337. {
  9338. result = PASS;
  9339. }
  9340. return result;
  9341. }
  9342. int sendStatusNotificationRequest(int gun_index)
  9343. {
  9344. mtrace();
  9345. int result = FAIL;
  9346. char message[600]={0};
  9347. char guid[37];
  9348. int currentStatus = 0;
  9349. struct timeval tmnow;
  9350. struct tm *tm;
  9351. char buf[28];//, usec_buf[6];
  9352. char tempdata[65]={0};
  9353. int tempIndex = 0;
  9354. uint8_t isStateChanged = TRUE;
  9355. DEBUG_INFO("sendStatusNotificationRequest...\n");
  9356. gettimeofday(&tmnow, NULL);
  9357. time_t t;
  9358. t = time(NULL);
  9359. /*UTC time and date*/
  9360. tm = gmtime(&t);
  9361. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  9362. #if 0 // remove temporally
  9363. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  9364. strcat(buf,".");
  9365. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  9366. strcat(buf,usec_buf);
  9367. #endif
  9368. printf("%s",buf);
  9369. ShmOCPP20Data->StatusNotification[gun_index].evseId = (gun_index + 1);
  9370. ShmOCPP20Data->StatusNotification[gun_index].connectorId = 1;
  9371. strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].timestamp, buf);
  9372. //strcpy(ShmOCPP20Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  9373. /*
  9374. enum _SYSTEM_STATUS
  9375. {
  9376. S_BOOTING = 0,
  9377. S_IDLE, = 1
  9378. S_AUTHORIZING, =2
  9379. S_REASSIGN_CHECK, =3
  9380. S_REASSIGN, =4
  9381. S_PRECHARGE, =5
  9382. S_PREPARING_FOR_EV, =6
  9383. S_PREPARING_FOR_EVSE, =7
  9384. S_CHARGING, =8
  9385. S_TERMINATING, =9
  9386. S_COMPLETE, =10
  9387. S_ALARM, =11
  9388. S_FAULT =12
  9389. }
  9390. */
  9391. //check Transaction active
  9392. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  9393. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9394. {
  9395. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9396. {
  9397. tempIndex = ((gun_index==2) ? 1: 0);
  9398. }
  9399. else
  9400. {
  9401. tempIndex = gun_index;
  9402. }
  9403. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9404. {
  9405. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  9406. {
  9407. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  9408. {
  9409. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9410. {
  9411. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9412. }
  9413. else
  9414. {
  9415. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9416. }
  9417. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9418. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9419. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9420. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9421. }
  9422. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9423. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9424. ) //S_PRECHARGE
  9425. {
  9426. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9427. }
  9428. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9429. {
  9430. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9431. }
  9432. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9433. {
  9434. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9435. }
  9436. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9437. {
  9438. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9439. }
  9440. 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
  9441. {
  9442. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9443. }
  9444. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9445. {
  9446. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9447. }
  9448. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9449. {
  9450. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9451. }
  9452. } //end of the same index
  9453. }//end of for CHAdeMO_QUANTITY
  9454. }
  9455. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9456. {
  9457. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9458. {
  9459. tempIndex = ((gun_index==2) ? 1: 0);
  9460. }
  9461. else
  9462. {
  9463. tempIndex = gun_index;
  9464. }
  9465. for (int index = 0; index < CCS_QUANTITY; index++)
  9466. {
  9467. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9468. {
  9469. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9470. {
  9471. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  9472. {
  9473. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9474. }
  9475. else
  9476. {
  9477. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9478. }
  9479. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9480. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9481. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9482. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9483. }
  9484. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9485. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9486. ) //S_PRECHARGE
  9487. {
  9488. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9489. }
  9490. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9491. {
  9492. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9493. }
  9494. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9495. {
  9496. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9497. }
  9498. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  9499. {
  9500. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9501. }
  9502. 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
  9503. {
  9504. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status : Unavailable
  9505. }
  9506. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  9507. {
  9508. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9509. }
  9510. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9511. {
  9512. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9513. }
  9514. } //end of the same index
  9515. } // end of for CCS_QUANTITY
  9516. }
  9517. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9518. {
  9519. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9520. {
  9521. tempIndex = ((gun_index==2) ? 1: 0);
  9522. }
  9523. else
  9524. {
  9525. tempIndex = gun_index;
  9526. }
  9527. for (int index = 0; index < GB_QUANTITY; index++)
  9528. {
  9529. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9530. {
  9531. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9532. {
  9533. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9534. {
  9535. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9536. }
  9537. else
  9538. {
  9539. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9540. }
  9541. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9542. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9543. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9544. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9545. }
  9546. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9547. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9548. ) //S_PRECHARGE
  9549. {
  9550. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9551. }
  9552. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9553. {
  9554. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9555. }
  9556. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9557. {
  9558. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9559. }
  9560. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9561. {
  9562. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9563. }
  9564. 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
  9565. {
  9566. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9567. }
  9568. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  9569. {
  9570. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9571. }
  9572. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9573. {
  9574. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9575. }
  9576. } //end of the same index
  9577. } // end of for GB_QUANTITY
  9578. }
  9579. else if(gunType[gun_index] == GUN_TYPE_DO)
  9580. {
  9581. tempIndex = gun_index;
  9582. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9583. {
  9584. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9585. {
  9586. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9587. {
  9588. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9589. {
  9590. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9591. }
  9592. else
  9593. {
  9594. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9595. }
  9596. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9597. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9598. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9599. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9600. }
  9601. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9602. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9603. ) //S_PRECHARGE
  9604. {
  9605. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9606. }
  9607. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9608. {
  9609. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9610. }
  9611. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9612. {
  9613. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9614. }
  9615. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9616. {
  9617. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9618. }
  9619. 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
  9620. {
  9621. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9622. }
  9623. 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
  9624. {
  9625. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9626. }
  9627. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9628. {
  9629. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9630. }
  9631. } //end of the same index
  9632. }
  9633. }
  9634. else
  9635. {
  9636. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9637. {
  9638. tempIndex = 2;
  9639. }
  9640. else
  9641. {
  9642. tempIndex = gun_index;
  9643. }
  9644. for (int index = 0; index < AC_QUANTITY; index++)
  9645. {
  9646. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9647. {
  9648. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  9649. {
  9650. 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))
  9651. {
  9652. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9653. }
  9654. else
  9655. {
  9656. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  9657. }
  9658. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9659. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9660. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9661. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9662. }
  9663. else if (/*(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || */(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  9664. {
  9665. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  9666. }
  9667. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  9668. {
  9669. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  9670. }
  9671. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  9672. {
  9673. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  9674. }
  9675. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9676. {
  9677. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  9678. }
  9679. 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
  9680. {
  9681. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  9682. }
  9683. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9684. {
  9685. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  9686. }
  9687. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9688. {
  9689. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  9690. }
  9691. }//end of the same index
  9692. }//end of for AC_QUANTITY
  9693. }
  9694. //it's option
  9695. if((strstr((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]) != NULL) &&
  9696. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  9697. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].value, "true") != 0))
  9698. {
  9699. isStateChanged = FALSE;
  9700. }
  9701. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  9702. strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]);
  9703. random_uuid(guid);
  9704. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"evseId\":%d,\"connectorStatus\":\"%s\",\"timestamp\":\"%s\"}]"
  9705. , MESSAGE_TYPE_CALL
  9706. , guid
  9707. , ShmOCPP20Data->StatusNotification[gun_index].connectorId
  9708. , ShmOCPP20Data->StatusNotification[gun_index].evseId
  9709. , ShmOCPP20Data->StatusNotification[gun_index].connectorStatus
  9710. , ShmOCPP20Data->StatusNotification[gun_index].timestamp);
  9711. if((server_sign == TRUE) && isStateChanged)
  9712. {
  9713. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  9714. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  9715. LWS_Send(message);
  9716. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  9717. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9718. {
  9719. result = PASS;
  9720. }
  9721. }
  9722. else
  9723. {
  9724. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  9725. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  9726. result = PASS;
  9727. }
  9728. return result;
  9729. }
  9730. int sendTransactionEventRequest(int gun_index)
  9731. {
  9732. mtrace();
  9733. int result = FAIL;
  9734. char message[QUEUE_MESSAGE_LENGTH]={0};
  9735. char guid[37]={0};
  9736. char tempdata[128]={0};
  9737. uint8_t tempIndex;
  9738. json_object *TransactionEvent = json_object_new_object();
  9739. json_object *transactionInfo = json_object_new_object();
  9740. json_object *idToken = json_object_new_object();
  9741. json_object *evse = json_object_new_object();
  9742. json_object *meterValues = json_object_new_array();
  9743. char TempStopTransaction[256];
  9744. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  9745. DEBUG_INFO("sendTransactionEventRequest...\n");
  9746. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  9747. {
  9748. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9749. {
  9750. tempIndex = ((gun_index==2) ? 1: 0);
  9751. }
  9752. else
  9753. {
  9754. tempIndex = gun_index;
  9755. }
  9756. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9757. {
  9758. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  9759. {
  9760. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9761. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9762. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9763. else
  9764. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9765. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9766. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9767. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = 1;
  9768. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  9769. {
  9770. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9771. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9772. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9773. {
  9774. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9775. }
  9776. else
  9777. {
  9778. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9779. }
  9780. }
  9781. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9782. {
  9783. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9784. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9785. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9786. }
  9787. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9788. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9789. ) //S_PRECHARGE
  9790. {
  9791. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9792. {
  9793. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9794. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartUserId);
  9795. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartIdType]);
  9796. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9797. }
  9798. else
  9799. {
  9800. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9801. }
  9802. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9803. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9804. }
  9805. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9806. {
  9807. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9808. {
  9809. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartMethod == 2)
  9810. {
  9811. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  9812. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  9813. }
  9814. else
  9815. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9816. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9817. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartUserId);
  9818. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartIdType]);
  9819. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9820. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9821. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  9822. }
  9823. else
  9824. {
  9825. storeTempStopTransaction(gun_index);
  9826. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9827. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9828. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9829. }
  9830. }
  9831. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9832. {
  9833. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9834. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9835. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9836. if((access(TempStopTransaction,F_OK))!=-1)
  9837. {
  9838. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9839. }
  9840. }
  9841. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9842. {
  9843. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9844. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9845. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9846. }
  9847. 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
  9848. {
  9849. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9850. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9851. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9852. }
  9853. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9854. {
  9855. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9856. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9857. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9858. }
  9859. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9860. {
  9861. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9862. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9863. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9864. }
  9865. } //end of the same index
  9866. }//end of for CHAdeMO_QUANTITY
  9867. }
  9868. else if(gunType[gun_index] == GUN_TYPE_CCS)
  9869. {
  9870. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9871. {
  9872. tempIndex = ((gun_index==2) ? 1: 0);
  9873. }
  9874. else
  9875. {
  9876. tempIndex = gun_index;
  9877. }
  9878. for (int index = 0; index < CCS_QUANTITY; index++)
  9879. {
  9880. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  9881. {
  9882. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9883. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9884. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9885. else
  9886. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9887. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9888. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9889. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = 1;
  9890. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9891. {
  9892. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9893. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9894. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  9895. {
  9896. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9897. }
  9898. else
  9899. {
  9900. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9901. }
  9902. }
  9903. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9904. {
  9905. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9906. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9907. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9908. }
  9909. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9910. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9911. ) //S_PRECHARGE
  9912. {
  9913. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9914. {
  9915. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9916. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartUserId);
  9917. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartIdType]);
  9918. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9919. }
  9920. else
  9921. {
  9922. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9923. }
  9924. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9925. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9926. }
  9927. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9928. {
  9929. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9930. {
  9931. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartMethod == 2)
  9932. {
  9933. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  9934. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  9935. }
  9936. else
  9937. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9938. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9939. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartUserId);
  9940. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartIdType]);
  9941. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9942. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9943. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  9944. }
  9945. else
  9946. {
  9947. storeTempStopTransaction(gun_index);
  9948. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9949. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9950. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9951. }
  9952. }
  9953. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9954. {
  9955. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9956. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9957. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9958. if((access(TempStopTransaction,F_OK))!=-1)
  9959. {
  9960. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9961. }
  9962. }
  9963. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9964. {
  9965. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9966. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9967. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9968. }
  9969. 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
  9970. {
  9971. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9972. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9973. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9974. }
  9975. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9976. {
  9977. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9978. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9979. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9980. }
  9981. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9982. {
  9983. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9984. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9985. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9986. }
  9987. } //end of the same index
  9988. } // end of for CCS_QUANTITY
  9989. }
  9990. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9991. {
  9992. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9993. {
  9994. tempIndex = ((gun_index==2) ? 1: 0);
  9995. }
  9996. else
  9997. {
  9998. tempIndex = gun_index;
  9999. }
  10000. for (int index = 0; index < GB_QUANTITY; index++)
  10001. {
  10002. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  10003. {
  10004. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  10005. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  10006. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  10007. else
  10008. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  10009. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  10010. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  10011. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = 1;
  10012. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10013. {
  10014. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10015. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  10016. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  10017. {
  10018. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  10019. }
  10020. else
  10021. {
  10022. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  10023. }
  10024. }
  10025. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  10026. {
  10027. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10028. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  10029. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  10030. }
  10031. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  10032. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  10033. ) //S_PRECHARGE
  10034. {
  10035. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  10036. {
  10037. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  10038. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartUserId);
  10039. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartIdType]);
  10040. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10041. }
  10042. else
  10043. {
  10044. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10045. }
  10046. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  10047. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10048. }
  10049. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  10050. {
  10051. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  10052. {
  10053. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartMethod == 2)
  10054. {
  10055. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  10056. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  10057. }
  10058. else
  10059. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  10060. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10061. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartUserId);
  10062. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartIdType]);
  10063. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10064. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10065. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  10066. }
  10067. else
  10068. {
  10069. storeTempStopTransaction(gun_index);
  10070. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10071. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10072. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  10073. }
  10074. }
  10075. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  10076. {
  10077. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  10078. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10079. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10080. if((access(TempStopTransaction,F_OK))!=-1)
  10081. {
  10082. remove(TempStopTransaction); // remove file "TempStopTransaction"
  10083. }
  10084. }
  10085. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  10086. {
  10087. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10088. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  10089. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10090. }
  10091. 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
  10092. {
  10093. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10094. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10095. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10096. }
  10097. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  10098. {
  10099. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10100. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10101. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10102. }
  10103. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  10104. {
  10105. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10106. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10107. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10108. }
  10109. } //end of the same index
  10110. } // end of for GB_QUANTITY
  10111. }
  10112. else if(gunType[gun_index] == GUN_TYPE_DO)
  10113. {
  10114. tempIndex = gun_index;
  10115. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10116. {
  10117. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  10118. {
  10119. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  10120. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  10121. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  10122. else
  10123. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  10124. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  10125. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  10126. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = 1;
  10127. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  10128. {
  10129. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10130. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  10131. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  10132. {
  10133. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  10134. }
  10135. else
  10136. {
  10137. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  10138. }
  10139. }
  10140. else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  10141. {
  10142. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10143. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  10144. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  10145. }
  10146. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  10147. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  10148. ) //S_PRECHARGE
  10149. {
  10150. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  10151. {
  10152. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  10153. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartUserId);
  10154. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartIdType]);
  10155. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10156. }
  10157. else
  10158. {
  10159. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10160. }
  10161. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  10162. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10163. }
  10164. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  10165. {
  10166. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  10167. {
  10168. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartMethod == 2)
  10169. {
  10170. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  10171. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  10172. }
  10173. else
  10174. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  10175. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10176. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartUserId);
  10177. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartIdType]);
  10178. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10179. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10180. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  10181. }
  10182. else
  10183. {
  10184. storeTempStopTransaction(gun_index);
  10185. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10186. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10187. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  10188. }
  10189. }
  10190. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  10191. {
  10192. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  10193. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10194. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10195. if((access(TempStopTransaction,F_OK))!=-1)
  10196. {
  10197. remove(TempStopTransaction); // remove file "TempStopTransaction"
  10198. }
  10199. }
  10200. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  10201. {
  10202. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10203. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  10204. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10205. }
  10206. 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
  10207. {
  10208. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10209. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10210. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10211. }
  10212. 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
  10213. {
  10214. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10215. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10216. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10217. }
  10218. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  10219. {
  10220. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10221. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10222. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10223. }
  10224. } //end of the same index
  10225. }
  10226. }
  10227. else
  10228. {
  10229. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10230. {
  10231. tempIndex = 2;
  10232. }
  10233. else
  10234. {
  10235. tempIndex = gun_index;
  10236. }
  10237. for (int index = 0; index < AC_QUANTITY; index++)
  10238. {
  10239. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  10240. {
  10241. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  10242. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  10243. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  10244. else
  10245. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  10246. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  10247. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  10248. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = 1;
  10249. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  10250. {
  10251. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10252. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  10253. 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))
  10254. {
  10255. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  10256. }
  10257. else
  10258. {
  10259. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  10260. }
  10261. }
  10262. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  10263. {
  10264. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10265. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  10266. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  10267. }
  10268. else if ( ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  10269. ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  10270. ) //S_PRECHARGE
  10271. {
  10272. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  10273. {
  10274. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  10275. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartUserId);
  10276. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartIdType]);
  10277. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10278. }
  10279. else
  10280. {
  10281. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10282. }
  10283. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  10284. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10285. }
  10286. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  10287. {
  10288. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  10289. {
  10290. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == 2)
  10291. {
  10292. ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId = ShmOCPP20Data->RequestStartTransaction[index].remoteStartId;
  10293. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, (char*)ShmOCPP20Data->RequestStartTransaction[index].Response_transactionId);
  10294. }
  10295. else
  10296. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  10297. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10298. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartUserId);
  10299. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartIdType]);
  10300. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10301. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10302. periousPeriodicPowerConsumption[gun_index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  10303. }
  10304. else
  10305. {
  10306. storeTempStopTransaction(gun_index);
  10307. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10308. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  10309. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  10310. }
  10311. }
  10312. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  10313. {
  10314. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  10315. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10316. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10317. if((access(TempStopTransaction,F_OK))!=-1)
  10318. {
  10319. remove(TempStopTransaction); // remove file "TempStopTransaction"
  10320. }
  10321. }
  10322. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  10323. {
  10324. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10325. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  10326. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  10327. }
  10328. 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
  10329. {
  10330. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10331. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10332. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10333. }
  10334. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  10335. {
  10336. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10337. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10338. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10339. }
  10340. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  10341. {
  10342. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  10343. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  10344. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  10345. }
  10346. }//end of the same index
  10347. }//end of for AC_QUANTITY
  10348. }
  10349. // Check if this message is triggered by TriggerMessage
  10350. if(cpinitateMsg.bits[gun_index].TriggerTransactionEventReq == ON)
  10351. {
  10352. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  10353. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Trigger]);
  10354. }
  10355. // Clear meterValue buffer for the next transaction
  10356. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Started]) != NULL)
  10357. {
  10358. meterValueBufferClear(gun_index);
  10359. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Transaction_Begin, FALSE);
  10360. }
  10361. // Message
  10362. json_object_object_add(TransactionEvent, "eventType", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  10363. json_object_object_add(TransactionEvent, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].timestamp));
  10364. json_object_object_add(TransactionEvent, "triggerReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason));
  10365. json_object_object_add(TransactionEvent, "seqNo", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].seqNo));
  10366. json_object_object_add(TransactionEvent, "offline", json_object_new_boolean(ShmOCPP20Data->TransactionEvent[gun_index].offline));
  10367. if(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed > 0)
  10368. json_object_object_add(TransactionEvent, "numberOfPhasesUsed", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed));
  10369. if(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent > 0)
  10370. json_object_object_add(TransactionEvent, "cableMaxCurrent", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent));
  10371. if(ShmOCPP20Data->TransactionEvent[gun_index].reservationId > 0)
  10372. json_object_object_add(TransactionEvent, "reservationId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].reservationId));
  10373. json_object_object_add(transactionInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId));
  10374. json_object_object_add(transactionInfo, "chargingState", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState));
  10375. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging > 0)
  10376. json_object_object_add(transactionInfo, "timeSpentCharging", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging));
  10377. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason) > 0) && (strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL))
  10378. json_object_object_add(transactionInfo, "stoppedReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason));
  10379. //if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId > 0)
  10380. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[gun_index].StartMethod == 2)
  10381. json_object_object_add(transactionInfo, "remoteStartId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId));
  10382. json_object_object_add(TransactionEvent, "transactionInfo", transactionInfo);
  10383. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken) > 0)
  10384. {
  10385. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
  10386. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type));
  10387. json_object_object_add(TransactionEvent, "idToken", idToken);
  10388. }
  10389. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.id));
  10390. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId));
  10391. json_object_object_add(TransactionEvent, "evse", evse);
  10392. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0].timestamp) > 0) && (strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) == NULL))
  10393. {
  10394. for(int idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue);idxMeter++)
  10395. {
  10396. json_object *meterValue = json_object_new_object();
  10397. json_object *sampledValues = json_object_new_array();
  10398. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].timestamp));
  10399. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  10400. {
  10401. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0) &&
  10402. ((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0) ||
  10403. (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) == 0) ||
  10404. (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) == 0) ||
  10405. (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) == 0)))
  10406. {
  10407. if(((strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Started]) != NULL) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].value, (char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) != NULL)) ||
  10408. ((strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Started]) == NULL)))
  10409. {
  10410. json_object *sampledValue = json_object_new_object();
  10411. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  10412. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  10413. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  10414. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  10415. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  10416. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  10417. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  10418. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  10419. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  10420. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  10421. {
  10422. json_object *unitOfMeasure = json_object_new_object();
  10423. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  10424. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  10425. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  10426. }
  10427. json_object_array_add(sampledValues, sampledValue);
  10428. }
  10429. }
  10430. }
  10431. json_object_object_add(meterValue, "sampledValue", sampledValues);
  10432. json_object_array_add(meterValues, meterValue);
  10433. }
  10434. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  10435. }
  10436. else if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL)
  10437. {
  10438. json_object *meterValues = json_object_new_array();
  10439. meterValueBufferQuery(gun_index, meterValues);
  10440. if(json_object_array_length(meterValues) > 0)
  10441. {
  10442. DEBUG_INFO("parsed meterValue: %s\n", json_object_to_json_string_ext(meterValues, JSON_C_TO_STRING_PLAIN));
  10443. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  10444. }
  10445. }
  10446. random_uuid(guid);
  10447. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "TransactionEvent", json_object_to_json_string_ext(TransactionEvent, JSON_C_TO_STRING_PLAIN));
  10448. json_object_put(TransactionEvent);
  10449. sprintf(tempdata, "TransactionEvent,%d", gun_index);
  10450. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  10451. {
  10452. result = PASS;
  10453. }
  10454. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  10455. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Started]) != NULL)
  10456. {
  10457. OCPP_insert_transaction_msg(YES, message);
  10458. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  10459. }
  10460. else if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL)
  10461. {
  10462. OCPP_insert_transaction_msg(NO, message);
  10463. memset(&ShmOCPP20Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  10464. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  10465. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  10466. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  10467. }
  10468. return result;
  10469. }
  10470. //==========================================
  10471. // send confirm routine
  10472. //==========================================
  10473. int sendCancelReservationConfirmation(char *uuid, unsigned char gun_index)
  10474. {
  10475. mtrace();
  10476. int result = FAIL;
  10477. char message[4096]={0};
  10478. json_object *CancelReservation = json_object_new_object();
  10479. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  10480. json_object_object_add(CancelReservation, "status", json_object_new_string((char*)ShmOCPP20Data->CancelReservation[gun_index].Response_status));
  10481. sprintf(message,"[%d,\"%s\",%s]"
  10482. ,MESSAGE_TYPE_CALLRESULT
  10483. ,uuid
  10484. ,json_object_to_json_string_ext(CancelReservation, JSON_C_TO_STRING_PLAIN));
  10485. json_object_put(CancelReservation);
  10486. ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationConf = OFF;
  10487. LWS_Send(message);
  10488. result = TRUE;
  10489. return result;
  10490. }
  10491. int sendCertificateSignedConfirmation(char *uuid)
  10492. {
  10493. mtrace();
  10494. int result = FAIL;
  10495. char message[4096]={0};
  10496. json_object *CertificateSigned = json_object_new_object();
  10497. json_object *statusInfo = json_object_new_object();
  10498. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  10499. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_status));
  10500. if(strlen((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.reasonCode) > 0)
  10501. {
  10502. json_object_object_add(statusInfo, "reasonCode", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.reasonCode));
  10503. if(strlen((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.additionalInfo) > 0)
  10504. json_object_object_add(statusInfo, "statadditionalInfous", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.additionalInfo));
  10505. }
  10506. json_object_object_add(CertificateSigned, "statusInfo", statusInfo);
  10507. sprintf(message,"[%d,\"%s\",%s]"
  10508. ,MESSAGE_TYPE_CALLRESULT
  10509. ,uuid
  10510. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  10511. json_object_put(CertificateSigned);
  10512. LWS_Send(message);
  10513. result = TRUE;
  10514. return result;
  10515. }
  10516. int sendChangeAvailabilityConfirmation(char *uuid, unsigned char gun_index)
  10517. {
  10518. mtrace();
  10519. int result = FAIL;
  10520. char message[4096]={0};
  10521. json_object *ChangeAvailability = json_object_new_object();
  10522. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  10523. json_object_object_add(ChangeAvailability, "status", json_object_new_string((char*)ShmOCPP20Data->ChangeAvailability[gun_index].Response_status));
  10524. sprintf(message,"[%d,\"%s\",%s]"
  10525. ,MESSAGE_TYPE_CALLRESULT
  10526. ,uuid
  10527. ,json_object_to_json_string_ext(ChangeAvailability, JSON_C_TO_STRING_PLAIN));
  10528. json_object_put(ChangeAvailability);
  10529. LWS_Send(message);
  10530. result = TRUE;
  10531. return result;
  10532. }
  10533. int sendClearCacheConfirmation(char *uuid)
  10534. {
  10535. mtrace();
  10536. int result = FAIL;
  10537. char message[4096]={0};
  10538. json_object *ClearCache = json_object_new_object();
  10539. DEBUG_INFO("sendClearCacheConfirmation...\n");
  10540. json_object_object_add(ClearCache, "status", json_object_new_string((char*)ShmOCPP20Data->ClearCache.Response_status));
  10541. sprintf(message,"[%d,\"%s\",%s]"
  10542. ,MESSAGE_TYPE_CALLRESULT
  10543. ,uuid
  10544. ,json_object_to_json_string_ext(ClearCache, JSON_C_TO_STRING_PLAIN));
  10545. json_object_put(ClearCache);
  10546. LWS_Send(message);
  10547. result = TRUE;
  10548. return result;
  10549. }
  10550. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  10551. {
  10552. mtrace();
  10553. int result = FAIL;
  10554. char message[500]={0};
  10555. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  10556. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  10557. LWS_Send(message);
  10558. return result;
  10559. }
  10560. int sendClearDisplayMessageConfirmation(char *uuid)
  10561. {
  10562. mtrace();
  10563. int result = FAIL;
  10564. char message[4096]={0};
  10565. json_object *ClearDisplayMessage = json_object_new_object();
  10566. DEBUG_INFO("sendClearDisplayMessageConfirmation...\n");
  10567. json_object_object_add(ClearDisplayMessage, "status", json_object_new_string((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status));
  10568. sprintf(message,"[%d,\"%s\",%s]"
  10569. ,MESSAGE_TYPE_CALLRESULT
  10570. ,uuid
  10571. ,json_object_to_json_string_ext(ClearDisplayMessage, JSON_C_TO_STRING_PLAIN));
  10572. json_object_put(ClearDisplayMessage);
  10573. LWS_Send(message);
  10574. result = TRUE;
  10575. return result;
  10576. }
  10577. int sendClearVariableMonitoringConfirmation(char *uuid, unsigned char variableQuantity)
  10578. {
  10579. mtrace();
  10580. int result = FAIL;
  10581. char message[4096]={0};
  10582. json_object *ClearVariableMonitoring = json_object_new_object();
  10583. json_object *clearMonitoringResults = json_object_new_array();
  10584. DEBUG_INFO("sendClearVariableMonitoringConfirmation...\n");
  10585. for(int idx=0;idx<variableQuantity;idx++)
  10586. {
  10587. json_object *clearMonitoringResult = json_object_new_object();
  10588. json_object_object_add(clearMonitoringResult, "id", json_object_new_int(ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].id));
  10589. json_object_object_add(clearMonitoringResult, "status", json_object_new_string((char*)ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].status));
  10590. json_object_array_add(clearMonitoringResults, clearMonitoringResult);
  10591. }
  10592. json_object_object_add(ClearVariableMonitoring, "clearMonitoringResult", clearMonitoringResults);
  10593. sprintf(message,"[%d,\"%s\",%s]"
  10594. ,MESSAGE_TYPE_CALLRESULT
  10595. ,uuid
  10596. ,json_object_to_json_string_ext(ClearVariableMonitoring, JSON_C_TO_STRING_PLAIN));
  10597. json_object_put(ClearVariableMonitoring);
  10598. LWS_Send(message);
  10599. result = TRUE;
  10600. return result;
  10601. }
  10602. int sendCostUpdatedConfirmation(char *uuid)
  10603. {
  10604. mtrace();
  10605. int result = FAIL;
  10606. char message[4096]={0};
  10607. DEBUG_INFO("sendCostUpdatedConfirmation...\n");
  10608. sprintf(message,"[%d,\"%s\",{}]"
  10609. ,MESSAGE_TYPE_CALLRESULT
  10610. ,uuid);
  10611. LWS_Send(message);
  10612. result = TRUE;
  10613. return result;
  10614. }
  10615. int sendCustomerInformationConfirmation(char *uuid)
  10616. {
  10617. mtrace();
  10618. int result = FAIL;
  10619. char message[4096]={0};
  10620. json_object *CustomerInformation = json_object_new_object();
  10621. DEBUG_INFO("sendCustomerInformationConfirmation...\n");
  10622. json_object_object_add(CustomerInformation, "status", json_object_new_string((char*)ShmOCPP20Data->CustomerInformation.Response_status));
  10623. sprintf(message,"[%d,\"%s\",%s]"
  10624. ,MESSAGE_TYPE_CALLRESULT
  10625. ,uuid
  10626. ,json_object_to_json_string_ext(CustomerInformation, JSON_C_TO_STRING_PLAIN));
  10627. json_object_put(CustomerInformation);
  10628. LWS_Send(message);
  10629. result = TRUE;
  10630. return result;
  10631. }
  10632. int sendDataTransferConfirmation(char *uuid, unsigned char gun_index)
  10633. {
  10634. mtrace();
  10635. int result = FAIL;
  10636. char message[4096]={0};
  10637. json_object *DataTransfer = json_object_new_object();
  10638. DEBUG_INFO("sendDataTransferConfirmation...\n");
  10639. json_object_object_add(DataTransfer, "status", json_object_new_string((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_status));
  10640. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_data));
  10641. sprintf(message,"[%d,\"%s\",%s]"
  10642. ,MESSAGE_TYPE_CALLRESULT
  10643. ,uuid
  10644. ,json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  10645. json_object_put(DataTransfer);
  10646. LWS_Send(message);
  10647. result = TRUE;
  10648. return result;
  10649. }
  10650. int sendDeleteCertificateConfirmation(char *uuid)
  10651. {
  10652. mtrace();
  10653. int result = FAIL;
  10654. char message[4096]={0};
  10655. json_object *DeleteCertificate = json_object_new_object();
  10656. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  10657. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP20Data->DeleteCertificate.Response_status));
  10658. sprintf(message,"[%d,\"%s\",%s]"
  10659. ,MESSAGE_TYPE_CALLRESULT
  10660. ,uuid
  10661. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  10662. json_object_put(DeleteCertificate);
  10663. LWS_Send(message);
  10664. result = TRUE;
  10665. return result;
  10666. }
  10667. int sendGetBaseReportConfirmation(char *uuid)
  10668. {
  10669. mtrace();
  10670. int result = FAIL;
  10671. char message[4096]={0};
  10672. json_object *GetBaseReport = json_object_new_object();
  10673. DEBUG_INFO("sendGetBaseReportConfirmation...\n");
  10674. json_object_object_add(GetBaseReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetBaseReport.Response_status));
  10675. sprintf(message,"[%d,\"%s\",%s]"
  10676. ,MESSAGE_TYPE_CALLRESULT
  10677. ,uuid
  10678. ,json_object_to_json_string_ext(GetBaseReport, JSON_C_TO_STRING_PLAIN));
  10679. json_object_put(GetBaseReport);
  10680. LWS_Send(message);
  10681. result = TRUE;
  10682. return result;
  10683. }
  10684. int sendGetChargingProfilesConfirmation(char *uuid, unsigned char gun_index)
  10685. {
  10686. mtrace();
  10687. int result = FAIL;
  10688. char message[4096]={0};
  10689. json_object *GetChargingProfiles = json_object_new_object();
  10690. DEBUG_INFO("sendGetChargingProfilesConfirmation...\n");
  10691. json_object_object_add(GetChargingProfiles, "status", json_object_new_string((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status));
  10692. sprintf(message,"[%d,\"%s\",%s]"
  10693. ,MESSAGE_TYPE_CALLRESULT
  10694. ,uuid
  10695. ,json_object_to_json_string_ext(GetChargingProfiles, JSON_C_TO_STRING_PLAIN));
  10696. json_object_put(GetChargingProfiles);
  10697. LWS_Send(message);
  10698. result = TRUE;
  10699. return result;
  10700. }
  10701. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int evseIdInt, int nPeriod)
  10702. {
  10703. mtrace();
  10704. int result = FAIL;
  10705. char message[4096]={0};
  10706. int CompositeScheduleIndex = 0;
  10707. json_object *GetCompositeSchedule = json_object_new_object();
  10708. json_object *schedule = json_object_new_object();
  10709. json_object *chargingSchedule = json_object_new_object();
  10710. json_object *chargingSchedulePeriod = json_object_new_array();
  10711. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  10712. json_object_object_add(GetCompositeSchedule, "status", json_object_new_string(payload));
  10713. CompositeScheduleIndex = (evseIdInt > 0) ?(evseIdInt -1) : 0;
  10714. json_object_object_add(schedule, "evseId", json_object_new_int(evseIdInt));
  10715. if(nPeriod == 0)
  10716. {
  10717. if(strcmp((const char *)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime,"")!=0)
  10718. {
  10719. if(strlen((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule))
  10720. json_object_object_add(schedule, "scheduleStart", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule));
  10721. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration > 0)
  10722. json_object_object_add(schedule, "duration", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration));
  10723. json_object_object_add(schedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit));
  10724. //if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate > 0)
  10725. //json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate));
  10726. //json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.id));
  10727. uint8_t isNullSchedulePeriod = TRUE;
  10728. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  10729. {
  10730. if(((ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  10731. (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  10732. {
  10733. json_object *Period = json_object_new_object();
  10734. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  10735. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  10736. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  10737. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  10738. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  10739. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  10740. json_object_array_add(chargingSchedulePeriod, Period);
  10741. isNullSchedulePeriod = FALSE;
  10742. }
  10743. }
  10744. if(isNullSchedulePeriod == TRUE)
  10745. {
  10746. json_object *Period = json_object_new_object();
  10747. json_object_object_add(Period, "startPeriod", json_object_new_int(0));
  10748. float limit = ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit[0]=='W'?modelnameInfo.ratedPower:(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  10749. json_object_object_add(Period, "limit", json_object_new_double(limit));
  10750. json_object_array_add(chargingSchedulePeriod, Period);
  10751. }
  10752. json_object_object_add(schedule, "chargingSchedulePeriod", chargingSchedulePeriod);
  10753. //json_object_object_add(schedule, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime));
  10754. //json_object_object_add(schedule, "chargingSchedule", chargingSchedule);
  10755. json_object_object_add(GetCompositeSchedule, "schedule", schedule);
  10756. }
  10757. }
  10758. else
  10759. {
  10760. if(strlen((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule))
  10761. json_object_object_add(chargingSchedule, "scheduleStart", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule));
  10762. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration > 0)
  10763. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration));
  10764. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit));
  10765. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate > 0)
  10766. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate));
  10767. //json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.id));
  10768. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  10769. {
  10770. if(((ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  10771. (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  10772. {
  10773. json_object *Period = json_object_new_object();
  10774. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  10775. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  10776. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  10777. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  10778. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  10779. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  10780. json_object_array_add(chargingSchedulePeriod, Period);
  10781. }
  10782. }
  10783. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriod);
  10784. //json_object_object_add(schedule, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime));
  10785. //json_object_object_add(schedule, "chargingSchedule", chargingSchedule);
  10786. json_object_object_add(GetCompositeSchedule, "schedule", schedule);
  10787. }
  10788. sprintf(message,"[%d,\"%s\",%s]"
  10789. ,MESSAGE_TYPE_CALLRESULT
  10790. ,uuid
  10791. ,json_object_to_json_string_ext(GetCompositeSchedule, JSON_C_TO_STRING_PLAIN));
  10792. json_object_put(GetCompositeSchedule);
  10793. LWS_Send(message);
  10794. result = TRUE;
  10795. return result;
  10796. }
  10797. int sendGetGetDisplayMessagesConfirmation(char *uuid)
  10798. {
  10799. mtrace();
  10800. int result = FAIL;
  10801. char message[4096]={0};
  10802. json_object *GetGetDisplayMessages = json_object_new_object();
  10803. DEBUG_INFO("sendGetGetDisplayMessagesConfirmation...\n");
  10804. json_object_object_add(GetGetDisplayMessages, "status", json_object_new_string((char*)ShmOCPP20Data->GetDisplayMessages.Response_status));
  10805. sprintf(message,"[%d,\"%s\",%s]"
  10806. ,MESSAGE_TYPE_CALLRESULT
  10807. ,uuid
  10808. ,json_object_to_json_string_ext(GetGetDisplayMessages, JSON_C_TO_STRING_PLAIN));
  10809. json_object_put(GetGetDisplayMessages);
  10810. LWS_Send(message);
  10811. result = TRUE;
  10812. return result;
  10813. }
  10814. int sendGetInstalledCertificateIdsConfirmation(char *uuid, unsigned char certQuantity)
  10815. {
  10816. mtrace();
  10817. int result = FAIL;
  10818. char message[4096]={0};
  10819. json_object *GetInstalledCertificateIds = json_object_new_object();
  10820. json_object *certificateHashDataChains = json_object_new_array();
  10821. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  10822. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status));
  10823. for(int idx=0;idx<certQuantity;idx++)
  10824. {
  10825. json_object *cert = json_object_new_object();
  10826. json_object *certificateHashData = json_object_new_object();
  10827. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.hashAlgorithm));
  10828. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.issuerNameHash));
  10829. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.issuerKeyHash));
  10830. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.serialNumber));
  10831. json_object_object_add(cert, "certificateHashData", certificateHashData);
  10832. json_object_object_add(cert, "certificateType", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateType));
  10833. json_object_array_add(certificateHashDataChains, cert);
  10834. }
  10835. json_object_object_add(GetInstalledCertificateIds , "certificateHashDataChain", certificateHashDataChains);
  10836. sprintf(message,"[%d,\"%s\",%s]"
  10837. ,MESSAGE_TYPE_CALLRESULT
  10838. ,uuid
  10839. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  10840. json_object_put(GetInstalledCertificateIds);
  10841. LWS_Send(message);
  10842. result = TRUE;
  10843. return result;
  10844. }
  10845. int sendGetLocalListVersionConfirmation(char *uuid)
  10846. {
  10847. mtrace();
  10848. int result = FAIL;
  10849. char message[4096]={0};
  10850. json_object *GetLocalListVersion = json_object_new_object();
  10851. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  10852. json_object_object_add(GetLocalListVersion, "versionNumber", json_object_new_int(ShmOCPP20Data->GetLocalListVersion.Response_versionNumber));
  10853. sprintf(message,"[%d,\"%s\",%s]"
  10854. ,MESSAGE_TYPE_CALLRESULT
  10855. ,uuid
  10856. ,json_object_to_json_string_ext(GetLocalListVersion, JSON_C_TO_STRING_PLAIN));
  10857. json_object_put(GetLocalListVersion);
  10858. LWS_Send(message);
  10859. result = TRUE;
  10860. return result;
  10861. }
  10862. int sendGetLogConfirmation(char *uuid)
  10863. {
  10864. mtrace();
  10865. int result = FAIL;
  10866. char message[4096]={0};
  10867. json_object *GetLog = json_object_new_object();
  10868. DEBUG_INFO("sendGetLogConfirmation...\n");
  10869. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP20Data->GetLog.Response_status));
  10870. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP20Data->GetLog.Response_filename));
  10871. sprintf(message,"[%d,\"%s\",%s]"
  10872. ,MESSAGE_TYPE_CALLRESULT
  10873. ,uuid
  10874. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  10875. json_object_put(GetLog);
  10876. LWS_Send(message);
  10877. result = TRUE;
  10878. return result;
  10879. }
  10880. int sendGetMonitoringReportConfirmation(char *uuid)
  10881. {
  10882. mtrace();
  10883. int result = FAIL;
  10884. char message[4096]={0};
  10885. json_object *GetMonitoringReport = json_object_new_object();
  10886. DEBUG_INFO("sendGetMonitoringReportConfirmation...\n");
  10887. json_object_object_add(GetMonitoringReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetMonitoringReport.Response_status));
  10888. sprintf(message,"[%d,\"%s\",%s]"
  10889. ,MESSAGE_TYPE_CALLRESULT
  10890. ,uuid
  10891. ,json_object_to_json_string_ext(GetMonitoringReport, JSON_C_TO_STRING_PLAIN));
  10892. json_object_put(GetMonitoringReport);
  10893. LWS_Send(message);
  10894. result = TRUE;
  10895. return result;
  10896. }
  10897. int sendGetReportConfirmation(char *uuid)
  10898. {
  10899. mtrace();
  10900. int result = FAIL;
  10901. char message[4096]={0};
  10902. json_object *GetReport = json_object_new_object();
  10903. DEBUG_INFO("sendGetReportConfirmation...\n");
  10904. json_object_object_add(GetReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetReport.Response_status));
  10905. sprintf(message,"[%d,\"%s\",%s]"
  10906. ,MESSAGE_TYPE_CALLRESULT
  10907. ,uuid
  10908. ,json_object_to_json_string_ext(GetReport, JSON_C_TO_STRING_PLAIN));
  10909. json_object_put(GetReport);
  10910. LWS_Send(message);
  10911. result = TRUE;
  10912. return result;
  10913. }
  10914. int sendGetTransactionStatusConfirmation(char *uuid)
  10915. {
  10916. mtrace();
  10917. int result = FAIL;
  10918. char message[4096]={0};
  10919. json_object *GetTransactionStatus = json_object_new_object();
  10920. DEBUG_INFO("sendGetTransactionStatusConfirmation...\n");
  10921. json_object_object_add(GetTransactionStatus, "ongoingIndicator", json_object_new_boolean(ShmOCPP20Data->GetTransactionStatus.Response_ongoingIndicator));
  10922. json_object_object_add(GetTransactionStatus, "messagesInQueue", json_object_new_boolean(ShmOCPP20Data->GetTransactionStatus.Response_messagesInQueue));
  10923. sprintf(message,"[%d,\"%s\",%s]"
  10924. ,MESSAGE_TYPE_CALLRESULT
  10925. ,uuid
  10926. ,json_object_to_json_string_ext(GetTransactionStatus, JSON_C_TO_STRING_PLAIN));
  10927. json_object_put(GetTransactionStatus);
  10928. LWS_Send(message);
  10929. result = TRUE;
  10930. return result;
  10931. }
  10932. int sendGetVariablesConfirmation(char *uuid, unsigned char variableQuantity)
  10933. {
  10934. mtrace();
  10935. int result = FAIL;
  10936. char message[4096]={0};
  10937. json_object *GetVariables = json_object_new_object();
  10938. json_object *getVariableResults = json_object_new_array();
  10939. DEBUG_INFO("sendGetVariablesConfirmation...\n");
  10940. for(int idx=0;idx<variableQuantity;idx++)
  10941. {
  10942. json_object *variableResult = json_object_new_object();
  10943. json_object *component = json_object_new_object();
  10944. json_object *variable = json_object_new_object();
  10945. json_object *evse = json_object_new_object();
  10946. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType) > 0)
  10947. json_object_object_add(variableResult, "attributeType", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType));
  10948. json_object_object_add(variableResult, "attributeStatus", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus));
  10949. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue) > 0)
  10950. json_object_object_add(variableResult, "attributeValue", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue));
  10951. if(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.id > 0)
  10952. {
  10953. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.id));
  10954. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.connectorId));
  10955. json_object_object_add(component, "evse", evse);
  10956. }
  10957. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.name));
  10958. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.instance) > 0)
  10959. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.instance));
  10960. json_object_object_add(variableResult, "component", component);
  10961. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.name));
  10962. if(strlen((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.instance) > 0)
  10963. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.instance));
  10964. json_object_object_add(variableResult, "variable", variable);
  10965. json_object_array_add(getVariableResults, variableResult);
  10966. }
  10967. json_object_object_add(GetVariables , "getVariableResult", getVariableResults);
  10968. sprintf(message,"[%d,\"%s\",%s]"
  10969. ,MESSAGE_TYPE_CALLRESULT
  10970. ,uuid
  10971. ,json_object_to_json_string_ext(GetVariables, JSON_C_TO_STRING_PLAIN));
  10972. json_object_put(GetVariables);
  10973. LWS_Send(message);
  10974. result = TRUE;
  10975. return result;
  10976. }
  10977. int sendInstallCertificateConfirmation(char *uuid)
  10978. {
  10979. mtrace();
  10980. int result = FAIL;
  10981. char message[4096]={0};
  10982. json_object *InstallCertificate = json_object_new_object();
  10983. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  10984. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP20Data->InstallCertificate.Response_status));
  10985. sprintf(message,"[%d,\"%s\",%s]"
  10986. ,MESSAGE_TYPE_CALLRESULT
  10987. ,uuid
  10988. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  10989. json_object_put(InstallCertificate);
  10990. LWS_Send(message);
  10991. result = TRUE;
  10992. return result;
  10993. }
  10994. int sendPublishFirmwareConfirmation(char *uuid)
  10995. {
  10996. mtrace();
  10997. int result = FAIL;
  10998. char message[4096]={0};
  10999. json_object *PublishFirmware = json_object_new_object();
  11000. json_object_object_add(PublishFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->PublishFirmware.Response_status));
  11001. DEBUG_INFO("sendPublishFirmwareConfirmation...\n");
  11002. sprintf(message,"[%d,\"%s\",%s]"
  11003. ,MESSAGE_TYPE_CALLRESULT
  11004. ,uuid
  11005. ,json_object_to_json_string_ext(PublishFirmware, JSON_C_TO_STRING_PLAIN));
  11006. json_object_put(PublishFirmware);
  11007. LWS_Send(message);
  11008. result = TRUE;
  11009. return result;
  11010. }
  11011. int sendRemoteStartTransactionConfirmation(char *uuid, unsigned char gun_index)
  11012. {
  11013. mtrace();
  11014. int result = FAIL;
  11015. char message[4096]={0};
  11016. json_object *RemoteStartTransaction = json_object_new_object();
  11017. json_object_object_add(RemoteStartTransaction, "status", json_object_new_string((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status));
  11018. if((strstr((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]) != NULL) &&
  11019. (strlen((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId) > 0))
  11020. json_object_object_add(RemoteStartTransaction, "transactionId", json_object_new_string((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId));
  11021. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  11022. sprintf(message,"[%d,\"%s\",%s]"
  11023. ,MESSAGE_TYPE_CALLRESULT
  11024. ,uuid
  11025. ,json_object_to_json_string_ext(RemoteStartTransaction, JSON_C_TO_STRING_PLAIN));
  11026. json_object_put(RemoteStartTransaction);
  11027. LWS_Send(message);
  11028. result = TRUE;
  11029. return result;
  11030. }
  11031. int sendRemoteStopTransactionConfirmation(char *uuid, unsigned char gun_index)
  11032. {
  11033. mtrace();
  11034. int result = FAIL;
  11035. char message[4096]={0};
  11036. json_object *RemoteStopTransaction = json_object_new_object();
  11037. json_object_object_add(RemoteStopTransaction, "status", json_object_new_string((char*)ShmOCPP20Data->RequestStopTransaction[gun_index].Response_status));
  11038. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  11039. sprintf(message,"[%d,\"%s\",%s]"
  11040. ,MESSAGE_TYPE_CALLRESULT
  11041. ,uuid
  11042. ,json_object_to_json_string_ext(RemoteStopTransaction, JSON_C_TO_STRING_PLAIN));
  11043. json_object_put(RemoteStopTransaction);
  11044. LWS_Send(message);
  11045. result = TRUE;
  11046. return result;
  11047. }
  11048. int sendReserveNowConfirmation(char *uuid, unsigned char gun_index)
  11049. {
  11050. mtrace();
  11051. int result = FAIL;
  11052. char message[4096]={0};
  11053. json_object *ReserveNow = json_object_new_object();
  11054. json_object_object_add(ReserveNow, "status", json_object_new_string((char*)ShmOCPP20Data->ReserveNow[gun_index].Response_status));
  11055. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  11056. sprintf(message,"[%d,\"%s\",%s]"
  11057. ,MESSAGE_TYPE_CALLRESULT
  11058. ,uuid
  11059. ,json_object_to_json_string_ext(ReserveNow, JSON_C_TO_STRING_PLAIN));
  11060. json_object_put(ReserveNow);
  11061. LWS_Send(message);
  11062. result = TRUE;
  11063. ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf = OFF;
  11064. return result;
  11065. }
  11066. int sendResetConfirmation(char *uuid)
  11067. {
  11068. mtrace();
  11069. int result = FAIL;
  11070. char message[4096]={0};
  11071. json_object *Reset = json_object_new_object();
  11072. DEBUG_INFO("sendResetConfirmation...\n");
  11073. ShmOCPP20Data->MsMsg.bits.ResetConf = OFF;
  11074. json_object_object_add(Reset, "status", json_object_new_string((char*)ShmOCPP20Data->Reset.Response_status));
  11075. sprintf(message,"[%d,\"%s\",%s]"
  11076. ,MESSAGE_TYPE_CALLRESULT
  11077. ,uuid
  11078. ,json_object_to_json_string_ext(Reset, JSON_C_TO_STRING_PLAIN));
  11079. json_object_put(Reset);
  11080. LWS_Send(message);
  11081. if(strcmp((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]) == 0)
  11082. {
  11083. DB_updateBootType(BootReasonEnumType_RemoteReset);
  11084. DB_updateSecurityEventType(SecurityEventEnumType_ResetOrReboot);
  11085. }
  11086. else if(strcmp((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Scheduled]) == 0)
  11087. {
  11088. DB_updateBootType(BootReasonEnumType_ScheduledReset);
  11089. DB_updateSecurityEventType(SecurityEventEnumType_ResetOrReboot);
  11090. }
  11091. result = TRUE;
  11092. return result;
  11093. }
  11094. int sendSendLocalListConfirmation(char *uuid)
  11095. {
  11096. mtrace();
  11097. int result = FAIL;
  11098. char message[4096]={0};
  11099. json_object *SendLocalList = json_object_new_object();
  11100. DEBUG_INFO("sendSendLocalListConfirmation...\n");
  11101. json_object_object_add(SendLocalList, "status", json_object_new_string((char*)ShmOCPP20Data->SendLocalList.Response_status));
  11102. sprintf(message,"[%d,\"%s\",%s]"
  11103. ,MESSAGE_TYPE_CALLRESULT
  11104. ,uuid
  11105. ,json_object_to_json_string_ext(SendLocalList, JSON_C_TO_STRING_PLAIN));
  11106. json_object_put(SendLocalList);
  11107. LWS_Send(message);
  11108. result = TRUE;
  11109. return result;
  11110. }
  11111. int sendSetChargingProfileConfirmation(char *uuid, unsigned char gun_index)
  11112. {
  11113. mtrace();
  11114. int result = FAIL;
  11115. char message[4096]={0};
  11116. json_object *SetChargingProfile = json_object_new_object();
  11117. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  11118. json_object_object_add(SetChargingProfile, "status", json_object_new_string((char*)ShmOCPP20Data->SetChargingProfile[gun_index].Response_status));
  11119. sprintf(message,"[%d,\"%s\",%s]"
  11120. ,MESSAGE_TYPE_CALLRESULT
  11121. ,uuid
  11122. ,json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  11123. json_object_put(SetChargingProfile);
  11124. LWS_Send(message);
  11125. result = TRUE;
  11126. return result;
  11127. }
  11128. int sendSetDisplayMessagesConfirmation(char *uuid)
  11129. {
  11130. mtrace();
  11131. int result = FAIL;
  11132. char message[4096]={0};
  11133. json_object *SetDisplayMessage = json_object_new_object();
  11134. DEBUG_INFO("sendSetDisplayMessageConfirmation...\n");
  11135. json_object_object_add(SetDisplayMessage, "status", json_object_new_string((char*)ShmOCPP20Data->SetDisplayMessage.Response_status));
  11136. sprintf(message,"[%d,\"%s\",%s]"
  11137. ,MESSAGE_TYPE_CALLRESULT
  11138. ,uuid
  11139. ,json_object_to_json_string_ext(SetDisplayMessage, JSON_C_TO_STRING_PLAIN));
  11140. json_object_put(SetDisplayMessage);
  11141. LWS_Send(message);
  11142. result = TRUE;
  11143. return result;
  11144. }
  11145. int sendSetMonitoringBaseConfirmation(char *uuid)
  11146. {
  11147. mtrace();
  11148. int result = FAIL;
  11149. char message[4096]={0};
  11150. json_object *SetMonitoringBase = json_object_new_object();
  11151. DEBUG_INFO("sendSetMonitoringBaseConfirmation...\n");
  11152. json_object_object_add(SetMonitoringBase, "status", json_object_new_string((char*)ShmOCPP20Data->SetMonitoringBase.Response_status));
  11153. sprintf(message,"[%d,\"%s\",%s]"
  11154. ,MESSAGE_TYPE_CALLRESULT
  11155. ,uuid
  11156. ,json_object_to_json_string_ext(SetMonitoringBase, JSON_C_TO_STRING_PLAIN));
  11157. json_object_put(SetMonitoringBase);
  11158. LWS_Send(message);
  11159. result = TRUE;
  11160. return result;
  11161. }
  11162. int sendSetMonitoringLevelConfirmation(char *uuid)
  11163. {
  11164. mtrace();
  11165. int result = FAIL;
  11166. char message[4096]={0};
  11167. json_object *SetMonitoringLevel = json_object_new_object();
  11168. DEBUG_INFO("sendSetMonitoringLevelConfirmation...\n");
  11169. json_object_object_add(SetMonitoringLevel, "status", json_object_new_string((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status));
  11170. sprintf(message,"[%d,\"%s\",%s]"
  11171. ,MESSAGE_TYPE_CALLRESULT
  11172. ,uuid
  11173. ,json_object_to_json_string_ext(SetMonitoringLevel, JSON_C_TO_STRING_PLAIN));
  11174. json_object_put(SetMonitoringLevel);
  11175. LWS_Send(message);
  11176. result = TRUE;
  11177. return result;
  11178. }
  11179. int sendSetNetworkProfileConfirmation(char *uuid)
  11180. {
  11181. mtrace();
  11182. int result = FAIL;
  11183. char message[4096]={0};
  11184. json_object *SetNetworkProfile = json_object_new_object();
  11185. DEBUG_INFO("sendSetNetworkProfileConfirmation...\n");
  11186. json_object_object_add(SetNetworkProfile, "status", json_object_new_string((char*)ShmOCPP20Data->SetNetworkProfile.Response_status));
  11187. sprintf(message,"[%d,\"%s\",%s]"
  11188. ,MESSAGE_TYPE_CALLRESULT
  11189. ,uuid
  11190. ,json_object_to_json_string_ext(SetNetworkProfile, JSON_C_TO_STRING_PLAIN));
  11191. json_object_put(SetNetworkProfile);
  11192. LWS_Send(message);
  11193. result = TRUE;
  11194. return result;
  11195. }
  11196. int sendSetVariableMonitoringConfirmation(char *uuid, unsigned char variableQuantity)
  11197. {
  11198. mtrace();
  11199. int result = FAIL;
  11200. char message[4096]={0};
  11201. json_object *SetVariableMonitoring = json_object_new_object();
  11202. json_object *setMonitoringResults = json_object_new_array();
  11203. DEBUG_INFO("sendSetVariableMonitoringConfirmation...\n");
  11204. for(int idx=0;idx<variableQuantity;idx++)
  11205. {
  11206. json_object *variableMonitorResult = json_object_new_object();
  11207. json_object *component = json_object_new_object();
  11208. json_object *variable = json_object_new_object();
  11209. json_object *evse = json_object_new_object();
  11210. json_object_object_add(variableMonitorResult, "id", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].id));
  11211. json_object_object_add(variableMonitorResult, "type", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type));
  11212. json_object_object_add(variableMonitorResult, "severity", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].severity));
  11213. json_object_object_add(variableMonitorResult, "status", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status));
  11214. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.id));
  11215. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.connectorId));
  11216. json_object_object_add(component, "evse", evse);
  11217. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.name));
  11218. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.instance));
  11219. json_object_object_add(variableMonitorResult, "component", component);
  11220. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.name));
  11221. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.instance));
  11222. json_object_object_add(variableMonitorResult, "variable", variable);
  11223. json_object_array_add(setMonitoringResults, variableMonitorResult);
  11224. }
  11225. json_object_object_add(SetVariableMonitoring , "setMonitoringResult", setMonitoringResults);
  11226. sprintf(message,"[%d,\"%s\",%s]"
  11227. ,MESSAGE_TYPE_CALLRESULT
  11228. ,uuid
  11229. ,json_object_to_json_string_ext(SetVariableMonitoring, JSON_C_TO_STRING_PLAIN));
  11230. json_object_put(SetVariableMonitoring);
  11231. LWS_Send(message);
  11232. result = TRUE;
  11233. return result;
  11234. }
  11235. int sendSetVariableConfirmation(char *uuid, unsigned char variableQuantity)
  11236. {
  11237. mtrace();
  11238. int result = FAIL;
  11239. char message[4096]={0};
  11240. json_object *SetVariable = json_object_new_object();
  11241. json_object *setVariableResults = json_object_new_array();
  11242. DEBUG_INFO("sendSetVariableConfirmation...\n");
  11243. for(int idx=0;idx<variableQuantity;idx++)
  11244. {
  11245. json_object *variableResult = json_object_new_object();
  11246. json_object *component = json_object_new_object();
  11247. json_object *variable = json_object_new_object();
  11248. json_object *evse = json_object_new_object();
  11249. json_object_object_add(variableResult, "attributeType", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType));
  11250. json_object_object_add(variableResult, "attributeStatus", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus));
  11251. if(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.id > 0)
  11252. {
  11253. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.id));
  11254. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.connectorId));
  11255. json_object_object_add(component, "evse", evse);
  11256. }
  11257. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.name));
  11258. if(strlen((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.instance) > 0)
  11259. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.instance));
  11260. json_object_object_add(variableResult, "component", component);
  11261. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.name));
  11262. if(strlen((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.instance)>0)
  11263. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.instance));
  11264. json_object_object_add(variableResult, "variable", variable);
  11265. json_object_array_add(setVariableResults, variableResult);
  11266. }
  11267. json_object_object_add(SetVariable , "setVariableResult", setVariableResults);
  11268. sprintf(message,"[%d,\"%s\",%s]"
  11269. ,MESSAGE_TYPE_CALLRESULT
  11270. ,uuid
  11271. ,json_object_to_json_string_ext(SetVariable, JSON_C_TO_STRING_PLAIN));
  11272. json_object_put(SetVariable);
  11273. LWS_Send(message);
  11274. result = TRUE;
  11275. return result;
  11276. }
  11277. int sendTriggerMessageConfirmation(char *uuid)
  11278. {
  11279. mtrace();
  11280. int result = FAIL;
  11281. char message[4096]={0};
  11282. json_object *TriggerMessage = json_object_new_object();
  11283. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  11284. json_object_object_add(TriggerMessage, "status", json_object_new_string((char*)ShmOCPP20Data->TriggerMessage.Response_status));
  11285. sprintf(message,"[%d,\"%s\",%s]",
  11286. MESSAGE_TYPE_CALLRESULT,
  11287. uuid,
  11288. json_object_to_json_string_ext(TriggerMessage, JSON_C_TO_STRING_PLAIN));
  11289. json_object_put(TriggerMessage);
  11290. LWS_Send(message);
  11291. result = TRUE;
  11292. return result;
  11293. }
  11294. int sendUnlockConnectorConfirmation(char *uuid, unsigned char gun_index)
  11295. {
  11296. mtrace();
  11297. int result = FAIL;
  11298. char message[4096]={0};
  11299. json_object *UnlockConnector = json_object_new_object();
  11300. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  11301. json_object_object_add(UnlockConnector, "status", json_object_new_string((char*)ShmOCPP20Data->UnlockConnector[gun_index].Response_status));
  11302. sprintf(message,"[%d,\"%s\",%s]",
  11303. MESSAGE_TYPE_CALLRESULT,
  11304. uuid,
  11305. json_object_to_json_string_ext(UnlockConnector, JSON_C_TO_STRING_PLAIN));
  11306. json_object_put(UnlockConnector);
  11307. LWS_Send(message);
  11308. result = TRUE;
  11309. ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf = OFF;
  11310. return result;
  11311. }
  11312. int sendUnpublishFirmwareConfirmation(char *uuid)
  11313. {
  11314. mtrace();
  11315. int result = FAIL;
  11316. char message[4096]={0};
  11317. json_object *UnpublishFirmware = json_object_new_object();
  11318. DEBUG_INFO("sendUnpublishFirmwareConfirmation...\n");
  11319. json_object_object_add(UnpublishFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->UnpublishFirmware.Response_status));
  11320. sprintf(message,"[%d,\"%s\",%s]"
  11321. ,MESSAGE_TYPE_CALLRESULT
  11322. ,uuid
  11323. ,json_object_to_json_string_ext(UnpublishFirmware, JSON_C_TO_STRING_PLAIN));
  11324. json_object_put(UnpublishFirmware);
  11325. LWS_Send(message);
  11326. result = TRUE;
  11327. return result;
  11328. }
  11329. int sendUpdateFirmwareConfirmation(char *uuid)
  11330. {
  11331. mtrace();
  11332. int result = FAIL;
  11333. char message[4096]={0};
  11334. json_object *UpdateFirmware = json_object_new_object();
  11335. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  11336. sprintf((char*)ShmOCPP20Data->UpdateFirmware.Response_status, "%s", UpdateFirmwareStatusEnumTypeStr[UpdateFirmwareStatusEnumType_Accepted]);
  11337. json_object_object_add(UpdateFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->UpdateFirmware.Response_status));
  11338. sprintf(message,"[%d,\"%s\",%s]"
  11339. ,MESSAGE_TYPE_CALLRESULT
  11340. ,uuid
  11341. ,json_object_to_json_string_ext(UpdateFirmware, JSON_C_TO_STRING_PLAIN));
  11342. json_object_put(UpdateFirmware);
  11343. LWS_Send(message);
  11344. result = TRUE;
  11345. return result;
  11346. }
  11347. int sendUnknownConfirmation(char *uuid)
  11348. {
  11349. mtrace();
  11350. int result = FAIL;
  11351. char message[256]={0};
  11352. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  11353. DEBUG_INFO("sendUnknownConfirmation...\n");
  11354. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  11355. LWS_Send(message);
  11356. result = TRUE;
  11357. return result;
  11358. }
  11359. //==========================================
  11360. // send CallError routine
  11361. //==========================================
  11362. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  11363. {
  11364. mtrace();
  11365. char message[220]={0};
  11366. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  11367. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  11368. LWS_Send(message);
  11369. }
  11370. //==========================================
  11371. // Handle server request routine Start
  11372. //==========================================
  11373. int handleCancelReservationRequest(char *uuid, char *payload)
  11374. {
  11375. mtrace();
  11376. int result = FAIL;
  11377. int gunNO = 0;
  11378. int reservationIdInt = -1;
  11379. DEBUG_INFO("handleCancelReservationRequest...\n");
  11380. json_object *CancelReservation;
  11381. CancelReservation = json_tokener_parse(payload);
  11382. if(!is_error(CancelReservation))
  11383. {
  11384. // Required data
  11385. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  11386. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  11387. }
  11388. json_object_put(CancelReservation);
  11389. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  11390. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->CancelReservation);idx++)
  11391. sprintf((char*)ShmOCPP20Data->CancelReservation[idx].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Rejected]);
  11392. if(reservationIdInt != -1)
  11393. {
  11394. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11395. //check Transaction active
  11396. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  11397. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11398. {
  11399. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  11400. {
  11401. sprintf((char*)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11402. if(gunType[2] == GUN_TYPE_CHAdeMO)
  11403. {
  11404. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  11405. }
  11406. else
  11407. {
  11408. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  11409. }
  11410. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11411. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11412. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11413. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11414. goto end;
  11415. }
  11416. }
  11417. for (int index = 0; index < CCS_QUANTITY; index++)
  11418. {
  11419. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  11420. {
  11421. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11422. if(gunType[2] == GUN_TYPE_CCS)
  11423. {
  11424. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  11425. }
  11426. else
  11427. {
  11428. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  11429. }
  11430. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11431. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11432. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11433. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11434. goto end;
  11435. }
  11436. }
  11437. for (int index = 0; index < GB_QUANTITY; index++)
  11438. {
  11439. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  11440. {
  11441. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11442. if(gunType[2] == GUN_TYPE_GBT)
  11443. {
  11444. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  11445. }
  11446. else
  11447. {
  11448. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  11449. }
  11450. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11451. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11452. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11453. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11454. goto end;
  11455. }
  11456. }
  11457. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11458. {
  11459. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  11460. {
  11461. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11462. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  11463. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11464. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11465. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11466. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11467. goto end;
  11468. }
  11469. }
  11470. for (int index = 0; index < AC_QUANTITY; index++)
  11471. {
  11472. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  11473. {
  11474. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  11475. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  11476. {
  11477. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  11478. }
  11479. else
  11480. {
  11481. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  11482. }
  11483. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  11484. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  11485. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  11486. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  11487. goto end;
  11488. }
  11489. }
  11490. }
  11491. //The reservationId does NOT match the reservationId
  11492. sendCancelReservationConfirmation(uuid, gunNO);
  11493. end:
  11494. // Fill in ocpp packet uuid
  11495. strcpy((char *)ShmOCPP20Data->CancelReservation[gunNO].guid, uuid);
  11496. return result;
  11497. }
  11498. int handleCertificateSignedRequest(char *uuid, char *payload)
  11499. {
  11500. mtrace();
  11501. int result = FAIL;
  11502. json_object *CertificateSigned;
  11503. DEBUG_INFO("handleCertificateSignedRequest...\n");
  11504. CertificateSigned = json_tokener_parse(payload);
  11505. if(!is_error(CertificateSigned))
  11506. {
  11507. memset(&ShmOCPP20Data->CertificateSigned, 0, sizeof(struct CertificateSigned_20));
  11508. memcpy(&ShmOCPP20Data->CertificateSigned.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->CertificateSigned.guid));
  11509. // Required data
  11510. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  11511. // Optional data
  11512. if(json_object_object_get(CertificateSigned, "certificateType") != NULL)
  11513. {
  11514. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateType, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateType")));
  11515. }
  11516. else
  11517. {
  11518. if(strcmp((char*)ShmOCPP20Data->SignCertificate.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_ChargingStationCertificate]) == 0)
  11519. {
  11520. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateType, "%s", CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_ChargingStationCertificate]);
  11521. }
  11522. else if(strcmp((char*)ShmOCPP20Data->SignCertificate.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0)
  11523. {
  11524. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateType, "%s", CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]);
  11525. }
  11526. }
  11527. if(strcmp((char*)ShmOCPP20Data->CertificateSigned.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_ChargingStationCertificate]) == 0)
  11528. {
  11529. FILE *fp = fopen("/Storage/OCPP/tempCP.pem", "w");
  11530. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  11531. fclose(fp);
  11532. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11533. ShmOCPP20Data->MsMsg.bits.CertificateSignedReq = 1;
  11534. if(certVerify(PRIVATE_KEY_CP, "/Storage/OCPP/tempCP.pem") == PASS)
  11535. {
  11536. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Accepted]);
  11537. system("rm -f /Storage/OCPP/certCP_fallback.pem");
  11538. rename(CERTIFICATE_CP, "/Storage/OCPP/certCP_fallback.pem");
  11539. rename("/Storage/OCPP/tempCP.pem", CERTIFICATE_CP);
  11540. }
  11541. else
  11542. {
  11543. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Rejected]);
  11544. sprintf((char*)ShmOCPP20Data->SecurityEventNotification.type, "InvalidChargePointCertificate");
  11545. memset(ShmOCPP20Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP20Data->SecurityEventNotification.techInfo));
  11546. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  11547. }
  11548. }
  11549. else if(strcmp((char*)ShmOCPP20Data->CertificateSigned.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0)
  11550. {
  11551. FILE *fp = fopen("/Storage/OCPP/tempV2G.pem", "w");
  11552. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  11553. fclose(fp);
  11554. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11555. ShmOCPP20Data->MsMsg.bits.CertificateSignedReq = 1;
  11556. if(certVerify(PRIVATE_KEY_V2G, "/Storage/OCPP/tempV2G.pem") == PASS)
  11557. {
  11558. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Accepted]);
  11559. system("rm -f /Storage/OCPP/certV2G_fallback.pem");
  11560. rename(CERTIFICATE_V2G, "/Storage/OCPP/certV2G_fallback.pem");
  11561. rename("/Storage/OCPP/tempV2G.pem", CERTIFICATE_V2G);
  11562. }
  11563. else
  11564. {
  11565. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Rejected]);
  11566. sprintf((char*)ShmOCPP20Data->SecurityEventNotification.type, "InvalidChargePointCertificate");
  11567. memset(ShmOCPP20Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP20Data->SecurityEventNotification.techInfo));
  11568. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  11569. }
  11570. }
  11571. else
  11572. {
  11573. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Rejected]);
  11574. }
  11575. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11576. }
  11577. else
  11578. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Rejected]);
  11579. json_object_put(CertificateSigned);
  11580. sendCertificateSignedConfirmation(uuid);
  11581. return result;
  11582. }
  11583. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  11584. {
  11585. mtrace();
  11586. int result = FAIL;
  11587. int evseId = 0, gunIndex = 0;
  11588. char operationalStatus[16]={0};
  11589. char comfirmstr[20];
  11590. //int specificId = FALSE;
  11591. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  11592. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  11593. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11594. json_object *ChangeAvailability;
  11595. ChangeAvailability = json_tokener_parse(payload);
  11596. if(!is_error(ChangeAvailability))
  11597. {
  11598. // Required data
  11599. if(json_object_object_get(ChangeAvailability, "operationalStatus") != NULL)
  11600. sprintf((char*)operationalStatus, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "operationalStatus")));
  11601. // Requested evse. (When omitted, the message refers to the Charging Station as a whole.)
  11602. if(json_object_object_get(ChangeAvailability, "evse") != NULL)
  11603. {
  11604. if(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "id") != NULL)
  11605. {
  11606. evseId = json_object_get_int(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "id"));
  11607. if(evseId > 0){}
  11608. //specificId = TRUE;
  11609. else
  11610. goto end;
  11611. }
  11612. if(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "connectorId") != NULL)
  11613. {
  11614. gunIndex = json_object_get_int(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "connectorId"));
  11615. if(gunIndex != 1)
  11616. goto end;
  11617. }
  11618. }
  11619. }
  11620. json_object_put(ChangeAvailability);
  11621. if((evseId != 0) && (evseId <= gunTotalNumber))
  11622. {
  11623. ShmOCPP20Data->ChangeAvailability[evseId-1].evse.id = evseId;
  11624. sprintf((char *)ShmOCPP20Data->ChangeAvailability[evseId - 1].operationalStatus, "%s", operationalStatus);
  11625. }
  11626. else if(evseId == 0)
  11627. {
  11628. for(int i=0; i < gunTotalNumber; i++)
  11629. {
  11630. ShmOCPP20Data->ChangeAvailability[i].evse.id = i+1;
  11631. sprintf((char *)ShmOCPP20Data->ChangeAvailability[i].operationalStatus, "%s", operationalStatus);
  11632. }
  11633. }
  11634. /*if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  11635. {
  11636. ShmOCPP20Data->ChangeAvailability[gunIndex - 1].evse.connectorId = 1;
  11637. sprintf((char *)ShmOCPP20Data->ChangeAvailability[gunIndex - 1].operationalStatus, "%s", operationalStatus);
  11638. }
  11639. else if(gunIndex == 0)
  11640. {
  11641. for(int i=0; i < gunTotalNumber; i++)
  11642. {
  11643. ShmOCPP20Data->ChangeAvailability[i].evse.connectorId = 1;
  11644. sprintf((char *)ShmOCPP20Data->ChangeAvailability[i].operationalStatus, "%s", operationalStatus);
  11645. }
  11646. }*/
  11647. if(strcmp((const char *)operationalStatus, OperationalStatusEnumTypeStr[OperationalStatusEnumType_Inoperative]) == 0)
  11648. {
  11649. //----------------------evseId is 0 ------------------------------------------------//
  11650. if(evseId == 0)
  11651. {
  11652. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11653. {
  11654. for(int i=0; i < gunTotalNumber; i++)
  11655. {
  11656. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11657. {
  11658. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  11659. {
  11660. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11661. {
  11662. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11663. goto end;
  11664. }
  11665. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11666. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11667. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11668. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11669. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11670. {
  11671. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11672. goto end;
  11673. }
  11674. }
  11675. }//END FOR CHAdeMO_QUANTITY
  11676. for (int index = 0; index < CCS_QUANTITY; index++)
  11677. {
  11678. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  11679. {
  11680. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  11681. {
  11682. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11683. goto end;
  11684. }
  11685. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11686. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11687. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11688. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11689. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11690. {
  11691. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11692. goto end;
  11693. }
  11694. }
  11695. }//END FOR CCS_QUANTITY
  11696. for (int index = 0; index < GB_QUANTITY; index++)
  11697. {
  11698. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  11699. {
  11700. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11701. {
  11702. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11703. goto end;
  11704. }
  11705. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11706. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11707. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11708. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11709. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11710. {
  11711. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11712. goto end;
  11713. }
  11714. }
  11715. }// END FOR GB_QUANTITY
  11716. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11717. {
  11718. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  11719. {
  11720. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11721. {
  11722. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11723. goto end;
  11724. }
  11725. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  11726. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  11727. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  11728. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  11729. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11730. {
  11731. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11732. goto end;
  11733. }
  11734. }
  11735. }// END FOR DO_QUANTITY
  11736. for (int index = 0; index < AC_QUANTITY; index++)
  11737. {
  11738. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  11739. {
  11740. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11741. {
  11742. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11743. goto end;
  11744. }
  11745. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11746. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11747. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11748. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11749. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11750. {
  11751. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11752. goto end;
  11753. }
  11754. }
  11755. }//END FOR AC_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. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  11763. {
  11764. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11765. goto end;
  11766. }
  11767. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11768. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  11769. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  11770. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  11771. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11772. {
  11773. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11774. goto end;
  11775. }
  11776. }
  11777. }
  11778. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11779. goto end;
  11780. }
  11781. //----------------------gunIndex is not 0 ------------------------------------------------//
  11782. //check Transaction active
  11783. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11784. {
  11785. if ((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_CHAdeMO))
  11786. {
  11787. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  11788. {
  11789. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11790. goto end;
  11791. }
  11792. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11793. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11794. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11795. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11796. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11797. {
  11798. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11799. goto end;
  11800. }
  11801. else
  11802. {
  11803. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  11804. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11805. goto end;
  11806. }
  11807. }
  11808. }//END FOR CHAdeMO_QUANTITY
  11809. for (int index = 0; index < CCS_QUANTITY; index++)
  11810. {
  11811. if ((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_CCS))
  11812. {
  11813. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  11814. {
  11815. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11816. goto end;
  11817. }
  11818. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11819. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11820. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11821. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11822. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11823. {
  11824. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11825. goto end;
  11826. }
  11827. else
  11828. {
  11829. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  11830. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11831. goto end;
  11832. }
  11833. }
  11834. }//END FOR CCS_QUANTITY
  11835. for (int index = 0; index < GB_QUANTITY; index++)
  11836. {
  11837. if ((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_GBT))
  11838. {
  11839. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  11840. {
  11841. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11842. goto end;
  11843. }
  11844. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11845. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11846. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11847. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11848. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11849. {
  11850. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11851. goto end;
  11852. }
  11853. else
  11854. {
  11855. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  11856. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11857. goto end;
  11858. }
  11859. }
  11860. }// END FOR GB_QUANTITY
  11861. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11862. {
  11863. if ((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_DO))
  11864. {
  11865. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  11866. {
  11867. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11868. goto end;
  11869. }
  11870. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  11871. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  11872. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  11873. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  11874. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11875. {
  11876. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11877. goto end;
  11878. }
  11879. else
  11880. {
  11881. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  11882. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11883. goto end;
  11884. }
  11885. }
  11886. }// END FOR DO_QUANTITY
  11887. for (int index = 0; index < AC_QUANTITY; index++)
  11888. {
  11889. if ((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_AC))
  11890. {
  11891. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  11892. {
  11893. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11894. goto end;
  11895. }
  11896. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  11897. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  11898. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  11899. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  11900. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  11901. {
  11902. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  11903. goto end;
  11904. }
  11905. else
  11906. {
  11907. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  11908. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11909. goto end;
  11910. }
  11911. }
  11912. }//END FOR AC_QUANTITY
  11913. }//END FOR AvailabilityEnumTypeStr[Inoperative]
  11914. if(strcmp((const char *)operationalStatus, OperationalStatusEnumTypeStr[OperationalStatusEnumType_Operative]) == 0)
  11915. {
  11916. //----------------------gunIndex is 0 ------------------------------------------------//
  11917. if(evseId == 0)
  11918. {
  11919. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11920. {
  11921. for(int i=0; i < gunTotalNumber; i++)
  11922. {
  11923. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11924. {
  11925. 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
  11926. {
  11927. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11928. goto end;
  11929. }
  11930. }//END FOR CHAdeMO_QUANTITY
  11931. for (int index = 0; index < CCS_QUANTITY; index++)
  11932. {
  11933. 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
  11934. {
  11935. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11936. goto end;
  11937. }
  11938. }//END FOR CCS_QUANTITY
  11939. for (int index = 0; index < GB_QUANTITY; index++)
  11940. {
  11941. 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
  11942. {
  11943. //ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  11944. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11945. goto end;
  11946. }
  11947. }// END FOR GB_QUANTITY
  11948. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11949. {
  11950. 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
  11951. {
  11952. //ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  11953. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11954. goto end;
  11955. }
  11956. }// END FOR DO_QUANTITY
  11957. for (int index = 0; index < AC_QUANTITY; index++)
  11958. {
  11959. 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
  11960. {
  11961. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11962. goto end;
  11963. }
  11964. }//END FOR CHAdeMO_QUANTITY
  11965. }// END FOR gunTotalNumber
  11966. }
  11967. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  11968. {
  11969. for(int i=0; i < gunTotalNumber; i++)
  11970. {
  11971. for (int index = 0; index < AC_QUANTITY; index++)
  11972. {
  11973. if ((gunType[i] == GUN_TYPE_AC) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT // (((gunIndex == 0)|| ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11974. {
  11975. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  11976. goto end;
  11977. }
  11978. }//END FOR CHAdeMO_QUANTITY
  11979. } // END FOR gunTotalNumber
  11980. }
  11981. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11982. goto end;
  11983. }
  11984. //----------------------gunIndex is not 0 ------------------------------------------------//
  11985. //check Transaction active
  11986. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11987. {
  11988. if (((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11989. {
  11990. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11991. goto end;
  11992. }
  11993. }//END FOR CHAdeMO_QUANTITY
  11994. for (int index = 0; index < CCS_QUANTITY; index++)
  11995. {
  11996. if ((((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  11997. {
  11998. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  11999. goto end;
  12000. }
  12001. }//END FOR CCS_QUANTITY
  12002. for (int index = 0; index < GB_QUANTITY; index++)
  12003. {
  12004. if (((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  12005. {
  12006. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  12007. goto end;
  12008. }
  12009. }// END FOR GB_QUANTITY
  12010. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12011. {
  12012. if (((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  12013. {
  12014. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  12015. goto end;
  12016. }
  12017. }// END FOR DO_QUANTITY
  12018. for (int index = 0; index < AC_QUANTITY; index++)
  12019. {
  12020. if (((evseId > 0)&&(gunType[evseId-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  12021. {
  12022. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  12023. goto end;
  12024. }
  12025. }//END FOR AC_QUANTITY
  12026. }//END FOR AvailabilityEnumTypeStr[Operative]
  12027. end:
  12028. if((evseId > 0) && (evseId <= gunTotalNumber))
  12029. {
  12030. sprintf((char *)ShmOCPP20Data->ChangeAvailability[evseId - 1].Response_status, "%s", comfirmstr );
  12031. if(strstr(comfirmstr, ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected]) == NULL)
  12032. ShmOCPP20Data->CsMsg.bits[evseId-1].ChangeAvailabilityReq = ON;
  12033. }
  12034. else if(evseId == 0)
  12035. {
  12036. sprintf((char *)ShmOCPP20Data->ChangeAvailability[0].Response_status, "%s", comfirmstr );
  12037. if(strstr(comfirmstr, ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected]) == NULL)
  12038. {
  12039. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  12040. ShmOCPP20Data->CsMsg.bits[i].ChangeAvailabilityReq = ON;
  12041. }
  12042. }
  12043. else
  12044. {
  12045. sprintf((char *)ShmOCPP20Data->ChangeAvailability[0].Response_status, "%s", comfirmstr );
  12046. }
  12047. sendChangeAvailabilityConfirmation(uuid, (evseId==0?evseId:evseId-1));
  12048. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12049. return result;
  12050. }
  12051. int handleClearCacheRequest(char *uuid, char *payload)
  12052. {
  12053. mtrace();
  12054. int result = FAIL;
  12055. char rmFileCmd[100]={0};
  12056. struct stat stats;
  12057. DEBUG_INFO("handleClearCacheRequest...\n");
  12058. stat("/Storage/OCPP", &stats);
  12059. // Check for directory existence
  12060. if (S_ISDIR(stats.st_mode) == 1)
  12061. {}
  12062. else
  12063. {
  12064. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  12065. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  12066. system(rmFileCmd);
  12067. }
  12068. if(DB_cleanLocalCache() != PASS)
  12069. {
  12070. DEBUG_INFO("open AuthorizationCache file failed\n");
  12071. sprintf((char*)ShmOCPP20Data->ClearCache.Response_status, "%s", ClearCacheStatusEnumTypeStr[ClearCacheStatusEnumType_Rejected] );
  12072. }
  12073. else
  12074. {
  12075. DEBUG_INFO("open AuthorizationCache file successful\n");
  12076. sprintf((char*)ShmOCPP20Data->ClearCache.Response_status, "%s", ClearCacheStatusEnumTypeStr[ClearCacheStatusEnumType_Accepted] );
  12077. }
  12078. sendClearCacheConfirmation(uuid);
  12079. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12080. return result;
  12081. }
  12082. int handleClearChargingProfileRequest(char *uuid, char *payload)
  12083. {
  12084. mtrace();
  12085. int result = FAIL;
  12086. int resultRename;
  12087. int evseIdInt, chargingProfileIdInt, stackLevelInt;
  12088. char chargingProfilePurposeStr[26]={0};
  12089. int tempevseIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  12090. char tempchargingProfilePurposeStr[26]={0};
  12091. char sstr[160]={0};
  12092. char str[100]={0};
  12093. int c = 0;
  12094. char *loc;
  12095. char fname[200]={0};
  12096. char comfirmstr[20]={0};
  12097. char word[1600]={0};
  12098. int clearflag = FALSE;
  12099. int chargingProfileIdIsNULL = FALSE;
  12100. int evseIsNULL = FALSE;
  12101. int chargingProfilePurposeIsNULL = FALSE;
  12102. int stackLevelIsNULL = FALSE;
  12103. //int GotoEnd = FALSE;
  12104. FILE *fptr1, *fptr2;
  12105. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  12106. int n_chargingProfile=0;
  12107. int isEmptyFile = FALSE;
  12108. char sLineWord[1600]={0};
  12109. char chargingProfiles[10][100]={0};
  12110. int ChargeProfileCount = 0;
  12111. int ch;
  12112. evseIdInt = chargingProfileIdInt = stackLevelInt = 0;
  12113. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  12114. json_object *ClearChargingProfile;
  12115. ClearChargingProfile = json_tokener_parse(payload);
  12116. if(!is_error(ClearChargingProfile))
  12117. {
  12118. // Optional data
  12119. if(json_object_object_get(ClearChargingProfile, "chargingProfileId") != NULL)
  12120. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "chargingProfileId"));
  12121. else
  12122. chargingProfileIdIsNULL = TRUE;
  12123. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "evseId") != NULL)
  12124. evseIdInt = json_object_get_int(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "evseId"));
  12125. else
  12126. evseIsNULL = TRUE;
  12127. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "chargingProfilePurpose") != NULL)
  12128. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "chargingProfilePurpose")));
  12129. else
  12130. chargingProfilePurposeIsNULL = TRUE;
  12131. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "stackLevel") != NULL)
  12132. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "stackLevel"));
  12133. else
  12134. stackLevelIsNULL = TRUE;
  12135. }
  12136. json_object_put(ClearChargingProfile);
  12137. if(evseIsNULL == FALSE)
  12138. {
  12139. switch(evseIdInt)
  12140. {
  12141. case 0:
  12142. if(chargingProfilePurposeIsNULL == TRUE)
  12143. {
  12144. int l = 0;
  12145. strcpy(fname, ChargingStationMaxProfile_JSON);
  12146. if((access(fname,F_OK))!=-1)
  12147. {
  12148. strcpy(chargingProfiles[l], fname);
  12149. l = l + 1;
  12150. }
  12151. strcpy(fname, TxDefaultProfile_0_JSON);
  12152. if((access(fname,F_OK))!=-1)
  12153. {
  12154. strcpy(chargingProfiles[l], fname);
  12155. l = l + 1;
  12156. }
  12157. ChargeProfileCount = l;
  12158. }
  12159. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  12160. {
  12161. strcpy(fname, ChargingStationMaxProfile_JSON);
  12162. if((access(fname,F_OK))!=-1)
  12163. {
  12164. strcpy(chargingProfiles[0], fname);
  12165. ChargeProfileCount = 1;
  12166. }
  12167. }
  12168. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  12169. {
  12170. strcpy(fname, TxDefaultProfile_0_JSON);
  12171. if((access(fname,F_OK))!=-1)
  12172. {
  12173. strcpy(chargingProfiles[0], fname);
  12174. ChargeProfileCount = 1;
  12175. }
  12176. }
  12177. break;
  12178. default:
  12179. if(chargingProfilePurposeIsNULL == TRUE)
  12180. {
  12181. int m = 0;
  12182. memset(fname, 0, ARRAY_SIZE(fname));
  12183. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", evseIdInt);
  12184. if((access(fname,F_OK))!=-1)
  12185. {
  12186. strcpy(chargingProfiles[m], fname);
  12187. m = m + 1;
  12188. }
  12189. memset(fname, 0, ARRAY_SIZE(fname));
  12190. sprintf(fname, "/Storage/OCPP/TxProfile_%d_OCPP20.json", evseIdInt);
  12191. if((access(fname,F_OK))!=-1)
  12192. {
  12193. strcpy(chargingProfiles[m], fname);
  12194. m = m + 1;
  12195. }
  12196. ChargeProfileCount = m;
  12197. }
  12198. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  12199. {
  12200. //strcpy(fname, TxDefaultProfile_1_JSON);
  12201. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", evseIdInt);
  12202. if((access(fname,F_OK))!=-1)
  12203. {
  12204. strcpy(chargingProfiles[0], fname);
  12205. ChargeProfileCount = 1;
  12206. }
  12207. }
  12208. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  12209. {
  12210. sprintf(fname, "/Storage/OCPP/TxProfile_%d_OCPP20.json", evseIdInt);
  12211. if((access(fname,F_OK))!=-1)
  12212. {
  12213. strcpy(chargingProfiles[0], fname);
  12214. ChargeProfileCount = 1;
  12215. }
  12216. }
  12217. //strcpy(fname, ChargePointMaxProfile_JSON );
  12218. break;
  12219. }
  12220. }
  12221. else // Check all Charging Profiles
  12222. {
  12223. int i = 0;
  12224. char fnametemp[200]={0};
  12225. ChargeProfileCount = 0;
  12226. //Check ChargePointMaxProfile.json exit
  12227. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  12228. {
  12229. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  12230. i = i + 1;
  12231. }
  12232. //Check TxDefaultProfile_%d.json
  12233. for(int j=1; j <= gunTotalNumber; j++)
  12234. {
  12235. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12236. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", j);
  12237. if((access(fnametemp,F_OK))!=-1)
  12238. {
  12239. strcpy(chargingProfiles[i], fnametemp);
  12240. i = i + 1;
  12241. }
  12242. }
  12243. //Check TxProfile_%d.json
  12244. for(int j=1; j <= gunTotalNumber; j++)
  12245. {
  12246. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  12247. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d_OCPP20.json", j);
  12248. if((access(fnametemp,F_OK))!=-1)
  12249. {
  12250. strcpy(chargingProfiles[i], fnametemp);
  12251. i = i + 1;
  12252. }
  12253. }
  12254. ChargeProfileCount = i;
  12255. }// End connectorIsNULL is TRUE
  12256. if(ChargeProfileCount == 0)
  12257. {
  12258. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  12259. goto end;
  12260. }
  12261. if(evseIsNULL == FALSE && (evseIdInt != 0) && ( (evseIdInt-1) > gunTotalNumber) )
  12262. {
  12263. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  12264. goto end;
  12265. }
  12266. if((evseIsNULL == FALSE) && (evseIdInt == 0) )
  12267. {
  12268. memset(str, 0, ARRAY_SIZE(str));
  12269. // clear temp file
  12270. sprintf(str,"rm -f %s",temp);
  12271. system(str);
  12272. for(int k=0; k < ChargeProfileCount; k++)
  12273. {
  12274. memset(str, 0, ARRAY_SIZE(str));
  12275. //clear file in C
  12276. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12277. system(str);
  12278. }
  12279. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12280. goto end;
  12281. }
  12282. else if(evseIsNULL == TRUE)
  12283. {
  12284. for(int k=0; k < ChargeProfileCount; k++)
  12285. {
  12286. fptr1 = fopen(chargingProfiles[k], "r");
  12287. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  12288. //Check Charging Profile Count
  12289. while(fscanf(fptr1, "%s", word) != EOF)
  12290. {
  12291. //DEBUG_INFO("word=%s\n",word);
  12292. if(strstr(word, "id")!= NULL)
  12293. {
  12294. //DEBUG_INFO("test id \n");
  12295. n_chargingProfile = n_chargingProfile + 1;
  12296. //DEBUG_INFO("id Found\n");
  12297. }
  12298. }
  12299. rewind(fptr1);
  12300. //search Charging Profile Element
  12301. //int i= 0;
  12302. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  12303. {
  12304. //------------------------tempconnectorIdInt------------------------//
  12305. loc = strstr(sLineWord, "evseId");
  12306. c = 0;
  12307. memset(sstr ,0, sizeof(sstr) );
  12308. while (loc[strlen("evseId")+2+c] != ',')
  12309. {
  12310. sstr[c] = loc[strlen("evseId")+2+c];
  12311. c++;
  12312. }
  12313. sstr[c] = '\0';
  12314. tempevseIdInt = atoi(sstr);
  12315. printf("file's gun number is %d\n", tempevseIdInt);
  12316. //--------------------------id--------------------//
  12317. c = 0;
  12318. loc = strstr(sLineWord, "id");
  12319. memset(sstr ,0, ARRAY_SIZE(sstr));
  12320. while (loc[strlen("id")+2+c] != ',')
  12321. {
  12322. sstr[c] = loc[strlen("id")+2+c];
  12323. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12324. c++;
  12325. }
  12326. sstr[c] = '\0';
  12327. tempchargingProfileIdInt = atoi(sstr);
  12328. //stackLevel
  12329. c = 0;
  12330. loc = strstr(sLineWord, "stackLevel");
  12331. memset(sstr ,0, ARRAY_SIZE(sstr));
  12332. while (loc[strlen("stackLevel")+2+c] != ',')
  12333. {
  12334. sstr[c] = loc[strlen("stackLevel")+2+c];
  12335. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12336. c++;
  12337. }
  12338. sstr[c] = '\0';
  12339. tempstackLevelInt = atoi(sstr);
  12340. c = 0;
  12341. loc = strstr(sLineWord, "chargingProfilePurpose");
  12342. memset(sstr ,0, ARRAY_SIZE(sstr));
  12343. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12344. {
  12345. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12346. c++;
  12347. }
  12348. sstr[c] = '\0';
  12349. strcpy(tempchargingProfilePurposeStr, sstr);
  12350. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  12351. {
  12352. //------- not write to fptr2-------//
  12353. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12354. //clearflag = TRUE;
  12355. }
  12356. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  12357. {
  12358. //------- not write to fptr2-------//
  12359. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12360. }
  12361. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  12362. {
  12363. //------- not write to fptr2-------//
  12364. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12365. }
  12366. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  12367. {
  12368. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12369. }
  12370. else
  12371. {
  12372. fprintf(fptr2, sLineWord);//writing data into file
  12373. }
  12374. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  12375. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  12376. if(clearflag == TRUE)
  12377. {
  12378. fclose(fptr1);
  12379. fclose(fptr2);
  12380. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12381. system(str);
  12382. // clear temp file
  12383. sprintf(str,"rm -f %s",temp);
  12384. system(str);
  12385. }
  12386. else
  12387. {
  12388. fclose(fptr1);
  12389. fclose(fptr2);
  12390. memset(str, 0, ARRAY_SIZE(str));
  12391. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12392. system(str);
  12393. resultRename = rename(temp, chargingProfiles[k]);
  12394. if(resultRename == 0)
  12395. {
  12396. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  12397. }
  12398. else
  12399. {
  12400. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  12401. }
  12402. if(comfirmstr[0]== 0)
  12403. {
  12404. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  12405. }
  12406. //Check chargingProfile is empty file
  12407. /*------ Read the file ----------------*/
  12408. fptr1=fopen(chargingProfiles[k],"r");
  12409. ch=fgetc(fptr1);
  12410. rewind(fptr1);
  12411. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  12412. if(ch!=EOF)
  12413. {
  12414. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  12415. {
  12416. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  12417. if(sLineWord[0]=='\0')
  12418. {
  12419. isEmptyFile = TRUE;
  12420. break;
  12421. }
  12422. else
  12423. {
  12424. isEmptyFile = FALSE;
  12425. break;
  12426. }
  12427. }
  12428. }
  12429. else
  12430. isEmptyFile = TRUE;
  12431. fclose(fptr1);
  12432. if(isEmptyFile == TRUE)
  12433. {
  12434. memset(str, 0, ARRAY_SIZE(str));
  12435. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12436. system(str);
  12437. }
  12438. }
  12439. }// End of while(int k=0; k < ChargePointCount; k++)
  12440. }
  12441. else if((evseIsNULL == FALSE) && (evseIdInt != 0) )
  12442. {
  12443. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  12444. for(int k=0; k < ChargeProfileCount; k++)
  12445. {
  12446. fptr1 = fopen(chargingProfiles[k], "r");
  12447. fptr2 = fopen(temp, "w+");
  12448. //Check Charging Profile Count
  12449. while(fscanf(fptr1, "%s", word) != EOF)
  12450. {
  12451. //DEBUG_INFO("word=%s\n",word);
  12452. if(strstr(word, "id")!= NULL)
  12453. {
  12454. n_chargingProfile = n_chargingProfile + 1;
  12455. }
  12456. }
  12457. rewind(fptr1);
  12458. //search Charging Profile Element
  12459. //int i= 0;
  12460. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  12461. {
  12462. //*************************tempevseIdInt*********************************/
  12463. loc = strstr(sLineWord, "evseId");
  12464. c = 0;
  12465. memset(sstr ,0, ARRAY_SIZE(sstr));
  12466. while (loc[strlen("evseId")+2+c] != ',')
  12467. {
  12468. sstr[c] = loc[strlen("evseId")+2+c];
  12469. c++;
  12470. }
  12471. sstr[c] = '\0';
  12472. tempevseIdInt = atoi(sstr);
  12473. //id
  12474. c = 0;
  12475. loc = strstr(sLineWord, "id");
  12476. memset(sstr ,0, ARRAY_SIZE(sstr));
  12477. while (loc[strlen("id")+2+c] != ',')
  12478. {
  12479. sstr[c] = loc[strlen("id")+2+c];
  12480. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12481. c++;
  12482. }
  12483. sstr[c] = '\0';
  12484. tempchargingProfileIdInt = atoi(sstr);
  12485. //stackLevel
  12486. c = 0;
  12487. loc = strstr(sLineWord, "stackLevel");
  12488. memset(sstr ,0, ARRAY_SIZE(sstr));
  12489. while (loc[strlen("stackLevel")+2+c] != ',')
  12490. {
  12491. sstr[c] = loc[strlen("stackLevel")+2+c];
  12492. //printf("i=%d sstr=%c\n",c, sstr[c]);
  12493. c++;
  12494. }
  12495. sstr[c] = '\0';
  12496. tempstackLevelInt = atoi(sstr);
  12497. c = 0;
  12498. loc = strstr(sLineWord, "chargingProfilePurpose");
  12499. memset(sstr ,0, ARRAY_SIZE(sstr));
  12500. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  12501. {
  12502. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  12503. c++;
  12504. }
  12505. sstr[c] = '\0';
  12506. strcpy(tempchargingProfilePurposeStr, sstr);
  12507. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  12508. {
  12509. //------- not write to fptr2-------//
  12510. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12511. //clearflag = TRUE;
  12512. }
  12513. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  12514. {
  12515. //------- not write to fptr2-------//
  12516. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12517. }
  12518. else if(stackLevelIsNULL == TRUE)
  12519. {
  12520. //Clear Whole File
  12521. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  12522. clearflag = TRUE;
  12523. break;
  12524. }
  12525. else
  12526. {
  12527. fprintf(fptr2, sLineWord);//writing data into file
  12528. }
  12529. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  12530. }
  12531. if(clearflag == TRUE)
  12532. {
  12533. fclose(fptr1);
  12534. fclose(fptr2);
  12535. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12536. system(str);
  12537. // clear temp file
  12538. sprintf(str,"rm -f %s",temp);
  12539. system(str);
  12540. }
  12541. else
  12542. {
  12543. fclose(fptr1);
  12544. fclose(fptr2);
  12545. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12546. system(str);
  12547. resultRename = rename(temp, chargingProfiles[k]);
  12548. if(resultRename == 0)
  12549. {
  12550. DEBUG_INFO("File ChargingProfile renamed successfully");
  12551. }
  12552. else
  12553. {
  12554. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  12555. }
  12556. if(comfirmstr[0]== 0)
  12557. {
  12558. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  12559. }
  12560. //Check chargingProfile is empty file
  12561. /*------ Read the file ----------------*/
  12562. fptr1=fopen(chargingProfiles[k],"r");
  12563. ch=fgetc(fptr1);
  12564. rewind(fptr1);
  12565. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  12566. if(ch!=EOF)
  12567. {
  12568. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  12569. {
  12570. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  12571. if(sLineWord[0]=='\0')
  12572. {
  12573. isEmptyFile = TRUE;
  12574. break;
  12575. }
  12576. else
  12577. {
  12578. isEmptyFile = FALSE;
  12579. break;
  12580. }
  12581. }
  12582. }
  12583. else
  12584. isEmptyFile = TRUE;
  12585. fclose(fptr1);
  12586. if(isEmptyFile == TRUE)
  12587. {
  12588. memset(str, 0, ARRAY_SIZE(str));
  12589. sprintf(str,"rm -f %s",chargingProfiles[k]);
  12590. system(str);
  12591. }
  12592. /*------- End of reading ---------------*/
  12593. }
  12594. } // while(int k=0; k < ChargeProfileCount; k++)
  12595. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  12596. end:
  12597. if(strcmp(comfirmstr, ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted]) == 0)
  12598. {
  12599. if(evseIdInt == 0)
  12600. {
  12601. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12602. {
  12603. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  12604. checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx], 0, TRUE);
  12605. }
  12606. }
  12607. else
  12608. {
  12609. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  12610. checkCompositeSchedule(evseIdInt, 86400, &ShmOCPP20Data->SmartChargingProfile[evseIdInt-1], 0, TRUE);
  12611. }
  12612. }
  12613. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  12614. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12615. return result;
  12616. }
  12617. int handleClearDisplayMessageRequest(char *uuid, char *payload)
  12618. {
  12619. mtrace();
  12620. int result = FAIL;
  12621. json_object *ClearDisplayMessage;
  12622. DEBUG_INFO("handleClearDisplayMessageRequest...\n");
  12623. sprintf((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status, ClearMessageStatusEnumTypeStr[ClearMessageStatusEnumType_Unknown]);
  12624. ClearDisplayMessage = json_tokener_parse(payload);
  12625. if(!is_error(ClearDisplayMessage))
  12626. {
  12627. // Required data
  12628. if(json_object_object_get(ClearDisplayMessage, "id") != NULL)
  12629. {
  12630. ShmOCPP20Data->ClearDisplayMessage.id = json_object_get_double(json_object_object_get(ClearDisplayMessage, "id"));
  12631. sprintf((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status, ClearMessageStatusEnumTypeStr[ClearMessageStatusEnumType_Accepted]);
  12632. }
  12633. }
  12634. json_object_put(ClearDisplayMessage);
  12635. sendCostUpdatedConfirmation(uuid);
  12636. return result;
  12637. }
  12638. int handleClearVariableMonitoringRequest(char *uuid, char *payload)
  12639. {
  12640. mtrace();
  12641. int result = FAIL;
  12642. json_object *ClearVariableMonitorin;
  12643. DEBUG_INFO("handleClearVariableMonitoringRequest...\n");
  12644. ClearVariableMonitorin = json_tokener_parse(payload);
  12645. if(!is_error(ClearVariableMonitorin))
  12646. {
  12647. // Required data
  12648. if(json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id")) <= ARRAY_SIZE(ShmOCPP20Data->ClearVariableMonitoring.id))
  12649. {
  12650. for(int idx=0;idx<json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id"));idx++)
  12651. {
  12652. ShmOCPP20Data->ClearVariableMonitoring.id[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(ClearVariableMonitorin, "id"), idx));
  12653. /*
  12654. * TODO:
  12655. * 1. Check response
  12656. */
  12657. ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].id = ShmOCPP20Data->ClearVariableMonitoring.id[idx];
  12658. strcpy((char*)ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].status, ClearMonitoringStatusEnumTypeStr[ClearMonitoringStatusEnumType_Accepted]);
  12659. }
  12660. sendClearVariableMonitoringConfirmation(uuid, json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id")));
  12661. }
  12662. }
  12663. json_object_put(ClearVariableMonitorin);
  12664. return result;
  12665. }
  12666. int handleCostUpdatedRequest(char *uuid, char *payload)
  12667. {
  12668. mtrace();
  12669. int result = FAIL;
  12670. json_object *CostUpdate;
  12671. DEBUG_INFO("handleCostUpdatedRequest...\n");
  12672. CostUpdate = json_tokener_parse(payload);
  12673. if(!is_error(CostUpdate))
  12674. {
  12675. // Required data
  12676. if(json_object_object_get(CostUpdate, "totalCost") != NULL)
  12677. {
  12678. ShmOCPP20Data->CostUpdated.totalCost = json_object_get_double(json_object_object_get(CostUpdate, "totalCost"));
  12679. }
  12680. if(json_object_object_get(CostUpdate, "transactionId") != NULL)
  12681. {
  12682. sprintf((char*)ShmOCPP20Data->CostUpdated.transactionId, "%s", json_object_get_string(json_object_object_get(CostUpdate, "transactionId")));
  12683. }
  12684. }
  12685. json_object_put(CostUpdate);
  12686. sendCostUpdatedConfirmation(uuid);
  12687. return result;
  12688. }
  12689. int handleCustomerInformationRequest(char *uuid, char *payload)
  12690. {
  12691. mtrace();
  12692. int result = FAIL;
  12693. json_object *CustomerInformation;
  12694. DEBUG_INFO("handleCustomerInformationRequest...\n");
  12695. CustomerInformation = json_tokener_parse(payload);
  12696. if(!is_error(CustomerInformation))
  12697. {
  12698. // Required data
  12699. if(json_object_object_get(CustomerInformation, "requestId") != NULL)
  12700. {
  12701. ShmOCPP20Data->CustomerInformation.requestId = json_object_get_int(json_object_object_get(CustomerInformation, "requestId"));
  12702. }
  12703. if(json_object_object_get(CustomerInformation, "report") != NULL)
  12704. {
  12705. ShmOCPP20Data->CustomerInformation.report = json_object_get_boolean(json_object_object_get(CustomerInformation, "report"));
  12706. }
  12707. if(json_object_object_get(CustomerInformation, "clear") != NULL)
  12708. {
  12709. ShmOCPP20Data->CustomerInformation.report = json_object_get_boolean(json_object_object_get(CustomerInformation, "clear"));
  12710. }
  12711. // Optional data
  12712. if(json_object_object_get(CustomerInformation, "idToken") != NULL)
  12713. {
  12714. if(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "idToken") != NULL)
  12715. {
  12716. sprintf((char*)ShmOCPP20Data->CustomerInformation.idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "idToken")));
  12717. }
  12718. if(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "type") != NULL)
  12719. {
  12720. sprintf((char*)ShmOCPP20Data->CustomerInformation.idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "type")));
  12721. }
  12722. }
  12723. if(json_object_object_get(CustomerInformation, "customerCertificate") != NULL)
  12724. {
  12725. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "hashAlgorithm") != NULL)
  12726. {
  12727. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "hashAlgorithm")));
  12728. }
  12729. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerNameHash") != NULL)
  12730. {
  12731. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerNameHash")));
  12732. }
  12733. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerKeyHash") != NULL)
  12734. {
  12735. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerKeyHash")));
  12736. }
  12737. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "serialNumber") != NULL)
  12738. {
  12739. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "serialNumber")));
  12740. }
  12741. }
  12742. strcpy((char*)ShmOCPP20Data->CustomerInformation.Response_status, CustomerInformationStatusEnumTypeStr[CustomerInformationStatusEnumType_Accepted]);
  12743. ShmOCPP20Data->SpMsg.bits.NotifyCustomerInformationReq = ON;
  12744. }
  12745. else
  12746. strcpy((char*)ShmOCPP20Data->CustomerInformation.Response_status, CustomerInformationStatusEnumTypeStr[CustomerInformationStatusEnumType_Rejected]);
  12747. json_object_put(CustomerInformation);
  12748. sendCustomerInformationConfirmation(uuid);
  12749. return result;
  12750. }
  12751. void createFirmwareVersionByDataTransfer(void)
  12752. {
  12753. json_object *FirmwareDataTransfer = json_object_new_object();
  12754. // AC & DC model
  12755. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  12756. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  12757. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  12758. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  12759. // DC model
  12760. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  12761. {
  12762. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  12763. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  12764. (gunType[3] != GUN_TYPE_UNKNOWN))
  12765. {
  12766. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  12767. }
  12768. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  12769. {
  12770. // DS DM DW
  12771. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  12772. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  12773. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  12774. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  12775. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  12776. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  12777. }
  12778. else
  12779. {
  12780. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  12781. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  12782. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  12783. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  12784. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  12785. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  12786. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  12787. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  12788. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  12789. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  12790. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  12791. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  12792. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  12793. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  12794. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  12795. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  12796. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  12797. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  12798. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  12799. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  12800. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  12801. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  12802. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  12803. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  12804. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  12805. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  12806. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  12807. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  12808. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  12809. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  12810. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  12811. }
  12812. }
  12813. // 4G model
  12814. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  12815. {
  12816. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  12817. }
  12818. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  12819. json_object_put(FirmwareDataTransfer);
  12820. }
  12821. int handleDataTransferRequest(char *uuid, char *payload)
  12822. {
  12823. mtrace();
  12824. int result = PASS;
  12825. DEBUG_INFO("handleDataTransferRequest...\n");
  12826. if((uuid != NULL) && (payload != NULL))
  12827. {
  12828. json_object *DataTransfer;
  12829. DataTransfer = json_tokener_parse(payload);
  12830. if(!is_error(DataTransfer))
  12831. {
  12832. // Required data
  12833. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  12834. sprintf((char*)ShmOCPP20Data->DataTransfer[0].vendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  12835. // Optional data
  12836. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  12837. sprintf((char*)ShmOCPP20Data->DataTransfer[0].messageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  12838. if(json_object_object_get(DataTransfer, "data") != NULL)
  12839. sprintf((char*)ShmOCPP20Data->DataTransfer[0].data, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  12840. result = PASS;
  12841. }
  12842. json_object_put(DataTransfer);
  12843. if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_FirmwareVersion") != NULL)
  12844. {
  12845. // Send all moudle firmware version on EVSE
  12846. createFirmwareVersionByDataTransfer();
  12847. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12848. }
  12849. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_Tmate") != NULL)
  12850. {
  12851. system("/usr/bin/run_tmate_restart.sh &");
  12852. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12853. }
  12854. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_ChargingPreference") != NULL)
  12855. {
  12856. json_object *data;
  12857. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12858. if(!is_error(data))
  12859. {
  12860. 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))
  12861. {
  12862. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  12863. memset(&ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  12864. if(json_object_object_get(data, "SOC") != NULL)
  12865. {
  12866. ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  12867. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  12868. }
  12869. if(json_object_object_get(data, "Energy") != NULL)
  12870. {
  12871. ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  12872. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  12873. }
  12874. if(json_object_object_get(data, "Duration") != NULL)
  12875. {
  12876. ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  12877. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  12878. }
  12879. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12880. }
  12881. else
  12882. {
  12883. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12884. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Connector id must > 0.");
  12885. }
  12886. }
  12887. else
  12888. {
  12889. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12890. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12891. }
  12892. json_object_put(data);
  12893. }
  12894. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "SetLEDBar") != NULL)
  12895. {
  12896. json_object *data;
  12897. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12898. if(!is_error(data))
  12899. {
  12900. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  12901. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  12902. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  12903. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  12904. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  12905. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  12906. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  12907. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  12908. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  12909. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  12910. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12911. }
  12912. else
  12913. {
  12914. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12915. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12916. }
  12917. json_object_put(data);
  12918. }
  12919. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_ConfigQR") != NULL)
  12920. {
  12921. json_object *data;
  12922. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12923. if(!is_error(data))
  12924. {
  12925. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12926. if(json_object_object_get(data, "Content_Type") != NULL)
  12927. {
  12928. 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))
  12929. {
  12930. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  12931. if(json_object_object_get(data, "Customization_Conent") != NULL)
  12932. {
  12933. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  12934. }
  12935. }
  12936. else
  12937. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12938. }
  12939. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  12940. }
  12941. else
  12942. {
  12943. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12944. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12945. }
  12946. json_object_put(data);
  12947. }
  12948. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_DisplayLcdPage") != NULL)
  12949. {
  12950. json_object *data;
  12951. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12952. if(!is_error(data))
  12953. {
  12954. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12955. if(json_object_object_get(data, "ConnectorId") != NULL)
  12956. {
  12957. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  12958. }
  12959. if(json_object_object_get(data, "Page_Index") != NULL)
  12960. {
  12961. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  12962. }
  12963. if(json_object_object_get(data, "Duration") != NULL)
  12964. {
  12965. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  12966. }
  12967. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = ON;
  12968. }
  12969. else
  12970. {
  12971. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12972. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12973. }
  12974. json_object_put(data);
  12975. }
  12976. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_CpConfiguration") != NULL)
  12977. {
  12978. json_object *data;
  12979. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  12980. if(!is_error(data))
  12981. {
  12982. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  12983. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, " ");
  12984. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  12985. {
  12986. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  12987. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  12988. else
  12989. {
  12990. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  12991. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  12992. }
  12993. }
  12994. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  12995. {
  12996. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  12997. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  12998. else
  12999. {
  13000. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  13001. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  13002. }
  13003. }
  13004. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  13005. {
  13006. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  13007. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  13008. else
  13009. {
  13010. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  13011. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  13012. }
  13013. }
  13014. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  13015. {
  13016. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  13017. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  13018. else
  13019. {
  13020. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  13021. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  13022. }
  13023. }
  13024. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  13025. {
  13026. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  13027. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  13028. else
  13029. {
  13030. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  13031. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  13032. }
  13033. }
  13034. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  13035. {
  13036. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  13037. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  13038. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  13039. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  13040. else
  13041. {
  13042. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  13043. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  13044. }
  13045. }
  13046. if(json_object_object_get(data, "isAuthentication") != NULL)
  13047. {
  13048. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  13049. {
  13050. case 0:
  13051. case 1:
  13052. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  13053. break;
  13054. default:
  13055. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  13056. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  13057. break;
  13058. }
  13059. }
  13060. if(strstr((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]) != NULL)
  13061. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  13062. }
  13063. else
  13064. {
  13065. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  13066. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  13067. }
  13068. json_object_put(data);
  13069. }
  13070. else
  13071. {
  13072. // Can not find valid message id
  13073. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_UnknownMessageId]);
  13074. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data,"vendorId: %s messageId: %s data: %s"
  13075. ,ShmOCPP20Data->DataTransfer[0].vendorId
  13076. ,ShmOCPP20Data->DataTransfer[0].messageId
  13077. ,ShmOCPP20Data->DataTransfer[0].data);
  13078. }
  13079. }
  13080. else
  13081. {
  13082. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_UnknownMessageId]);
  13083. result = FAIL;
  13084. }
  13085. sendDataTransferConfirmation(uuid, 0);
  13086. return result;
  13087. }
  13088. int handleDeleteCertificateRequest(char *uuid, char *payload)
  13089. {
  13090. mtrace();
  13091. int result = FAIL;
  13092. json_object *DeleteCertificate;
  13093. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  13094. DeleteCertificate = json_tokener_parse(payload);
  13095. if(!is_error(DeleteCertificate))
  13096. {
  13097. memset(&ShmOCPP20Data->DeleteCertificate, 0, sizeof(struct DeleteCertificate_20));
  13098. memcpy(&ShmOCPP20Data->DeleteCertificate.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->DeleteCertificate.guid));
  13099. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  13100. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  13101. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  13102. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  13103. DEBUG_INFO("hashAlgorithm: %s\n", ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm);
  13104. DEBUG_INFO("issuerNameHash: %s\n", ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash);
  13105. DEBUG_INFO("issuerKeyHash: %s\n", ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash);
  13106. DEBUG_INFO("serialNumber: %s\n", ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber);
  13107. for(int i = 0; ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash[i]; i++)
  13108. {
  13109. ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash[i] = tolower(ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash[i]);
  13110. }
  13111. for(int i = 0; ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash[i]; i++)
  13112. {
  13113. ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash[i] = tolower(ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash[i]);
  13114. }
  13115. for(int i = 0; ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber[i]; i++)
  13116. {
  13117. ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber[i] = tolower(ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber[i]);
  13118. }
  13119. char temp[256] = {0};
  13120. char compareData[256] = {0};
  13121. int isMatch = TRUE;
  13122. // Check CentralSystemRootCertificate
  13123. if(access(ROOTCA_CS,F_OK) != -1)
  13124. {
  13125. DEBUG_INFO("Checking CentralSystemRootCertificate...\n");
  13126. parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, compareData);
  13127. for(int i = 0; compareData[i]; i++)
  13128. {
  13129. compareData[i] = tolower(compareData[i]);
  13130. }
  13131. if(strcmp(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  13132. isMatch = FALSE;
  13133. if(isMatch == TRUE)
  13134. {
  13135. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, compareData);
  13136. for(int i = 0; compareData[i]; i++)
  13137. {
  13138. compareData[i] = tolower(compareData[i]);
  13139. }
  13140. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  13141. isMatch = FALSE;
  13142. }
  13143. if(isMatch == TRUE)
  13144. {
  13145. parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, compareData);
  13146. for(int i = 0; compareData[i]; i++)
  13147. {
  13148. compareData[i] = tolower(compareData[i]);
  13149. }
  13150. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  13151. isMatch = FALSE;
  13152. }
  13153. if(isMatch == TRUE)
  13154. {
  13155. DEBUG_INFO("Deleting CentralSystemRootCertificate...\n");
  13156. sprintf(temp, "rm -f %s", ROOTCA_CS);
  13157. system(temp);
  13158. sprintf((char*)ShmOCPP20Data->DeleteCertificate.Response_status, "Accepted");
  13159. goto End;
  13160. }
  13161. }
  13162. // Check ManufacturerRootCertificate
  13163. if(access(ROOTCA_MF,F_OK) != -1)
  13164. {
  13165. DEBUG_INFO("Checking ManufacturerRootCertificate...\n");
  13166. isMatch = TRUE;
  13167. parseCertInfo(ROOTCA_MF, CERT_PARSE_SerialNumber, compareData);
  13168. for(int i = 0; compareData[i]; i++)
  13169. {
  13170. compareData[i] = tolower(compareData[i]);
  13171. }
  13172. if(strcmp(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  13173. isMatch = FALSE;
  13174. if(isMatch == TRUE)
  13175. {
  13176. parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerNameHash, compareData);
  13177. for(int i = 0; compareData[i]; i++)
  13178. {
  13179. compareData[i] = tolower(compareData[i]);
  13180. }
  13181. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  13182. isMatch = FALSE;
  13183. }
  13184. if(isMatch == TRUE)
  13185. {
  13186. parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerKeyHash, compareData);
  13187. for(int i = 0; compareData[i]; i++)
  13188. {
  13189. compareData[i] = tolower(compareData[i]);
  13190. }
  13191. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  13192. isMatch = FALSE;
  13193. }
  13194. if(isMatch == TRUE)
  13195. {
  13196. DEBUG_INFO("Deleting ManufacturerRootCertificate...\n");
  13197. sprintf(temp, "rm -f %s", ROOTCA_MF);
  13198. system(temp);
  13199. sprintf((char*)ShmOCPP20Data->DeleteCertificate.Response_status, "Accepted");
  13200. goto End;
  13201. }
  13202. }
  13203. if(access(ROOTCA_V2G,F_OK) != -1)
  13204. {
  13205. DEBUG_INFO("Checking V2GRootCertificate...\n");
  13206. isMatch = TRUE;
  13207. parseCertInfo(ROOTCA_V2G, CERT_PARSE_SerialNumber, compareData);
  13208. for(int i = 0; compareData[i]; i++)
  13209. {
  13210. compareData[i] = tolower(compareData[i]);
  13211. }
  13212. if(strcmp(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  13213. isMatch = FALSE;
  13214. if(isMatch == TRUE)
  13215. {
  13216. parseCertInfo(ROOTCA_V2G, CERT_PARSE_IssuerNameHash, compareData);
  13217. for(int i = 0; compareData[i]; i++)
  13218. {
  13219. compareData[i] = tolower(compareData[i]);
  13220. }
  13221. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  13222. isMatch = FALSE;
  13223. }
  13224. if(isMatch == TRUE)
  13225. {
  13226. parseCertInfo(ROOTCA_V2G, CERT_PARSE_IssuerKeyHash, compareData);
  13227. for(int i = 0; compareData[i]; i++)
  13228. {
  13229. compareData[i] = tolower(compareData[i]);
  13230. }
  13231. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  13232. isMatch = FALSE;
  13233. }
  13234. if(isMatch == TRUE)
  13235. {
  13236. DEBUG_INFO("Deleting V2GRootCertificate...\n");
  13237. sprintf(temp, "rm -f %s", ROOTCA_V2G);
  13238. system(temp);
  13239. sprintf((char*)ShmOCPP20Data->DeleteCertificate.Response_status, "Accepted");
  13240. goto End;
  13241. }
  13242. }
  13243. if(access(ROOTCA_MO,F_OK) != -1)
  13244. {
  13245. DEBUG_INFO("Checking MORootCertificate...\n");
  13246. isMatch = TRUE;
  13247. parseCertInfo(ROOTCA_MO, CERT_PARSE_SerialNumber, compareData);
  13248. for(int i = 0; compareData[i]; i++)
  13249. {
  13250. compareData[i] = tolower(compareData[i]);
  13251. }
  13252. if(strcmp(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  13253. isMatch = FALSE;
  13254. if(isMatch == TRUE)
  13255. {
  13256. parseCertInfo(ROOTCA_MO, CERT_PARSE_IssuerNameHash, compareData);
  13257. for(int i = 0; compareData[i]; i++)
  13258. {
  13259. compareData[i] = tolower(compareData[i]);
  13260. }
  13261. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  13262. isMatch = FALSE;
  13263. }
  13264. if(isMatch == TRUE)
  13265. {
  13266. parseCertInfo(ROOTCA_MO, CERT_PARSE_IssuerKeyHash, compareData);
  13267. for(int i = 0; compareData[i]; i++)
  13268. {
  13269. compareData[i] = tolower(compareData[i]);
  13270. }
  13271. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  13272. isMatch = FALSE;
  13273. }
  13274. if(isMatch == TRUE)
  13275. {
  13276. DEBUG_INFO("Deleting MORootCertificate...\n");
  13277. sprintf(temp, "rm -f %s", ROOTCA_MO);
  13278. system(temp);
  13279. sprintf((char*)ShmOCPP20Data->DeleteCertificate.Response_status, "Accepted");
  13280. goto End;
  13281. }
  13282. }
  13283. // Check certCP
  13284. if(access(CERTIFICATE_CP,F_OK) != -1)
  13285. {
  13286. DEBUG_INFO("Checking certCP...\n");
  13287. isMatch = TRUE;
  13288. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_SerialNumber, compareData);
  13289. for(int i = 0; compareData[i]; i++)
  13290. {
  13291. compareData[i] = tolower(compareData[i]);
  13292. }
  13293. if(strcmp(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber) != 0)
  13294. isMatch = FALSE;
  13295. if(isMatch == TRUE)
  13296. {
  13297. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_IssuerNameHash, compareData);
  13298. for(int i = 0; compareData[i]; i++)
  13299. {
  13300. compareData[i] = tolower(compareData[i]);
  13301. }
  13302. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash) == NULL)
  13303. isMatch = FALSE;
  13304. }
  13305. if(isMatch == TRUE)
  13306. {
  13307. parseCertInfo(CERTIFICATE_CP, CERT_PARSE_IssuerKeyHash, compareData);
  13308. for(int i = 0; compareData[i]; i++)
  13309. {
  13310. compareData[i] = tolower(compareData[i]);
  13311. }
  13312. if(strstr(compareData, (char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash) == NULL)
  13313. isMatch = FALSE;
  13314. }
  13315. if(isMatch == TRUE)
  13316. {
  13317. DEBUG_INFO("Deleting certCP...\n");
  13318. sprintf(temp, "rm -f %s", CERTIFICATE_CP);
  13319. system(temp);
  13320. sprintf((char*)ShmOCPP20Data->DeleteCertificate.Response_status, "Accepted");
  13321. goto End;
  13322. }
  13323. }
  13324. }
  13325. else
  13326. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, DeleteCertificateStatusEnumTypeStr[DeleteCertificateStatusEnumType_Failed]);
  13327. End:
  13328. json_object_put(DeleteCertificate);
  13329. ShmOCPP20Data->MsMsg.bits.DeleteCertificateReq = 1;
  13330. sendDeleteCertificateConfirmation(uuid);
  13331. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13332. return result;
  13333. }
  13334. int handleGetBaseReportRequest(char *uuid, char *payload)
  13335. {
  13336. mtrace();
  13337. int result = FAIL;
  13338. json_object *GetBaseRepor;
  13339. DEBUG_INFO("handleGetBaseReportRequest...\n");
  13340. GetBaseRepor = json_tokener_parse(payload);
  13341. if(!is_error(GetBaseRepor))
  13342. {
  13343. memset(&ShmOCPP20Data->GetBaseReport, 0, sizeof(struct GetBaseReport_20));
  13344. memcpy(&ShmOCPP20Data->GetBaseReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetBaseReport.guid));
  13345. // Required data
  13346. if(json_object_object_get(GetBaseRepor, "requestId") != NULL)
  13347. {
  13348. ShmOCPP20Data->GetBaseReport.requestId = json_object_get_int(json_object_object_get(GetBaseRepor, "requestId"));
  13349. }
  13350. if(json_object_object_get(GetBaseRepor, "reportBase") != NULL)
  13351. {
  13352. sprintf((char*)ShmOCPP20Data->GetBaseReport.reportBase, "%s", json_object_get_string(json_object_object_get(GetBaseRepor, "reportBase")));
  13353. }
  13354. if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_SummaryInventory]) == 0)
  13355. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  13356. else
  13357. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  13358. }
  13359. else
  13360. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  13361. json_object_put(GetBaseRepor);
  13362. sendGetBaseReportConfirmation(uuid);
  13363. return result;
  13364. }
  13365. int handleGetChargingProfilesRequest(char *uuid, char *payload)
  13366. {
  13367. mtrace();
  13368. int result = FAIL;
  13369. int gun_index = -1;
  13370. json_object *GetChargingProfiles;
  13371. DEBUG_INFO("handleGetChargingProfilesRequest...\n");
  13372. GetChargingProfiles = json_tokener_parse(payload);
  13373. if(!is_error(GetChargingProfiles))
  13374. {
  13375. if(json_object_object_get(GetChargingProfiles, "evseId") != NULL)
  13376. {
  13377. 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;
  13378. }
  13379. if(gun_index >-1)
  13380. {
  13381. memset(&ShmOCPP20Data->GetChargingProfiles[gun_index], 0, sizeof(struct GetChargingProfiles_20));
  13382. memcpy(&ShmOCPP20Data->GetChargingProfiles[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetChargingProfiles[gun_index].guid));
  13383. // Required data
  13384. if(json_object_object_get(GetChargingProfiles, "requestId") != NULL)
  13385. {
  13386. ShmOCPP20Data->GetChargingProfiles[gun_index].requestId = json_object_get_int(json_object_object_get(GetChargingProfiles, "requestId"));
  13387. }
  13388. if(json_object_object_get(GetChargingProfiles, "chargingProfile") != NULL)
  13389. {
  13390. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfilePurpose") != NULL)
  13391. {
  13392. sprintf((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.chargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfilePurpose")));
  13393. }
  13394. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "stackLevel") != NULL)
  13395. {
  13396. ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "stackLevel"));
  13397. }
  13398. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingLimitSource") != NULL)
  13399. {
  13400. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingLimitSource"));idx++)
  13401. {
  13402. 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)));
  13403. }
  13404. }
  13405. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfileId") != NULL)
  13406. {
  13407. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfileId"));idx++)
  13408. {
  13409. 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));
  13410. }
  13411. }
  13412. }
  13413. strcpy((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status, GetChargingProfileStatusEnumTypeStr[GetChargingProfileStatusEnumType_Accepted]);
  13414. }
  13415. else
  13416. strcpy((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status, GetChargingProfileStatusEnumTypeStr[GetChargingProfileStatusEnumType_NoProfiles]);
  13417. }
  13418. json_object_put(GetChargingProfiles);
  13419. sendGetChargingProfilesConfirmation(uuid, gun_index);
  13420. return result;
  13421. }
  13422. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  13423. {
  13424. mtrace();
  13425. int result = FAIL;
  13426. int evseIdInt, durationInt;
  13427. char chargingRateUnitStr[4]={0};
  13428. char comfirmstr[20];
  13429. int confirmPeriods = 0;
  13430. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  13431. json_object *GetCompositeSchedule;
  13432. GetCompositeSchedule = json_tokener_parse(payload);
  13433. if(!is_error(GetCompositeSchedule))
  13434. {
  13435. // Required data
  13436. if(json_object_object_get(GetCompositeSchedule, "evseId") != NULL)
  13437. evseIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "evseId"));
  13438. else
  13439. evseIdInt = -1;
  13440. if(json_object_object_get(GetCompositeSchedule, "duration"))
  13441. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  13442. else
  13443. durationInt = 86400;
  13444. // Optional data
  13445. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  13446. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  13447. }
  13448. json_object_put(GetCompositeSchedule);
  13449. memset(ShmOCPP20Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  13450. if((evseIdInt == 0) ||
  13451. ((evseIdInt > 0) && ((evseIdInt -1) < gunTotalNumber)))
  13452. {
  13453. int gun_index = (evseIdInt==0?0:evseIdInt-1);
  13454. struct ChargingProfileType tmpProfile[1];
  13455. memset(&ShmOCPP20Data->GetCompositeSchedule[gun_index], 0, sizeof(struct GetCompositeSchedule_20));
  13456. memcpy(&ShmOCPP20Data->GetCompositeSchedule[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].guid));
  13457. if(strstr(chargingRateUnitStr, "W") != NULL || strlen(chargingRateUnitStr) == 0)
  13458. {
  13459. sprintf((char*)ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingRateUnit, "W");
  13460. checkChargingStationMaxProfile(durationInt, &tmpProfile[0], 0, FALSE);
  13461. checkCompositeSchedule(evseIdInt, durationInt, &tmpProfile[0], 0, FALSE);
  13462. }
  13463. else
  13464. {
  13465. sprintf((char*)ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingRateUnit, "A");
  13466. checkChargingStationMaxProfile(durationInt, &tmpProfile[0], 0, TRUE);
  13467. checkCompositeSchedule(evseIdInt, durationInt, &tmpProfile[0], 0, TRUE);
  13468. }
  13469. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod);idx++)
  13470. {
  13471. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].chargingSchedule[0].chargingSchedulePeriod[idx].startPeriod);
  13472. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].chargingSchedule[0].chargingSchedulePeriod[idx].limit);
  13473. }
  13474. memcpy(&ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule, &tmpProfile[0].chargingSchedule[0], sizeof(struct ChargingScheduleType));
  13475. strcpy((char *)ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.startDateTime, (char *)tmpProfile[0].chargingSchedule[0].startSchedule);
  13476. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod);idx++)
  13477. {
  13478. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].startPeriod);
  13479. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit);
  13480. if((ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].startPeriod==0) &&
  13481. (ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit==0) &&
  13482. (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))
  13483. {
  13484. confirmPeriods = idx;
  13485. break;
  13486. }
  13487. }
  13488. if((confirmPeriods == 0) && (tmpProfile[0].id > 0))
  13489. {
  13490. confirmPeriods += 1;
  13491. }
  13492. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  13493. }
  13494. else
  13495. {
  13496. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusEnumTypeStr[GenericStatusEnumType_Rejected]);
  13497. }
  13498. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, evseIdInt, confirmPeriods);
  13499. return result;
  13500. }
  13501. int handleGetDisplayMessagesRequest(char *uuid, char *payload)
  13502. {
  13503. mtrace();
  13504. int result = FAIL;
  13505. json_object *GetDisplayMessages;
  13506. DEBUG_INFO("handleGetDisplayMessagesRequest...\n");
  13507. GetDisplayMessages = json_tokener_parse(payload);
  13508. if(!is_error(GetDisplayMessages))
  13509. {
  13510. memset(&ShmOCPP20Data->GetDisplayMessages, 0, sizeof(struct GetDisplayMessages_20));
  13511. memcpy(&ShmOCPP20Data->GetDisplayMessages.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetDisplayMessages.guid));
  13512. // Required data
  13513. if(json_object_object_get(GetDisplayMessages, "requestId") != NULL)
  13514. {
  13515. ShmOCPP20Data->GetDisplayMessages.requestId = json_object_get_int(json_object_object_get(GetDisplayMessages, "requestId"));
  13516. }
  13517. // Optional data
  13518. if(json_object_object_get(GetDisplayMessages, "priority") != NULL)
  13519. {
  13520. sprintf((char*)ShmOCPP20Data->GetDisplayMessages.priority, "%s", json_object_get_string(json_object_object_get(GetDisplayMessages, "priority")));
  13521. }
  13522. if(json_object_object_get(GetDisplayMessages, "state") != NULL)
  13523. {
  13524. sprintf((char*)ShmOCPP20Data->GetDisplayMessages.state, "%s", json_object_get_string(json_object_object_get(GetDisplayMessages, "state")));
  13525. }
  13526. if(json_object_array_length(json_object_object_get(GetDisplayMessages, "id")) <= ARRAY_SIZE(ShmOCPP20Data->GetDisplayMessages.id))
  13527. {
  13528. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetDisplayMessages, "id"));idx++)
  13529. {
  13530. ShmOCPP20Data->GetDisplayMessages.id[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(GetDisplayMessages, "id"), idx));
  13531. }
  13532. strcpy((char*)ShmOCPP20Data->GetDisplayMessages.Response_status, GetDisplayMessagesStatusEnumTypeStr[GetDisplayMessagesStatusEnumType_Accepted]);
  13533. ShmOCPP20Data->MsMsg.bits.GetDisplayMessagesReq = ON;
  13534. }
  13535. else
  13536. strcpy((char*)ShmOCPP20Data->GetDisplayMessages.Response_status, GetDisplayMessagesStatusEnumTypeStr[GetDisplayMessagesStatusEnumType_Unknown]);
  13537. }
  13538. json_object_put(GetDisplayMessages);
  13539. return result;
  13540. }
  13541. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  13542. {
  13543. mtrace();
  13544. int result = FAIL;
  13545. int certCnt = 0;
  13546. unsigned char foundCertCnt = 0;
  13547. json_object *GetInstalledCertificateIds;
  13548. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  13549. GetInstalledCertificateIds = json_tokener_parse(payload);
  13550. if(!is_error(GetInstalledCertificateIds))
  13551. {
  13552. memset(&ShmOCPP20Data->GetInstalledCertificateIds, 0, sizeof(struct GetInstalledCertificateIds_20));
  13553. memcpy(&ShmOCPP20Data->GetInstalledCertificateIds.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetInstalledCertificateIds.guid));
  13554. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_NotFound]);
  13555. // Optional data
  13556. if(json_object_array_length(json_object_object_get(GetInstalledCertificateIds, "certificateType")) <= ARRAY_SIZE(ShmOCPP20Data->GetInstalledCertificateIds.certificateType))
  13557. {
  13558. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetInstalledCertificateIds, "certificateType"));idx++)
  13559. {
  13560. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetInstalledCertificateIds, "certificateType"), idx)));
  13561. DEBUG_INFO("Requested Certificate: %s\n", (char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx]);
  13562. //sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, "Accepted");
  13563. DEBUG_INFO("Access ROOTCA_CS result: %d\n", access(ROOTCA_CS,F_OK));
  13564. // Check CSMSRootCertificate
  13565. if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "CSMSRootCertificate")!= NULL)
  13566. {
  13567. if(access(ROOTCA_CS,F_OK) != -1)
  13568. {
  13569. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateType, "CSMSRootCertificate");
  13570. char parseData[512] = {0};
  13571. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  13572. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.hashAlgorithm, parseData);
  13573. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_SerialNumber, parseData) == PASS)
  13574. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.serialNumber, parseData);
  13575. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  13576. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerNameHash, parseData);
  13577. if(parseCertInfo(ROOTCA_CS, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  13578. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerKeyHash, parseData);
  13579. certCnt++;
  13580. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  13581. }
  13582. else
  13583. {
  13584. DEBUG_INFO(">>> No CentralSystemRootCertificate was found.\n");
  13585. //sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13586. }
  13587. }
  13588. // Check ManufacturerRootCertificate
  13589. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "ManufacturerRootCertificate") != NULL)
  13590. {
  13591. if(access(ROOTCA_MF,F_OK) != -1)
  13592. {
  13593. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateType, "ManufacturerRootCertificate");
  13594. char parseData[512] = {0};
  13595. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  13596. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.hashAlgorithm, parseData);
  13597. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_SerialNumber, parseData) == PASS)
  13598. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.serialNumber, parseData);
  13599. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  13600. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerNameHash, parseData);
  13601. if(parseCertInfo(ROOTCA_MF, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  13602. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerKeyHash, parseData);
  13603. certCnt++;
  13604. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  13605. }
  13606. else
  13607. {
  13608. DEBUG_INFO(">>> No ManufacturerRootCertificate was found.\n");
  13609. //sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13610. }
  13611. }
  13612. // Check MORootCertificate
  13613. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "MORootCertificate") != NULL)
  13614. {
  13615. if(access(ROOTCA_MO,F_OK) != -1)
  13616. {
  13617. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateType, "MORootCertificate");
  13618. char parseData[512] = {0};
  13619. if(parseCertInfo(ROOTCA_MO, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  13620. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.hashAlgorithm, parseData);
  13621. if(parseCertInfo(ROOTCA_MO, CERT_PARSE_SerialNumber, parseData) == PASS)
  13622. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.serialNumber, parseData);
  13623. if(parseCertInfo(ROOTCA_MO, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  13624. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerNameHash, parseData);
  13625. if(parseCertInfo(ROOTCA_MO, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  13626. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerKeyHash, parseData);
  13627. certCnt++;
  13628. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  13629. }
  13630. else
  13631. {
  13632. DEBUG_INFO(">>> No MORootCertificate was found.\n");
  13633. //sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13634. }
  13635. }
  13636. // Check V2GRootCertificate
  13637. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "V2GRootCertificate") != NULL)
  13638. {
  13639. if(access(ROOTCA_V2G,F_OK) != -1)
  13640. {
  13641. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateType, "V2GRootCertificate");
  13642. char parseData[512] = {0};
  13643. if(parseCertInfo(ROOTCA_V2G, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  13644. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.hashAlgorithm, parseData);
  13645. if(parseCertInfo(ROOTCA_V2G, CERT_PARSE_SerialNumber, parseData) == PASS)
  13646. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.serialNumber, parseData);
  13647. if(parseCertInfo(ROOTCA_V2G, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  13648. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerNameHash, parseData);
  13649. if(parseCertInfo(ROOTCA_V2G, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  13650. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerKeyHash, parseData);
  13651. certCnt++;
  13652. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  13653. }
  13654. else
  13655. {
  13656. DEBUG_INFO(">>> No V2GRootCertificate was found.\n");
  13657. //sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13658. }
  13659. }
  13660. // Check V2GCertificateChain
  13661. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "V2GCertificateChain") != NULL)
  13662. {
  13663. if(access(CERTIFICATE_V2G,F_OK) != -1)
  13664. {
  13665. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateType, "V2GCertificateChain");
  13666. char parseData[512] = {0};
  13667. if(parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_HashAlgorithm, parseData) == PASS)
  13668. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.hashAlgorithm, parseData);
  13669. if(parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_SerialNumber, parseData) == PASS)
  13670. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.serialNumber, parseData);
  13671. if(parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerNameHash, parseData) == PASS)
  13672. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerNameHash, parseData);
  13673. if(parseCertInfo(CERTIFICATE_V2G, CERT_PARSE_IssuerKeyHash, parseData) == PASS)
  13674. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[certCnt].certificateHashData.issuerKeyHash, parseData);
  13675. certCnt++;
  13676. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  13677. }
  13678. else
  13679. {
  13680. DEBUG_INFO(">>> No V2GCertificateChain was found.\n");
  13681. //sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, "NotFound");
  13682. }
  13683. }
  13684. else
  13685. {
  13686. DEBUG_INFO(">>> No %s was found.\n", (char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx]);
  13687. }
  13688. }
  13689. }
  13690. else
  13691. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_NotFound]);
  13692. }
  13693. json_object_put(GetInstalledCertificateIds);
  13694. sendGetInstalledCertificateIdsConfirmation(uuid, foundCertCnt);
  13695. return result;
  13696. }
  13697. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  13698. {
  13699. mtrace();
  13700. int result = FAIL;
  13701. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  13702. if(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "false") == 0)
  13703. {
  13704. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  13705. localversion = 0;
  13706. }
  13707. else
  13708. {
  13709. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  13710. localversion = 0;
  13711. DB_getListVerion();
  13712. }
  13713. ShmOCPP20Data->GetLocalListVersion.Response_versionNumber = localversion;
  13714. sendGetLocalListVersionConfirmation(uuid);
  13715. return result;
  13716. }
  13717. static char fnamePlusPath[100]={0};
  13718. static char fnamePWithNoPath[60]={0};
  13719. void checkUploadLog(void)
  13720. {
  13721. FILE *fp;
  13722. /* Open the command for reading. */
  13723. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  13724. if (fp == NULL) {
  13725. printf("Failed to run command\n" );
  13726. exit(1);
  13727. }
  13728. int ftppathlen = 0;
  13729. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  13730. int i = 0;
  13731. /* Read the output a line at a time - output it. */
  13732. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  13733. if(i==0)
  13734. {
  13735. ftppathlen = strlen(fnamePlusPath);
  13736. printf("%s\n", fnamePlusPath);
  13737. fnamePlusPath[ftppathlen]='\0';
  13738. break;
  13739. }
  13740. i= i+1;
  13741. }
  13742. /* close */
  13743. pclose(fp);
  13744. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  13745. {
  13746. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  13747. {
  13748. fnamePlusPath[k]='\0';
  13749. }
  13750. }
  13751. i=1;
  13752. //char fname[60]={0};
  13753. while(i < ftppathlen)
  13754. {
  13755. int len=ftppathlen-i;
  13756. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  13757. {
  13758. printf("compare '/' all right\n");
  13759. break;
  13760. }
  13761. i=i+1;
  13762. }
  13763. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  13764. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  13765. fnamePWithNoPath[i+1] = '\0';
  13766. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  13767. {
  13768. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  13769. {
  13770. fnamePWithNoPath[j]='\0';
  13771. }
  13772. }
  13773. FILE* fp1 = fopen(fnamePlusPath, "r");
  13774. if (fp1)
  13775. {
  13776. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  13777. // file exists
  13778. fclose(fp1);
  13779. }
  13780. else
  13781. {
  13782. // file doesn't exist
  13783. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  13784. }
  13785. }
  13786. void* GetLogProcess(void* data)
  13787. {
  13788. th_GetLog = pthread_self();
  13789. pthread_detach(pthread_self());
  13790. mtrace();
  13791. int requestId, retriesInt=0, retryIntervalInt=0;
  13792. char logType[32], remoteLocation[1024]={0}, oldestTimestamp[30]={0}, latestTimestamp[30]={0};
  13793. 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};
  13794. int port=0;
  13795. int isSuccess = FALSE;
  13796. char ftpbuf[1024]={0};
  13797. char cmdBuf[2048];
  13798. struct tm *tmNow;
  13799. time_t CurrentTime;
  13800. struct tm tmStart;
  13801. struct tm tmStop;
  13802. CurrentTime = time(NULL);
  13803. tmNow=localtime(&CurrentTime);
  13804. uint16_t targetYear, targetMonth;
  13805. json_object *GetLog;
  13806. DEBUG_INFO("GetGetProcess...\n");
  13807. GetLog = json_tokener_parse(data);
  13808. if(!is_error(GetLog))
  13809. {
  13810. // Required data
  13811. if(json_object_object_get(GetLog, "requestId") != NULL)
  13812. requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  13813. if(json_object_object_get(GetLog, "logType") != NULL)
  13814. sprintf(logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  13815. if(json_object_object_get(GetLog, "log") != NULL)
  13816. {
  13817. if(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation") != NULL)
  13818. sprintf(remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  13819. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  13820. sprintf(oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  13821. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  13822. sprintf(latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  13823. }
  13824. // Optional data
  13825. if(json_object_object_get(GetLog, "retries") != NULL)
  13826. retriesInt = json_object_get_int(json_object_object_get(GetLog, "retries"));
  13827. else
  13828. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  13829. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  13830. retryIntervalInt = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  13831. else
  13832. retryIntervalInt = 30;
  13833. }
  13834. json_object_put(GetLog);
  13835. ShmOCPP20Data->GetLog.requestId = requestId;
  13836. if(strstr(logType, LogEnumTypeStr[LogEnumType_SecurityLog]))
  13837. {
  13838. /*
  13839. * TODO:
  13840. * 1. Pack security log
  13841. */
  13842. }
  13843. else
  13844. {
  13845. // Pack log to compress file
  13846. 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) &&
  13847. (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))
  13848. {
  13849. // Pack system log
  13850. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  13851. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  13852. targetYear = tmStart.tm_year;
  13853. targetMonth = tmStart.tm_mon;
  13854. do
  13855. {
  13856. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  13857. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  13858. if(targetMonth+1>=13)
  13859. {
  13860. targetYear += 1;
  13861. targetMonth = 1;
  13862. }
  13863. else
  13864. {
  13865. targetMonth += 1;
  13866. }
  13867. }while((targetYear < (tmNow->tm_year+1900)) ||
  13868. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  13869. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  13870. system(cmdBuf);
  13871. // Pack charging & event log
  13872. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  13873. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  13874. targetYear = tmStart.tm_year;
  13875. targetMonth = tmStart.tm_mon;
  13876. do
  13877. {
  13878. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  13879. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*Ocpp*MessageLog*", cmdBuf, targetYear, targetMonth);
  13880. if(targetMonth+1>=13)
  13881. {
  13882. targetYear += 1;
  13883. targetMonth = 1;
  13884. }
  13885. else
  13886. {
  13887. targetMonth += 1;
  13888. }
  13889. }while((targetYear < (tmNow->tm_year+1900)) ||
  13890. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  13891. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  13892. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  13893. system(cmdBuf);
  13894. // Combine log file
  13895. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  13896. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  13897. }
  13898. else
  13899. {
  13900. system("exec /root/logPackTools 'log' 6");
  13901. }
  13902. }
  13903. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP20Data->GetLog.Response_filename);
  13904. system(cmdBuf);
  13905. checkUploadLog();
  13906. //****************location*******************/
  13907. if(strcmp(remoteLocation,"")==0)
  13908. {
  13909. DEBUG_INFO("remoteLocation is <Empty>!\n");
  13910. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13911. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13912. goto end;
  13913. }
  13914. memset(protocol, 0, ARRAY_SIZE(protocol));
  13915. memset(user, 0, ARRAY_SIZE(user) );
  13916. memset(password, 0, ARRAY_SIZE(password));
  13917. memset(host, 0, ARRAY_SIZE(host));
  13918. memset(path, 0, ARRAY_SIZE(path));
  13919. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13920. memset(host1, 0, ARRAY_SIZE(host1));
  13921. memset(path1, 0, ARRAY_SIZE(path1));
  13922. /*location: ftp://user:password@host:port/path*/
  13923. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  13924. if((access(fnamePlusPath,F_OK))!=-1)
  13925. {
  13926. DEBUG_INFO("fnamePlusPath exist.\n");
  13927. }
  13928. else
  13929. {
  13930. DEBUG_INFO("fnamePlusPath not exist!\n");
  13931. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13932. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13933. goto end;
  13934. }
  13935. if(strchr(remoteLocation,'@')==NULL)
  13936. {
  13937. sscanf(remoteLocation,
  13938. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13939. protocol, host, &port, path);
  13940. strcpy(user,"anonymous");
  13941. strcpy(password,"");
  13942. }
  13943. else
  13944. {
  13945. //DEBUG_INFO("pch=%s\n", pch);
  13946. sscanf(remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13947. protocol, user, password, host, &port, path);
  13948. }
  13949. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  13950. {
  13951. DEBUG_INFO("protocol is not ftp/http ! \n");
  13952. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13953. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13954. goto end;
  13955. }
  13956. if(strncmp(remoteLocation,"http", 4) == 0)
  13957. {
  13958. sscanf(remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13959. sprintf(ftppath,"/%s", path);
  13960. do
  13961. {
  13962. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploading]);
  13963. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13964. sleep(3);
  13965. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, remoteLocation);
  13966. if(!isSuccess)
  13967. {
  13968. DEBUG_INFO("sendLogStatusNotificationRequest fail...retries: %d\n", retriesInt);
  13969. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  13970. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13971. sleep(retryIntervalInt);
  13972. }
  13973. else
  13974. {
  13975. DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
  13976. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
  13977. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13978. }
  13979. retriesInt--;
  13980. }while((isSuccess == 0)&&(retriesInt >= 0));
  13981. }
  13982. else
  13983. {
  13984. sscanf(host,"%[^/]%s",host1, path1);
  13985. if(strlen(path) > 0)
  13986. sprintf(ftppath,"/%s", path);
  13987. else
  13988. sprintf(ftppath,"/%s", path1);
  13989. int ftppathlen=strlen(ftppath);
  13990. int i=1;
  13991. char filenametemp[50];
  13992. while(i < ftppathlen)
  13993. {
  13994. int len=ftppathlen-i;
  13995. if(ftppath[len]== 47) // '/' ascll code: 47
  13996. {
  13997. DEBUG_INFO("find '/' all right\n");
  13998. break;
  13999. }
  14000. i=i+1;
  14001. }
  14002. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14003. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  14004. filenametemp[i+1] = 0;
  14005. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14006. if(port == 0)
  14007. port = 21;
  14008. do
  14009. {
  14010. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploading]);
  14011. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  14012. sleep(3);
  14013. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  14014. if(!isSuccess)
  14015. {
  14016. DEBUG_INFO("sendLogStatusNotificationRequest fail...retries: %d\n", retriesInt);
  14017. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  14018. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  14019. sleep(retryIntervalInt);
  14020. }
  14021. else
  14022. {
  14023. DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
  14024. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
  14025. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  14026. }
  14027. retriesInt--;
  14028. }while((!isSuccess)&&(retriesInt >= 0));
  14029. }
  14030. end:
  14031. system("rm -f /mnt/*");
  14032. sleep(5);
  14033. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle;
  14034. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  14035. interLock.isGetLogGoing = OFF;
  14036. pthread_exit(NULL);
  14037. }
  14038. int handleGetLogRequest(char *uuid, char *payload)
  14039. {
  14040. mtrace();
  14041. int result = FAIL;
  14042. char fName[258];
  14043. time_t CurrentTime;
  14044. struct tm *tm;
  14045. pthread_t th_Status;
  14046. DEBUG_INFO("handleGetLogRequest...\n");
  14047. CurrentTime = time(NULL);
  14048. tm = localtime(&CurrentTime);
  14049. 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);
  14050. sprintf((char*)ShmOCPP20Data->GetLog.Response_filename, "%s", fName);
  14051. if(interLock.isGetLogGoing)
  14052. {
  14053. sprintf((char*)ShmOCPP20Data->GetLog.Response_status, "%s", LogStatusEnumTypeStr[LogStatusEnumType_AcceptedCanceled]);
  14054. isCancelUploadLog = TRUE;
  14055. pthread_cancel(th_GetLog);
  14056. interLock.isGetLogGoing = OFF;
  14057. sleep(1);
  14058. isCancelUploadLog = OFF;
  14059. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_AcceptedCanceled]);
  14060. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  14061. sleep(1);
  14062. }
  14063. else
  14064. sprintf((char*)ShmOCPP20Data->GetLog.Response_status, "%s", LogStatusEnumTypeStr[LogStatusEnumType_Accepted]);
  14065. sendGetLogConfirmation(uuid);
  14066. if(!interLock.isGetLogGoing)
  14067. {
  14068. interLock.isGetLogGoing = ON;
  14069. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  14070. sleep(1);
  14071. }
  14072. else
  14073. {
  14074. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  14075. }
  14076. return result;
  14077. }
  14078. int handleGetMonitoringReportRequest(char *uuid, char *payload)
  14079. {
  14080. mtrace();
  14081. int result = FAIL;
  14082. uint8_t cntCriteria = 0;
  14083. int cntComponentVariable = 0;
  14084. uint8_t cntFoundMonitoringVariable = 0;
  14085. json_object *GetMonitoringReport;
  14086. DEBUG_INFO("handleGetMonitoringReportRequest...\n");
  14087. GetMonitoringReport = json_tokener_parse(payload);
  14088. if(!is_error(GetMonitoringReport))
  14089. {
  14090. memset(&ShmOCPP20Data->GetMonitoringReport, 0, sizeof(struct GetMonitoringReport_20));
  14091. memcpy(&ShmOCPP20Data->GetMonitoringReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.guid));
  14092. // Required data
  14093. if(json_object_object_get(GetMonitoringReport, "requestId") != NULL)
  14094. {
  14095. ShmOCPP20Data->GetMonitoringReport.requestId = json_object_get_int(json_object_object_get(GetMonitoringReport, "requestId"));
  14096. }
  14097. // Optional data
  14098. if(json_object_object_get(GetMonitoringReport, "monitoringCriteria") != NULL)
  14099. {
  14100. cntCriteria = json_object_array_length(json_object_object_get(GetMonitoringReport, "monitoringCriteria"));
  14101. for(int idx=0; idx<cntCriteria; idx++)
  14102. {
  14103. sprintf((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idx], "%s", json_object_get_string(json_object_object_get(GetMonitoringReport, "monitoringCriteria")));
  14104. }
  14105. }
  14106. if(json_object_object_get(GetMonitoringReport, "componentVariable") != NULL)
  14107. {
  14108. cntComponentVariable = json_object_array_length(json_object_object_get(GetMonitoringReport, "componentVariable"));
  14109. if(cntComponentVariable <= ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.componentVariable))
  14110. {
  14111. for(int idx=0;idx<cntComponentVariable;idx++)
  14112. {
  14113. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component") != NULL)
  14114. {
  14115. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "name") != NULL)
  14116. {
  14117. 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")));
  14118. }
  14119. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "instance") != NULL)
  14120. {
  14121. 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")));
  14122. }
  14123. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "evse") != NULL)
  14124. {
  14125. 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)
  14126. {
  14127. 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"));
  14128. }
  14129. 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)
  14130. {
  14131. 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"));
  14132. }
  14133. }
  14134. }
  14135. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable") != NULL)
  14136. {
  14137. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "name") != NULL)
  14138. {
  14139. 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")));
  14140. }
  14141. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "instance") != NULL)
  14142. {
  14143. 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")));
  14144. }
  14145. }
  14146. }
  14147. }
  14148. }
  14149. }
  14150. json_object_put(GetMonitoringReport);
  14151. strcpy((char*)ShmOCPP20Data->GetMonitoringReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  14152. if(cntComponentVariable>0)
  14153. {
  14154. uint8_t cntTypeSupport = 0;
  14155. for(int idx_cv=0; idx_cv < cntComponentVariable; idx_cv++)
  14156. {
  14157. for(int idx=0; idx < 10; idx++)
  14158. {
  14159. if((strcmp((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].component.name, (char*)ShmOCPP20Data->GetMonitoringReport.componentVariable[idx_cv].component.name)==0) &&
  14160. (strcmp((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].variable.name, (char*)ShmOCPP20Data->GetMonitoringReport.componentVariable[idx_cv].variable.name)==0))
  14161. {
  14162. cntTypeSupport = 0;
  14163. if(strlen((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[0]) > 0)
  14164. {
  14165. for(int idx_cri=0; idx_cri<cntCriteria; idx_cri++)
  14166. {
  14167. if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idx_cri], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_ThresholdMonitoring]) == 0)
  14168. {
  14169. if(strcmp((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type, MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_ThresholdMonitoring])==0)
  14170. {
  14171. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[cntFoundMonitoringVariable].component, &ShmOCPP20Data->MonitoringComponentVariable[idx].component, sizeof(struct ComponentType));
  14172. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[cntFoundMonitoringVariable].variable, &ShmOCPP20Data->MonitoringComponentVariable[idx].variable, sizeof(struct VariableType));
  14173. ShmOCPP20Data->NotifyMonitoringReport.monitor[cntFoundMonitoringVariable].variableMonitoring[cntTypeSupport].id = ShmOCPP20Data->MonitoringComponentVariable[idx].id;
  14174. ShmOCPP20Data->NotifyMonitoringReport.monitor[cntFoundMonitoringVariable].variableMonitoring[cntTypeSupport].severity = ShmOCPP20Data->MonitoringComponentVariable[idx].severity;
  14175. ShmOCPP20Data->NotifyMonitoringReport.monitor[cntFoundMonitoringVariable].variableMonitoring[cntTypeSupport].transaction = ShmOCPP20Data->MonitoringComponentVariable[idx].transaction;
  14176. strcpy((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[cntFoundMonitoringVariable].variableMonitoring[cntTypeSupport].type,(char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type);
  14177. ShmOCPP20Data->NotifyMonitoringReport.monitor[cntFoundMonitoringVariable].variableMonitoring[cntTypeSupport].value = ShmOCPP20Data->MonitoringComponentVariable[idx].value;
  14178. cntTypeSupport++;
  14179. break;
  14180. }
  14181. }
  14182. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idx_cri], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_DeltaMonitoring]) == 0)
  14183. {
  14184. if(strcmp((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type, MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_DeltaMonitoring])==0)
  14185. {
  14186. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[cntFoundMonitoringVariable].component, &ShmOCPP20Data->MonitoringComponentVariable[idx].component, sizeof(struct ComponentType));
  14187. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[cntFoundMonitoringVariable].variable, &ShmOCPP20Data->MonitoringComponentVariable[idx].variable, sizeof(struct VariableType));
  14188. ShmOCPP20Data->NotifyMonitoringReport.monitor[cntFoundMonitoringVariable].variableMonitoring[cntTypeSupport].id = ShmOCPP20Data->MonitoringComponentVariable[idx].id;
  14189. ShmOCPP20Data->NotifyMonitoringReport.monitor[cntFoundMonitoringVariable].variableMonitoring[cntTypeSupport].severity = ShmOCPP20Data->MonitoringComponentVariable[idx].severity;
  14190. ShmOCPP20Data->NotifyMonitoringReport.monitor[cntFoundMonitoringVariable].variableMonitoring[cntTypeSupport].transaction = ShmOCPP20Data->MonitoringComponentVariable[idx].transaction;
  14191. strcpy((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[cntFoundMonitoringVariable].variableMonitoring[cntTypeSupport].type,(char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type);
  14192. ShmOCPP20Data->NotifyMonitoringReport.monitor[cntFoundMonitoringVariable].variableMonitoring[cntTypeSupport].value = ShmOCPP20Data->MonitoringComponentVariable[idx].value;
  14193. cntTypeSupport++;
  14194. break;
  14195. }
  14196. }
  14197. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idx_cri], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_PeriodicMonitoring]) == 0)
  14198. {
  14199. if(strcmp((char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type, MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_PeriodicMonitoring])==0)
  14200. {
  14201. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[cntFoundMonitoringVariable].component, &ShmOCPP20Data->MonitoringComponentVariable[idx].component, sizeof(struct ComponentType));
  14202. memcpy(&ShmOCPP20Data->NotifyMonitoringReport.monitor[cntFoundMonitoringVariable].variable, &ShmOCPP20Data->MonitoringComponentVariable[idx].variable, sizeof(struct VariableType));
  14203. ShmOCPP20Data->NotifyMonitoringReport.monitor[cntFoundMonitoringVariable].variableMonitoring[cntTypeSupport].id = ShmOCPP20Data->MonitoringComponentVariable[idx].id;
  14204. ShmOCPP20Data->NotifyMonitoringReport.monitor[cntFoundMonitoringVariable].variableMonitoring[cntTypeSupport].severity = ShmOCPP20Data->MonitoringComponentVariable[idx].severity;
  14205. ShmOCPP20Data->NotifyMonitoringReport.monitor[cntFoundMonitoringVariable].variableMonitoring[cntTypeSupport].transaction = ShmOCPP20Data->MonitoringComponentVariable[idx].transaction;
  14206. strcpy((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[cntFoundMonitoringVariable].variableMonitoring[cntTypeSupport].type,(char*)ShmOCPP20Data->MonitoringComponentVariable[idx].type);
  14207. ShmOCPP20Data->NotifyMonitoringReport.monitor[cntFoundMonitoringVariable].variableMonitoring[cntTypeSupport].value = ShmOCPP20Data->MonitoringComponentVariable[idx].value;
  14208. cntTypeSupport++;
  14209. break;
  14210. }
  14211. }
  14212. }
  14213. }
  14214. cntFoundMonitoringVariable++;
  14215. }
  14216. }
  14217. }
  14218. }
  14219. /*
  14220. * TODO:
  14221. * 1. Response result
  14222. */
  14223. strcpy((char*)ShmOCPP20Data->GetMonitoringReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  14224. sendGetMonitoringReportConfirmation(uuid);
  14225. return result;
  14226. }
  14227. int handleGetReportRequest(char *uuid, char *payload)
  14228. {
  14229. mtrace();
  14230. int result = FAIL;
  14231. json_object *GetReport;
  14232. DEBUG_INFO("handleGetReportRequest...\n");
  14233. GetReport = json_tokener_parse(payload);
  14234. if(!is_error(GetReport))
  14235. {
  14236. memset(&ShmOCPP20Data->GetReport, 0, sizeof(struct GetReport_20));
  14237. memcpy(&ShmOCPP20Data->GetReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetReport.guid));
  14238. // Required data
  14239. if(json_object_object_get(GetReport, "requestId") != NULL)
  14240. {
  14241. ShmOCPP20Data->GetReport.requestId = json_object_get_int(json_object_object_get(GetReport, "requestId"));
  14242. }
  14243. // Optional data
  14244. if(json_object_object_get(GetReport, "componentCriteria") != NULL)
  14245. {
  14246. sprintf((char*)ShmOCPP20Data->GetReport.componentCriteria, "%s", json_object_get_string(json_object_object_get(GetReport, "componentCriteria")));
  14247. }
  14248. if(json_object_object_get(GetReport, "componentVariable") != NULL)
  14249. {
  14250. if(json_object_array_length(json_object_object_get(GetReport, "componentVariable")) <= ARRAY_SIZE(ShmOCPP20Data->GetReport.componentVariable))
  14251. {
  14252. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetReport, "componentVariable"));idx++)
  14253. {
  14254. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component") != NULL)
  14255. {
  14256. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "name") != NULL)
  14257. {
  14258. 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")));
  14259. }
  14260. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "instance") != NULL)
  14261. {
  14262. 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")));
  14263. }
  14264. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "evse") != NULL)
  14265. {
  14266. 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)
  14267. {
  14268. 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"));
  14269. }
  14270. 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)
  14271. {
  14272. 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"));
  14273. }
  14274. }
  14275. }
  14276. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable") != NULL)
  14277. {
  14278. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "name") != NULL)
  14279. {
  14280. 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")));
  14281. }
  14282. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "instance") != NULL)
  14283. {
  14284. 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")));
  14285. }
  14286. }
  14287. }
  14288. }
  14289. }
  14290. }
  14291. json_object_put(GetReport);
  14292. /*
  14293. * TODO:
  14294. * 1. Response result
  14295. */
  14296. strcpy((char*)ShmOCPP20Data->GetReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  14297. sendGetReportConfirmation(uuid);
  14298. return result;
  14299. }
  14300. int handleGetTransactionStatusRequest(char *uuid, char *payload)
  14301. {
  14302. mtrace();
  14303. int result = FAIL;
  14304. uint8_t tempIndex;
  14305. json_object *GetTransactionStatus;
  14306. DEBUG_INFO("handleGetTransactionStatusRequest...\n");
  14307. GetTransactionStatus = json_tokener_parse(payload);
  14308. if(!is_error(GetTransactionStatus))
  14309. {
  14310. memset(&ShmOCPP20Data->GetTransactionStatus, 0, sizeof(struct GetTransactionStatus_20));
  14311. memcpy(&ShmOCPP20Data->GetTransactionStatus.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetTransactionStatus.guid));
  14312. ShmOCPP20Data->GetTransactionStatus.Response_messagesInQueue = FALSE;
  14313. ShmOCPP20Data->GetTransactionStatus.Response_ongoingIndicator = FALSE;
  14314. if(json_object_object_get(GetTransactionStatus, "transactionId") != NULL)
  14315. {
  14316. sprintf((char*)ShmOCPP20Data->GetTransactionStatus.transactionId, "%s", json_object_get_string(json_object_object_get(GetTransactionStatus, "transactionId")));
  14317. }
  14318. if(strlen((char*)ShmOCPP20Data->GetTransactionStatus.transactionId)>0)
  14319. {
  14320. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  14321. {
  14322. if(strcmp((char*)ShmOCPP20Data->GetTransactionStatus.transactionId, (char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId)==0)
  14323. {
  14324. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14325. {
  14326. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14327. tempIndex = ((gun_index==2) ? 1: 0);
  14328. else
  14329. tempIndex = gun_index;
  14330. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14331. {
  14332. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) &&
  14333. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)))
  14334. ShmOCPP20Data->GetTransactionStatus.Response_ongoingIndicator = TRUE;
  14335. }
  14336. }
  14337. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14338. {
  14339. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14340. tempIndex = ((gun_index==2) ? 1: 0);
  14341. else
  14342. tempIndex = gun_index;
  14343. for (int index = 0; index < CCS_QUANTITY; index++)
  14344. {
  14345. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) &&
  14346. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)))
  14347. ShmOCPP20Data->GetTransactionStatus.Response_ongoingIndicator = TRUE;
  14348. }
  14349. }
  14350. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14351. {
  14352. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14353. tempIndex = ((gun_index==2) ? 1: 0);
  14354. else
  14355. tempIndex = gun_index;
  14356. for (int index = 0; index < GB_QUANTITY; index++)
  14357. {
  14358. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) &&
  14359. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)))
  14360. ShmOCPP20Data->GetTransactionStatus.Response_ongoingIndicator = TRUE;
  14361. }
  14362. }
  14363. else if(gunType[gun_index] == GUN_TYPE_DO)
  14364. {
  14365. tempIndex = gun_index;
  14366. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14367. {
  14368. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) &&
  14369. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)))
  14370. ShmOCPP20Data->GetTransactionStatus.Response_ongoingIndicator = TRUE;
  14371. }
  14372. }
  14373. else
  14374. {
  14375. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14376. tempIndex = 2;
  14377. else
  14378. tempIndex = gun_index;
  14379. for (int index = 0; index < AC_QUANTITY; index++)
  14380. {
  14381. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) &&
  14382. ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)))
  14383. ShmOCPP20Data->GetTransactionStatus.Response_ongoingIndicator = TRUE;
  14384. }
  14385. }
  14386. }
  14387. }
  14388. }
  14389. char rmFileCmd[100]={0};
  14390. int TransactionQueueNum = 0;
  14391. struct stat stats;
  14392. stat("/Storage/OCPP", &stats);
  14393. // Check for directory existence
  14394. if (S_ISDIR(stats.st_mode) == 1)
  14395. {
  14396. //DEBUG_INFO("\n OCPP directory exist \n");
  14397. }
  14398. else
  14399. {
  14400. //DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  14401. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  14402. system(rmFileCmd);
  14403. }
  14404. memset(rmFileCmd, 0, ARRAY_SIZE(rmFileCmd));
  14405. if((access("/Storage/OCPP/TransactionRelatedQueue20",F_OK))!=-1)
  14406. {
  14407. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  14408. }
  14409. else
  14410. {
  14411. FILE *fp = fopen("/Storage/OCPP/TransactionRelatedQueue20", "r");
  14412. char line[QUEUE_MESSAGE_LENGTH]={0};
  14413. if (fp == NULL) {
  14414. DEBUG_INFO("cannot open file TransactionRelatedQueue!");
  14415. }
  14416. TransactionQueueNum = 0; // the number of packets in queue
  14417. while(fgets(line, sizeof line, fp) != NULL) {
  14418. if(strlen((char*)ShmOCPP20Data->GetTransactionStatus.transactionId)>0)
  14419. {
  14420. if(strstr(line, (char*)ShmOCPP20Data->GetTransactionStatus.transactionId) != NULL)
  14421. ShmOCPP20Data->GetTransactionStatus.Response_messagesInQueue = TRUE;
  14422. }
  14423. TransactionQueueNum += 1; //the number of packets in queue
  14424. }
  14425. fclose(fp);
  14426. }
  14427. if((strlen((char*)ShmOCPP20Data->GetTransactionStatus.transactionId) == 0) && (TransactionQueueNum>0))
  14428. ShmOCPP20Data->GetTransactionStatus.Response_messagesInQueue = TRUE;
  14429. }
  14430. json_object_put(GetTransactionStatus);
  14431. sendGetTransactionStatusConfirmation(uuid);
  14432. return result;
  14433. }
  14434. int handleGetVariablesRequest(char *uuid, char *payload)
  14435. {
  14436. mtrace();
  14437. int result = FAIL;
  14438. int isUnknownComponent = TRUE;
  14439. json_object *GetVariables;
  14440. DEBUG_INFO("handleGetVariablesRequest...\n");
  14441. GetVariables = json_tokener_parse(payload);
  14442. if(!is_error(GetVariables))
  14443. {
  14444. memset(&ShmOCPP20Data->GetVariables, 0, sizeof(struct SetVariables_20));
  14445. memcpy(&ShmOCPP20Data->GetVariables.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetVariables.guid));
  14446. // Required data
  14447. if(json_object_array_length(json_object_object_get(GetVariables, "getVariableData")) <= ARRAY_SIZE(ShmOCPP20Data->GetVariables.getVariableData))
  14448. {
  14449. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetVariables, "getVariableData"));idx++)
  14450. {
  14451. if(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx) != NULL)
  14452. {
  14453. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "attributeType") != NULL)
  14454. {
  14455. 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")));
  14456. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, (char*)ShmOCPP20Data->GetVariables.getVariableData[idx].attributeType);
  14457. }
  14458. /*if(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType != NULL)
  14459. {
  14460. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, "Actual");
  14461. }*/
  14462. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component") != NULL)
  14463. {
  14464. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "name") != NULL)
  14465. {
  14466. 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")));
  14467. }
  14468. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "instance") != NULL)
  14469. {
  14470. 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")));
  14471. }
  14472. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "evse") != NULL)
  14473. {
  14474. 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)
  14475. {
  14476. 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"));
  14477. }
  14478. 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)
  14479. {
  14480. 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"));
  14481. }
  14482. }
  14483. memcpy(&ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component, &ShmOCPP20Data->GetVariables.getVariableData[idx].component, sizeof(struct ComponentType));
  14484. }
  14485. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable") != NULL)
  14486. {
  14487. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "name") != NULL)
  14488. {
  14489. 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")));
  14490. }
  14491. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "instance") != NULL)
  14492. {
  14493. 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")));
  14494. }
  14495. memcpy(&ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable , &ShmOCPP20Data->GetVariables.getVariableData[idx].variable, sizeof(struct VariableType));
  14496. }
  14497. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  14498. {
  14499. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name) == 0) &&
  14500. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.instance, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.instance) == 0) &&
  14501. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name) == 0) &&
  14502. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.instance, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.instance) == 0))
  14503. {
  14504. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_Accepted]);
  14505. isUnknownComponent = FALSE;
  14506. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].attributeType, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].type) != 0) &&
  14507. (json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "attributeType") != NULL))
  14508. {
  14509. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_NotSupportedAttributeType]);
  14510. break;
  14511. }
  14512. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, "ChargingStation") == 0) &&
  14513. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, "SystemUptimeSec") == 0))
  14514. {
  14515. struct sysinfo s_info;
  14516. int error = sysinfo(&s_info);
  14517. if(error != 0)
  14518. {
  14519. DEBUG_WARN("System uptime get error: %d\n", error);
  14520. }
  14521. else
  14522. {
  14523. sprintf((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, "%ld", s_info.uptime);
  14524. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value, "%ld", s_info.uptime);
  14525. }
  14526. }
  14527. else if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, "ChargingStation") == 0) &&
  14528. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, "FreeVend") == 0))
  14529. {
  14530. sprintf((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"true":"false"));
  14531. }
  14532. else
  14533. {
  14534. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value);
  14535. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].type);
  14536. }
  14537. break;
  14538. }
  14539. else
  14540. {
  14541. if(strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name) != 0)
  14542. {
  14543. isUnknownComponent = FALSE;
  14544. }
  14545. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_UnknownVariable]);
  14546. memset(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, 0x00, ARRAY_SIZE(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue));
  14547. }
  14548. }
  14549. if(isUnknownComponent == TRUE)
  14550. {
  14551. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_UnknownComponent]);
  14552. }
  14553. }
  14554. }
  14555. }
  14556. sendGetVariablesConfirmation(uuid, json_object_array_length(json_object_object_get(GetVariables, "getVariableData")));
  14557. }
  14558. json_object_put(GetVariables);
  14559. return result;
  14560. }
  14561. int handleInstallCertificateRequest(char *uuid, char *payload)
  14562. {
  14563. mtrace();
  14564. int result = PASS;
  14565. char tempCert[] = "/Storage/OCPP/tempInstallCertificate.pem";
  14566. json_object *InstallCertificate;
  14567. sprintf((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted");
  14568. DEBUG_INFO("handleInstallCertificateRequest...\n");
  14569. InstallCertificate = json_tokener_parse(payload);
  14570. if(!is_error(InstallCertificate))
  14571. {
  14572. memset(&ShmOCPP20Data->InstallCertificate, 0, sizeof(struct InstallCertificate_20));
  14573. memcpy(&ShmOCPP20Data->InstallCertificate.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->InstallCertificate.guid));
  14574. // Required data
  14575. if(json_object_object_get(InstallCertificate, "certificateType") != NULL)
  14576. {
  14577. sprintf((char*)ShmOCPP20Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  14578. }
  14579. if(json_object_object_get(InstallCertificate, "certificate") != NULL)
  14580. {
  14581. sprintf((char*)ShmOCPP20Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  14582. }
  14583. DEBUG_INFO("certificateType: %s\n", (char*)ShmOCPP20Data->InstallCertificate.certificateType);
  14584. DEBUG_INFO("certificate: %s\n", (char*)ShmOCPP20Data->InstallCertificate.certificate);
  14585. char temp[1024];
  14586. FILE *fp = fopen(tempCert, "w");
  14587. fprintf(fp, "%s", ShmOCPP20Data->InstallCertificate.certificate);
  14588. fclose(fp);
  14589. // Check the expired date (exp: notAfter=Oct 2 18:10:27 2048 GMT)
  14590. char strExpDate[30];
  14591. sprintf(temp ,"openssl x509 -noout -enddate -in /Storage/OCPP/tempInstallCertificate.pem");
  14592. fp = popen(temp, "r");
  14593. if(fp)
  14594. {
  14595. while(fgets(temp, sizeof(temp), fp) != NULL)
  14596. {
  14597. if(strstr(temp, "notAfter=") != NULL)
  14598. {
  14599. DEBUG_INFO("Certificate enddate info: %s\n", temp);
  14600. sscanf(temp, "%*[^=]=%[^G]G", strExpDate);
  14601. break;
  14602. }
  14603. }
  14604. }
  14605. DEBUG_INFO("ExpDate: %s\n", strExpDate);
  14606. struct tm tmExpDate;
  14607. struct timeb tbExpDate;
  14608. strptime(strExpDate, "%b %d %H:%M:%S %Y", &tmExpDate);
  14609. tbExpDate.time = mktime(&tmExpDate);
  14610. if(DiffTimebWithNowSec(tbExpDate) >= 0)
  14611. {
  14612. DEBUG_INFO("The enddate is already expired...\n");
  14613. sprintf((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Rejected");
  14614. goto End;
  14615. }
  14616. // Verify certificate with rootCA
  14617. sprintf(temp ,"openssl verify -CAfile /root/cacert.pem /Storage/OCPP/tempInstallCertificate.pem");
  14618. fp = popen(temp, "r");
  14619. if(fp)
  14620. {
  14621. while(fgets(temp, sizeof(temp), fp) != NULL)
  14622. {
  14623. if((strstr(temp, "tempInstallCertificate.pem: OK") != NULL) || (strstr(temp, "self signed certificate") != NULL))
  14624. {
  14625. sprintf((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted");
  14626. break;
  14627. }
  14628. else
  14629. {
  14630. sprintf((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Rejected");
  14631. }
  14632. }
  14633. }
  14634. if(strcmp((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted") != 0)
  14635. {
  14636. //=====================================================
  14637. // Verify if the certificate is valid or not. (OCSP?)
  14638. //=====================================================
  14639. /*
  14640. DEBUG_INFO("openssl CA verifying...FAIL --> Start OCSP process...\n");
  14641. // Get ocsp url
  14642. char ocspUrl[512];
  14643. sprintf(temp ,"openssl x509 -noout -ocsp_uri -in %s", tempCert);
  14644. fp = popen(temp, "r");
  14645. if(fp)
  14646. {
  14647. while(fgets(temp, sizeof(temp), fp) != NULL)
  14648. {
  14649. if(strstr(temp, "://") != NULL)
  14650. {
  14651. strcpy(ocspUrl, temp);
  14652. break;
  14653. }
  14654. }
  14655. }
  14656. // Get certificate chain for issuer
  14657. * openssl s_client -connect [serverURL:port] -showcerts | sed -n '/-----BEGIN/,/-------END/p' > tempChain.pem
  14658. *
  14659. // Execute OCSP
  14660. sprintf(temp ,"openssl ocsp -issuer tempChain.pem -cert /Storage/OCPP/tempInstallCertificate.pem -text -url %s", ocspUrl);
  14661. fp = popen(temp, "r");
  14662. if(fp)
  14663. {
  14664. while(fgets(temp, sizeof(temp), fp) != NULL)
  14665. {
  14666. if(strstr(temp, "tempInstallCertificate.pem: good") != NULL)
  14667. {
  14668. sprintf((char*)ShmOCPP16Data->InstallCertificate.Response_status, "Accepted");
  14669. break;
  14670. }
  14671. }
  14672. }
  14673. system("rm -f /Storage/OCPP/tempChain.pem");
  14674. pclose(fp);
  14675. */
  14676. sprintf((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted");
  14677. if(strcmp((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted") != 0)
  14678. {
  14679. DEBUG_INFO("OCSP verifying...FAIL.\n");
  14680. goto End;
  14681. }
  14682. else
  14683. DEBUG_INFO("OCSP verifying...PASS.\n");
  14684. }
  14685. else
  14686. DEBUG_INFO("openssl CA verifying...PASS.\n");
  14687. }
  14688. json_object_put(InstallCertificate);
  14689. End:
  14690. if(strcmp((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted") == 0)
  14691. {
  14692. if(strcmp((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_CSMSRootCertificate]) == 0)
  14693. {
  14694. if(access(ROOTCA_CS,F_OK) != -1)
  14695. {
  14696. DEBUG_INFO("Existed CSMSRootCertificate is found. Replacing...\n");
  14697. rename(ROOTCA_CS, "/Storage/OCPP/CentralSystemRootCertificate_fallback.pem");
  14698. rename(tempCert, ROOTCA_CS);
  14699. }
  14700. else
  14701. {
  14702. DEBUG_INFO("No existed CSMSRootCertificate Creating...\n");
  14703. rename(tempCert, ROOTCA_CS);
  14704. }
  14705. }
  14706. else if(strcmp((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_MORootCertificate]) == 0)
  14707. {
  14708. if(access(ROOTCA_MF,F_OK) != -1)
  14709. {
  14710. DEBUG_INFO("Existed ManufacturerRootCertificate is found. Replacing...\n");
  14711. rename(ROOTCA_MF, "/Storage/OCPP/ManufacturerRootCertificate_fallback.pem");
  14712. rename(tempCert, ROOTCA_MF);
  14713. }
  14714. else
  14715. {
  14716. DEBUG_INFO("No existed ManufacturerRootCertificate. Creating...\n");
  14717. rename(tempCert, ROOTCA_MF);
  14718. }
  14719. }
  14720. else if(strcmp((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_V2GRootCertificate]) == 0)
  14721. {
  14722. if(access(ROOTCA_V2G,F_OK) != -1)
  14723. {
  14724. DEBUG_INFO("Existed ManufacturerRootCertificate is found. Replacing...\n");
  14725. rename(ROOTCA_V2G, "/Storage/OCPP/ManufacturerRootCertificate_fallback.pem");
  14726. rename(tempCert, ROOTCA_V2G);
  14727. }
  14728. else
  14729. {
  14730. DEBUG_INFO("No existed ManufacturerRootCertificate. Creating...\n");
  14731. rename(tempCert, ROOTCA_V2G);
  14732. }
  14733. }
  14734. ShmOCPP20Data->MsMsg.bits.InstallCertificateReq = 1;
  14735. }
  14736. sendInstallCertificateConfirmation(uuid);
  14737. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14738. if(strcmp((char*)ShmOCPP20Data->InstallCertificate.Response_status, "Accepted") != 0)
  14739. {
  14740. sprintf((char*)ShmOCPP20Data->SecurityEventNotification.type, "InvalidCentralSystemCertificate");
  14741. memset(ShmOCPP20Data->SecurityEventNotification.techInfo, 0x00, ARRAY_SIZE(ShmOCPP20Data->SecurityEventNotification.techInfo));
  14742. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = 1;
  14743. }
  14744. return result;
  14745. }
  14746. int handlePublishFirmwareRequest(char *uuid, char *payload)
  14747. {
  14748. mtrace();
  14749. int result = FAIL;
  14750. json_object *PublishFirmware;
  14751. DEBUG_INFO("handlePublishFirmwareRequest...\n");
  14752. PublishFirmware = json_tokener_parse(payload);
  14753. if(!is_error(PublishFirmware))
  14754. {
  14755. memset(&ShmOCPP20Data->PublishFirmware, 0, sizeof(struct PublishFirmware_20));
  14756. memcpy(&ShmOCPP20Data->PublishFirmware.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->PublishFirmware.guid));
  14757. // Required data
  14758. if(json_object_object_get(PublishFirmware, "requestId") != NULL)
  14759. {
  14760. ShmOCPP20Data->PublishFirmware.requestId = json_object_get_int(json_object_object_get(PublishFirmware, "requestId"));
  14761. }
  14762. if(json_object_object_get(PublishFirmware, "checksum") != NULL)
  14763. {
  14764. sprintf((char*)ShmOCPP20Data->PublishFirmware.checksum, "%s", json_object_get_string(json_object_object_get(PublishFirmware, "checksum")));
  14765. }
  14766. // Optional data
  14767. if(json_object_object_get(PublishFirmware, "location") != NULL)
  14768. {
  14769. sprintf((char*)ShmOCPP20Data->PublishFirmware.location, "%s", json_object_get_string(json_object_object_get(PublishFirmware, "location")));
  14770. }
  14771. if(json_object_object_get(PublishFirmware, "retries") != NULL)
  14772. {
  14773. ShmOCPP20Data->PublishFirmware.retries = json_object_get_int(json_object_object_get(PublishFirmware, "retries"));
  14774. }
  14775. if(json_object_object_get(PublishFirmware, "retryInterval") != NULL)
  14776. {
  14777. ShmOCPP20Data->PublishFirmware.retryInterval = json_object_get_int(json_object_object_get(PublishFirmware, "retryInterval"));
  14778. }
  14779. }
  14780. json_object_put(PublishFirmware);
  14781. /*
  14782. * TODO:
  14783. * 1. Publish firmware preocess and response
  14784. */
  14785. strcpy((char*)ShmOCPP20Data->PublishFirmware.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  14786. sendPublishFirmwareConfirmation(uuid);
  14787. return result;
  14788. }
  14789. int handleRequestStartTransactionRequest(char *uuid, char *payload)
  14790. {
  14791. mtrace();
  14792. int result = FAIL;
  14793. int8_t evseId = -1;
  14794. uint8_t tempIndex;
  14795. uint8_t isOverConnectorMax = FALSE;
  14796. uint8_t isPeriodOverMax = FALSE;
  14797. uint8_t isTxProfile = TRUE;
  14798. uint8_t isAllowStart = TRUE;
  14799. uint8_t filename[128]={0};
  14800. char cmdBuf[128];
  14801. FILE *filePtr;
  14802. json_object *RemoteStartTransaction;
  14803. DEBUG_INFO("handleRequestStartTransactionRequest...\n");
  14804. RemoteStartTransaction = json_tokener_parse(payload);
  14805. if(!is_error(RemoteStartTransaction))
  14806. {
  14807. if(json_object_object_get(RemoteStartTransaction, "evseId") != NULL)
  14808. {
  14809. if((0 < json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"))) && (json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"))<=gunTotalNumber))
  14810. {
  14811. evseId = json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"));
  14812. }
  14813. else
  14814. {
  14815. isOverConnectorMax = TRUE;
  14816. DEBUG_WARN("Evse id shall not equal 0 and should be less than gunTotalNumber.\n");
  14817. }
  14818. }
  14819. else
  14820. {
  14821. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  14822. {
  14823. if(!cpinitateMsg.bits[idx].isOnCharging && (strstr((char*)ShmOCPP20Data->StatusNotification[idx].connectorStatus, ConnectorStatusEnumTypeStr[ConnectorStatusEnumType_Occupied]) != NULL))
  14824. {
  14825. evseId = (idx+1);
  14826. DEBUG_INFO("Remote start without evseId but detect connector of evse-%02d connected ready to start.\n", evseId);
  14827. break;
  14828. }
  14829. }
  14830. }
  14831. if(isOverConnectorMax == FALSE)
  14832. {
  14833. if(evseId > 0)
  14834. {
  14835. DEBUG_INFO("Requested evseId id: %d\n", evseId);
  14836. memset(&ShmOCPP20Data->RequestStartTransaction[evseId-1], 0, sizeof(struct RequestStartTransaction_20));
  14837. memcpy(&ShmOCPP20Data->RequestStartTransaction[evseId-1].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->RequestStartTransaction[evseId-1].guid));
  14838. // Required data
  14839. if(json_object_object_get(RemoteStartTransaction, "remoteStartId") != NULL)
  14840. {
  14841. ShmOCPP20Data->RequestStartTransaction[evseId-1].remoteStartId = json_object_get_int(json_object_object_get(RemoteStartTransaction, "remoteStartId"));
  14842. }
  14843. if(json_object_object_get(RemoteStartTransaction, "idToken") != NULL)
  14844. {
  14845. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken") != NULL)
  14846. {
  14847. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken")));
  14848. }
  14849. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type") != NULL)
  14850. {
  14851. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type")));
  14852. }
  14853. }
  14854. // Optional data
  14855. if(json_object_object_get(RemoteStartTransaction, "groupIdToken") != NULL)
  14856. {
  14857. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken") != NULL)
  14858. {
  14859. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken")));
  14860. }
  14861. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type") != NULL)
  14862. {
  14863. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type")));
  14864. }
  14865. }
  14866. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  14867. {
  14868. // Check periods is over max configuration
  14869. 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))
  14870. {
  14871. isPeriodOverMax = TRUE;
  14872. }
  14873. // Check profile purpose is TxProfile
  14874. if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  14875. {
  14876. ShmOCPP20Data->RequestStartTransaction[evseId-1].chargingProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "id"));
  14877. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", evseId);
  14878. }
  14879. else
  14880. {
  14881. isTxProfile = FALSE;
  14882. }
  14883. }
  14884. //check Transaction active
  14885. if(gunType[evseId-1] == GUN_TYPE_CHAdeMO)
  14886. {
  14887. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14888. {
  14889. tempIndex = ((evseId-1) == 2) ? 1: 0;
  14890. }
  14891. else
  14892. {
  14893. tempIndex = (evseId-1);
  14894. }
  14895. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14896. {
  14897. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  14898. {
  14899. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken) == 0))
  14900. {
  14901. //Reserved
  14902. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  14903. }
  14904. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken) != 0))
  14905. {
  14906. //Reserved
  14907. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  14908. isAllowStart = FALSE;
  14909. }
  14910. else
  14911. {
  14912. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  14913. {
  14914. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  14915. isAllowStart = FALSE;
  14916. }
  14917. }//END FOR ELSE
  14918. }
  14919. }// END FOR CHAdeMO_QUANTITY
  14920. }
  14921. else if(gunType[evseId-1] == GUN_TYPE_CCS)
  14922. {
  14923. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14924. {
  14925. tempIndex = ((evseId-1) == 2) ? 1: 0;
  14926. }
  14927. else
  14928. {
  14929. tempIndex = (evseId-1);
  14930. }
  14931. for (int index = 0; index < CCS_QUANTITY; index++)
  14932. {
  14933. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14934. {
  14935. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken) == 0))
  14936. {
  14937. //Reserved
  14938. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  14939. }
  14940. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken) != 0))
  14941. {
  14942. //Reserved
  14943. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  14944. isAllowStart = FALSE;
  14945. }
  14946. else
  14947. {
  14948. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  14949. {
  14950. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  14951. isAllowStart = FALSE;
  14952. }
  14953. }// END FOR ELSE
  14954. }
  14955. }// END FOR CCS_QUANTITY
  14956. }
  14957. else if(gunType[evseId-1] == GUN_TYPE_GBT)
  14958. {
  14959. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14960. {
  14961. tempIndex = ((evseId-1) == 2) ? 1: 0;
  14962. }
  14963. else
  14964. {
  14965. tempIndex = (evseId-1);
  14966. }
  14967. for (int index = 0; index < GB_QUANTITY; index++)
  14968. {
  14969. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  14970. {
  14971. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken) == 0))
  14972. {
  14973. //Reserved
  14974. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  14975. }
  14976. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken) != 0))
  14977. {
  14978. //Reserved
  14979. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  14980. isAllowStart = FALSE;
  14981. }
  14982. else
  14983. {
  14984. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  14985. {
  14986. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  14987. isAllowStart = FALSE;
  14988. }
  14989. }// END FOR ELSE
  14990. }
  14991. } // END FOR GB_QUANTITY
  14992. }
  14993. else if(gunType[evseId-1] == GUN_TYPE_DO)
  14994. {
  14995. tempIndex = (evseId-1);
  14996. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14997. {
  14998. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  14999. {
  15000. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken) == 0))
  15001. {
  15002. //Reserved
  15003. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  15004. }
  15005. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken) != 0))
  15006. {
  15007. //Reserved
  15008. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  15009. isAllowStart = FALSE;
  15010. }
  15011. else
  15012. {
  15013. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) || ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  15014. {
  15015. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  15016. isAllowStart = FALSE;
  15017. }
  15018. }// END FOR ELSE
  15019. }
  15020. } // END FOR GB_QUANTITY
  15021. }
  15022. else
  15023. {
  15024. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15025. {
  15026. tempIndex = 2;
  15027. }
  15028. else
  15029. {
  15030. tempIndex = (evseId-1);
  15031. }
  15032. for (int index = 0; index < AC_QUANTITY; index++)
  15033. {
  15034. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  15035. {
  15036. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken) == 0))
  15037. {
  15038. //Reserved
  15039. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  15040. }
  15041. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].idToken.idToken) != 0))
  15042. {
  15043. //Reserved
  15044. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  15045. isAllowStart = FALSE;
  15046. }
  15047. else
  15048. {
  15049. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) || ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  15050. {
  15051. DEBUG_WARN("AC connector not allow start cause busy.\n");
  15052. isAllowStart = FALSE;
  15053. }
  15054. }//END FOR ELSE
  15055. }
  15056. }// END FOR AC_QUANTITY
  15057. }
  15058. }
  15059. else
  15060. {
  15061. DEBUG_INFO("Connector id does not specific.\n");
  15062. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  15063. {
  15064. memset(&ShmOCPP20Data->RequestStartTransaction[gun_index], 0, sizeof(struct RequestStartTransaction_20));
  15065. memcpy(&ShmOCPP20Data->RequestStartTransaction[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->RequestStartTransaction[gun_index].guid));
  15066. // Required data
  15067. if(json_object_object_get(RemoteStartTransaction, "remoteStartId") != NULL)
  15068. {
  15069. ShmOCPP20Data->RequestStartTransaction[gun_index].remoteStartId = json_object_get_int(json_object_object_get(RemoteStartTransaction, "remoteStartId"));
  15070. }
  15071. if(json_object_object_get(RemoteStartTransaction, "idToken") != NULL)
  15072. {
  15073. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken") != NULL)
  15074. {
  15075. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken")));
  15076. }
  15077. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type") != NULL)
  15078. {
  15079. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type")));
  15080. }
  15081. }
  15082. // Optional data
  15083. if(json_object_object_get(RemoteStartTransaction, "groupIdToken") != NULL)
  15084. {
  15085. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken") != NULL)
  15086. {
  15087. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken")));
  15088. }
  15089. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type") != NULL)
  15090. {
  15091. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type")));
  15092. }
  15093. }
  15094. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  15095. {
  15096. // Check periods is over max configuration
  15097. 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))
  15098. {
  15099. isPeriodOverMax = TRUE;
  15100. }
  15101. // Check profile purpose is TxProfile
  15102. if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  15103. {
  15104. ShmOCPP20Data->RequestStartTransaction[gun_index].chargingProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "id"));
  15105. sprintf((char*)filename, "/Storage/OCPP/TxProfile_Tmp_OCPP20.json");
  15106. }
  15107. else
  15108. {
  15109. isTxProfile = FALSE;
  15110. }
  15111. }
  15112. }
  15113. }
  15114. }
  15115. // Profile replace or add info
  15116. if((isOverConnectorMax == FALSE) && !isPeriodOverMax && isTxProfile && isAllowStart)
  15117. {
  15118. if(evseId != -1)
  15119. {
  15120. if(strlen((char*)filename) > 0)
  15121. {
  15122. // Save profile to file
  15123. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d_OCPP20.json", evseId);
  15124. system(cmdBuf);
  15125. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json.json", evseId);
  15126. filePtr = fopen((char*)filename, "w");
  15127. fprintf(filePtr, "{\"evseId\":%d,\"chargingProfile\":%s}\n", evseId, json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  15128. fclose(filePtr);
  15129. }
  15130. ShmOCPP20Data->CsMsg.bits[evseId-1].RequestStartTransactionReq = ON;
  15131. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  15132. random_uuid((char*)ShmOCPP20Data->RequestStartTransaction[evseId-1].Response_transactionId);
  15133. result = PASS;
  15134. }
  15135. else
  15136. {
  15137. uint8_t isHasIdleConnector = FALSE;
  15138. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  15139. {
  15140. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  15141. {
  15142. isHasIdleConnector = TRUE;
  15143. break;
  15144. }
  15145. }
  15146. if((isHasIdleConnector == TRUE) && !ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  15147. {
  15148. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value);
  15149. if(strlen((char*)filename) > 0)
  15150. {
  15151. // Save profile to file
  15152. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp_OCPP20.json");
  15153. system(cmdBuf);
  15154. sprintf((char*)filename, "/Storage/OCPP/TxProfile_Tmp_OCPP20.json.json");
  15155. filePtr = fopen((char*)filename, "w");
  15156. fprintf(filePtr, "{\"evseId\":0,\"chargingProfile\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  15157. fclose(filePtr);
  15158. }
  15159. refreshStartTimer(&clientTime.RemoteStartWait);
  15160. ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = ON;
  15161. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  15162. {
  15163. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  15164. random_uuid((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId);
  15165. }
  15166. result = PASS;
  15167. }
  15168. else
  15169. {
  15170. DEBUG_INFO("There is not any connector is idle.\n");
  15171. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  15172. strcpy((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  15173. }
  15174. }
  15175. }
  15176. else
  15177. {
  15178. if(isOverConnectorMax != FALSE)
  15179. DEBUG_WARN("evseId id equal 0 or over maximun id.\n");
  15180. if(isPeriodOverMax)
  15181. DEBUG_WARN("Profile periods quantity is over spec.\n");
  15182. if(!isTxProfile)
  15183. DEBUG_WARN("Profile purpose is not TxProfile.\n");
  15184. if(!isAllowStart)
  15185. DEBUG_WARN("Target connector does not allow start.\n");
  15186. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[((evseId-1)<0?0:(evseId-1))].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected] );
  15187. }
  15188. }
  15189. json_object_put(RemoteStartTransaction);
  15190. sendRemoteStartTransactionConfirmation(uuid, ((evseId-1)<0?0:(evseId-1)));
  15191. return result;
  15192. }
  15193. int handleRequestStopTransactionRequest(char *uuid, char *payload)
  15194. {
  15195. mtrace();
  15196. int result = FAIL;
  15197. int match = FALSE;
  15198. int GunNO = 0;
  15199. int tempIndex = 0;
  15200. char transactionIdStr[37];
  15201. int transactionIdIsNULL= TRUE;
  15202. json_object *RemoteStopTransaction;
  15203. DEBUG_INFO("handleRequestStopTransactionRequest...\n");
  15204. if(server_pending == TRUE)
  15205. {
  15206. return 0;
  15207. }
  15208. RemoteStopTransaction = json_tokener_parse(payload);
  15209. if(!is_error(RemoteStopTransaction))
  15210. {
  15211. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  15212. {
  15213. sprintf(transactionIdStr, "%s", json_object_get_string(json_object_object_get(RemoteStopTransaction, "transactionId")));
  15214. transactionIdIsNULL = FALSE;
  15215. }
  15216. }
  15217. json_object_put(RemoteStopTransaction);
  15218. if(transactionIdIsNULL == FALSE)
  15219. {
  15220. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  15221. {
  15222. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, transactionIdStr) != NULL)
  15223. {
  15224. //check Transaction active
  15225. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15226. {
  15227. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15228. {
  15229. tempIndex = ((gun_index==2) ? 1: 0);
  15230. }
  15231. else
  15232. {
  15233. tempIndex = gun_index;
  15234. }
  15235. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15236. {
  15237. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15238. {
  15239. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  15240. {
  15241. match = TRUE;
  15242. GunNO = gun_index;
  15243. }
  15244. }
  15245. }// END FOR CHAdeMO_QUANTITY
  15246. }
  15247. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15248. {
  15249. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15250. {
  15251. tempIndex = ((gun_index==2) ? 1: 0);
  15252. }
  15253. else
  15254. {
  15255. tempIndex = gun_index;
  15256. }
  15257. for (int index = 0; index < CCS_QUANTITY; index++)
  15258. {
  15259. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15260. {
  15261. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  15262. {
  15263. match = TRUE;
  15264. GunNO = gun_index;
  15265. }
  15266. }
  15267. }// END FOR CCS_QUANTITY
  15268. }
  15269. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15270. {
  15271. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15272. {
  15273. tempIndex = ((gun_index==2) ? 1: 0);
  15274. }
  15275. else
  15276. {
  15277. tempIndex = gun_index;
  15278. }
  15279. for (int index = 0; index < GB_QUANTITY; index++)
  15280. {
  15281. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15282. {
  15283. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  15284. {
  15285. match = TRUE;
  15286. GunNO = gun_index;
  15287. }
  15288. }
  15289. }// END FOR GB_QUANTITY
  15290. }
  15291. else if(gunType[gun_index] == GUN_TYPE_DO)
  15292. {
  15293. tempIndex = gun_index;
  15294. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15295. {
  15296. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15297. {
  15298. 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
  15299. {
  15300. match = TRUE;
  15301. GunNO = gun_index;
  15302. }
  15303. }
  15304. }// END FOR GB_QUANTITY
  15305. }
  15306. else
  15307. {
  15308. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15309. {
  15310. tempIndex = 2;
  15311. }
  15312. else
  15313. {
  15314. tempIndex = gun_index;
  15315. }
  15316. for (int index = 0; index < AC_QUANTITY; index++)
  15317. {
  15318. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15319. {
  15320. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  15321. {
  15322. match = TRUE;
  15323. GunNO = gun_index;
  15324. }
  15325. }
  15326. }// END FOR CHAdeMO_QUANTITY
  15327. } // END FOR AC ELSE
  15328. }// CHECK IF ResponseTransactionId == transactionIdInt
  15329. }//END FOR
  15330. if( match == TRUE)
  15331. {
  15332. ShmOCPP20Data->CsMsg.bits[GunNO].RequestStopTransactionReq = ON; // inform csu of StopTransaction
  15333. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  15334. }
  15335. else
  15336. {
  15337. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  15338. }
  15339. }
  15340. else
  15341. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  15342. sendRemoteStopTransactionConfirmation(uuid, GunNO);
  15343. return result;
  15344. }
  15345. int handleReserveNowRequest(char *uuid, char *payload)
  15346. {
  15347. mtrace();
  15348. int result = FAIL;
  15349. int evseIdInt=0, reservationIdInt=0;
  15350. int tempIndex = 0;
  15351. json_object *ReserveNow;
  15352. DEBUG_INFO("handleReserveNowRequest ...\n");
  15353. ReserveNow = json_tokener_parse(payload);
  15354. if(!is_error(ReserveNow))
  15355. {
  15356. if(json_object_object_get(ReserveNow, "evseId") != NULL)
  15357. {
  15358. evseIdInt = json_object_get_int(json_object_object_get(ReserveNow, "evseId"));
  15359. evseIdInt = (evseIdInt==0)?1:evseIdInt;
  15360. memset(&ShmOCPP20Data->ReserveNow[evseIdInt-1], 0x00, sizeof(struct ReserveNow_20));
  15361. ShmOCPP20Data->ReserveNow[evseIdInt-1].evseId = json_object_get_int(json_object_object_get(ReserveNow, "evseId"));
  15362. }
  15363. // Required data
  15364. if(json_object_object_get(ReserveNow, "id") != NULL)
  15365. ShmOCPP20Data->ReserveNow[evseIdInt-1].id = json_object_get_int(json_object_object_get(ReserveNow, "id"));
  15366. if(json_object_object_get(ReserveNow, "expiryDateTime") != NULL)
  15367. sprintf((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].expiryDateTime, "%s", json_object_get_string(json_object_object_get(ReserveNow, "expiryDateTime")));
  15368. if(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "idToken") != NULL)
  15369. sprintf((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "idToken")));
  15370. if(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "type") != NULL)
  15371. sprintf((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "type")));
  15372. // Optional data
  15373. if(json_object_object_get(ReserveNow, "connectorType") != NULL)
  15374. sprintf((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].connectorType, "%s", json_object_get_string(json_object_object_get(ReserveNow, "connectorType")));
  15375. if(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "idToken") != NULL)
  15376. sprintf((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "idToken")));
  15377. if(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "type") != NULL)
  15378. sprintf((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "type")));
  15379. result = PASS;
  15380. }
  15381. json_object_put(ReserveNow);
  15382. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15383. if((evseIdInt > 0) && ((evseIdInt -1) <= gunTotalNumber))
  15384. {
  15385. //check Transaction active
  15386. if(gunType[evseIdInt -1] == GUN_TYPE_CHAdeMO)
  15387. {
  15388. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15389. {
  15390. tempIndex = (((evseIdInt -1)==2) ? 1: 0);
  15391. }
  15392. else
  15393. {
  15394. tempIndex = evseIdInt -1;
  15395. }
  15396. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15397. {
  15398. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  15399. {
  15400. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  15401. {
  15402. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  15403. {
  15404. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  15405. {
  15406. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].InProgress == 1))
  15407. {
  15408. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15409. }
  15410. else
  15411. {
  15412. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15413. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15414. }
  15415. }
  15416. 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'))
  15417. {
  15418. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15419. }
  15420. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  15421. {
  15422. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15423. }
  15424. else
  15425. {
  15426. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15427. }
  15428. }
  15429. 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
  15430. {
  15431. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15432. }
  15433. }
  15434. else
  15435. {
  15436. //replace reservation
  15437. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15438. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15439. }
  15440. }
  15441. } // END FOR CHAdeMO_QUANTITY
  15442. }
  15443. else if(gunType[evseIdInt -1] == GUN_TYPE_CCS)
  15444. {
  15445. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15446. {
  15447. tempIndex = (((evseIdInt -1)==2) ? 1: 0);
  15448. }
  15449. else
  15450. {
  15451. tempIndex = evseIdInt -1;
  15452. }
  15453. for (int index = 0; index < CCS_QUANTITY; index++)
  15454. {
  15455. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15456. {
  15457. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  15458. {
  15459. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  15460. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  15461. {
  15462. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  15463. {
  15464. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].InProgress == 1))
  15465. {
  15466. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15467. }
  15468. else
  15469. {
  15470. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15471. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15472. }
  15473. }
  15474. 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'))
  15475. {
  15476. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15477. }
  15478. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  15479. {
  15480. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15481. }
  15482. else
  15483. {
  15484. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15485. }
  15486. }
  15487. 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
  15488. {
  15489. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15490. }
  15491. }
  15492. else
  15493. {
  15494. //replace reservation
  15495. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15496. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15497. }
  15498. }
  15499. } // END FOR CCS_QUANTITY
  15500. }
  15501. else if(gunType[evseIdInt -1] == GUN_TYPE_GBT)
  15502. {
  15503. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15504. {
  15505. tempIndex = (((evseIdInt -1)==2) ? 1: 0);
  15506. }
  15507. else
  15508. {
  15509. tempIndex = evseIdInt -1;
  15510. }
  15511. for (int index = 0; index < GB_QUANTITY; index++)
  15512. {
  15513. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15514. {
  15515. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  15516. {
  15517. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  15518. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  15519. {
  15520. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  15521. {
  15522. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].InProgress == 1))
  15523. {
  15524. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15525. }
  15526. else
  15527. {
  15528. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15529. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15530. }
  15531. }
  15532. 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'))
  15533. {
  15534. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15535. }
  15536. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  15537. {
  15538. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15539. }
  15540. else
  15541. {
  15542. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15543. }
  15544. }
  15545. 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
  15546. {
  15547. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15548. }
  15549. }
  15550. else
  15551. {
  15552. //replace reservation
  15553. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15554. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15555. }
  15556. }
  15557. }// END FOR GB_QUANTITY
  15558. }
  15559. else if(gunType[evseIdInt -1] == GUN_TYPE_DO)
  15560. {
  15561. tempIndex = evseIdInt -1;
  15562. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15563. {
  15564. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15565. {
  15566. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  15567. {
  15568. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  15569. 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
  15570. {
  15571. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  15572. {
  15573. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.InProgress == 1))
  15574. {
  15575. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15576. }
  15577. else
  15578. {
  15579. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15580. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15581. }
  15582. }
  15583. 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'))
  15584. {
  15585. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15586. }
  15587. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  15588. {
  15589. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15590. }
  15591. else
  15592. {
  15593. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15594. }
  15595. }
  15596. 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
  15597. {
  15598. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15599. }
  15600. }
  15601. else
  15602. {
  15603. //replace reservation
  15604. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15605. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15606. }
  15607. }
  15608. }// END FOR DO_QUANTITY
  15609. }
  15610. else
  15611. {
  15612. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15613. {
  15614. tempIndex = 2;
  15615. }
  15616. else
  15617. {
  15618. tempIndex = (evseIdInt -1);
  15619. }
  15620. for (int index = 0; index < AC_QUANTITY; index++)
  15621. {
  15622. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15623. {
  15624. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  15625. {
  15626. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  15627. {
  15628. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  15629. {
  15630. 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))
  15631. {
  15632. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15633. }
  15634. else
  15635. {
  15636. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15637. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15638. }
  15639. }
  15640. 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'))
  15641. {
  15642. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15643. }
  15644. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  15645. {
  15646. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15647. }
  15648. else
  15649. {
  15650. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15651. }
  15652. }
  15653. 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
  15654. {
  15655. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15656. }
  15657. }
  15658. else
  15659. {
  15660. //replace reservation
  15661. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].ReserveNowReq = ON;
  15662. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15663. }
  15664. }
  15665. } // END FOR AC_QUANTITY
  15666. }
  15667. }
  15668. else if(evseIdInt == 0)
  15669. {
  15670. //check Transaction active
  15671. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15672. {
  15673. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  15674. {
  15675. 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'))
  15676. {
  15677. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15678. goto end;
  15679. }
  15680. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  15681. {
  15682. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15683. goto end;
  15684. }
  15685. 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
  15686. {
  15687. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15688. goto end;
  15689. }
  15690. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  15691. {
  15692. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15693. goto end;
  15694. }
  15695. }
  15696. }// END FOR CHAdeMO_QUANTITY
  15697. for (int index = 0; index < CCS_QUANTITY; index++)
  15698. {
  15699. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  15700. {
  15701. 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'))
  15702. {
  15703. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15704. goto end;
  15705. }
  15706. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  15707. {
  15708. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15709. goto end;
  15710. }
  15711. 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
  15712. {
  15713. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15714. goto end;
  15715. }
  15716. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  15717. {
  15718. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15719. goto end;
  15720. }
  15721. }
  15722. } // END FOR CCS_QUANTITY
  15723. for (int index = 0; index < GB_QUANTITY; index++)
  15724. {
  15725. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  15726. {
  15727. 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'))
  15728. {
  15729. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15730. goto end;
  15731. }
  15732. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  15733. {
  15734. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15735. goto end;
  15736. }
  15737. 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
  15738. {
  15739. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15740. goto end;
  15741. }
  15742. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  15743. {
  15744. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15745. goto end;
  15746. }
  15747. }
  15748. } // END FOR GB_QUANTITY
  15749. for (int index = 0; index < AC_QUANTITY; index++)
  15750. {
  15751. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  15752. {
  15753. 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'))
  15754. {
  15755. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  15756. goto end;
  15757. }
  15758. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  15759. {
  15760. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15761. goto end;
  15762. }
  15763. 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
  15764. {
  15765. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  15766. goto end;
  15767. }
  15768. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  15769. {
  15770. 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))
  15771. {
  15772. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  15773. goto end;
  15774. }
  15775. }
  15776. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  15777. {
  15778. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15779. goto end;
  15780. }
  15781. }
  15782. }// END FOR AC_QUANTITY
  15783. //The connectorId is 0
  15784. ShmOCPP20Data->CsMsg.bits[0].ReserveNowReq = ON;
  15785. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  15786. strcpy((char *)ShmOCPP20Data->ReserveNow[0].guid, uuid);
  15787. result = TRUE;
  15788. return result;
  15789. }
  15790. else
  15791. {
  15792. strcpy((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  15793. }
  15794. if(strcmp((char*)ShmOCPP20Data->ReserveNow[evseIdInt-1].Response_status,ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]) == 0)
  15795. {
  15796. strcpy((char *)ShmOCPP20Data->ReserveNow[evseIdInt-1].guid, uuid);
  15797. result = TRUE;
  15798. return result;
  15799. }
  15800. end:
  15801. sendReserveNowConfirmation(uuid, (evseIdInt==0?evseIdInt:evseIdInt-1));
  15802. return result;
  15803. }
  15804. int handleResetRequest(char *uuid, char *payload)
  15805. {
  15806. mtrace();
  15807. int result = FAIL;
  15808. json_object *Reset = json_object_new_object();
  15809. DEBUG_INFO("handleResetRequest...\n");
  15810. Reset = json_tokener_parse(payload);
  15811. ShmOCPP20Data->Reset.evseId = 0;
  15812. if(!is_error(Reset))
  15813. {
  15814. // Required data
  15815. if(json_object_object_get(Reset, "type") != NULL)
  15816. {
  15817. sprintf((char*)ShmOCPP20Data->Reset.type, "%s", json_object_get_string(json_object_object_get(Reset, "type")));
  15818. }
  15819. if(json_object_object_get(Reset, "evseId") != NULL)
  15820. {
  15821. ShmOCPP20Data->Reset.evseId = json_object_get_int(json_object_object_get(Reset, "evseId"));
  15822. }
  15823. }
  15824. json_object_put(Reset);
  15825. if((ShmOCPP20Data->Reset.evseId == 0) && ((strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_Immediate])==0) || (strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_OnIdle])==0)))
  15826. {
  15827. strcpy((char *)ShmOCPP20Data->Reset.guid, uuid);
  15828. strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]);
  15829. ShmOCPP20Data->MsMsg.bits.ResetReq = ON;
  15830. result = PASS;
  15831. }
  15832. else
  15833. {
  15834. strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Rejected]);
  15835. }
  15836. if(strlen((char*)ShmOCPP20Data->Reset.Response_status) > 0)
  15837. sendResetConfirmation(uuid);
  15838. return result;
  15839. }
  15840. int handleSendLocalListRequest(char *uuid, char *payload)
  15841. {
  15842. mtrace();
  15843. int result = FAIL;
  15844. int checkState_Faulted = FALSE;
  15845. json_object *SendLocalList;
  15846. DEBUG_INFO("handleSendLocalListRequest...\n");
  15847. if(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "false") == 0)
  15848. {
  15849. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  15850. goto end;
  15851. }
  15852. SendLocalList = json_tokener_parse(payload);
  15853. if(!is_error(SendLocalList))
  15854. {
  15855. memset(&ShmOCPP20Data->SendLocalList, 0x00, sizeof(struct SendLocalList_20));
  15856. // Required data
  15857. if(json_object_object_get(SendLocalList, "versionNumber") != NULL)
  15858. {
  15859. ShmOCPP20Data->SendLocalList.versionNumber = json_object_get_int(json_object_object_get(SendLocalList, "versionNumber"));
  15860. }
  15861. if(json_object_object_get(SendLocalList, "updateType") != NULL)
  15862. sprintf((char*)ShmOCPP20Data->SendLocalList.updateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  15863. // Optional data
  15864. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  15865. {
  15866. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  15867. {
  15868. // Required data
  15869. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idToken") != NULL)
  15870. {
  15871. 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")));
  15872. sprintf((char*)ShmOCPP20Data->SendLocalList.localAuthorizationList[idx].idToken.type, "%s", stringtrimspace((char *)json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idToken"), "type"))));
  15873. }
  15874. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  15875. {
  15876. sprintf((char*)ShmOCPP20Data->SendLocalList.localAuthorizationList[idx].idTokenInfo.status, "%s", stringtrimspace((char *)json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status"))));
  15877. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "cacheExpiryDateTime") != NULL)
  15878. 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")));
  15879. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "chargingPriority") != NULL)
  15880. 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"));
  15881. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "groupIdToken") != NULL)
  15882. {
  15883. 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")));
  15884. 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")));
  15885. }
  15886. }
  15887. }
  15888. }
  15889. }
  15890. json_object_put(SendLocalList);
  15891. //check Charge Point state
  15892. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15893. {
  15894. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  15895. {
  15896. checkState_Faulted = TRUE; //OCPP Status: Faulted
  15897. }
  15898. }
  15899. for (int index = 0; index < CCS_QUANTITY; index++)
  15900. {
  15901. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  15902. {
  15903. checkState_Faulted = TRUE; //OCPP Status
  15904. }
  15905. }
  15906. for (int index = 0; index < GB_QUANTITY; index++)
  15907. {
  15908. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  15909. {
  15910. checkState_Faulted = TRUE; //OCPP Status: Faulted
  15911. }
  15912. }
  15913. for (int index = 0; index < AC_QUANTITY; index++)
  15914. {
  15915. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  15916. {
  15917. checkState_Faulted = TRUE; //OCPP Status: Faulted
  15918. }
  15919. }
  15920. if(checkState_Faulted == TRUE)
  15921. {
  15922. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  15923. goto end;
  15924. }
  15925. // Check update type
  15926. if(strcmp((char*)ShmOCPP20Data->SendLocalList.updateType, UpdateEnumTypeStr[UpdateEnumType_Full]) == 0)
  15927. {
  15928. //Local list full update
  15929. DEBUG_INFO("Local list full update.\n");
  15930. DB_getListVerion();
  15931. /*if(ShmOCPP20Data->SendLocalList.versionNumber < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  15932. {
  15933. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  15934. goto end;
  15935. }*/
  15936. DB_cleanLocalList();
  15937. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->SendLocalList.localAuthorizationList);idx++)
  15938. DB_addLocalList(ShmOCPP20Data->SendLocalList.versionNumber, &ShmOCPP20Data->SendLocalList.localAuthorizationList[idx]);
  15939. }
  15940. else if(strcmp((char*)ShmOCPP20Data->SendLocalList.updateType, UpdateEnumTypeStr[UpdateEnumType_Differential]) == 0)
  15941. {
  15942. //Local list different update
  15943. DEBUG_INFO("Local list different update.\n");
  15944. DB_getListVerion();
  15945. if(ShmOCPP20Data->SendLocalList.versionNumber < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  15946. {
  15947. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_VersionMismatch]);
  15948. goto end;
  15949. }
  15950. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->SendLocalList.localAuthorizationList);idx++)
  15951. DB_addLocalList(ShmOCPP20Data->SendLocalList.versionNumber, &ShmOCPP20Data->SendLocalList.localAuthorizationList[idx]);
  15952. }
  15953. else
  15954. {
  15955. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  15956. goto end;
  15957. }
  15958. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Accepted]);
  15959. end:
  15960. sendSendLocalListConfirmation(uuid);
  15961. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  15962. return result;
  15963. }
  15964. int handleSetChargingProfileRequest(char *uuid, char *payload)
  15965. {
  15966. mtrace();
  15967. int result = FAIL;
  15968. struct SetChargingProfile_20 SetProfileReq = {0};
  15969. uint8_t isLostEvseId = FALSE;
  15970. uint8_t isPeriodOverMax = FALSE;
  15971. uint8_t isStackOverMax = FALSE;
  15972. uint8_t isProfileOverMax = FALSE;
  15973. uint8_t isEvseMismatch = FALSE;
  15974. uint8_t isTransactiodIdMismatch = FALSE;
  15975. uint8_t isInvalidLimit = FALSE;
  15976. uint8_t isWrongFormat = FALSE;
  15977. uint8_t replaceableProfileCnt = 0;
  15978. uint8_t existProfileQuantity = 0;
  15979. uint8_t filename[128]={0};
  15980. uint8_t dataLine[4096]={0};
  15981. FILE *filePtr;
  15982. json_object *SetChargingProfile;
  15983. DEBUG_INFO("handleSetChargingProfileRequest...\n");
  15984. SetChargingProfile = json_tokener_parse(payload);
  15985. if(!is_error(SetChargingProfile))
  15986. {
  15987. // Required data
  15988. if(json_object_object_get(SetChargingProfile, "evseId") != NULL)
  15989. SetProfileReq.evseId = json_object_get_int(json_object_object_get(SetChargingProfile, "evseId"));
  15990. else
  15991. isLostEvseId = TRUE;
  15992. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "id") != NULL)
  15993. SetProfileReq.chargingProfile.id = json_object_get_int((json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "id")));
  15994. if(json_object_object_get(SetChargingProfile, "chargingProfile") != NULL)
  15995. {
  15996. sprintf((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")));
  15997. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "stackLevel") != NULL)
  15998. {
  15999. SetProfileReq.chargingProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "stackLevel"));
  16000. }
  16001. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose") != NULL)
  16002. {
  16003. strcpy((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")));
  16004. }
  16005. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfileKind") != NULL)
  16006. {
  16007. strcpy((char*)SetProfileReq.chargingProfile.chargingProfileKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfileKind")));
  16008. }
  16009. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "transactionId") != NULL)
  16010. {
  16011. strcpy((char*)SetProfileReq.chargingProfile.transactionId, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "transactionId")));
  16012. }
  16013. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "recurrencyKind") != NULL)
  16014. {
  16015. strcpy((char*)SetProfileReq.chargingProfile.recurrencyKind, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "recurrencyKind")));
  16016. }
  16017. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validFrom") != NULL)
  16018. {
  16019. strcpy((char*)SetProfileReq.chargingProfile.validFrom, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validFrom")));
  16020. }
  16021. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validTo") != NULL)
  16022. {
  16023. strcpy((char*)SetProfileReq.chargingProfile.validTo, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "validTo")));
  16024. }
  16025. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule") != NULL)
  16026. {
  16027. int chargingScheduleCount = 0;
  16028. int chargingSchedulePeriodCount = 0;
  16029. if(json_object_is_type(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), 5))
  16030. {
  16031. chargingScheduleCount = json_object_array_length(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"));
  16032. for(int idxSchedule=0;idxSchedule<chargingScheduleCount;idxSchedule++)
  16033. {
  16034. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingRateUnit") != NULL)
  16035. {
  16036. 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")));
  16037. }
  16038. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "duration") != NULL)
  16039. {
  16040. 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"));
  16041. }
  16042. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "minChargingRate") != NULL)
  16043. {
  16044. 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"));
  16045. }
  16046. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "startSchedule") != NULL)
  16047. {
  16048. 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")));
  16049. }
  16050. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "chargingSchedulePeriod") != NULL)
  16051. {
  16052. 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"));
  16053. if(chargingSchedulePeriodCount <= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].value))
  16054. {
  16055. for(int idxPeriod=0;idxPeriod<chargingSchedulePeriodCount;idxPeriod++)
  16056. {
  16057. 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)
  16058. {
  16059. 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"));
  16060. }
  16061. 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)
  16062. {
  16063. 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"));
  16064. }
  16065. 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)
  16066. {
  16067. 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"));
  16068. }
  16069. 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)
  16070. {
  16071. 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"));
  16072. }
  16073. // Check invalid limit
  16074. if((strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) == NULL) ||
  16075. ((strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL) && (ShmSysConfigAndInfo->SysConfig.isEnableLocalPowerSharing != 1)))
  16076. {
  16077. if(ShmSysConfigAndInfo->SysConfig.ModelName[0] == 'A')
  16078. {
  16079. 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)))) ||
  16080. (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit > (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit[0]=='W'?modelnameInfo.ratedPower:ShmSysConfigAndInfo->SysConfig.RatingCurrent)))
  16081. {
  16082. DEBUG_WARN("Profile chargingSchedule-%d period-%02d is invalid limit: %.2f %s with phase %d.\n", idxSchedule, idxPeriod,
  16083. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit,
  16084. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit,
  16085. (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases==0?3:SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  16086. DEBUG_WARN("Rated Power: %d, Rating Current: %d\n", modelnameInfo.ratedPower, ShmSysConfigAndInfo->SysConfig.RatingCurrent);
  16087. isInvalidLimit = TRUE;
  16088. }
  16089. }
  16090. else
  16091. {
  16092. 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) ||
  16093. (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)))
  16094. {
  16095. DEBUG_WARN("Profile period-%02d is invalid limit: %.2f %s with phase %d.\n", idxPeriod,
  16096. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit,
  16097. SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingRateUnit,
  16098. (SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases==0?3:SetProfileReq.chargingProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  16099. DEBUG_WARN("Rated Power: %d \n", modelnameInfo.ratedPower);
  16100. isInvalidLimit = TRUE;
  16101. }
  16102. }
  16103. }
  16104. }
  16105. }
  16106. else
  16107. {
  16108. isPeriodOverMax = TRUE;
  16109. }
  16110. }
  16111. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), idxSchedule), "salesTariff") != NULL)
  16112. {
  16113. 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)
  16114. {
  16115. 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"));
  16116. }
  16117. 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)
  16118. {
  16119. 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")));
  16120. }
  16121. 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)
  16122. {
  16123. 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"));
  16124. }
  16125. 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)
  16126. {
  16127. 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"));
  16128. if(cntEntry<=1024)
  16129. {
  16130. for(int idxEntry=0; idxEntry<cntEntry; idxEntry++)
  16131. {
  16132. 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)
  16133. {
  16134. 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"));
  16135. }
  16136. 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)
  16137. {
  16138. 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)
  16139. 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"));
  16140. 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)
  16141. 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"));
  16142. }
  16143. 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)
  16144. {
  16145. 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"));
  16146. if(cntConCost<=3)
  16147. {
  16148. for(uint8_t idxConCost=0; idxConCost<cntConCost; idxConCost++)
  16149. {
  16150. 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)
  16151. 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"));
  16152. 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)
  16153. {
  16154. 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"));
  16155. if(cntConCost<=3)
  16156. {
  16157. for(uint8_t idxCost=0; idxCost<cntCost; idxCost++)
  16158. {
  16159. 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)
  16160. 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")));
  16161. 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)
  16162. 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"));
  16163. 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)
  16164. 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"));
  16165. }
  16166. }
  16167. }
  16168. }
  16169. }
  16170. 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"));
  16171. }
  16172. }
  16173. }
  16174. }
  16175. }
  16176. }
  16177. }
  16178. else
  16179. {
  16180. isWrongFormat = TRUE;
  16181. }
  16182. }
  16183. // Check periods is over max configuration
  16184. if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL)
  16185. {
  16186. if(SetProfileReq.evseId == 0)
  16187. {
  16188. sprintf((char*)filename, ChargingStationMaxProfile_JSON);
  16189. filePtr = fopen((char*)filename, "r");
  16190. if (!filePtr)
  16191. {
  16192. DEBUG_INFO("%s not exist, create it.\n", ChargingStationMaxProfile_JSON);
  16193. filePtr = fopen((char*)filename, "w+");
  16194. }
  16195. else
  16196. {
  16197. //Check Charging Profile Count
  16198. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  16199. char *line = NULL;
  16200. size_t len = 0;
  16201. while(getline(&line, &len, filePtr) != -1)
  16202. {
  16203. json_object *obj = NULL;
  16204. obj = json_tokener_parse(line);
  16205. if(is_error(obj))
  16206. {
  16207. DEBUG_ERROR("Parse ChargingStationMaxProfile from file error.\n");
  16208. }
  16209. else
  16210. {
  16211. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  16212. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  16213. {
  16214. existProfileQuantity += 1;
  16215. }
  16216. else
  16217. replaceableProfileCnt += 1;
  16218. }
  16219. //DEBUG_INFO("word=%s\n",word);
  16220. /*if(strstr((char*)dataLine, "id")!= NULL)
  16221. {
  16222. existProfileQuantity += 1;
  16223. }*/
  16224. }
  16225. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", existProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  16226. if(existProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  16227. {
  16228. isStackOverMax = TRUE;
  16229. }
  16230. }
  16231. fclose(filePtr);
  16232. }
  16233. else
  16234. isEvseMismatch = TRUE;
  16235. }
  16236. else if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) != NULL)
  16237. {
  16238. if((0 < SetProfileReq.evseId) && (SetProfileReq.evseId > gunTotalNumber))
  16239. isEvseMismatch = TRUE;
  16240. if(!isEvseMismatch)
  16241. {
  16242. if(SetProfileReq.evseId == 0)
  16243. {
  16244. int tmpExistProfileQuantity;
  16245. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  16246. {
  16247. tmpExistProfileQuantity = 0;
  16248. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", idxCon);
  16249. filePtr = fopen((char*)filename, "r");
  16250. if (!filePtr)
  16251. {
  16252. DEBUG_INFO("%s not exist, create it.\n", filename);
  16253. filePtr = fopen((char*)filename, "w+");
  16254. }
  16255. else
  16256. {
  16257. //Check Charging Profile Count
  16258. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  16259. char *line = NULL;
  16260. size_t len = 0;
  16261. while(getline(&line, &len, filePtr) != -1)
  16262. {
  16263. json_object *obj = NULL;
  16264. obj = json_tokener_parse(line);
  16265. if(is_error(obj))
  16266. {
  16267. DEBUG_ERROR("Parse ChargingStationMaxProfile from file error.\n");
  16268. }
  16269. else
  16270. {
  16271. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  16272. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  16273. {
  16274. tmpExistProfileQuantity += 1;
  16275. }
  16276. else
  16277. replaceableProfileCnt += 1;
  16278. }
  16279. //DEBUG_INFO("word=%s\n",word);
  16280. /*if(strstr((char*)dataLine, "id")!= NULL)
  16281. {
  16282. tmpExistProfileQuantity += 1;
  16283. }*/
  16284. }
  16285. }
  16286. fclose(filePtr);
  16287. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", tmpExistProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  16288. if(tmpExistProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  16289. {
  16290. isStackOverMax = TRUE;
  16291. }
  16292. //existProfileQuantity = (existProfileQuantity < tmpExistProfileQuantity) ? tmpExistProfileQuantity : existProfileQuantity;
  16293. }
  16294. }
  16295. else
  16296. {
  16297. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", SetProfileReq.evseId);
  16298. filePtr = fopen((char*)filename, "r");
  16299. if (!filePtr)
  16300. {
  16301. DEBUG_INFO("%s not exist, create it.\n", filename);
  16302. filePtr = fopen((char*)filename, "w+");
  16303. }
  16304. else
  16305. {
  16306. //Check Charging Profile Count
  16307. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  16308. char *line = NULL;
  16309. size_t len = 0;
  16310. while(getline(&line, &len, filePtr) != -1)
  16311. {
  16312. json_object *obj = NULL;
  16313. obj = json_tokener_parse(line);
  16314. if(is_error(obj))
  16315. {
  16316. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  16317. }
  16318. else
  16319. {
  16320. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  16321. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  16322. {
  16323. existProfileQuantity += 1;
  16324. }
  16325. else
  16326. replaceableProfileCnt += 1;
  16327. }
  16328. //DEBUG_INFO("word=%s\n",word);
  16329. /*if(strstr((char*)dataLine, "id")!= NULL)
  16330. {
  16331. existProfileQuantity += 1;
  16332. }*/
  16333. }
  16334. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", existProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  16335. if(existProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  16336. {
  16337. isStackOverMax = TRUE;
  16338. }
  16339. }
  16340. fclose(filePtr);
  16341. }
  16342. }
  16343. }
  16344. else if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  16345. {
  16346. if((SetProfileReq.evseId > 0) && (SetProfileReq.evseId <= gunTotalNumber))
  16347. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", SetProfileReq.evseId);
  16348. else
  16349. isEvseMismatch = TRUE;
  16350. if(!isEvseMismatch)
  16351. {
  16352. filePtr = fopen((char*)filename, "r");
  16353. if (!filePtr)
  16354. {
  16355. DEBUG_INFO("%s not exist, create it.\n", filename);
  16356. filePtr = fopen((char*)filename, "w+");
  16357. }
  16358. else
  16359. {
  16360. //Check Charging Profile Count
  16361. //while(fscanf(filePtr, "%s", dataLine) != EOF)
  16362. char *line = NULL;
  16363. size_t len = 0;
  16364. while(getline(&line, &len, filePtr) != -1)
  16365. {
  16366. json_object *obj = NULL;
  16367. obj = json_tokener_parse(line);
  16368. if(is_error(obj))
  16369. {
  16370. DEBUG_ERROR("Parse TxProfile from file error.\n");
  16371. }
  16372. else
  16373. {
  16374. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != SetProfileReq.chargingProfile.id) &&
  16375. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) != SetProfileReq.chargingProfile.stackLevel))
  16376. {
  16377. existProfileQuantity += 1;
  16378. }
  16379. else
  16380. replaceableProfileCnt += 1;
  16381. }
  16382. //DEBUG_INFO("word=%s\n",word);
  16383. /*if(strstr((char*)dataLine, "id")!= NULL)
  16384. {
  16385. existProfileQuantity += 1;
  16386. }*/
  16387. }
  16388. DEBUG_INFO("existProfileQuantity: %d, Max stack limit: %d\n", existProfileQuantity, atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value));
  16389. if(existProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value))
  16390. {
  16391. isStackOverMax = TRUE;
  16392. }
  16393. }
  16394. fclose(filePtr);
  16395. if(strcmp((char*)SetProfileReq.chargingProfile.transactionId, (char*)ShmOCPP20Data->TransactionEvent[SetProfileReq.evseId-1].transactionInfo.transactionId) != 0)
  16396. isTransactiodIdMismatch = TRUE;
  16397. }
  16398. }
  16399. else if(strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationExternalConstraints]) != NULL)
  16400. {
  16401. /*
  16402. * TODO:
  16403. *
  16404. */
  16405. }
  16406. else
  16407. {}
  16408. //------------------------------Start: Check ChargingProfileEntries Logic---------------------------------------//
  16409. {
  16410. FILE *fp;
  16411. char dataLine[4096]={0};
  16412. char fnametemp[128]={0};
  16413. int tmpProfileQuantity;
  16414. //Check ChargePointMaxProfile.json exit
  16415. existProfileQuantity = 0;
  16416. if((access(ChargingStationMaxProfile_JSON,F_OK))!=-1)
  16417. {
  16418. fp = fopen(ChargingStationMaxProfile_JSON, "r");
  16419. //Check Charging Profile Count
  16420. tmpProfileQuantity = 0;
  16421. while(fscanf(fp, "%s", dataLine) != EOF)
  16422. {
  16423. if(strstr(dataLine, "id")!= NULL)
  16424. {
  16425. existProfileQuantity += 1;
  16426. tmpProfileQuantity += 1;
  16427. }
  16428. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  16429. }
  16430. fclose(fp);
  16431. DEBUG_INFO("ChargePointMaxProfile_OCPP20.json has %d charging Profile\n", tmpProfileQuantity);
  16432. }
  16433. //Check TxDefaultProfile_%d.json
  16434. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  16435. {
  16436. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  16437. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", idxCon);
  16438. if((access(fnametemp,F_OK))!=-1)
  16439. {
  16440. fp = fopen(fnametemp, "r");
  16441. //Check Charging Profile Count
  16442. tmpProfileQuantity = 0;
  16443. while(fscanf(fp, "%s", dataLine) != EOF)
  16444. {
  16445. //DEBUG_INFO("word=%s\n",word);
  16446. if(strstr(dataLine, "id")!= NULL)
  16447. {
  16448. existProfileQuantity += 1;
  16449. tmpProfileQuantity += 1;
  16450. }
  16451. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  16452. }
  16453. fclose(fp);
  16454. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  16455. }
  16456. }
  16457. //Check TxProfile_%d.json
  16458. for(int idxCon=1; idxCon <= gunTotalNumber; idxCon++)
  16459. {
  16460. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  16461. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d_OCPP20.json", idxCon);
  16462. if((access(fnametemp,F_OK))!=-1)
  16463. {
  16464. fp = fopen(fnametemp, "r");
  16465. //Check Charging Profile Count
  16466. tmpProfileQuantity = 0;
  16467. while(fscanf(fp, "%s", dataLine) != EOF)
  16468. {
  16469. if(strstr(dataLine, "id")!= NULL)
  16470. {
  16471. existProfileQuantity += 1;
  16472. tmpProfileQuantity += 1;
  16473. }
  16474. memset(dataLine, 0, ARRAY_SIZE(dataLine));
  16475. }
  16476. fclose(fp);
  16477. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, tmpProfileQuantity);
  16478. }
  16479. }
  16480. DEBUG_INFO("All purpose profile quantity: %d\n", existProfileQuantity);
  16481. DEBUG_INFO("Replaceable profile quantity: %d\n", replaceableProfileCnt);
  16482. // To check total Profile quantity
  16483. if((SetProfileReq.evseId > 0) || (strstr((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL))
  16484. {
  16485. if((existProfileQuantity-replaceableProfileCnt) >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value))
  16486. isProfileOverMax = TRUE;
  16487. }
  16488. else
  16489. {
  16490. if((existProfileQuantity+gunTotalNumber-replaceableProfileCnt) > atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value))
  16491. isProfileOverMax = TRUE;
  16492. }
  16493. }
  16494. //------------------------------End: Check ChargingProfileEntries Logic---------------------------------------//
  16495. }
  16496. // Profile replace or add info
  16497. if(!isLostEvseId && !isPeriodOverMax && !isProfileOverMax && !isEvseMismatch && !isTransactiodIdMismatch && !isInvalidLimit && !isWrongFormat && !isStackOverMax)
  16498. {
  16499. FILE *infile;
  16500. FILE *outfile;
  16501. char tmpProfileName[] = "/Storage/OCPP/SetChargingProfiletemp_OCPP20.json";
  16502. char rmFileCmd[128];
  16503. int tempchargingProfileIdInt;
  16504. int tempchargingProfileStackLevelInt;
  16505. int chkChar;
  16506. for(int idxCon=1; idxCon <= (SetProfileReq.evseId==0?gunTotalNumber:1); idxCon++)
  16507. {
  16508. if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) == 0)
  16509. {
  16510. sprintf((char*)filename, "%s", ChargingStationMaxProfile_JSON);
  16511. }
  16512. else if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0)
  16513. {
  16514. if(SetProfileReq.evseId==0)
  16515. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", idxCon);
  16516. else
  16517. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", SetProfileReq.evseId);
  16518. }
  16519. else if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) == 0)
  16520. {
  16521. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", SetProfileReq.evseId);
  16522. }
  16523. else
  16524. {
  16525. /*
  16526. * TODO:
  16527. *
  16528. */
  16529. }
  16530. infile = fopen ((char*)filename, "r");
  16531. outfile = fopen ((char*)tmpProfileName, "w");
  16532. chkChar = fgetc(infile);
  16533. rewind(infile);
  16534. if(chkChar == EOF)
  16535. {
  16536. // Profile is empty
  16537. if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
  16538. json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
  16539. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  16540. fclose(infile);
  16541. fclose(outfile);
  16542. sprintf(rmFileCmd,"rm -f %s",filename);
  16543. system(rmFileCmd);
  16544. rename((char*)tmpProfileName, (char*)filename);
  16545. }
  16546. else
  16547. {
  16548. // Profile is not empty
  16549. int ChargingProfileAdded = FALSE;
  16550. while (fgets((char*)dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  16551. {
  16552. dataLine[strlen((char*)dataLine) - 1] = '\0'; // eat the newline fgets() stores
  16553. json_object *tmpChargingProfile;
  16554. tmpChargingProfile = json_tokener_parse((char*)dataLine);
  16555. if(!is_error(tmpChargingProfile))
  16556. {
  16557. if(json_object_object_get(tmpChargingProfile, "chargingProfile") != NULL)
  16558. {
  16559. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "id") != NULL)
  16560. {
  16561. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "id"));
  16562. DEBUG_INFO("tempchargingProfileIdInt: %d\n", tempchargingProfileIdInt);
  16563. DEBUG_INFO("SetProfileReq.chargingProfile.id: %d\n", SetProfileReq.chargingProfile.id);
  16564. }
  16565. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "stackLevel") != NULL)
  16566. {
  16567. tempchargingProfileStackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "stackLevel"));
  16568. DEBUG_INFO("tempchargingProfileStackLevelInt: %d\n", tempchargingProfileStackLevelInt);
  16569. DEBUG_INFO("SetProfileReq.chargingProfile.stackLevel: %d\n", SetProfileReq.chargingProfile.stackLevel);
  16570. }
  16571. }
  16572. }
  16573. json_object_put(tmpChargingProfile);
  16574. if((tempchargingProfileIdInt == SetProfileReq.chargingProfile.id) || (tempchargingProfileStackLevelInt == SetProfileReq.chargingProfile.stackLevel))
  16575. {
  16576. if(ChargingProfileAdded == FALSE)
  16577. {
  16578. if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
  16579. json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
  16580. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  16581. ChargingProfileAdded = TRUE;
  16582. }
  16583. }
  16584. else
  16585. {
  16586. fprintf(outfile,"%s\n",dataLine);
  16587. if(ChargingProfileAdded == FALSE)
  16588. {
  16589. if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
  16590. json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
  16591. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  16592. ChargingProfileAdded = TRUE;
  16593. }
  16594. }
  16595. } // end of while loop
  16596. fclose(infile);
  16597. fclose(outfile);
  16598. sprintf(rmFileCmd,"rm -f %s",filename);
  16599. system(rmFileCmd);
  16600. rename((char*)tmpProfileName, (char*)filename);
  16601. }
  16602. }
  16603. sleep(1);
  16604. sprintf((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted] );
  16605. result = PASS;
  16606. }
  16607. else
  16608. {
  16609. if(isLostEvseId)
  16610. DEBUG_WARN("Connector id is wrong.\n");
  16611. if(isEvseMismatch)
  16612. DEBUG_WARN("Connector id is mismatch.\n");
  16613. if(isPeriodOverMax)
  16614. DEBUG_WARN("Profile periods quantity is over spec.\n");
  16615. if(isProfileOverMax)
  16616. DEBUG_WARN("Profile quantity is over spec.\n");
  16617. if(isTransactiodIdMismatch)
  16618. DEBUG_WARN("Transaction id is mismatch.\n");
  16619. if(isInvalidLimit)
  16620. DEBUG_WARN("Limit value is invalid.\n");
  16621. if(isStackOverMax)
  16622. DEBUG_WARN("Profile stack is over spec.\n");
  16623. if(isWrongFormat)
  16624. DEBUG_WARN("Profile format is wrong.\n");
  16625. sprintf((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Rejected] );
  16626. }
  16627. }
  16628. json_object_put(SetChargingProfile);
  16629. if(strcmp((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted]) == 0)
  16630. {
  16631. if(SetProfileReq.evseId == 0)
  16632. {
  16633. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  16634. {
  16635. //ShmOCPP20Data->CSUMsg.bits[idx].ChargingProfileReq = ON;
  16636. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  16637. checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx], 0, TRUE);
  16638. }
  16639. }
  16640. else
  16641. {
  16642. //ShmOCPP20Data->CSUMsg.bits[SetProfileReq.evseId-1].ChargingProfileReq = ON;
  16643. checkChargingStationMaxProfile(86400, &ShmOCPP20Data->MaxChargingProfile, 0, TRUE);
  16644. checkCompositeSchedule(SetProfileReq.evseId, 86400, &ShmOCPP20Data->SmartChargingProfile[SetProfileReq.evseId-1], 0, TRUE);
  16645. }
  16646. }
  16647. sendSetChargingProfileConfirmation(uuid, (SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1));
  16648. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  16649. return result;
  16650. }
  16651. int handleSetDisplayMessageRequest(char *uuid, char *payload)
  16652. {
  16653. mtrace();
  16654. int result = FAIL;
  16655. json_object *SetDisplayMessage;
  16656. DEBUG_INFO("handleSetDisplayMessageRequest...\n");
  16657. SetDisplayMessage = json_tokener_parse(payload);
  16658. if(!is_error(SetDisplayMessage))
  16659. {
  16660. memset(&ShmOCPP20Data->SetDisplayMessage, 0, sizeof(struct SetDisplayMessage_20));
  16661. memcpy(&ShmOCPP20Data->SetDisplayMessage.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetDisplayMessage.guid));
  16662. // Required data
  16663. if(json_object_object_get(SetDisplayMessage, "message") != NULL)
  16664. {
  16665. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "id") != NULL)
  16666. ShmOCPP20Data->SetDisplayMessage.message.id = json_object_get_int(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "id"));
  16667. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "priority") != NULL)
  16668. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.priority, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "priority")));
  16669. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "state") != NULL)
  16670. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.state, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "state")));
  16671. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "startDateTime") != NULL)
  16672. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.startDateTime, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "startDateTime")));
  16673. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "endDateTime") != NULL)
  16674. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.endDateTime, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "endDateTime")));
  16675. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "transactionId") != NULL)
  16676. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.transactionId, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "transactionId")));
  16677. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message") != NULL)
  16678. {
  16679. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "format") != NULL)
  16680. 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")));
  16681. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "language") != NULL)
  16682. 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")));
  16683. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "content") != NULL)
  16684. 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")));
  16685. }
  16686. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display") != NULL)
  16687. {
  16688. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "name") != NULL)
  16689. 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")));
  16690. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "instance") != NULL)
  16691. 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")));
  16692. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse") != NULL)
  16693. {
  16694. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "id") != NULL)
  16695. 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"));
  16696. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "connectorId") != NULL)
  16697. 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"));
  16698. }
  16699. }
  16700. }
  16701. }
  16702. json_object_put(SetDisplayMessage);
  16703. strcpy((char*)ShmOCPP20Data->SetDisplayMessage.Response_status, DisplayMessageStatusEnumTypeStr[DisplayMessageStatusEnumType_Accepted]);
  16704. sendSetDisplayMessagesConfirmation(uuid);
  16705. // Announce CSU there is display request come from server
  16706. ShmOCPP20Data->MsMsg.bits.SetDisplayMessageReq = ON;
  16707. return result;
  16708. }
  16709. int handleSetMonitoringBaseRequest(char *uuid, char *payload)
  16710. {
  16711. mtrace();
  16712. int result = FAIL;
  16713. json_object *SetMonitoringBase;
  16714. DEBUG_INFO("handleSetMonitoringBaseRequest...\n");
  16715. SetMonitoringBase = json_tokener_parse(payload);
  16716. if(!is_error(SetMonitoringBase))
  16717. {
  16718. memset(&ShmOCPP20Data->SetMonitoringBase, 0, sizeof(struct SetMonitoringBase_20));
  16719. memcpy(&ShmOCPP20Data->SetMonitoringBase.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetMonitoringBase.guid));
  16720. // Required data
  16721. if(json_object_object_get(SetMonitoringBase, "monitoringBase") != NULL)
  16722. sprintf((char*)ShmOCPP20Data->SetMonitoringBase.monitoringBase, "%s",json_object_get_string(json_object_object_get(SetMonitoringBase, "monitoringBase")));
  16723. }
  16724. json_object_put(SetMonitoringBase);
  16725. /*
  16726. * TODO:
  16727. * 1. Configure monitor base and response
  16728. */
  16729. strcpy((char*)ShmOCPP20Data->SetMonitoringBase.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  16730. sendSetMonitoringBaseConfirmation(uuid);
  16731. return result;
  16732. }
  16733. int handleSetMonitoringLevelRequest(char *uuid, char *payload)
  16734. {
  16735. mtrace();
  16736. int result = FAIL;
  16737. json_object *SetMonitoringLevel;
  16738. DEBUG_INFO("handleSetMonitoringLevelRequest...\n");
  16739. SetMonitoringLevel = json_tokener_parse(payload);
  16740. if(!is_error(SetMonitoringLevel))
  16741. {
  16742. memset(&ShmOCPP20Data->SetMonitoringLevel, 0, sizeof(struct SetMonitoringLevel_20));
  16743. memcpy(&ShmOCPP20Data->SetMonitoringLevel.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetMonitoringLevel.guid));
  16744. // Required data
  16745. if(json_object_object_get(SetMonitoringLevel, "severity") != NULL)
  16746. ShmOCPP20Data->SetMonitoringLevel.severity = json_object_get_int(json_object_object_get(SetMonitoringLevel, "severity"));
  16747. }
  16748. json_object_put(SetMonitoringLevel);
  16749. /*
  16750. * TODO:
  16751. * Configure monitor status and response
  16752. */
  16753. strcpy((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  16754. sendSetMonitoringLevelConfirmation(uuid);
  16755. return result;
  16756. }
  16757. int handleSetNetworkProfileRequest(char *uuid, char *payload)
  16758. {
  16759. mtrace();
  16760. int result = FAIL;
  16761. json_object *SetNetworkProfile;
  16762. DEBUG_INFO("handleSetNetworkProfileRequest...\n");
  16763. SetNetworkProfile = json_tokener_parse(payload);
  16764. if(!is_error(SetNetworkProfile))
  16765. {
  16766. memset(&ShmOCPP20Data->SetNetworkProfile, 0, sizeof(struct SetNetworkProfile_20));
  16767. memcpy(&ShmOCPP20Data->SetNetworkProfile.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.guid));
  16768. // Required data
  16769. if(json_object_object_get(SetNetworkProfile, "configurationSlot") != NULL)
  16770. ShmOCPP20Data->SetNetworkProfile.configurationSlot = json_object_get_int(json_object_object_get(SetNetworkProfile, "configurationSlot"));
  16771. if(json_object_object_get(SetNetworkProfile, "connectionData") != NULL)
  16772. {
  16773. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppVersion") != NULL)
  16774. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppVersion")));
  16775. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport") != NULL)
  16776. {
  16777. if(strcmp(json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport")), "JSON") == 0)
  16778. {
  16779. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport")));
  16780. }
  16781. else
  16782. {
  16783. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Rejected]);
  16784. goto end;
  16785. }
  16786. }
  16787. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl") != NULL)
  16788. {
  16789. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl")));
  16790. if((strncmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl,"wss", 3) == 0) || (strncmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl,"ws", 2) == 0))
  16791. {
  16792. char protocol[10], host[128], path[512], port[10];
  16793. int check = sscanf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl,"%[^:]:%*2[/]%[^:]:%[^/]/%199[^\n]", protocol, host, port, path);
  16794. if(check >= 3)
  16795. {
  16796. DEBUG_INFO("URL: %s\n", ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl);
  16797. DEBUG_INFO("protocol: %s\n",protocol);
  16798. DEBUG_INFO("host: %s\n",host);
  16799. DEBUG_INFO("port: %s\n",port);
  16800. DEBUG_INFO("path: %s\n",path);
  16801. memcpy((char*)ShmOCPP20Data->OcppServerURL, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl));
  16802. }
  16803. else
  16804. {
  16805. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Rejected]);
  16806. goto end;
  16807. }
  16808. }
  16809. else
  16810. {
  16811. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Rejected]);
  16812. goto end;
  16813. }
  16814. }
  16815. else
  16816. {
  16817. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Rejected]);
  16818. goto end;
  16819. }
  16820. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout") != NULL)
  16821. ShmOCPP20Data->SetNetworkProfile.connectionData.messageTimeout = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout"));
  16822. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppInterface") != NULL)
  16823. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppInterface, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppInterface")));
  16824. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn") != NULL)
  16825. {
  16826. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "server") != NULL)
  16827. 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")));
  16828. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "user") != NULL)
  16829. 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")));
  16830. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "group") != NULL)
  16831. 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")));
  16832. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "password") != NULL)
  16833. 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")));
  16834. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "key") != NULL)
  16835. 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")));
  16836. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "type") != NULL)
  16837. 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")));
  16838. }
  16839. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn") != NULL)
  16840. {
  16841. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apn") != NULL)
  16842. {
  16843. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn));
  16844. 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")));
  16845. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn);
  16846. }
  16847. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnUserName") != NULL)
  16848. {
  16849. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName));
  16850. 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")));
  16851. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName);
  16852. }
  16853. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnPassword") != NULL)
  16854. {
  16855. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword));
  16856. 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")));
  16857. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword);
  16858. }
  16859. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "simPin") != NULL)
  16860. 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"));
  16861. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "preferredNetwork") != NULL)
  16862. 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")));
  16863. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "useOnlyPreferredNetwork") != NULL)
  16864. 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"));
  16865. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnAuthentication") != NULL)
  16866. 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")));
  16867. }
  16868. DB_addNetworkProfile(ShmOCPP20Data->SetNetworkProfile.configurationSlot, (char*)json_object_get_string(json_object_object_get(SetNetworkProfile, "connectionData")));
  16869. }
  16870. }
  16871. json_object_put(SetNetworkProfile);
  16872. /*
  16873. * TODO:
  16874. * 1. Process network configuration and response
  16875. */
  16876. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP12]) == 0)
  16877. {
  16878. }
  16879. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP15]) == 0)
  16880. {
  16881. }
  16882. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP16]) == 0)
  16883. {
  16884. }
  16885. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP20]) == 0)
  16886. {
  16887. }
  16888. else
  16889. {
  16890. }
  16891. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, OCPPTransportEnumTypeStr[OCPPTransportEnumType_JSON]) == 0)
  16892. {
  16893. }
  16894. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, OCPPTransportEnumTypeStr[OCPPTransportEnumType_SOAP]) == 0)
  16895. {
  16896. }
  16897. else
  16898. {
  16899. }
  16900. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired0]) == 0)
  16901. {
  16902. }
  16903. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired1]) == 0)
  16904. {
  16905. }
  16906. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired2]) == 0)
  16907. {
  16908. }
  16909. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired3]) == 0)
  16910. {
  16911. }
  16912. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless0]) == 0)
  16913. {
  16914. }
  16915. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless1]) == 0)
  16916. {
  16917. }
  16918. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless2]) == 0)
  16919. {
  16920. }
  16921. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless3]) == 0)
  16922. {
  16923. }
  16924. else
  16925. {
  16926. }
  16927. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_IKEv2]) == 0)
  16928. {
  16929. }
  16930. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_IPSec]) == 0)
  16931. {
  16932. }
  16933. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_L2TP]) == 0)
  16934. {
  16935. }
  16936. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_PPTP]) == 0)
  16937. {
  16938. }
  16939. else
  16940. {
  16941. }
  16942. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_CHAP]) == 0)
  16943. {
  16944. }
  16945. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_NONE]) == 0)
  16946. {
  16947. }
  16948. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_PAP]) == 0)
  16949. {
  16950. }
  16951. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_AUTO]) == 0)
  16952. {
  16953. }
  16954. else
  16955. {
  16956. }
  16957. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Accepted]);
  16958. end:
  16959. sendSetNetworkProfileConfirmation(uuid);
  16960. return result;
  16961. }
  16962. int handleSetVariableMonitoringRequest(char *uuid, char *payload)
  16963. {
  16964. mtrace();
  16965. int result = FAIL;
  16966. json_object *SetVariableMonitoring;
  16967. uint8_t variableQuantity = 0;
  16968. DEBUG_INFO("handleSetVariableMonitoringRequest...\n");
  16969. SetVariableMonitoring = json_tokener_parse(payload);
  16970. if(!is_error(SetVariableMonitoring))
  16971. {
  16972. memset(&ShmOCPP20Data->SetVariableMonitoring, 0, sizeof(struct SetVariableMonitoring_20));
  16973. memcpy(&ShmOCPP20Data->SetVariableMonitoring.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetVariableMonitoring.guid));
  16974. // Required data
  16975. for(int idx=0;idx<json_object_array_length(json_object_object_get(SetVariableMonitoring, "setMonitoringData"));idx++)
  16976. {
  16977. variableQuantity++;
  16978. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "id") != NULL)
  16979. {
  16980. 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"));
  16981. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].id = ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].id;
  16982. }
  16983. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "value") != NULL)
  16984. {
  16985. 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"));
  16986. }
  16987. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "type") != NULL)
  16988. {
  16989. 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")));
  16990. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type, (char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type);
  16991. }
  16992. else
  16993. {
  16994. sprintf((char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type, "Actual");
  16995. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type, (char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type);
  16996. }
  16997. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "severity") != NULL)
  16998. {
  16999. 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"));
  17000. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].severity = ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].severity;
  17001. }
  17002. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "transaction") != NULL)
  17003. {
  17004. 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"));
  17005. }
  17006. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component") != NULL)
  17007. {
  17008. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "name") != NULL)
  17009. {
  17010. 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")));
  17011. }
  17012. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "instance") != NULL)
  17013. {
  17014. 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")));
  17015. }
  17016. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "component"), "evse") != NULL)
  17017. {
  17018. 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)
  17019. {
  17020. 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"));
  17021. }
  17022. 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)
  17023. {
  17024. 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"));
  17025. }
  17026. }
  17027. memcpy(&ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component, &ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].component, sizeof(struct ComponentType));
  17028. }
  17029. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "variable") != NULL)
  17030. {
  17031. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "variable"), "name") != NULL)
  17032. {
  17033. 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")));
  17034. }
  17035. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "variable"), "instance") != NULL)
  17036. {
  17037. 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")));
  17038. }
  17039. memcpy(&ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable , &ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].variable, sizeof(struct VariableType));
  17040. }
  17041. /*
  17042. * TODO
  17043. * Set Variables and save to DB
  17044. */
  17045. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status, SetMonitoringStatusEnumTypeStr[SetMonitoringStatusEnumType_Accepted]);
  17046. }
  17047. }
  17048. json_object_put(SetVariableMonitoring);
  17049. sendSetVariableMonitoringConfirmation(uuid, variableQuantity);
  17050. return result;
  17051. }
  17052. int handleSetVariablesRequest(char *uuid, char *payload)
  17053. {
  17054. mtrace();
  17055. uint8_t result = FAIL;
  17056. uint8_t isUnknownComponent = TRUE;
  17057. uint8_t isNeedReconnect = FALSE;
  17058. json_object *SetVariables;
  17059. DEBUG_INFO("handleSetVariablesRequest...\n");
  17060. SetVariables = json_tokener_parse(payload);
  17061. if(!is_error(SetVariables))
  17062. {
  17063. memset(&ShmOCPP20Data->SetVariables, 0, sizeof(struct SetVariables_20));
  17064. memcpy(&ShmOCPP20Data->SetVariables.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetVariables.guid));
  17065. // Required data
  17066. for(int idx=0;idx<json_object_array_length(json_object_object_get(SetVariables, "setVariableData"));idx++)
  17067. {
  17068. if(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx) != NULL)
  17069. {
  17070. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component") != NULL)
  17071. {
  17072. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "name") != NULL)
  17073. {
  17074. 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")));
  17075. }
  17076. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "instance") != NULL)
  17077. {
  17078. 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")));
  17079. }
  17080. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "evse") != NULL)
  17081. {
  17082. 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)
  17083. {
  17084. 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"));
  17085. }
  17086. 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)
  17087. {
  17088. 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"));
  17089. }
  17090. }
  17091. memcpy(&ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component, &ShmOCPP20Data->SetVariables.setVariableData[idx].component, sizeof(struct ComponentType));
  17092. }
  17093. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable") != NULL)
  17094. {
  17095. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "name") != NULL)
  17096. {
  17097. 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")));
  17098. }
  17099. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "instance") != NULL)
  17100. {
  17101. 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")));
  17102. }
  17103. memcpy(&ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable , &ShmOCPP20Data->SetVariables.setVariableData[idx].variable, sizeof(struct VariableType));
  17104. }
  17105. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeType") != NULL)
  17106. {
  17107. 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")));
  17108. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeType);
  17109. }
  17110. if(strlen((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType) == 0)
  17111. {
  17112. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType, "Actual");
  17113. }
  17114. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeValue") != NULL)
  17115. {
  17116. 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")));
  17117. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownComponent]);
  17118. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  17119. {
  17120. if((strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name) != NULL) &&
  17121. (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) &&
  17122. (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name) != NULL) &&
  17123. (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))
  17124. {
  17125. isUnknownComponent = FALSE;
  17126. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17127. //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);
  17128. if(strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.dataType,DataEnumTypeStr[DataEnumType_decimal]) == 0)
  17129. {
  17130. if(isNumber(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,TRUE)!=YES)
  17131. {
  17132. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17133. break;
  17134. }
  17135. }
  17136. else if(strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.dataType,DataEnumTypeStr[DataEnumType_integer]) == 0)
  17137. {
  17138. if(isNumber(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue, FALSE)!=YES)
  17139. {
  17140. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17141. break;
  17142. }
  17143. }
  17144. else if(strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.dataType,DataEnumTypeStr[DataEnumType_dateTime]) == 0)
  17145. {
  17146. if(isMatchTimeFormat(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)!=YES)
  17147. {
  17148. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17149. break;
  17150. }
  17151. }
  17152. else if(strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.dataType,DataEnumTypeStr[DataEnumType_boolean]) == 0)
  17153. {
  17154. // To make sure all boolean value is in uppercase
  17155. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"true") != NULL) ||
  17156. (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"True") != NULL) ||
  17157. (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"TRUE") != NULL))
  17158. {
  17159. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"true");
  17160. }
  17161. else if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"false") != NULL) ||
  17162. (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"False") != NULL) ||
  17163. (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"FALSE") != NULL))
  17164. {
  17165. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,"false");
  17166. }
  17167. else
  17168. {
  17169. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17170. break;
  17171. }
  17172. }
  17173. if((strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].type, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeType) == NULL) &&
  17174. (json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeType") != NULL))
  17175. {
  17176. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_NotSupportedAttributeType]);
  17177. break;
  17178. }
  17179. if(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].mutability, MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]) != NULL)
  17180. {
  17181. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17182. break;
  17183. }
  17184. if(((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "AuthCtrlr") != NULL)) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "Enabled") != NULL))
  17185. {
  17186. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  17187. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  17188. tmp[tmpidx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  17189. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  17190. {
  17191. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "true" : "false");
  17192. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17193. if(strstr((char*)tmp, "true") != NULL)
  17194. {
  17195. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = AUTH_MODE_ENABLE;
  17196. }
  17197. else
  17198. {
  17199. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = AUTH_MODE_DISABLE;
  17200. }
  17201. //StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  17202. }
  17203. else
  17204. {
  17205. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17206. break;
  17207. }
  17208. }
  17209. if(((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL)) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "NetworkConfigurationPriority") != NULL))
  17210. {
  17211. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_RebootRequired]);
  17212. }
  17213. else
  17214. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17215. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "WebSocketPingInterval") != NULL))
  17216. {
  17217. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < 10) )
  17218. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17219. else
  17220. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17221. }
  17222. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "HeartbeatInterval") != NULL))
  17223. {
  17224. if((atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  17225. {
  17226. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17227. }
  17228. else
  17229. HeartBeatWaitTime = atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  17230. }
  17231. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "StatusNotificationPeriodically") != NULL))
  17232. {
  17233. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  17234. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  17235. tmp[tmpidx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  17236. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  17237. {
  17238. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "true" : "false");
  17239. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17240. }
  17241. else
  17242. {
  17243. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17244. break;
  17245. }
  17246. }
  17247. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "StatusNotificationInterval") != NULL))
  17248. {
  17249. if((atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  17250. {
  17251. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17252. }
  17253. else
  17254. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17255. }
  17256. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "CharingProfileRefreshInterval") != NULL))
  17257. {
  17258. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  17259. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17260. else
  17261. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17262. }
  17263. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "MessageAttempts") != NULL))
  17264. {
  17265. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  17266. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17267. else
  17268. {
  17269. TransactionMessageAttemptsValue = atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  17270. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17271. }
  17272. }
  17273. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "MessageAttemptInterval") != NULL))
  17274. {
  17275. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  17276. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17277. else
  17278. {
  17279. TransactionMessageRetryIntervalValue = atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  17280. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17281. }
  17282. }
  17283. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "RfidEndianType") != NULL))
  17284. {
  17285. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  17286. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  17287. tmp[tmpidx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  17288. if((strstr((char*)tmp, "big") != NULL) || (strstr((char*)tmp, "little") != NULL))
  17289. {
  17290. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "big") != NULL)? "big" : "little");
  17291. ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian = (strstr((char*)tmp, "big") != NULL)?1:0;
  17292. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17293. }
  17294. else
  17295. {
  17296. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17297. break;
  17298. }
  17299. }
  17300. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "AuthorizeTimeout") != NULL))
  17301. {
  17302. if((atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) <=0) ||
  17303. (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) ||
  17304. (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) > (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.maxLimit))
  17305. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17306. else
  17307. {
  17308. TransactionMessageRetryIntervalValue = atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  17309. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17310. }
  17311. }
  17312. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "EnableAcCcs") != NULL))
  17313. {
  17314. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  17315. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  17316. tmp[tmpidx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  17317. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  17318. {
  17319. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "true" : "false");
  17320. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17321. }
  17322. else
  17323. {
  17324. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17325. break;
  17326. }
  17327. }
  17328. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "SecurityCtrlr") != NULL) &&
  17329. ((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "SecurityProfile") != NULL) || (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "BasicAuthPassword") != NULL)))
  17330. {
  17331. isNeedReconnect = TRUE;
  17332. //StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  17333. //SetOcppConnStatus(FALSE);
  17334. }
  17335. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "AlignedDataCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "Interval") != NULL))
  17336. {
  17337. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  17338. {
  17339. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17340. }
  17341. else
  17342. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17343. }
  17344. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "AlignedDataCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "SendDuringIdle") != NULL))
  17345. {
  17346. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  17347. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  17348. tmp[tmpidx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  17349. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  17350. {
  17351. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "true" : "false");
  17352. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17353. }
  17354. else
  17355. {
  17356. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17357. break;
  17358. }
  17359. }
  17360. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "AlignedDataCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "SignReadings") != NULL))
  17361. {
  17362. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  17363. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  17364. tmp[tmpidx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  17365. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  17366. {
  17367. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "true" : "false");
  17368. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17369. }
  17370. else
  17371. {
  17372. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Rejected]);
  17373. break;
  17374. }
  17375. }
  17376. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "SampledDataCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "TxUpdatedInterval") != NULL))
  17377. {
  17378. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  17379. {
  17380. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17381. }
  17382. else
  17383. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17384. }
  17385. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "ChargingStation") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "FreeVend") != NULL))
  17386. {
  17387. char tmp[ARRAY_SIZE(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)];
  17388. for(int tmpidx=0;tmpidx<ARRAY_SIZE(tmp);tmpidx++)
  17389. tmp[tmpidx] = tolower(ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue[tmpidx]);
  17390. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  17391. {
  17392. strcpy((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue,(strstr((char*)tmp, "true") != NULL)? "true" : "false");
  17393. ShmSysConfigAndInfo->SysConfig.AuthorisationMode =((strstr((char*)tmp, "true") != NULL)? 1 : 0);
  17394. //StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  17395. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17396. }
  17397. }
  17398. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "ChargingStation") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "FreeVendIdtag") != NULL))
  17399. {
  17400. if(strlen((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) > 20)
  17401. {
  17402. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17403. }
  17404. else
  17405. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17406. }
  17407. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "ChargingStation") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "OffLineMaxChargingPower") != NULL))
  17408. {
  17409. if(atoi((const char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) > modelnameInfo.ratedPower)
  17410. {
  17411. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  17412. }
  17413. else
  17414. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  17415. }
  17416. if((strstr((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]) != NULL) ||
  17417. (strstr((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_RebootRequired]) != NULL))
  17418. {
  17419. strcpy((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  17420. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[idx_var]);
  17421. }
  17422. break;
  17423. }
  17424. else
  17425. {
  17426. // When there is no matched variable, check the component name again
  17427. if(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name) != NULL)
  17428. {
  17429. isUnknownComponent = FALSE;
  17430. }
  17431. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownVariable]);
  17432. }
  17433. }
  17434. if(isUnknownComponent == TRUE)
  17435. {
  17436. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownComponent]);
  17437. }
  17438. }
  17439. }
  17440. }
  17441. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  17442. sendSetVariableConfirmation(uuid, json_object_array_length(json_object_object_get(SetVariables, "setVariableData")));
  17443. if(isNeedReconnect)
  17444. {
  17445. SetOcppConnStatus(FALSE);
  17446. }
  17447. }
  17448. json_object_put(SetVariables);
  17449. return result;
  17450. }
  17451. int handleTriggerMessageRequest(char *uuid, char *payload)
  17452. {
  17453. mtrace();
  17454. int result = FAIL;
  17455. int evseIdIsNULL = FALSE;
  17456. //int connectorIdIsNULL = FALSE;
  17457. int evseIdInt =0;
  17458. //int connectorIdInt =0;
  17459. json_object *TriggerMessage;
  17460. DEBUG_INFO("handleTriggerMessageRequest\n");
  17461. TriggerMessage = json_tokener_parse(payload);
  17462. if(!is_error(TriggerMessage))
  17463. {
  17464. memset(&ShmOCPP20Data->TriggerMessage, 0, sizeof(struct TriggerMessage_20));
  17465. memcpy(&ShmOCPP20Data->TriggerMessage.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->TriggerMessage.guid));
  17466. // Required data
  17467. if(json_object_object_get(TriggerMessage, "requestedMessage") != NULL)
  17468. sprintf((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(TriggerMessage, "requestedMessage")));
  17469. // Optional data
  17470. if(json_object_object_get(TriggerMessage, "evse") != NULL)
  17471. {
  17472. // Required data
  17473. if(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "id") != NULL)
  17474. {
  17475. ShmOCPP20Data->TriggerMessage.evse.id = json_object_get_int(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "id"));
  17476. evseIdInt = ShmOCPP20Data->TriggerMessage.evse.id;
  17477. }
  17478. else
  17479. evseIdIsNULL = TRUE;
  17480. // Optional data
  17481. if(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "connectorId") != NULL)
  17482. {
  17483. ShmOCPP20Data->TriggerMessage.evse.connectorId = json_object_get_int(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "connectorId"));
  17484. //connectorIdInt = ShmOCPP20Data->TriggerMessage.evse.connectorId;
  17485. }
  17486. //else
  17487. //connectorIdIsNULL = TRUE;
  17488. }
  17489. else
  17490. evseIdIsNULL = TRUE;
  17491. }
  17492. json_object_put(TriggerMessage);
  17493. if((evseIdIsNULL == TRUE) || ((evseIdIsNULL == FALSE) && ((evseIdInt > 0) && (evseIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  17494. {
  17495. if((strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_BootNotification]) != 0) &&
  17496. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_LogStatusNotification]) != 0) &&
  17497. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_FirmwareStatusNotification]) != 0 ) &&
  17498. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_Heartbeat]) != 0) &&
  17499. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_MeterValues]) != 0) &&
  17500. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) != 0 ) &&
  17501. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignV2GCertificate]) != 0 ) &&
  17502. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_StatusNotification]) != 0 ) &&
  17503. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_TransactionEvent]) != 0 ) &&
  17504. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignCombinedCertificate]) != 0 ) &&
  17505. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_PublishFirmwareStatusNotification]) != 0 ))
  17506. {
  17507. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_NotImplemented] );
  17508. sendTriggerMessageConfirmation(uuid);
  17509. return TRUE;
  17510. }
  17511. else
  17512. {
  17513. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Accepted] );
  17514. sendTriggerMessageConfirmation(uuid);
  17515. }
  17516. }
  17517. else if(evseIdIsNULL == FALSE && ((evseIdInt <= 0) || (evseIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  17518. {
  17519. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Rejected] );
  17520. sendTriggerMessageConfirmation(uuid);
  17521. return TRUE;
  17522. }
  17523. //==========================
  17524. // Trigger message
  17525. //==========================
  17526. if( strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_FirmwareStatusNotification]) == 0)
  17527. {
  17528. if((strlen((char*)ShmOCPP20Data->FirmwareStatusNotification.status) == 0) ||
  17529. ((FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Downloading) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Downloaded) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Idle) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Installing)))
  17530. {
  17531. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle;
  17532. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  17533. }
  17534. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17535. }
  17536. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_LogStatusNotification]) == 0 )
  17537. {
  17538. if(strlen((char*)ShmOCPP20Data->LogStatusNotification.status) == 0)
  17539. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Idle]);
  17540. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  17541. }
  17542. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_BootNotification]) == 0 )
  17543. {
  17544. if(server_sign)
  17545. {
  17546. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Rejected] );
  17547. sendTriggerMessageConfirmation(uuid);
  17548. return TRUE;
  17549. }
  17550. else
  17551. {
  17552. if(DB_updateBootType(BootReasonEnumType_Triggered))
  17553. server_sign = FALSE;
  17554. }
  17555. }
  17556. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_Heartbeat]) == 0 )
  17557. {
  17558. refreshStartTimer(&clientTime.Heartbeat);
  17559. clientTime.Heartbeat.tv_sec -= ShmOCPP20Data->BootNotification.Response_interval;
  17560. }
  17561. else if (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_MeterValues]) == 0 )
  17562. {
  17563. if(evseIdIsNULL == FALSE)
  17564. {
  17565. if((evseIdInt > 0) && ((evseIdInt-1) < gunTotalNumber))
  17566. {
  17567. cpinitateMsg.bits[evseIdInt-1].TriggerMeterValueReq = ON;
  17568. }
  17569. }
  17570. else
  17571. {
  17572. for(int idx=0;idx< gunTotalNumber;idx++)
  17573. {
  17574. cpinitateMsg.bits[idx].TriggerMeterValueReq = ON;
  17575. }
  17576. }
  17577. }
  17578. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_StatusNotification]) == 0 )
  17579. {
  17580. if(evseIdIsNULL == FALSE)
  17581. {
  17582. if((evseIdInt > 0) && ((evseIdInt-1) < gunTotalNumber))
  17583. {
  17584. cpinitateMsg.bits[evseIdInt-1].TriggerStatusNotificationReq = ON;
  17585. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  17586. }
  17587. }
  17588. else
  17589. {
  17590. for(int idx=0;idx< gunTotalNumber;idx++)
  17591. {
  17592. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = ON;
  17593. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  17594. }
  17595. }
  17596. }
  17597. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) == 0 )
  17598. {
  17599. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  17600. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  17601. {
  17602. 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\" &");
  17603. }
  17604. }
  17605. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignV2GCertificate]) == 0 )
  17606. {
  17607. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  17608. if(access("/Storage/OCPP/certV2G.csr",F_OK) == -1)
  17609. {
  17610. 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\" &");
  17611. }
  17612. }
  17613. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_TransactionEvent]) == 0 )
  17614. {
  17615. if(evseIdIsNULL == FALSE)
  17616. {
  17617. if((evseIdInt > 0) && ((evseIdInt -1) < gunTotalNumber))
  17618. {
  17619. //ShmOCPP20Data->CpMsg.bits[connectorIdInt -1].TransactionEventReq = ON;
  17620. cpinitateMsg.bits[evseIdInt -1].TriggerTransactionEventReq = ON;
  17621. }
  17622. }
  17623. else
  17624. {
  17625. for(int idx=0;idx< gunTotalNumber;idx++)
  17626. {
  17627. //ShmOCPP20Data->CpMsg.bits[idx].TransactionEventReq = ON;
  17628. cpinitateMsg.bits[idx].TriggerTransactionEventReq = ON;
  17629. }
  17630. }
  17631. }
  17632. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignCombinedCertificate]) == 0 )
  17633. {
  17634. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  17635. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  17636. {
  17637. 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\" &");
  17638. }
  17639. if(access("/Storage/OCPP/certV2G.csr",F_OK) == -1)
  17640. {
  17641. 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\" &");
  17642. }
  17643. }
  17644. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_PublishFirmwareStatusNotification]) == 0 )
  17645. {
  17646. ShmOCPP20Data->MsMsg.bits.PublishFirmwareReq = ON;
  17647. }
  17648. return result;
  17649. }
  17650. int handleUnlockConnectorRequest(char *uuid, char *payload)
  17651. {
  17652. mtrace();
  17653. int result = FAIL;
  17654. int evseIdInt =0;
  17655. int tempIndex = 0;
  17656. json_object *UnlockConnector;
  17657. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  17658. UnlockConnector = json_tokener_parse(payload);
  17659. if(!is_error(UnlockConnector))
  17660. {
  17661. if(json_object_object_get(UnlockConnector, "evseId") != NULL)
  17662. {
  17663. evseIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "evseId"));
  17664. ShmOCPP20Data->UnlockConnector[(evseIdInt>0?evseIdInt-1:0)].evseId = evseIdInt;
  17665. //it should not be array!!
  17666. }
  17667. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  17668. {
  17669. if(json_object_get_int(json_object_object_get(UnlockConnector, "connectorId")) != 1)
  17670. {
  17671. sprintf((char*)ShmOCPP20Data->UnlockConnector[evseIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  17672. goto end;
  17673. }
  17674. }
  17675. }
  17676. json_object_put(UnlockConnector);
  17677. DEBUG_INFO("Unlock evseIdInt = %d\n",evseIdInt);
  17678. if(gunTotalNumber == 0)
  17679. {
  17680. sprintf((char*)ShmOCPP20Data->UnlockConnector[evseIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  17681. goto end;
  17682. }
  17683. else if((evseIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (evseIdInt <= 0))
  17684. {
  17685. sprintf((char*)ShmOCPP20Data->UnlockConnector[evseIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  17686. goto end;
  17687. }
  17688. else
  17689. {
  17690. memset(&ShmOCPP20Data->UnlockConnector[evseIdInt-1], 0, sizeof(struct UnlockConnector_20));
  17691. memcpy(&ShmOCPP20Data->UnlockConnector[evseIdInt-1].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->UnlockConnector[evseIdInt-1].guid));
  17692. //check Transaction active
  17693. if(gunType[evseIdInt-1] == GUN_TYPE_CHAdeMO)
  17694. {
  17695. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17696. {
  17697. tempIndex = (((evseIdInt -1)==2) ? 1: 0);
  17698. }
  17699. else
  17700. {
  17701. tempIndex = evseIdInt -1;
  17702. }
  17703. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  17704. {
  17705. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  17706. {
  17707. //stop Transaction
  17708. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].UnlockConnectorReq = ON;
  17709. }
  17710. }
  17711. }
  17712. else if(gunType[evseIdInt-1] == GUN_TYPE_CCS)
  17713. {
  17714. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17715. {
  17716. tempIndex = (((evseIdInt -1)==2) ? 1: 0);
  17717. }
  17718. else
  17719. {
  17720. tempIndex = evseIdInt -1;
  17721. }
  17722. for (int index = 0; index < CCS_QUANTITY; index++)
  17723. {
  17724. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  17725. {
  17726. //stop Transaction
  17727. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].UnlockConnectorReq = ON;
  17728. }
  17729. }
  17730. }
  17731. else if(gunType[evseIdInt-1] == GUN_TYPE_GBT)
  17732. {
  17733. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  17734. {
  17735. tempIndex = (((evseIdInt -1)==2) ? 1: 0);
  17736. }
  17737. else
  17738. {
  17739. tempIndex = evseIdInt -1;
  17740. }
  17741. for (int index = 0; index < GB_QUANTITY; index++)
  17742. {
  17743. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  17744. {
  17745. //stop Transaction
  17746. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].UnlockConnectorReq = ON;
  17747. }
  17748. }
  17749. }
  17750. else if(gunType[evseIdInt-1] == GUN_TYPE_DO)
  17751. {
  17752. tempIndex = evseIdInt -1;
  17753. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  17754. {
  17755. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  17756. {
  17757. //stop Transaction
  17758. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].UnlockConnectorReq = ON;
  17759. }
  17760. }
  17761. }
  17762. else
  17763. {
  17764. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  17765. {
  17766. tempIndex = 2;
  17767. }
  17768. else
  17769. {
  17770. tempIndex = evseIdInt-1;
  17771. }
  17772. for (int index = 0; index < AC_QUANTITY; index++)
  17773. {
  17774. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  17775. {
  17776. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].UnlockConnectorReq = ON;
  17777. }
  17778. }
  17779. }
  17780. ShmOCPP20Data->UnlockConnector[evseIdInt-1].connectorId = evseIdInt;
  17781. strcpy((char *)ShmOCPP20Data->UnlockConnector[evseIdInt-1].guid, uuid);
  17782. result = TRUE;
  17783. return result;
  17784. }
  17785. end:
  17786. ShmOCPP20Data->CsMsg.bits[evseIdInt-1].UnlockConnectorConf = ON;
  17787. return result;
  17788. }
  17789. int handleUnpublishFirmwareRequest(char *uuid, char *payload)
  17790. {
  17791. mtrace();
  17792. int result = FAIL;
  17793. json_object *UnpublishFirmware;
  17794. DEBUG_INFO("handleUnpublishFirmwareRequest...\n");
  17795. UnpublishFirmware = json_tokener_parse(payload);
  17796. if(!is_error(UnpublishFirmware))
  17797. {
  17798. memset(&ShmOCPP20Data->UnpublishFirmware, 0, sizeof(struct UnpublishFirmware_20));
  17799. memcpy(&ShmOCPP20Data->UnpublishFirmware.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->UnpublishFirmware.guid));
  17800. // Required data
  17801. if(json_object_object_get(UnpublishFirmware, "checksum") != NULL)
  17802. sprintf((char*)ShmOCPP20Data->UnpublishFirmware.checksum, json_object_get_string(json_object_object_get(UnpublishFirmware, "checksum")));
  17803. }
  17804. json_object_put(UnpublishFirmware);
  17805. ShmOCPP20Data->MsMsg.bits.UnpublishFirmwareReq = ON;
  17806. /*
  17807. * TODO:
  17808. * 1. Check unpublished status
  17809. */
  17810. sprintf((char*)ShmOCPP20Data->UnpublishFirmware.Response_status, UnpublishFirmwareStatusEnumTypeStr[Unpublished_NoFirmware]);
  17811. sendUnpublishFirmwareConfirmation(uuid);
  17812. return result;
  17813. }
  17814. static char UpdateFirmwarepayloadData[512]={0};
  17815. void *UpdateFirmwareProcess(void *data)
  17816. {
  17817. pthread_detach(pthread_self());
  17818. mtrace();
  17819. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  17820. int port=0;
  17821. int isSuccess = 0;
  17822. char ftpbuf[1024];
  17823. char temp[1024];
  17824. char * pch;
  17825. DEBUG_INFO("handleUpdateFirmwareRequest...\n");
  17826. json_object *UpdateFirmware;
  17827. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  17828. if(!is_error(UpdateFirmware))
  17829. {
  17830. // Required data
  17831. if(json_object_object_get(UpdateFirmware, "requestId"))
  17832. {
  17833. ShmOCPP20Data->UpdateFirmware.requestId = json_object_get_int(json_object_object_get(UpdateFirmware, "requestId"));
  17834. }
  17835. if(json_object_object_get(UpdateFirmware, "firmware"))
  17836. {
  17837. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "location") != NULL)
  17838. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "location")));
  17839. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "retrieveDate") != NULL)
  17840. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "retrieveDate")));
  17841. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "installDateTime") != NULL)
  17842. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.installDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "installDateTime")));
  17843. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signingCertificate") != NULL)
  17844. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.signingCertificate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signingCertificate")));
  17845. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signature") != NULL)
  17846. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.signature, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signature")));
  17847. }
  17848. // Optional data
  17849. if(json_object_object_get(UpdateFirmware, "retries"))
  17850. {
  17851. ShmOCPP20Data->UpdateFirmware.retries = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  17852. }
  17853. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  17854. {
  17855. ShmOCPP20Data->UpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  17856. }
  17857. }
  17858. json_object_put(UpdateFirmware);
  17859. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  17860. memset(path, 0, ARRAY_SIZE(path));
  17861. // Wait retrieveData
  17862. if(strlen((char*)ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime) > 10)
  17863. {
  17864. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17865. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadScheduled]);
  17866. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17867. do
  17868. {
  17869. sleep(1);
  17870. }while(!isOvertNow(ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime));
  17871. }
  17872. system("rm -f /mnt/*");
  17873. if(strncmp((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"http", 4) == 0)
  17874. {
  17875. sscanf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  17876. sprintf(ftppath,"/%s", path);
  17877. DEBUG_INFO("locationstr: %s\n", ShmOCPP20Data->UpdateFirmware.firmware.location);
  17878. DEBUG_INFO("protocol: %s\n",protocol);
  17879. DEBUG_INFO("host: %s\n",host);
  17880. DEBUG_INFO("path: %s\n",path);
  17881. DEBUG_INFO("ftppath: %s\n",ftppath);
  17882. int ftppathlen=strlen(ftppath);
  17883. int i=1;
  17884. char filenametemp[50];
  17885. while(i < ftppathlen)
  17886. {
  17887. int len=ftppathlen-i;
  17888. if(ftppath[len]== 47) // '/' ascll code: 47
  17889. {
  17890. DEBUG_INFO("compare '/' all right\n");
  17891. break;
  17892. }
  17893. i=i+1;
  17894. }
  17895. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  17896. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  17897. filenametemp[i+1] = 0;
  17898. do
  17899. {
  17900. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17901. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading]);
  17902. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17903. sleep(3);
  17904. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  17905. if(!isSuccess)
  17906. {
  17907. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17908. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  17909. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17910. if(ShmOCPP20Data->UpdateFirmware.retries>0)sleep(ShmOCPP20Data->UpdateFirmware.retryInterval);else sleep(1);
  17911. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17912. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  17913. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17914. }
  17915. else
  17916. {
  17917. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17918. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]);
  17919. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17920. }
  17921. ShmOCPP20Data->UpdateFirmware.retries--;
  17922. }while((isSuccess == 0)&&(ShmOCPP20Data->UpdateFirmware.retries >= 0));
  17923. }
  17924. else if(strncmp((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"ftp", 3) == 0)
  17925. {
  17926. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  17927. memset(temp, 0, ARRAY_SIZE(temp));
  17928. strcpy(ftpbuf, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  17929. int ftppathlen=strlen(ftpbuf);
  17930. int i=1;
  17931. char filenametemp[50];
  17932. while(i < ftppathlen)
  17933. {
  17934. int len=ftppathlen-i;
  17935. if(ftpbuf[len]== 47) // '/' ascll code: 47
  17936. {
  17937. DEBUG_INFO(" compare '/' all right\n");
  17938. break;
  17939. }
  17940. i=i+1;
  17941. }
  17942. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  17943. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  17944. filenametemp[i+1] = 0;
  17945. strncpy(temp, ftpbuf, ftppathlen-i+1);
  17946. pch=strchr(temp,'@');
  17947. if(pch==NULL)
  17948. {
  17949. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  17950. protocol, host, &port, path);
  17951. strcpy(user,"anonymous");
  17952. strcpy(password,"");
  17953. }
  17954. else
  17955. {
  17956. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  17957. protocol, user, password, host, &port, path);
  17958. }
  17959. sscanf(host,"%[^/]%s",host1, path1);
  17960. sprintf(ftppath,"%s", path1);
  17961. if(port == 0)
  17962. {
  17963. port = 21;
  17964. }
  17965. do
  17966. {
  17967. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17968. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading]);
  17969. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17970. sleep(3);
  17971. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  17972. if(!isSuccess)
  17973. {
  17974. //BulldogUtil.sleepMs(interval*1000);
  17975. DEBUG_INFO("Update firmware request and download file fail.\n");
  17976. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17977. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  17978. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17979. if(ShmOCPP20Data->UpdateFirmware.retries>0)sleep(ShmOCPP20Data->UpdateFirmware.retryInterval);else sleep(1);
  17980. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17981. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  17982. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17983. }
  17984. else
  17985. {
  17986. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17987. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]);
  17988. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17989. }
  17990. ShmOCPP20Data->UpdateFirmware.retries--;
  17991. }while((!isSuccess)&&(ShmOCPP20Data->UpdateFirmware.retries >= 0));
  17992. }
  17993. else
  17994. {
  17995. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  17996. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  17997. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  17998. sleep(1);
  17999. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  18000. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  18001. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  18002. }
  18003. if(strstr((char*)ShmOCPP20Data->FirmwareStatusNotification.status, FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]) != NULL)ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq = ON;
  18004. interLock.isUpdateFirmwareGoing = OFF;
  18005. pthread_exit(NULL);
  18006. }
  18007. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  18008. {
  18009. mtrace();
  18010. int result = FAIL;
  18011. pthread_t t;
  18012. sendUpdateFirmwareConfirmation(uuid);
  18013. memset(UpdateFirmwarepayloadData, 0, ARRAY_SIZE(UpdateFirmwarepayloadData));
  18014. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  18015. memset(&ShmOCPP20Data->UpdateFirmware, 0, sizeof(struct UpdateFirmware_20));
  18016. if(!interLock.isUpdateFirmwareGoing)
  18017. {
  18018. interLock.isUpdateFirmwareGoing = ON;
  18019. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  18020. sleep(1);
  18021. }
  18022. else
  18023. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  18024. ShmOCPP20Data->MsMsg.bits.UpdateFirmwareConf = ON;
  18025. return result;
  18026. }
  18027. int handleUnknownRequest(char *uuid, char *payload)
  18028. {
  18029. mtrace();
  18030. int result = FAIL;
  18031. DEBUG_INFO("handleUnknownRequest...\n");
  18032. sendUnknownConfirmation(uuid);
  18033. result = PASS;
  18034. return result;
  18035. }
  18036. //==========================================
  18037. // Handle server response routine
  18038. //==========================================
  18039. void handleAuthorizeResponse(char *payload, int gun_index)
  18040. {
  18041. mtrace();
  18042. DEBUG_INFO("handleAuthorizeResponse...\n");
  18043. json_object *Authorize;
  18044. Authorize = json_tokener_parse(payload);
  18045. if(!is_error(Authorize))
  18046. {
  18047. if(json_object_object_get(Authorize, "idTokenInfo") != NULL)
  18048. {
  18049. // Required data
  18050. sprintf((char *)(char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "status")));
  18051. // Optional data
  18052. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "cacheExpiryDateTime") != NULL)
  18053. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "cacheExpiryDateTime")));
  18054. else
  18055. memset(ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime));
  18056. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "chargingPriority") != NULL)
  18057. ShmOCPP20Data->Authorize.Response_idTokenInfo.chargingPriority = json_object_get_int(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "chargingPriority"));
  18058. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language1") != NULL)
  18059. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.language1, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language1")));
  18060. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "evseId") != NULL)
  18061. {
  18062. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(Authorize, "idTokenInfo"), "evseId"));idx++)
  18063. {
  18064. 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));
  18065. }
  18066. }
  18067. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language2") != NULL)
  18068. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.language2, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language2")));
  18069. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken") != NULL)
  18070. {
  18071. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "idToken") != NULL)
  18072. 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")));
  18073. else
  18074. memset(ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken));
  18075. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "type") != NULL)
  18076. 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")));
  18077. }
  18078. if(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage") != NULL)
  18079. {
  18080. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "format") != NULL)
  18081. 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")));
  18082. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "language") != NULL)
  18083. 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")));
  18084. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "content") != NULL)
  18085. 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")));
  18086. }
  18087. }
  18088. if(json_object_object_get(Authorize, "certificateStatus") != NULL)
  18089. {
  18090. strcpy((char *)ShmOCPP20Data->Authorize.Response_certificateStatus, json_object_get_string(json_object_object_get(Authorize, "certificateStatus")));
  18091. }
  18092. }
  18093. json_object_put(Authorize);
  18094. //Update idTag information to authorization cache if supported
  18095. if((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].value, "true") == 0) &&
  18096. /*(strlen((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken) > 0) &&
  18097. (strlen((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime) >0) &&*/
  18098. strstr((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != NULL)
  18099. {
  18100. DB_addLocalCache(&ShmOCPP20Data->Authorize.idToken, &ShmOCPP20Data->Authorize.Response_idTokenInfo);
  18101. }
  18102. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  18103. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  18104. authorizeRetryTimes = 0;
  18105. }
  18106. void handleBootNotificationResponse(char *payload, int gun_index)
  18107. {
  18108. mtrace();
  18109. char statusStr[12]={0};
  18110. char currentTimeStr[30]={0};
  18111. int intervalInt = 0;
  18112. DEBUG_INFO("handleBootNotificationResponse...\n");
  18113. json_object *BootNotification;
  18114. BootNotification = json_tokener_parse(payload);
  18115. if(!is_error(BootNotification))
  18116. {
  18117. // Required data
  18118. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  18119. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  18120. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  18121. }
  18122. json_object_put(BootNotification);
  18123. DEBUG_INFO("statusStr: %s\n", statusStr);
  18124. ShmOCPP20Data->BootNotification.Response_interval = intervalInt;
  18125. BootNotificationInterval = intervalInt;
  18126. //write back to ShmOCPP20Data->BootNotification
  18127. strcpy((char *)ShmOCPP20Data->BootNotification.Response_currentTime, currentTimeStr);
  18128. strcpy((char *)ShmOCPP20Data->BootNotification.Response_status, statusStr);
  18129. if((strcmp(statusStr, RegistrationStatusEnumTypeStr[RegistrationStatusEnumType_Accepted]) == 0 ))
  18130. {
  18131. if(intervalInt < (int)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.minLimit)
  18132. {
  18133. //Do nothing because the value is out of range.
  18134. }
  18135. else
  18136. {
  18137. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value,"%d", HeartBeatWaitTime);
  18138. HeartBeatWaitTime = intervalInt;
  18139. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  18140. }
  18141. server_sign = TRUE;
  18142. server_pending =FALSE;
  18143. DB_updateBootType(BootReasonEnumType_PowerUp);
  18144. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = ON;
  18145. }
  18146. else if(strcmp(statusStr, RegistrationStatusEnumTypeStr[RegistrationStatusEnumType_Pending]) == 0)
  18147. {
  18148. server_pending = TRUE;
  18149. }
  18150. syncDateTimeRTC(ShmOCPP20Data->BootNotification.Response_currentTime);
  18151. srand(time(NULL));
  18152. refreshStartTimer(&clientTime.Heartbeat);
  18153. clientTime.Heartbeat.tv_sec -= (ShmOCPP20Data->BootNotification.Response_interval-((rand()%8)+3));
  18154. SetOcppConnStatus(TRUE);
  18155. ShmOCPP20Data->SpMsg.bits.BootNotificationConf = ON;
  18156. }
  18157. void handleClearedChargingLimitResponse(char *payload, int gun_index)
  18158. {
  18159. mtrace();
  18160. json_object *ClearedChargingLimit;
  18161. DEBUG_INFO("handleClearedChargingLimitResponse...\n");
  18162. ClearedChargingLimit = json_tokener_parse(payload);
  18163. if(!is_error(ClearedChargingLimit))
  18164. {
  18165. // Required data
  18166. if(json_object_object_get(ClearedChargingLimit,"status") != NULL)
  18167. sprintf((char*)ShmOCPP20Data->ClearChargingProfile[gun_index].Response_status, json_object_get_string(json_object_object_get(ClearedChargingLimit,"status")));
  18168. }
  18169. json_object_put(ClearedChargingLimit);
  18170. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq = OFF;
  18171. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitConf = ON;
  18172. }
  18173. void handleDataTransferResponse(char *payload, int gun_index)
  18174. {
  18175. mtrace();
  18176. json_object *DataTrans;
  18177. DEBUG_INFO("handleDataTransferResponse...\n");
  18178. DataTrans = json_tokener_parse(payload);
  18179. if(!is_error(DataTrans))
  18180. {
  18181. // Required data
  18182. if(json_object_object_get(DataTrans,"status") != NULL)
  18183. sprintf((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_status, json_object_get_string(json_object_object_get(DataTrans,"status")));
  18184. // Optional data
  18185. if(json_object_object_get(DataTrans,"data") != NULL)
  18186. sprintf((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_data, json_object_get_string(json_object_object_get(DataTrans,"data")));
  18187. }
  18188. json_object_put(DataTrans);
  18189. ShmOCPP20Data->CpMsg.bits[gun_index].DataTransferReq = OFF;
  18190. ShmOCPP20Data->CpMsg.bits[gun_index].DataTransferConf = ON;
  18191. }
  18192. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  18193. {
  18194. mtrace();
  18195. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  18196. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = OFF;
  18197. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationConf = ON;
  18198. }
  18199. void handleGet15118EVCertificateResponse(char *payload, int gun_index)
  18200. {
  18201. mtrace();
  18202. json_object *Get15118EVCertificate;
  18203. DEBUG_INFO("handleGet15118EVCertificateResponse...\n");
  18204. Get15118EVCertificate = json_tokener_parse(payload);
  18205. if(!is_error(Get15118EVCertificate))
  18206. {
  18207. // Required data
  18208. if(json_object_object_get(Get15118EVCertificate,"status") != NULL)
  18209. sprintf((char*)ShmOCPP20Data->Get15118EVCertificate.Response_status, json_object_get_string(json_object_object_get(Get15118EVCertificate,"status")));
  18210. // Optional data
  18211. if(json_object_object_get(Get15118EVCertificate,"exiResponse") != NULL)
  18212. sprintf((char*)ShmOCPP20Data->Get15118EVCertificate.Response_exiResponse, json_object_get_string(json_object_object_get(Get15118EVCertificate,"exiResponse")));
  18213. }
  18214. json_object_put(Get15118EVCertificate);
  18215. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq = OFF;
  18216. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateConf = ON;
  18217. }
  18218. void handleGetCertificateStatusResponse(char *payload, int gun_index)
  18219. {
  18220. mtrace();
  18221. json_object *GetCertificateStatus;
  18222. DEBUG_INFO("handleGetCertificateStatusResponse...\n");
  18223. GetCertificateStatus = json_tokener_parse(payload);
  18224. if(!is_error(GetCertificateStatus))
  18225. {
  18226. // Required data
  18227. if(json_object_object_get(GetCertificateStatus,"status") != NULL)
  18228. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_status, json_object_get_string(json_object_object_get(GetCertificateStatus,"status")));
  18229. // Optional data
  18230. if(json_object_object_get(GetCertificateStatus,"ocspResult") != NULL)
  18231. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_ocspResult, json_object_get_string(json_object_object_get(GetCertificateStatus,"ocspResult")));
  18232. if(json_object_object_get(GetCertificateStatus,"statusInfo") != NULL)
  18233. {
  18234. if(json_object_object_get(json_object_object_get(GetCertificateStatus,"statusInfo"), "reasonCode") != NULL)
  18235. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_statusInfo.reasonCode, json_object_get_string(json_object_object_get(json_object_object_get(GetCertificateStatus,"ocspResult"), "reasonCode")));
  18236. if(json_object_object_get(json_object_object_get(GetCertificateStatus,"statusInfo"), "additionalInfo") != NULL)
  18237. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_statusInfo.additionalInfo, json_object_get_string(json_object_object_get(json_object_object_get(GetCertificateStatus,"ocspResult"), "additionalInfo")));
  18238. }
  18239. }
  18240. json_object_put(GetCertificateStatus);
  18241. if(strstr((char*)ShmOCPP20Data->GetCertificateStatus.Response_status, GetCertificateStatusEnumTypeStr[GetCertificateStatusEnumType_Accepted]) != NULL)
  18242. {
  18243. /*
  18244. * TODO:
  18245. * 1. If get certificate response accepted process something here
  18246. */
  18247. }
  18248. ShmOCPP20Data->SpMsg.bits.GetCertificateStatusReq = OFF;
  18249. ShmOCPP20Data->SpMsg.bits.GetCertificateStatusConf = ON;
  18250. }
  18251. void handleHeartbeatResponse(char *payload, int gun_index)
  18252. {
  18253. mtrace();
  18254. DEBUG_INFO("handleHeartbeatResponse...\n");
  18255. json_object *Heartbeat;
  18256. Heartbeat = json_tokener_parse(payload);
  18257. if(!is_error(Heartbeat))
  18258. {
  18259. // Required data
  18260. if(json_object_object_get(Heartbeat,"currentTime") != NULL)
  18261. sprintf((char *)ShmOCPP20Data->Heartbeat.Response_currentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  18262. }
  18263. json_object_put(Heartbeat);
  18264. if(FirstHeartBeat == OFF)
  18265. {
  18266. FirstHeartBeat = ON;
  18267. DEBUG_INFO("FirstHeartBeat \n");
  18268. }
  18269. HeartBeatWithNOResponse = 0;
  18270. refreshStartTimer(&clientTime.Heartbeat);
  18271. syncDateTimeRTC(ShmOCPP20Data->Heartbeat.Response_currentTime);
  18272. }
  18273. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  18274. {
  18275. mtrace();
  18276. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  18277. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  18278. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationConf = ON;
  18279. }
  18280. void handleMeterValuesResponse(char *payload, int gun_index)
  18281. {
  18282. mtrace();
  18283. DEBUG_INFO("handleMeterValuesResponse...\n");
  18284. isQueueSendable = ON;
  18285. }
  18286. void handleNotifyChargingLimitResponse(char *payload, int gun_index)
  18287. {
  18288. mtrace();
  18289. DEBUG_INFO("handleNotifyChargingLimitResponse...\n");
  18290. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitReq = OFF;
  18291. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitConf = ON;
  18292. }
  18293. void handleNotifyCustomerInformationResponse(char *payload, int gun_index)
  18294. {
  18295. mtrace();
  18296. DEBUG_INFO("handleNotifyCustomerInformationResponse...\n");
  18297. }
  18298. void handleNotifyDisplayMessagesResponse(char *payload, int gun_index)
  18299. {
  18300. mtrace();
  18301. DEBUG_INFO("handleNotifyDisplayMessagesResponse...\n");
  18302. ShmOCPP20Data->SpMsg.bits.NotifyDisplayMessagesReq = OFF;
  18303. ShmOCPP20Data->SpMsg.bits.NotifyDisplayMessagesConf = ON;
  18304. }
  18305. void handleNotifyEVChargingNeedsResponse(char *payload, int gun_index)
  18306. {
  18307. mtrace();
  18308. json_object *NotifyEVChargingNeeds;
  18309. DEBUG_INFO("handleNotifyEVChargingNeedsResponse...\n");
  18310. NotifyEVChargingNeeds = json_tokener_parse(payload);
  18311. if(!is_error(NotifyEVChargingNeeds))
  18312. {
  18313. // Required data
  18314. if(json_object_object_get(NotifyEVChargingNeeds,"status") != NULL)
  18315. sprintf((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].Response_status, json_object_get_string(json_object_object_get(NotifyEVChargingNeeds,"status")));
  18316. }
  18317. json_object_put(NotifyEVChargingNeeds);
  18318. //ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitReq = OFF;
  18319. //ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitConf = ON;
  18320. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsReq = OFF;
  18321. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsConf = ON;
  18322. }
  18323. void handleNotifyEVChargingScheduleResponse(char *payload, int gun_index)
  18324. {
  18325. mtrace();
  18326. json_object *NotifyEVChargingSchedule;
  18327. DEBUG_INFO("handleNotifyEVChargingScheduleResponse...\n");
  18328. NotifyEVChargingSchedule = json_tokener_parse(payload);
  18329. if(!is_error(NotifyEVChargingSchedule))
  18330. {
  18331. // Required data
  18332. if(json_object_object_get(NotifyEVChargingSchedule,"status") != NULL)
  18333. sprintf((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].Response_status, json_object_get_string(json_object_object_get(NotifyEVChargingSchedule,"status")));
  18334. }
  18335. json_object_put(NotifyEVChargingSchedule);
  18336. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingScheduleReq = OFF;
  18337. ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingScheduleConf = ON;
  18338. }
  18339. void handleNotifyEventResponse(char *payload, int gun_index)
  18340. {
  18341. mtrace();
  18342. DEBUG_INFO("handleNotifyEventResponse...\n");
  18343. ShmOCPP20Data->SpMsg.bits.NotifyEventReq = OFF;
  18344. ShmOCPP20Data->SpMsg.bits.NotifyEventConf = ON;
  18345. }
  18346. void handleNotifyMonitoringReportResponse(char *payload, int gun_index)
  18347. {
  18348. mtrace();
  18349. DEBUG_INFO("handleNotifyMonitoringReportResponse...\n");
  18350. ShmOCPP20Data->SpMsg.bits.NotifyMonitoringReportReq = OFF;
  18351. ShmOCPP20Data->SpMsg.bits.NotifyMonitoringReportConf = ON;
  18352. }
  18353. void handleNotifyReportResponse(char *payload, int gun_index)
  18354. {
  18355. mtrace();
  18356. DEBUG_INFO("handleNotifyReportResponse...\n");
  18357. ShmOCPP20Data->SpMsg.bits.NotifyReportReq = OFF;
  18358. ShmOCPP20Data->SpMsg.bits.NotifyReportConf = ON;
  18359. }
  18360. void handlePublishFirmwareStatusNotificationResponse(char *payload, int gun_index)
  18361. {
  18362. mtrace();
  18363. DEBUG_INFO("handlePublishFirmwareStatusNotificationResponse...\n");
  18364. ShmOCPP20Data->CsMsg.bits[gun_index].PublishFirmwareStatusNotificationReq = OFF;
  18365. ShmOCPP20Data->CsMsg.bits[gun_index].PublishFirmwareStatusNotificationConf = ON;
  18366. }
  18367. void handleReportChargingProfilesResponse(char *payload, int gun_index)
  18368. {
  18369. mtrace();
  18370. DEBUG_INFO("handleReportChargingProfilesResponse...gun_index: %d\n", gun_index);
  18371. ShmOCPP20Data->SpMsg.bits.ReportChargingProfilesReq = OFF;
  18372. ShmOCPP20Data->SpMsg.bits.ReportChargingProfilesConf = ON;
  18373. }
  18374. void handleReservationStatusUpdateResponse(char *payload, int gun_index)
  18375. {
  18376. mtrace();
  18377. DEBUG_INFO("handleReservationStatusUpdateResponse...gun_index: %d\n", gun_index);
  18378. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = OFF;
  18379. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateConf = ON;
  18380. }
  18381. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  18382. {
  18383. mtrace();
  18384. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  18385. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = OFF;
  18386. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationConf = ON;
  18387. DB_updateSecurityEventType(SecurityEventEnumType_ResetOrReboot);
  18388. }
  18389. void handleSignCertificateResponse(char *payload, int gun_index)
  18390. {
  18391. mtrace();
  18392. json_object *SignCertificate;
  18393. DEBUG_INFO("handleSignCertificateResponse...\n");
  18394. SignCertificate = json_tokener_parse(payload);
  18395. if(!is_error(SignCertificate))
  18396. {
  18397. // Required data
  18398. if(json_object_object_get(SignCertificate,"status") != NULL)
  18399. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_status, json_object_get_string(json_object_object_get(SignCertificate,"status")));
  18400. // Optional data
  18401. if(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "reasonCode") != NULL)
  18402. {
  18403. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_statusInfo.reasonCode, json_object_get_string(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "reasonCode")));
  18404. if(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "additionalInfo") != NULL)
  18405. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_statusInfo.additionalInfo, json_object_get_string(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "additionalInfo")));
  18406. }
  18407. }
  18408. json_object_put(SignCertificate);
  18409. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = OFF;
  18410. ShmOCPP20Data->SpMsg.bits.SignCertificateConf = ON;
  18411. }
  18412. void handleStatusNotificationResponse(char *payload, int gun_index)
  18413. {
  18414. mtrace();
  18415. DEBUG_INFO("handleStatusNotificationResponse...gun_index: %d\n", gun_index);
  18416. //cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  18417. //cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  18418. cpinitateMsg.bits[gun_index].StatusNotificationConf = ON;
  18419. }
  18420. void handleTransactionEventResponse(char *payload, int gun_index)
  18421. {
  18422. mtrace();
  18423. json_object *TransactionEven;
  18424. DEBUG_INFO("handleTransactionEventResponse...\n");
  18425. TransactionEven = json_tokener_parse(payload);
  18426. if(!is_error(TransactionEven))
  18427. {
  18428. // Required data
  18429. // Optional data
  18430. if(json_object_object_get(TransactionEven,"totalCost") != NULL)
  18431. ShmOCPP20Data->TransactionEvent[gun_index].Response_totalCost = json_object_get_double(json_object_object_get(TransactionEven,"totalCost"));
  18432. if(json_object_object_get(TransactionEven,"chargingPriority") != NULL)
  18433. ShmOCPP20Data->TransactionEvent[gun_index].Response_chargingPriority = json_object_get_int(json_object_object_get(TransactionEven,"chargingPriority"));
  18434. if(json_object_object_get(TransactionEven,"idTokenInfo") != NULL)
  18435. {
  18436. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "status") != NULL)
  18437. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "status")));
  18438. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "cacheExpiryDateTime") != NULL)
  18439. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.cacheExpiryDateTime, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "cacheExpiryDateTime")));
  18440. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "chargingPriority") != NULL)
  18441. ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.chargingPriority = json_object_get_int(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "chargingPriority"));
  18442. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "language1") != NULL)
  18443. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.language1, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "language1")));
  18444. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken") != NULL)
  18445. {
  18446. if(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "idToken") != NULL)
  18447. 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")));
  18448. if(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "type") != NULL)
  18449. 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")));
  18450. }
  18451. }
  18452. if(json_object_object_get(TransactionEven,"updatedPersonalMessage") != NULL)
  18453. {
  18454. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "format") != NULL)
  18455. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.format, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "format")));
  18456. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "language") != NULL)
  18457. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.language, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "language")));
  18458. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "content") != NULL)
  18459. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.content, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "content")));
  18460. }
  18461. }
  18462. json_object_put(TransactionEven);
  18463. isQueueSendable = ON;
  18464. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf = ON;
  18465. }
  18466. //==========================================
  18467. // Handle Error routine
  18468. //==========================================
  18469. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  18470. {
  18471. mtrace();
  18472. #ifdef SystemLogMessage
  18473. DEBUG_INFO("errorCode: %s\n", errorCode);
  18474. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  18475. DEBUG_INFO("errorDetails: %s\n", payload);
  18476. #endif
  18477. }
  18478. //===============================================
  18479. // Common routine
  18480. //===============================================
  18481. int initialConfigurationTable(void)
  18482. {
  18483. DEBUG_INFO("initialConfigurationTable...\n");
  18484. memset(&ShmOCPP20Data->ControllerComponentVariable[0], 0, ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable));
  18485. DB_variableIsCreate();
  18486. DB_variableLoadFromDb();
  18487. if(atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].value) != variableVersion)
  18488. {
  18489. DEBUG_WARN("EVSE variable version in local db older than firmware.\n");
  18490. DB_variableClear();
  18491. DB_variableIsCreate();
  18492. DB_variableLoadFromDb();
  18493. }
  18494. DB_getNetworkProfileFromDb();
  18495. //DB_variableMonitoringLoadFromDb();
  18496. return 0;
  18497. }
  18498. int TransactionMessageAttemptsGet(void)
  18499. {
  18500. return TransactionMessageAttemptsValue;
  18501. }
  18502. int FirstHeartBeatResponse(void)
  18503. {
  18504. return FirstHeartBeat;
  18505. }
  18506. int TransactionMessageRetryIntervalGet(void)
  18507. {
  18508. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP20Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  18509. }
  18510. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  18511. {
  18512. int result = TRUE;
  18513. char rmFileCmd[100]={0};
  18514. char FilePath[100]={0};
  18515. char ftpbuf[200];
  18516. int systemresult;
  18517. sprintf(FilePath,"/mnt/%s",filename);
  18518. system("ping 8.8.8.8 &");
  18519. if((access(FilePath,F_OK))!=-1)
  18520. {
  18521. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18522. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18523. system(rmFileCmd);
  18524. }
  18525. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18526. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  18527. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18528. systemresult = system(ftpbuf);
  18529. if(systemresult != 0)
  18530. {
  18531. DEBUG_INFO("HTTP/HTTPS download fail!\n");
  18532. result = FALSE;
  18533. }
  18534. system("pkill ping");
  18535. return result;
  18536. }
  18537. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  18538. {
  18539. int result = TRUE;
  18540. char rmFileCmd[100]={0};
  18541. char FilePath[100]={0};
  18542. char ftpbuf[200];
  18543. int systemresult;
  18544. sprintf(FilePath,"/mnt/%s",filename);
  18545. system("ping 8.8.8.8 &");
  18546. if((access(FilePath,F_OK))!=-1)
  18547. {
  18548. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18549. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18550. system(rmFileCmd);
  18551. }
  18552. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18553. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120",filename, url);
  18554. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18555. systemresult = system(ftpbuf);
  18556. if(systemresult != 0)
  18557. {
  18558. sprintf(ftpbuf, "wget --tries=1 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  18559. DEBUG_INFO("Download command: %s\n",ftpbuf);
  18560. systemresult = system(ftpbuf);
  18561. if(systemresult != 0)
  18562. {
  18563. DEBUG_WARN("FTP download fail!\n");
  18564. result = FALSE;
  18565. }
  18566. }
  18567. system("pkill ping");
  18568. return result;
  18569. }
  18570. int httpUploadFile(char *location, char *path, char *filename,char *url)
  18571. {
  18572. char rmFileCmd[100]={0};
  18573. char FilePath[100]={0};
  18574. char buf[512];
  18575. int systemresult = 0;
  18576. //DEBUG_INFO("filename=%s\n",filename);
  18577. //DEBUG_INFO("url=%s\n",url);
  18578. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  18579. if((access(FilePath,F_OK))!=-1)
  18580. {
  18581. DEBUG_INFO("filename=%s exist.\n",FilePath);
  18582. sprintf(rmFileCmd,"rm -f %s",FilePath);
  18583. system(rmFileCmd);
  18584. }
  18585. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  18586. if(fp == NULL)
  18587. {
  18588. DEBUG_INFO("log is NULL\n");
  18589. return FALSE;
  18590. }
  18591. else
  18592. {
  18593. fprintf(fp, "%s\n", url);
  18594. fprintf(fp, "%s\n", filename);
  18595. fclose(fp);
  18596. }
  18597. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  18598. if(phpFP == NULL)
  18599. {
  18600. DEBUG_INFO("PHP upload fail.\n");
  18601. return FALSE;
  18602. }
  18603. else
  18604. {
  18605. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  18606. {
  18607. if(strstr(buf, "result") != NULL)
  18608. {
  18609. sscanf(buf, "result: %d", &systemresult);
  18610. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  18611. }
  18612. }
  18613. pclose(phpFP);
  18614. }
  18615. if(systemresult != 1)
  18616. {
  18617. DEBUG_WARN("HTTP POST upload error, change to PUT method\n");
  18618. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload_put.php", "r");
  18619. if(phpFP == NULL)
  18620. {
  18621. DEBUG_WARN("PHP PUT upload fail.\n");
  18622. return FALSE;
  18623. }
  18624. else
  18625. {
  18626. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  18627. {
  18628. if(strstr(buf, "result") != NULL)
  18629. {
  18630. sscanf(buf, "result: %d", &systemresult);
  18631. DEBUG_INFO("PHP HTTP PUT upload result: %d\n", systemresult);
  18632. }
  18633. }
  18634. pclose(phpFP);
  18635. }
  18636. }
  18637. if(systemresult != 1)
  18638. {
  18639. DEBUG_WARN("PHP PUT upload fail.\n");
  18640. return FALSE;
  18641. }
  18642. return TRUE;
  18643. }
  18644. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  18645. {
  18646. int result = FALSE;
  18647. char ftpbuf[200];
  18648. int systemresult;
  18649. /*
  18650. // Domaind name transfer to IP address
  18651. struct hostent* server;
  18652. char *IPbuffer;
  18653. server = gethostbyname(location);
  18654. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  18655. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  18656. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  18657. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  18658. systemresult = system(ftpbuf);
  18659. if(systemresult != 0)
  18660. {
  18661. DEBUG_INFO("ftpput error!\n");
  18662. }
  18663. else
  18664. {
  18665. result = TRUE;
  18666. DEBUG_INFO("ftpput OK!\n");
  18667. }
  18668. return result;
  18669. }
  18670. //=========================================
  18671. // Routine
  18672. //=========================================
  18673. int GetOcppServerURL()
  18674. {
  18675. int result = FALSE;
  18676. struct yuarel url;
  18677. char urlStr[512];
  18678. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  18679. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  18680. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  18681. if((ShmOCPP20Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP20Data->OcppServerURL,"") != 0))
  18682. {
  18683. memcpy(urlStr, ShmOCPP20Data->OcppServerURL, ARRAY_SIZE(ShmOCPP20Data->OcppServerURL));
  18684. if(yuarel_parse(&url, urlStr) != -1)
  18685. {
  18686. sprintf(OcppProtocol, "%s", url.scheme);
  18687. sprintf(OcppHost, "%s", url.host);
  18688. if(url.path == NULL)
  18689. OcppTempPath[0] = '\0';
  18690. else
  18691. sprintf(OcppTempPath, "%s", url.path);
  18692. if(url.port == 0)
  18693. {
  18694. if(strcmp(OcppProtocol, "wss") == 0)
  18695. OcppPort = 443;
  18696. else
  18697. OcppPort = 80;
  18698. }
  18699. else
  18700. OcppPort = url.port;
  18701. result = TRUE;
  18702. }
  18703. }
  18704. else
  18705. {
  18706. strcpy(OcppHost,"");
  18707. }
  18708. return result;
  18709. }
  18710. int GetOcppPath()
  18711. {
  18712. int result = FALSE;
  18713. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  18714. {
  18715. if(OcppTempPath == NULL)
  18716. {
  18717. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18718. }
  18719. else
  18720. {
  18721. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18722. }
  18723. result = TRUE;
  18724. }
  18725. else if((ShmOCPP20Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP20Data->ChargeBoxId,"") != 0))
  18726. {
  18727. if(OcppTempPath == NULL)
  18728. {
  18729. sprintf(OcppPath,"/%s",ShmOCPP20Data->ChargeBoxId);
  18730. }
  18731. else
  18732. {
  18733. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP20Data->ChargeBoxId);
  18734. }
  18735. result = TRUE;
  18736. }
  18737. else
  18738. {
  18739. strcpy(OcppPath,"");
  18740. }
  18741. return result;
  18742. }
  18743. int GetOcppPort()
  18744. {
  18745. return OcppPort;
  18746. }
  18747. int GetOcppConnStatus(void)
  18748. {
  18749. return ShmOCPP20Data->OcppConnStatus;
  18750. }
  18751. void SetOcppConnStatus(uint8_t status)
  18752. {
  18753. ShmOCPP20Data->OcppConnStatus = status;
  18754. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  18755. }
  18756. int GetHeartBeatWithNOResponse(void)
  18757. {
  18758. return HeartBeatWithNOResponse;
  18759. }
  18760. void SetHeartBeatWithNOResponse(void)
  18761. {
  18762. HeartBeatWithNOResponse = 0;
  18763. }
  18764. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  18765. void storeTempStopTransaction(int gun_index)
  18766. {
  18767. char TempStopTransaction[256];
  18768. //char message[1024*20]={0};
  18769. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  18770. char guid[37]={0};
  18771. json_object *TransactionEvent = json_object_new_object();
  18772. json_object *transactionInfo = json_object_new_object();
  18773. json_object *idToken = json_object_new_object();
  18774. json_object *evse = json_object_new_object();
  18775. json_object *meterValues = json_object_new_array();
  18776. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  18777. DEBUG_INFO("storeTempStopTransaction...\n");
  18778. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  18779. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  18780. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  18781. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = 1;
  18782. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  18783. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  18784. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  18785. // Message
  18786. json_object_object_add(TransactionEvent, "eventType", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  18787. json_object_object_add(TransactionEvent, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].timestamp));
  18788. json_object_object_add(TransactionEvent, "triggerReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason));
  18789. json_object_object_add(TransactionEvent, "seqNo", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].seqNo+1));
  18790. json_object_object_add(TransactionEvent, "offline", json_object_new_boolean(ShmOCPP20Data->TransactionEvent[gun_index].offline));
  18791. if(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed > 0)
  18792. json_object_object_add(TransactionEvent, "numberOfPhasesUsed", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed));
  18793. if(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent > 0)
  18794. json_object_object_add(TransactionEvent, "cableMaxCurrent", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent));
  18795. if(ShmOCPP20Data->TransactionEvent[gun_index].reservationId > 0)
  18796. json_object_object_add(TransactionEvent, "reservationId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].reservationId));
  18797. json_object_object_add(transactionInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId));
  18798. json_object_object_add(transactionInfo, "chargingState", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState));
  18799. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging > 0)
  18800. json_object_object_add(transactionInfo, "timeSpentCharging", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging));
  18801. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason) > 0)
  18802. json_object_object_add(transactionInfo, "stoppedReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason));
  18803. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId > 0)
  18804. json_object_object_add(transactionInfo, "remoteStartId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId));
  18805. json_object_object_add(TransactionEvent, "transactionInfo", transactionInfo);
  18806. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken) > 0)
  18807. {
  18808. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
  18809. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type));
  18810. json_object_object_add(TransactionEvent, "idToken", idToken);
  18811. }
  18812. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.id));
  18813. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId));
  18814. json_object_object_add(TransactionEvent, "evse", evse);
  18815. meterValueBufferQuery(gun_index, meterValues);
  18816. if(json_object_array_length(meterValues) > 0)
  18817. {
  18818. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  18819. }
  18820. random_uuid(guid);
  18821. sprintf(queuedata,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL
  18822. , guid
  18823. , "TransactionEvent"
  18824. , json_object_to_json_string_ext(TransactionEvent, JSON_C_TO_STRING_PLAIN));
  18825. json_object_put(TransactionEvent);
  18826. // open file for writing
  18827. FILE *outfile;
  18828. outfile = fopen (TempStopTransaction, "w+");
  18829. //DEBUG_INFO("data = %s\n", queuedata);
  18830. fputs(queuedata, outfile);
  18831. fputs("\n", outfile);
  18832. fclose (outfile);
  18833. }
  18834. void checkTempStopTransaction(int gun_index)
  18835. {
  18836. FILE *fptr1;
  18837. char ch;
  18838. char str[QUEUE_MESSAGE_LENGTH]={0};
  18839. char guid[37]={0};
  18840. char tempdata[65]={0};
  18841. char TempStopTransaction[256];
  18842. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  18843. fptr1 = fopen(TempStopTransaction, "r");
  18844. if (!fptr1)
  18845. {
  18846. //DEBUG_INFO("TempStopTransaction20_%d not found or unable to open the input file!\n", (gun_index+1));
  18847. return ;
  18848. }
  18849. ch=fgetc(fptr1);
  18850. rewind(fptr1);
  18851. if(ch!=EOF)
  18852. {
  18853. // copy all contents to the temporary file except the specific line
  18854. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  18855. {
  18856. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  18857. if(str[0]=='\0')
  18858. {
  18859. break;
  18860. }
  18861. strncpy(guid, str+4, 36); //copy guid
  18862. sprintf(tempdata, "TransactionEvent,%d", (gun_index));
  18863. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  18864. {
  18865. //DEBUG_INFO("StopTransaction mapitem pass\n");
  18866. }
  18867. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  18868. memset(str,0,ARRAY_SIZE(str));
  18869. }
  18870. }
  18871. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  18872. fclose(fptr1);
  18873. remove(TempStopTransaction); // remove the original file
  18874. }
  18875. int GetWebSocketPingInterval(void)
  18876. {
  18877. return atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].value);
  18878. }
  18879. int GetServerSign(void)
  18880. {
  18881. return server_sign;
  18882. }
  18883. uint8_t GetOcppSecurityProfile()
  18884. {
  18885. return atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].value);
  18886. }
  18887. void MergeCertificates()
  18888. {
  18889. char cmdBuf[2048]={0};
  18890. if(access(ROOTCA_CS,F_OK) != -1)
  18891. {
  18892. sprintf(cmdBuf, "cat /root/cacert.pem %s > /root/certCA.pem", ROOTCA_CS);
  18893. }
  18894. else
  18895. {
  18896. sprintf(cmdBuf, "cat /root/cacert.pem > /root/certCA.pem");
  18897. }
  18898. system(cmdBuf);
  18899. }
  18900. void GetOcppChargerBoxId(uint8_t *data)
  18901. {
  18902. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  18903. }
  18904. void GetOcppSecurityPassword(uint8_t *data)
  18905. {
  18906. sprintf((char*)data, "%s", ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].value);
  18907. }
  18908. void SetServerSign(int value)
  18909. {
  18910. server_sign = value;
  18911. }
  18912. int GetBootNotificationInterval(void)
  18913. {
  18914. return BootNotificationInterval;
  18915. }
  18916. int GetInternetConn(void)
  18917. {
  18918. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  18919. }
  18920. int GetBackendConnectionTimeout(void)
  18921. {
  18922. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  18923. }
  18924. int isConnectorInitMode(int gun_index)
  18925. {
  18926. int tempIndex = 0;
  18927. int result = TRUE;
  18928. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  18929. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  18930. {
  18931. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18932. {
  18933. tempIndex = ((gun_index==2) ? 1: 0);
  18934. }
  18935. else
  18936. {
  18937. tempIndex = gun_index;
  18938. }
  18939. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  18940. {
  18941. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  18942. {
  18943. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18944. } //end of the same index
  18945. }//end of for CHAdeMO_QUANTITY
  18946. }
  18947. else if(gunType[gun_index] == GUN_TYPE_CCS)
  18948. {
  18949. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18950. {
  18951. tempIndex = ((gun_index==2) ? 1: 0);
  18952. }
  18953. else
  18954. {
  18955. tempIndex = gun_index;
  18956. }
  18957. for (int index = 0; index < CCS_QUANTITY; index++)
  18958. {
  18959. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  18960. {
  18961. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18962. } //end of the same index
  18963. } // end of for CCS_QUANTITY
  18964. }
  18965. else if(gunType[gun_index] == GUN_TYPE_GBT)
  18966. {
  18967. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  18968. {
  18969. tempIndex = ((gun_index==2) ? 1: 0);
  18970. }
  18971. else
  18972. {
  18973. tempIndex = gun_index;
  18974. }
  18975. for (int index = 0; index < GB_QUANTITY; index++)
  18976. {
  18977. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  18978. {
  18979. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18980. } //end of the same index
  18981. } // end of for GB_QUANTITY
  18982. }
  18983. else if(gunType[gun_index] == GUN_TYPE_DO)
  18984. {
  18985. tempIndex = gun_index;
  18986. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  18987. {
  18988. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  18989. {
  18990. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  18991. } //end of the same index
  18992. }
  18993. }
  18994. else
  18995. {
  18996. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  18997. {
  18998. tempIndex = 2;
  18999. }
  19000. else
  19001. {
  19002. tempIndex = gun_index;
  19003. }
  19004. for (int index = 0; index < AC_QUANTITY; index++)
  19005. {
  19006. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  19007. {
  19008. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  19009. }//end of the same index
  19010. }//end of for AC_QUANTITY
  19011. }
  19012. return result;
  19013. }
  19014. void refreshProcDogTimer()
  19015. {
  19016. ShmOCPP20Data->procDogTime = time((time_t*)NULL);
  19017. }
  19018. void InitialSystemValue(void)
  19019. {
  19020. localversion=0;
  19021. BootNotificationInterval = 10;
  19022. authorizeRetryTimes = 0;
  19023. GunStatusInterval = 10;
  19024. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].value);
  19025. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].value);
  19026. //Heart Beat
  19027. HeartBeatWithNOResponse = 0;
  19028. HeartBeatCountPerHour = 0;
  19029. HeartBeatWaitTime = atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value);
  19030. if(HeartBeatWaitTime == 0)
  19031. FirstHeartBeat = TRUE;
  19032. else
  19033. FirstHeartBeat = FALSE;
  19034. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle; // Idle
  19035. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle; // Idle
  19036. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  19037. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  19038. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  19039. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  19040. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  19041. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  19042. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  19043. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  19044. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  19045. //Status && ConnectorPlugIn Setting
  19046. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  19047. {
  19048. ChademoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  19049. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  19050. }
  19051. for (int index = 0; index < CCS_QUANTITY; index++)
  19052. {
  19053. CcsPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  19054. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  19055. }
  19056. for (int index = 0; index < GB_QUANTITY; index++)
  19057. {
  19058. GbPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  19059. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  19060. }
  19061. for (int index = 0; index < AC_QUANTITY; index++)
  19062. {
  19063. AcPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  19064. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  19065. }
  19066. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  19067. {
  19068. DoPreviousSystemStatus[index] = 99; //ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  19069. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  19070. }
  19071. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  19072. {
  19073. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  19074. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  19075. cpinitateMsg.bits[gun_index].StatusNotificationConf = OFF;
  19076. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  19077. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  19078. //memset(&ShmOCPP20Data->StatusNotification[gun_index], 0x00, sizeof(struct StatusNotification_20));
  19079. memset(&ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, 0x00, sizeof(ShmOCPP20Data->StatusNotification[gun_index].connectorStatus));
  19080. }
  19081. refreshStartTimer(&clientTime.Heartbeat);
  19082. sleep(1);
  19083. }
  19084. void LWS_Send(char *str)
  19085. {
  19086. //=====================================================
  19087. // Check InternetConn 0: disconnected, 1: connected
  19088. //====================================================
  19089. if(GetOcppConnStatus() == 0)
  19090. {
  19091. DEBUG_INFO("offline now !!!\n");
  19092. return;
  19093. }
  19094. // Only disable isWebsocketSendable operation initiated by charger
  19095. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19096. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19097. || (strstr((char*)str, "\"ClearedChargingLimit\"") != NULL)
  19098. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19099. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19100. || (strstr((char*)str, "\"Get15118EVCertificate\"") != NULL)
  19101. || (strstr((char*)str, "\"GetCertificateStatus\"") != NULL)
  19102. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19103. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19104. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19105. || (strstr((char*)str, "\"NotifyChargingLimit\"") != NULL)
  19106. || (strstr((char*)str, "\"NotifyCustomerInformation\"") != NULL)
  19107. || (strstr((char*)str, "\"NotifyDisplayMessages\"") != NULL)
  19108. || (strstr((char*)str, "\"NotifyEVChargingNeeds\"") != NULL)
  19109. || (strstr((char*)str, "\"NotifyEVChargingSchedule\"") != NULL)
  19110. || (strstr((char*)str, "\"NotifyEvent\"") != NULL)
  19111. || (strstr((char*)str, "\"NotifyMonitoringReport\"") != NULL)
  19112. || (strstr((char*)str, "\"NotifyReport\"") != NULL)
  19113. || (strstr((char*)str, "\"PublishFirmwareStatusNotification\"") != NULL)
  19114. || (strstr((char*)str, "\"ReportChargingProfiles\"") != NULL)
  19115. || (strstr((char*)str, "\"ReservationStatusUpdate\"") != NULL)
  19116. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19117. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19118. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19119. || (strstr((char*)str, "\"TransactionEvent\"") != NULL))
  19120. {
  19121. isWebsocketSendable = OFF;
  19122. }
  19123. pthread_mutex_lock(&lock_send);
  19124. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19125. sprintf((char *)SendBuffer, "%s", str);
  19126. SendBufLen = strlen(str);
  19127. pthread_mutex_unlock(&lock_send);
  19128. lws_callback_on_writable(wsi_client);
  19129. //lws_service(context, 0);
  19130. //sleep(1);
  19131. }
  19132. void LWS_SendNow(char *str)
  19133. {
  19134. //=====================================================
  19135. // Check InternetConn 0: disconnected, 1: connected
  19136. //====================================================
  19137. if(GetOcppConnStatus() == 0)
  19138. {
  19139. DEBUG_INFO("offline now !!!\n");
  19140. return;
  19141. }
  19142. // Only disable isWebsocketSendable operation initiated by charger
  19143. if((strstr((char*)str, "\"Authorize\"") != NULL)
  19144. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  19145. || (strstr((char*)str, "\"ClearedChargingLimit\"") != NULL)
  19146. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  19147. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  19148. || (strstr((char*)str, "\"Get15118EVCertificate\"") != NULL)
  19149. || (strstr((char*)str, "\"GetCertificateStatus\"") != NULL)
  19150. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  19151. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  19152. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  19153. || (strstr((char*)str, "\"NotifyChargingLimit\"") != NULL)
  19154. || (strstr((char*)str, "\"NotifyCustomerInformation\"") != NULL)
  19155. || (strstr((char*)str, "\"NotifyDisplayMessages\"") != NULL)
  19156. || (strstr((char*)str, "\"NotifyEVChargingNeeds\"") != NULL)
  19157. || (strstr((char*)str, "\"NotifyEVChargingSchedule\"") != NULL)
  19158. || (strstr((char*)str, "\"NotifyEvent\"") != NULL)
  19159. || (strstr((char*)str, "\"NotifyMonitoringReport\"") != NULL)
  19160. || (strstr((char*)str, "\"NotifyReport\"") != NULL)
  19161. || (strstr((char*)str, "\"PublishFirmwareStatusNotification\"") != NULL)
  19162. || (strstr((char*)str, "\"ReportChargingProfiles\"") != NULL)
  19163. || (strstr((char*)str, "\"ReservationStatusUpdate\"") != NULL)
  19164. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  19165. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  19166. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  19167. || (strstr((char*)str, "\"TransactionEvent\"") != NULL))
  19168. {
  19169. isWebsocketSendable = OFF;
  19170. }
  19171. pthread_mutex_lock(&lock_send);
  19172. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  19173. sprintf((char *)SendBuffer, "%s", str);
  19174. SendBufLen = strlen(str);
  19175. pthread_mutex_unlock(&lock_send);
  19176. lws_callback_on_writable(wsi_client);
  19177. lws_service(context, 0);
  19178. //sleep(1);
  19179. }