MessageHandler.c 998 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196
  1. #include "Module_OcppBackend20.h"
  2. #include "define.h"
  3. static char *APNAuthenticationEnumTypeStr[] = {
  4. MACROSTR(CHAP),
  5. MACROSTR(NONE),
  6. MACROSTR(PAP),
  7. MACROSTR(AUTO)
  8. };
  9. static char *AttributeEnumTypeStr[] = {
  10. MACROSTR(Actual),
  11. MACROSTR(Target),
  12. MACROSTR(MinSet),
  13. MACROSTR(MaxSet)
  14. };
  15. static char *AuthorizationStatusEnumTypeStr[] = {
  16. MACROSTR(Accepted),
  17. MACROSTR(Blocked),
  18. MACROSTR(ConcurrentTx),
  19. MACROSTR(Expired),
  20. MACROSTR(Invalid),
  21. MACROSTR(NoCredit),
  22. MACROSTR(NotAllowedTypeEVSE),
  23. MACROSTR(NotAtThisLocation),
  24. MACROSTR(NotAtThisTime),
  25. MACROSTR(Unknown)
  26. };
  27. #if 0
  28. static char *AuthorizeCertificateStatusEnumTypeStr[] = {
  29. MACROSTR(Accepted),
  30. MACROSTR(SignatureError),
  31. MACROSTR(CertificateExpired),
  32. MACROSTR(CertificateRevoked),
  33. MACROSTR(NoCertificateAvailable),
  34. MACROSTR(CertChainError),
  35. MACROSTR(ContractCancelled)
  36. };
  37. #endif
  38. static char *BootReasonEnumTypeStr[] = {
  39. MACROSTR(ApplicationReset),
  40. MACROSTR(FirmwareUpdate),
  41. MACROSTR(LocalReset),
  42. MACROSTR(PowerUp),
  43. MACROSTR(RemoteReset),
  44. MACROSTR(ScheduledReset),
  45. MACROSTR(Triggered),
  46. MACROSTR(Unknown),
  47. MACROSTR(Watchdog)
  48. };
  49. static char *CancelReservationStatusEnumTypeStr[] = {
  50. MACROSTR(Accepted),
  51. MACROSTR(Rejected)
  52. };
  53. static char *CertificateActionEnumTypeStr[] = {
  54. MACROSTR(Install),
  55. MACROSTR(Update)
  56. };
  57. static char *CertificateSignedStatusEnumTypeStr[] = {
  58. MACROSTR(Accepted),
  59. MACROSTR(Rejected)
  60. };
  61. static char *CertificateSigningUseEnumTypeStr[] = {
  62. MACROSTR(ChargingStationCertificate),
  63. MACROSTR(V2GCertificate)
  64. };
  65. static char *ChangeAvailabilityStatusEnumTypeStr[] = {
  66. MACROSTR(Accepted),
  67. MACROSTR(Rejected),
  68. MACROSTR(Scheduled)
  69. };
  70. #if 0
  71. static char *ChargingLimitSourceEnumTypeStr[] = {
  72. MACROSTR(EMS),
  73. MACROSTR(Other),
  74. MACROSTR(SO),
  75. MACROSTR(CSO)
  76. };
  77. #endif
  78. static char *ChargingProfileKindEnumTypeStr[] = {
  79. MACROSTR(Absolute),
  80. MACROSTR(Recurring),
  81. MACROSTR(Relative)
  82. };
  83. static char *ChargingProfilePurposeEnumTypeStr[] = {
  84. MACROSTR(ChargingStationExternalConstraints),
  85. MACROSTR(ChargingStationMaxProfile),
  86. MACROSTR(TxDefaultProfile),
  87. MACROSTR(TxProfile)
  88. };
  89. static char *ChargingProfileStatusEnumTypeStr[] = {
  90. MACROSTR(Accepted),
  91. MACROSTR(Rejected)
  92. };
  93. static char *ChargingRateUnitEnumTypeStr[] = {
  94. MACROSTR(W),
  95. MACROSTR(A)
  96. };
  97. static char *ChargingStateEnumTypeStr[] = {
  98. MACROSTR(Charging),
  99. MACROSTR(EVConnected),
  100. MACROSTR(SuspendedEV),
  101. MACROSTR(SuspendedEVSE),
  102. MACROSTR(Idle)
  103. };
  104. static char *ClearCacheStatusEnumTypeStr[] = {
  105. MACROSTR(Accepted),
  106. MACROSTR(Rejected)
  107. };
  108. static char *ClearChargingProfileStatusEnumTypeStr[] = {
  109. MACROSTR(Accepted),
  110. MACROSTR(Unknown)
  111. };
  112. static char *ClearMessageStatusEnumTypeStr[] = {
  113. MACROSTR(Accepted),
  114. MACROSTR(Unknown)
  115. };
  116. static char *ClearMonitoringStatusEnumTypeStr[] = {
  117. MACROSTR(Accepted),
  118. MACROSTR(Rejected),
  119. MACROSTR(NotFound)
  120. };
  121. static char *ComponentCriterionEnumTypeStr[] = {
  122. MACROSTR(Active),
  123. MACROSTR(Available),
  124. MACROSTR(Enabled),
  125. MACROSTR(Problem)
  126. };
  127. #if 0
  128. static char *ConnectorEnumTypeStr[] = {
  129. MACROSTR(cCCS1),
  130. MACROSTR(cCCS2),
  131. MACROSTR(cG105),
  132. MACROSTR(cTesla),
  133. MACROSTR(cType1),
  134. MACROSTR(cType2),
  135. MACROSTR(s309-1P-16A),
  136. MACROSTR(s309-1P-32A),
  137. MACROSTR(s309-3P-16A),
  138. MACROSTR(s309-3P-32A),
  139. MACROSTR(sBS1361),
  140. MACROSTR(sCEE-7-7),
  141. MACROSTR(sType2),
  142. MACROSTR(sType3),
  143. MACROSTR(Other1PhMax16A),
  144. MACROSTR(Other1PhOver16A),
  145. MACROSTR(Other3Ph),
  146. MACROSTR(Pan),
  147. MACROSTR(wInductive),
  148. MACROSTR(wResonant),
  149. MACROSTR(Undetermined),
  150. MACROSTR(Unknown)
  151. };
  152. #endif
  153. static char *ConnectorStatusEnumTypeStr[] = {
  154. MACROSTR(Available),
  155. MACROSTR(Occupied),
  156. MACROSTR(Reserved),
  157. MACROSTR(Unavailable),
  158. MACROSTR(Faulted)
  159. };
  160. #if 0
  161. static char *CostKindEnumTypeStr[] = {
  162. MACROSTR(CarbonDioxideEmission),
  163. MACROSTR(RelativePricePercentage),
  164. MACROSTR(RenewableGenerationPercentage)
  165. };
  166. #endif
  167. static char *CustomerInformationStatusEnumTypeStr[] = {
  168. MACROSTR(Accepted),
  169. MACROSTR(Rejected),
  170. MACROSTR(Invalid)
  171. };
  172. static char *DataEnumTypeStr[] = {
  173. MACROSTR(string),
  174. MACROSTR(decimal),
  175. MACROSTR(integer),
  176. MACROSTR(dateTime),
  177. MACROSTR(boolean),
  178. MACROSTR(OptionList),
  179. MACROSTR(SequenceList),
  180. MACROSTR(MemberList)
  181. };
  182. static char *DataTransferStatusEnumTypeStr[] = {
  183. MACROSTR(Accepted),
  184. MACROSTR(Rejected),
  185. MACROSTR(UnknownMessageId),
  186. MACROSTR(UnknownVendorId)
  187. };
  188. static char *DeleteCertificateStatusEnumTypeStr[] = {
  189. MACROSTR(Accepted),
  190. MACROSTR(Failed),
  191. MACROSTR(NotFound)
  192. };
  193. static char *DisplayMessageStatusEnumTypeStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(NotSupportedMessageFormat),
  196. MACROSTR(Rejected),
  197. MACROSTR(NotSupportedPriority),
  198. MACROSTR(NotSupportedState),
  199. MACROSTR(UnknownTransaction)
  200. };
  201. #if 0
  202. static char *EnergyTransferModeEnumTypeStr[] = {
  203. MACROSTR(DC),
  204. MACROSTR(AC_single_phase),
  205. MACROSTR(AC_two_phase),
  206. MACROSTR(AC_three_phase)
  207. };
  208. #endif
  209. static char *EventNotificationEnumTypeStr[] = {
  210. MACROSTR(HardWiredNotification),
  211. MACROSTR(HardWiredMonitor),
  212. MACROSTR(PreconfiguredMonitor),
  213. MACROSTR(CustomMonitor)
  214. };
  215. static char *EventTriggerEnumTypeStr[] = {
  216. MACROSTR(Alerting),
  217. MACROSTR(Delta),
  218. MACROSTR(Periodic)
  219. };
  220. static char *FirmwareStatusEnumTypeStr[] = {
  221. MACROSTR(Downloaded),
  222. MACROSTR(DownloadFailed),
  223. MACROSTR(Downloading),
  224. MACROSTR(DownloadScheduled),
  225. MACROSTR(DownloadPaused),
  226. MACROSTR(Idle),
  227. MACROSTR(InstallationFailed),
  228. MACROSTR(Installing),
  229. MACROSTR(Installed),
  230. MACROSTR(InstallRebooting),
  231. MACROSTR(InstallScheduled),
  232. MACROSTR(InstallVerificationFailed),
  233. MACROSTR(InvalidSignature),
  234. MACROSTR(SignatureVerified)
  235. };
  236. static char *GenericDeviceModelStatusEnumTypeStr[] = {
  237. MACROSTR(Accepted),
  238. MACROSTR(Rejected),
  239. MACROSTR(NotSupported),
  240. MACROSTR(EmptyResultSet)
  241. };
  242. static char *GenericStatusEnumTypeStr[] = {
  243. MACROSTR(Accepted),
  244. MACROSTR(Rejected)
  245. };
  246. static char *GetCertificateIdUseEnumTypeStr[] = {
  247. MACROSTR(V2GRootCertificate),
  248. MACROSTR(MORootCertificate),
  249. MACROSTR(CSMSRootCertificate),
  250. MACROSTR(V2GCertificateChain),
  251. MACROSTR(ManufacturerRootCertificate)
  252. };
  253. static char *GetCertificateStatusEnumTypeStr[] = {
  254. MACROSTR(Accepted),
  255. MACROSTR(Failed)
  256. };
  257. static char *GetChargingProfileStatusEnumTypeStr[] = {
  258. MACROSTR(Accepted),
  259. MACROSTR(NoProfiles)
  260. };
  261. static char *GetDisplayMessagesStatusEnumTypeStr[] = {
  262. MACROSTR(Accepted),
  263. MACROSTR(Unknown)
  264. };
  265. static char *GetInstalledCertificateStatusEnumTypeStr[] = {
  266. MACROSTR(Accepted),
  267. MACROSTR(NotFound)
  268. };
  269. static char *GetVariableStatusEnumTypeStr[] = {
  270. MACROSTR(Accepted),
  271. MACROSTR(Rejected),
  272. MACROSTR(UnknownComponent),
  273. MACROSTR(UnknownVariable),
  274. MACROSTR(NotSupportedAttributeType)
  275. };
  276. static char *HashAlgorithmEnumTypeStr[] = {
  277. MACROSTR(SHA256),
  278. MACROSTR(SHA384),
  279. MACROSTR(SHA512)
  280. };
  281. static char *IdTokenEnumTypeStr[] = {
  282. MACROSTR(Central),
  283. MACROSTR(eMAID),
  284. MACROSTR(ISO14443),
  285. MACROSTR(KeyCode),
  286. MACROSTR(Local),
  287. MACROSTR(NoAuthorization),
  288. MACROSTR(ISO15693)
  289. };
  290. static char *InstallCertificateUseEnumTypeStr[] = {
  291. MACROSTR(V2GRootCertificate),
  292. MACROSTR(MORootCertificate),
  293. MACROSTR(CSMSRootCertificate),
  294. MACROSTR(ManufacturerRootCertificate)
  295. };
  296. static char *InstallCertificateStatusEnumTypeStr[]={
  297. MACROSTR(Accepted),
  298. MACROSTR(Failed),
  299. MACROSTR(Rejected)
  300. };
  301. static char *Iso15118EVCertificateStatusEnumTypeStr[] = {
  302. MACROSTR(Accepted),
  303. MACROSTR(Failed)
  304. };
  305. static char *LocationEnumTypeStr[] = {
  306. MACROSTR(Body),
  307. MACROSTR(Cable),
  308. MACROSTR(EV),
  309. MACROSTR(Inlet),
  310. MACROSTR(Outlet)
  311. };
  312. static char *LogEnumTypeStr[] = {
  313. MACROSTR(DiagnosticsLog),
  314. MACROSTR(SecurityLog)
  315. };
  316. static char *LogStatusEnumTypeStr[] = {
  317. MACROSTR(Accepted),
  318. MACROSTR(Rejected),
  319. MACROSTR(AcceptedCanceled)
  320. };
  321. static char *MeasurandEnumTypeStr[] = {
  322. MACROSTR(Current.Export),
  323. MACROSTR(Current.Import),
  324. MACROSTR(Current.Offered),
  325. MACROSTR(Energy.Active.Export.Register),
  326. MACROSTR(Energy.Active.Import.Register),
  327. MACROSTR(Energy.Reactive.Export.Register),
  328. MACROSTR(Energy.Reactive.Import.Register),
  329. MACROSTR(Energy.Active.Export.Interval),
  330. MACROSTR(Energy.Active.Import.Interval),
  331. MACROSTR(Energy.Active.Net),
  332. MACROSTR(Energy.Reactive.Export.Interval),
  333. MACROSTR(Energy.Reactive.Import.Interval),
  334. MACROSTR(Energy.Reactive.Net),
  335. MACROSTR(Energy.Apparent.Net),
  336. MACROSTR(Energy.Apparent.Import),
  337. MACROSTR(Energy.Apparent.Export),
  338. MACROSTR(Frequency),
  339. MACROSTR(Power.Active.Export),
  340. MACROSTR(Power.Active.Import),
  341. MACROSTR(Power.Factor),
  342. MACROSTR(Power.Offered),
  343. MACROSTR(Power.Reactive.Export),
  344. MACROSTR(Power.Reactive.Import),
  345. MACROSTR(SoC),
  346. MACROSTR(Voltage)
  347. };
  348. static char *MessageFormatEnumTypeStr[] = {
  349. MACROSTR(ASCII),
  350. MACROSTR(HTML),
  351. MACROSTR(URI),
  352. MACROSTR(UTF8)
  353. };
  354. static char *MessagePriorityEnumTypeStr[] = {
  355. MACROSTR(AlwaysFront),
  356. MACROSTR(InFront),
  357. MACROSTR(NormalCycle)
  358. };
  359. static char *MessageStateEnumTypeStr[] = {
  360. MACROSTR(Charging),
  361. MACROSTR(Faulted),
  362. MACROSTR(Idle),
  363. MACROSTR(Unavailable)
  364. };
  365. static char *MessageTriggerEnumTypeStr[] = {
  366. MACROSTR(BootNotification),
  367. MACROSTR(LogStatusNotification),
  368. MACROSTR(FirmwareStatusNotification),
  369. MACROSTR(Heartbeat),
  370. MACROSTR(MeterValues),
  371. MACROSTR(SignChargingStationCertificate),
  372. MACROSTR(SignV2GCertificate),
  373. MACROSTR(StatusNotification),
  374. MACROSTR(TransactionEvent),
  375. MACROSTR(SignCombinedCertificate),
  376. MACROSTR(PublishFirmwareStatusNotification)
  377. };
  378. static char *MonitorEnumTypeStr[] = {
  379. MACROSTR(UpperThreshold),
  380. MACROSTR(LowerThreshold),
  381. MACROSTR(Delta),
  382. MACROSTR(Periodic),
  383. MACROSTR(PeriodicClockAligned)
  384. };
  385. static char *MonitoringBaseEnumTypeStr[] = {
  386. MACROSTR(All),
  387. MACROSTR(FactoryDefault),
  388. MACROSTR(HardWiredOnly)
  389. };
  390. static char *MonitoringCriterionEnumTypeStr[] = {
  391. MACROSTR(ThresholdMonitoring),
  392. MACROSTR(DeltaMonitoring),
  393. MACROSTR(PeriodicMonitoring)
  394. };
  395. static char *MutabilityEnumTypeStr[] = {
  396. MACROSTR(ReadOnly),
  397. MACROSTR(WriteOnly),
  398. MACROSTR(ReadWrite)
  399. };
  400. static char *NotifyEVChargingNeedsStatusEnumTypeStr[] = {
  401. MACROSTR(Accepted),
  402. MACROSTR(Rejected),
  403. MACROSTR(Processing)
  404. };
  405. static char *OCPPInterfaceEnumTypeStr[] = {
  406. MACROSTR(Wired0),
  407. MACROSTR(Wired1),
  408. MACROSTR(Wired2),
  409. MACROSTR(Wired3),
  410. MACROSTR(Wireless0),
  411. MACROSTR(Wireless1),
  412. MACROSTR(Wireless2),
  413. MACROSTR(Wireless3)
  414. };
  415. static char *OCPPTransportEnumTypeStr[] = {
  416. MACROSTR(JSON),
  417. MACROSTR(SOAP)
  418. };
  419. static char *OCPPVersionEnumTypeStr[] = {
  420. MACROSTR(OCPP12),
  421. MACROSTR(OCPP15),
  422. MACROSTR(OCPP16),
  423. MACROSTR(OCPP20)
  424. };
  425. static char *OperationalStatusEnumTypeStr[] = {
  426. MACROSTR(Inoperative),
  427. MACROSTR(Operative)
  428. };
  429. static char *PhaseEnumTypeStr[] = {
  430. MACROSTR(L1),
  431. MACROSTR(L2),
  432. MACROSTR(L3),
  433. MACROSTR(N),
  434. MACROSTR(L1-N),
  435. MACROSTR(L2-N),
  436. MACROSTR(L3-N),
  437. MACROSTR(L1-L2),
  438. MACROSTR(L2-L3),
  439. MACROSTR(L3-L1)
  440. };
  441. static char *PublishFirmwareStatusEnumTypeStr[] = {
  442. MACROSTR(Downloaded),
  443. MACROSTR(DownloadFailed),
  444. MACROSTR(Downloading),
  445. MACROSTR(DownloadScheduled),
  446. MACROSTR(DownloadPaused),
  447. MACROSTR(PublishFailed),
  448. MACROSTR(Published),
  449. MACROSTR(InvalidChecksum),
  450. MACROSTR(ChecksumVerified)
  451. };
  452. static char *ReadingContextEnumTypeStr[] = {
  453. MACROSTR(Interruption.Begin),
  454. MACROSTR(Interruption.End),
  455. MACROSTR(Other),
  456. MACROSTR(Sample.Clock),
  457. MACROSTR(Sample.Periodic),
  458. MACROSTR(Transaction.Begin),
  459. MACROSTR(Transaction.End),
  460. MACROSTR(Trigger)
  461. };
  462. #if 0
  463. static char *ReasonEnumTypeStr[] = {
  464. MACROSTR(DeAuthorized),
  465. MACROSTR(EmergencyStop),
  466. MACROSTR(EnergyLimitReached),
  467. MACROSTR(EVDisconnected),
  468. MACROSTR(GroundFault),
  469. MACROSTR(ImmediateReset),
  470. MACROSTR(Local),
  471. MACROSTR(LocalOutOfCredit),
  472. MACROSTR(MasterPass),
  473. MACROSTR(Other),
  474. MACROSTR(OvercurrentFault),
  475. MACROSTR(PowerLoss),
  476. MACROSTR(PowerQuality),
  477. MACROSTR(Reboot),
  478. MACROSTR(Remote),
  479. MACROSTR(SOCLimitReached),
  480. MACROSTR(StoppedByEV),
  481. MACROSTR(TimeLimitReached),
  482. MACROSTR(TimeLimitReached)
  483. };
  484. #endif
  485. static char *RecurrencyKindEnumTypeStr[] = {
  486. MACROSTR(Daily),
  487. MACROSTR(Weekly)
  488. };
  489. static char *RegistrationStatusEnumTypeStr[] = {
  490. MACROSTR(Accepted),
  491. MACROSTR(Pending),
  492. MACROSTR(Rejected)
  493. };
  494. static char *ReportBaseEnumTypeStr[] = {
  495. MACROSTR(ConfigurationInventory),
  496. MACROSTR(FullInventory),
  497. MACROSTR(SummaryInventory)
  498. };
  499. static char *RequestStartStopStatusEnumTypeStr[] = {
  500. MACROSTR(Accepted),
  501. MACROSTR(Rejected)
  502. };
  503. static char *ReservationUpdateStatusEnumTypeStr[] = {
  504. MACROSTR(Expired),
  505. MACROSTR(Removed)
  506. };
  507. static char *ReserveNowStatusEnumTypeStr[] = {
  508. MACROSTR(Accepted),
  509. MACROSTR(Faulted),
  510. MACROSTR(Occupied),
  511. MACROSTR(Rejected),
  512. MACROSTR(Unavailable)
  513. };
  514. static char *ResetEnumTypeStr[] = {
  515. MACROSTR(Immediate),
  516. MACROSTR(OnIdle)
  517. };
  518. static char *ResetStatusEnumTypeStr[] = {
  519. MACROSTR(Accepted),
  520. MACROSTR(Rejected),
  521. MACROSTR(Scheduled)
  522. };
  523. static char *SetMonitoringStatusEnumTypeStr[] = {
  524. MACROSTR(Accepted),
  525. MACROSTR(UnknownComponent),
  526. MACROSTR(UnknownVariable),
  527. MACROSTR(UnsupportedMonitorType),
  528. MACROSTR(Rejected),
  529. MACROSTR(OutOfRange),
  530. MACROSTR(Duplicate)
  531. };
  532. static char *SetNetworkProfileStatusEnumTypeStr[] = {
  533. MACROSTR(Accepted),
  534. MACROSTR(Rejected),
  535. MACROSTR(Failed)
  536. };
  537. static char *SetVariableStatusEnumTypeStr[] = {
  538. MACROSTR(Accepted),
  539. MACROSTR(Rejected),
  540. MACROSTR(InvalidValue),
  541. MACROSTR(UnknownComponent),
  542. MACROSTR(UnknownVariable),
  543. MACROSTR(NotSupportedAttributeType),
  544. MACROSTR(OutOfRange),
  545. MACROSTR(RebootRequired)
  546. };
  547. static char *TransactionEventEnumTypeStr[] = {
  548. MACROSTR(Ended),
  549. MACROSTR(Started),
  550. MACROSTR(Updated)
  551. };
  552. static char *TriggerMessageStatusEnumTypeStr[] = {
  553. MACROSTR(Accepted),
  554. MACROSTR(Rejected),
  555. MACROSTR(NotImplemented)
  556. };
  557. static char *TriggerReasonEnumTypeStr[] = {
  558. MACROSTR(Authorized),
  559. MACROSTR(CablePluggedIn),
  560. MACROSTR(ChargingRateChanged),
  561. MACROSTR(ChargingStateChanged),
  562. MACROSTR(Deauthorized),
  563. MACROSTR(EnergyLimitReached),
  564. MACROSTR(EVCommunicationLost),
  565. MACROSTR(EVConnectTimeout),
  566. MACROSTR(MeterValueClock),
  567. MACROSTR(MeterValuePeriodic),
  568. MACROSTR(TimeLimitReached),
  569. MACROSTR(Trigger),
  570. MACROSTR(UnlockCommand),
  571. MACROSTR(StopAuthorized),
  572. MACROSTR(EVDeparted),
  573. MACROSTR(EVDetected),
  574. MACROSTR(RemoteStop),
  575. MACROSTR(RemoteStart),
  576. MACROSTR(AbnormalCondition),
  577. MACROSTR(SignedDataReceived),
  578. MACROSTR(ResetCommand)
  579. };
  580. static char *UnlockStatusEnumTypeStr[] = {
  581. MACROSTR(Unlocked),
  582. MACROSTR(UnlockFailed),
  583. MACROSTR(OngoingAuthorizedTransaction),
  584. MACROSTR(UnknownConnector)
  585. };
  586. static char *UnpublishFirmwareStatusEnumTypeStr[] = {
  587. MACROSTR(DownloadOngoing),
  588. MACROSTR(NoFirmware),
  589. MACROSTR(Unpublished)
  590. };
  591. static char *UpdateEnumTypeStr[] = {
  592. MACROSTR(Differential),
  593. MACROSTR(Full)
  594. };
  595. static char *UpdateFirmwareStatusEnumTypeStr[] = {
  596. MACROSTR(Accepted),
  597. MACROSTR(Rejected),
  598. MACROSTR(AcceptedCanceled),
  599. MACROSTR(InvalidCertificate),
  600. MACROSTR(RevokedCertificate)
  601. };
  602. static char *UpdateStatusEnumTypeStr[] = {
  603. MACROSTR(Accepted),
  604. MACROSTR(Failed),
  605. MACROSTR(VersionMismatch)
  606. };
  607. static char *UploadLogStatusEnumTypeStr[] = {
  608. MACROSTR(BadMessage),
  609. MACROSTR(Idle),
  610. MACROSTR(NotSupportedOperation),
  611. MACROSTR(PermissionDenied),
  612. MACROSTR(Uploaded),
  613. MACROSTR(UploadFailure),
  614. MACROSTR(Uploading)
  615. };
  616. static char *VPNEnumTypeStr[] = {
  617. MACROSTR(IKEv2),
  618. MACROSTR(IPSec),
  619. MACROSTR(L2TP),
  620. MACROSTR(PPTP)
  621. };
  622. #if 0
  623. static char *ChargePointErrorCodeEnumTypeStr[] = {
  624. MACROSTR(ConnectorLockFailure),
  625. MACROSTR(EVCommunicationError),
  626. MACROSTR(GroundFailure),
  627. MACROSTR(HighTemperature),
  628. MACROSTR(InternalError),
  629. MACROSTR(LocalListConflict),
  630. MACROSTR(NoError),
  631. MACROSTR(OtherError),
  632. MACROSTR(OverCurrentFailure),
  633. MACROSTR(OverVoltage),
  634. MACROSTR(PowerMeterFailure),
  635. MACROSTR(PowerSwitchFailure),
  636. MACROSTR(ReaderFailure),
  637. MACROSTR(ResetFailure),
  638. MACROSTR(UnderVoltage),
  639. MACROSTR(WeakSignal)
  640. };
  641. #endif
  642. static char *GetCompositeScheduleStatusEnumTypeStr[] = {
  643. MACROSTR(Accepted),
  644. MACROSTR(Rejected)
  645. };
  646. static char *RemoteStartStopStatusEnumTypeStr[] = {
  647. MACROSTR(Accepted),
  648. MACROSTR(Rejected)
  649. };
  650. #if 0
  651. static char * StopTransactionReasonEnumTypeStr[] = {
  652. MACROSTR(EmergencyStop),
  653. MACROSTR(EVDisconnected),
  654. MACROSTR(HardReset),
  655. MACROSTR(Local),
  656. MACROSTR(Other),
  657. MACROSTR(PowerLoss),
  658. MACROSTR(Reboot),
  659. MACROSTR(Remote),
  660. MACROSTR(SoftReset),
  661. MACROSTR(UnlockCommand),
  662. MACROSTR(DeAuthorized)
  663. };
  664. #endif
  665. //ChargePointMaxProfile
  666. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile_OCPP20.json"
  667. //TxDefaultProfile
  668. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0_OCPP20.json"
  669. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  670. struct StatusCodeData *ShmStatusCodeData;
  671. struct PsuData *ShmPsuData ;
  672. struct OCPP20Data *ShmOCPP20Data;
  673. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  674. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  675. //===============================
  676. // Gun Total Numbers
  677. //===============================
  678. static ParsingRatedCur modelnameInfo = {0};
  679. static int gunTotalNumber = 0;
  680. static uint8_t gunType[4] = {0};
  681. //===============================
  682. // Local List Version
  683. //===============================
  684. static int localversion=0;
  685. //===============================
  686. // Variable Version
  687. //===============================
  688. static int variableVersion=5;
  689. //===============================
  690. // OCPP sign variable
  691. //===============================
  692. static int server_sign = FALSE;
  693. int server_pending = FALSE;
  694. static int BootNotificationInterval = 10;
  695. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  696. //===============================
  697. // OCPP auth variable
  698. //===============================
  699. static int authorizeRetryTimes = 0; //number of Retry times
  700. //===============================
  701. // OCPP other variables
  702. //===============================
  703. static int HeartBeatWaitTime = 10;
  704. static int FirstHeartBeat = 0;
  705. static int FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle; // Idle
  706. static int LogStatusNotificationStatus = UploadLogStatusEnumType_Idle; // Idle
  707. static char CurrentChargingProfileScheduleStr[30] = {0};
  708. //========================================
  709. // OCPP status/previous related variables
  710. //========================================
  711. static int GunStatusInterval = 10;
  712. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  713. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  714. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  715. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  716. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  717. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  718. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  719. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  720. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  721. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  722. static int TransactionMessageAttemptsValue = 0;
  723. static int TransactionMessageRetryIntervalValue = 0;
  724. static struct AuthorizationData idTagQuery;
  725. //=============================================
  726. // OCPP HeartBeat Response Not Receive Counts
  727. //============================================
  728. static int HeartBeatWithNOResponse = 0;
  729. static int HeartBeatCountPerHour = 0;
  730. sqlite3 *db;
  731. int TransactionMessageAttemptsGet(void);
  732. int TransactionMessageRetryIntervalGet(void);
  733. int GetOcppConnStatus(void);
  734. void SetOcppConnStatus(uint8_t status);
  735. int setKeyValue(char *key, char *value);
  736. void OCPP_get_TableAuthlocalAllData(void);
  737. void processUnkownKey(void);
  738. struct InterLock
  739. {
  740. unsigned char isGetLogGoing:1;
  741. unsigned char isUpdateFirmwareGoing:1;
  742. }interLock;
  743. struct ClientTime
  744. {
  745. struct timespec Heartbeat;
  746. struct timespec StatusNotification[CONNECTOR_QUANTITY];
  747. struct timespec StartTransaction;
  748. struct timespec StopTransaction;
  749. struct timespec MeterValues[CONNECTOR_QUANTITY];
  750. struct timespec RemoteStartWait;
  751. }clientTime;
  752. typedef union
  753. {
  754. //Operations Initiated by Central System
  755. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  756. struct
  757. {
  758. //CsMsgValue[0]
  759. unsigned char StatusNotificationReq:1; //bit 0,
  760. unsigned char StatusNotificationConf:1; //bit 1,
  761. unsigned char TriggerMeterValueReq:1; //bit 2,
  762. unsigned char SampleMeterReq:1; //bit 3,
  763. unsigned char ClockAlignMeterReq:1; //bit 4,
  764. unsigned char TriggerStatusNotificationReq:1; //bit 5,
  765. unsigned char isOnCharging:1; //bit6,
  766. unsigned char :1; //bit7
  767. }bits[CONNECTOR_QUANTITY];
  768. }CpinitiateMsg;
  769. CpinitiateMsg cpinitateMsg;
  770. //=========================================
  771. // Save configuration
  772. //=========================================
  773. int runShellCmd(const char*cmd)
  774. {
  775. int result = FAIL;
  776. char buf[256];
  777. FILE *fp;
  778. fp = popen(cmd, "r");
  779. if(fp != NULL)
  780. {
  781. while(fgets(buf, sizeof(buf), fp) != NULL)
  782. {
  783. DEBUG_INFO("%s\n", buf);
  784. }
  785. result = PASS;
  786. }
  787. pclose(fp);
  788. return result;
  789. }
  790. int StoreUsrConfigData(struct SysConfigData *UsrData)
  791. {
  792. int result = PASS;
  793. int fd,wrd;
  794. unsigned int i,Chk;
  795. unsigned char *ptr, *BufTmp;
  796. int MtdBlockSize = 0x300000;
  797. Chk=0;
  798. ptr=(unsigned char *)UsrData;
  799. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  800. {
  801. memset(BufTmp,0,MtdBlockSize);
  802. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  803. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  804. Chk+=*(BufTmp+i);
  805. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  806. // Output configuration to file.
  807. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  808. if (fd < 0)
  809. {
  810. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  811. free(BufTmp);
  812. return 0;
  813. }
  814. wrd=write(fd, BufTmp, MtdBlockSize);
  815. close(fd);
  816. if(wrd<MtdBlockSize)
  817. {
  818. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  819. free(BufTmp);
  820. return 0;
  821. }
  822. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  823. DEBUG_INFO("Erase /dev/mtd10.\n");
  824. runShellCmd("flash_erase /dev/mtd10 0 0");
  825. DEBUG_INFO("Write /dev/mtd10.\n");
  826. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  827. DEBUG_INFO("Erase /dev/mtd11.\n");
  828. runShellCmd("flash_erase /dev/mtd11 0 0");
  829. DEBUG_INFO("Write /dev/mtd11.\n");
  830. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  831. system("rm -f /mnt/EvseConfig.bin");
  832. DEBUG_INFO("EvseConfig write to flash OK\n");
  833. }
  834. else
  835. {
  836. DEBUG_ERROR("alloc BlockSize NG\r\n");
  837. result = FAIL;
  838. }
  839. if(BufTmp!=NULL)
  840. free(BufTmp);
  841. return result;
  842. }
  843. //=========================================
  844. // Date time related function
  845. //=========================================
  846. void getNowDatetime(uint8_t *data)
  847. {
  848. time_t t = time(NULL);
  849. struct tm tm = *localtime(&t);
  850. 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);
  851. }
  852. //=========================================
  853. // Sqlite3 related function
  854. //=========================================
  855. int DB_Initial()
  856. {
  857. int result = PASS;
  858. char* errMsg = NULL;
  859. char *sqlOcppAuthCache = "create table if not exists ocpp20_auth_cache (idx integer primary key,"
  860. "idToken text UNIQUE,"
  861. "type text,"
  862. "status text,"
  863. "cacheExpiryDateTime text,"
  864. "chargingPriority integer,"
  865. "language1 text,"
  866. "evseId text,"
  867. "language2 text,"
  868. "groupIdToken_idToken text,"
  869. "groupIdToken_type text,"
  870. "personalMessage text);";
  871. char *sqlOcppAuthLocal = "create table if not exists ocpp20_auth_local (idx integer primary key,"
  872. "idToken text UNIQUE,"
  873. "type text,"
  874. "status text,"
  875. "cacheExpiryDateTime text,"
  876. "chargingPriority integer,"
  877. "language1 text,"
  878. "evseId text,"
  879. "language2 text,"
  880. "groupIdToken_idToken text,"
  881. "groupIdToken_type text,"
  882. "personalMessage text,"
  883. "version text);";
  884. char *sqlOcppVariable = "create table if not exists ocpp20_variable (idx integer primary key,"
  885. "componentName text NOT NULL ,"
  886. "componentInstance text, "
  887. "variableName text NOT NULL, "
  888. "variableInstance text, "
  889. "variableCharacteristicsDataType integer, "
  890. "variableCharacteristicsUnit text, "
  891. "variableCharacteristicsMaxLimit real,"
  892. "variableAttributesType text, "
  893. "variableAttributesTypeMutability text, "
  894. "variableAttributesTypeValue text, "
  895. "variableCharacteristicsMinLimit real,"
  896. "unique(componentName, componentInstance,variableName, variableInstance) on conflict replace);";
  897. char *sqlBootType = "create table if not exists ocpp20_boot_type (idx integer primary key,"
  898. "type text);";
  899. char *sqlNetworkProfile = "create table if not exists ocpp20_networkprofile (idx integer primary key,"
  900. "slot integer UNIQUE, connectionData text);";
  901. char *sqlTransaction = "create table if not exists ocpp20_transaction_record (idx integer primary key,"
  902. "occurDatetime text,"
  903. "message_type text,"
  904. "message_content text)";
  905. //sqlite3_config(SQLITE_CONFIG_URI, 1);
  906. if(sqlite3_open(OCPP_LOCAL_DB_FILE, &db))
  907. {
  908. result = FAIL;
  909. DEBUG_ERROR( "Can't open database: %s\n", sqlite3_errmsg(db));
  910. sqlite3_close(db);
  911. }
  912. else
  913. {
  914. DEBUG_INFO( "OCPP local database open successfully.\n");
  915. if (sqlite3_exec(db, sqlOcppAuthCache, 0, 0, &errMsg) != SQLITE_OK)
  916. {
  917. result = FAIL;
  918. DEBUG_ERROR( "Create OCPP 2.0 auth cache table error message: %s\n", errMsg);
  919. }
  920. else
  921. {
  922. DEBUG_INFO( "Create OCPP 2.0 auth cache table table successfully\n");
  923. }
  924. if (sqlite3_exec(db, sqlOcppAuthLocal, 0, 0, &errMsg) != SQLITE_OK)
  925. {
  926. result = FAIL;
  927. DEBUG_ERROR( "Create OCPP 2.0 auth list table error message: %s\n", errMsg);
  928. }
  929. else
  930. {
  931. DEBUG_INFO( "Create OCPP 2.0 auth list table successfully\n");
  932. }
  933. if (sqlite3_exec(db, sqlOcppVariable, 0, 0, &errMsg) != SQLITE_OK)
  934. {
  935. result = FAIL;
  936. DEBUG_ERROR( "Create OCPP 2.0 variable table error message: %s\n", errMsg);
  937. }
  938. else
  939. {
  940. DEBUG_INFO( "Create OCPP 2.0 variable table successfully\n");
  941. }
  942. if (sqlite3_exec(db, sqlBootType, 0, 0, &errMsg) != SQLITE_OK)
  943. {
  944. result = FAIL;
  945. DEBUG_ERROR( "Create OCPP 2.0 boot_type table error message: %s\n", errMsg);
  946. }
  947. else
  948. {
  949. DEBUG_INFO( "Create OCPP 2.0 boot_type table successfully\n");
  950. }
  951. if (sqlite3_exec(db, sqlNetworkProfile, 0, 0, &errMsg) != SQLITE_OK)
  952. {
  953. result = FAIL;
  954. DEBUG_ERROR( "Create OCPP 2.0 ocpp20_networkprofile table error message: %s\n", errMsg);
  955. }
  956. else
  957. {
  958. DEBUG_INFO( "Create OCPP 2.0 ocpp20_networkprofile table successfully\n");
  959. }
  960. if (sqlite3_exec(db, sqlTransaction, 0, 0, &errMsg) != SQLITE_OK)
  961. {
  962. result = FAIL;
  963. DEBUG_ERROR( "Create OCPP 2.0 ocpp20_transaction_record table error message: %s\n", errMsg);
  964. }
  965. else
  966. {
  967. DEBUG_INFO( "Create OCPP 2.0 ocpp20_transaction_record table successfully\n");
  968. }
  969. //sqlite3_close(db);
  970. }
  971. return result;
  972. }
  973. int DB_cbGetVersion(void *para, int columnCount, char **columnValue, char **columnName)
  974. {
  975. localversion = columnValue[12] ? atoi(columnValue[12]) : 0;
  976. return 0;
  977. }
  978. void DB_getListVerion()
  979. {
  980. char sql[256];
  981. char* errMsg = NULL;
  982. strcpy(sql, "select * from ocpp20_auth_local order by version desc, idx desc limit 1");
  983. /* Execute SQL statement */
  984. if( sqlite3_exec(db, sql, DB_cbGetVersion, 0, &errMsg) != SQLITE_OK )
  985. {
  986. DEBUG_INFO("SQL error: %s", errMsg);
  987. }
  988. }
  989. int DB_cbGetIdTag(void *para, int columnCount, char **columnValue, char **columnName)
  990. {
  991. sprintf((char*)idTagQuery.idToken.idToken,"%s", columnValue[1] ? columnValue[1] : "NULL");
  992. sprintf((char*)idTagQuery.idToken.type,"%s", columnValue[2] ? columnValue[2] : "NULL");
  993. sprintf((char*)idTagQuery.idTokenInfo.status,"%s", columnValue[3] ? columnValue[3] : "NULL");
  994. sprintf((char*)idTagQuery.idTokenInfo.cacheExpiryDateTime,"%s", columnValue[4] ? columnValue[4] : "NULL");
  995. idTagQuery.idTokenInfo.chargingPriority = columnValue[5] ? atoi(columnValue[5]) : -1;
  996. sprintf((char*)idTagQuery.idTokenInfo.language1,"%s", columnValue[6] ? columnValue[6] : "NULL");
  997. sprintf((char*)idTagQuery.idTokenInfo.language2,"%s", columnValue[8] ? columnValue[8] : "NULL");
  998. sprintf((char*)idTagQuery.idTokenInfo.groupIdToken.idToken,"%s", columnValue[9] ? columnValue[9] : "NULL");
  999. sprintf((char*)idTagQuery.idTokenInfo.groupIdToken.type,"%s", columnValue[10] ? columnValue[10] : "NULL");
  1000. return 0;
  1001. }
  1002. void DB_getIdTag(char idTag[], uint8_t isQueryFromCache)
  1003. {
  1004. char sql[256];
  1005. char* errMsg = NULL;
  1006. memset(&idTagQuery, 0, sizeof(idTagQuery));
  1007. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  1008. if(isQueryFromCache)
  1009. sprintf(sql,"select * from ocpp20_auth_cache where idToken='%s'", idTag);
  1010. else
  1011. sprintf(sql,"select * from ocpp20_auth_local where idToken='%s'", idTag);
  1012. /* Execute SQL statement */
  1013. if(sqlite3_exec(db, sql, DB_cbGetIdTag, 0, &errMsg) != SQLITE_OK )
  1014. {
  1015. DEBUG_INFO("SQL error: %s", errMsg);
  1016. }
  1017. }
  1018. int DB_cbTableAuthlocalAllData(void *para, int columnCount, char **columnValue, char **columnName)
  1019. {
  1020. for (int i = 0; i < columnCount; i++)
  1021. {
  1022. DEBUG_INFO("%s = %s, ", columnName[i], columnValue[i]);
  1023. }
  1024. return 0;
  1025. }
  1026. void DB_get_TableAuthlocalAllData(void)
  1027. {
  1028. char sql[256];
  1029. char* errMsg = NULL;
  1030. sprintf(sql,"select * from ocpp20_auth_local;");
  1031. /* Execute SQL statement */
  1032. if(sqlite3_exec(db, sql, DB_cbTableAuthlocalAllData, 0,&errMsg) != SQLITE_OK)
  1033. {
  1034. DEBUG_INFO("SQL error: %s", errMsg);
  1035. }
  1036. }
  1037. int DB_cbAddLocalListCache(void *para, int columnCount, char **columnValue, char **columnName)
  1038. {
  1039. for(int i = 0; i<columnCount; i++)
  1040. {
  1041. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1042. }
  1043. return 0;
  1044. }
  1045. int DB_addLocalList(int listVersion, struct AuthorizationData *data)
  1046. {
  1047. int result = PASS;
  1048. char sql[512];
  1049. char* errMsg = NULL;
  1050. 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;",
  1051. data->idToken.idToken,
  1052. data->idToken.type,
  1053. data->idTokenInfo.status,
  1054. data->idTokenInfo.cacheExpiryDateTime,
  1055. data->idTokenInfo.chargingPriority,
  1056. data->idTokenInfo.language1,
  1057. data->idTokenInfo.language2,
  1058. data->idTokenInfo.groupIdToken.idToken,
  1059. data->idTokenInfo.groupIdToken.type,
  1060. listVersion);
  1061. //* Execute SQL statement */
  1062. if(sqlite3_exec(db, sql, DB_cbAddLocalListCache, 0, &errMsg) != SQLITE_OK)
  1063. {
  1064. DEBUG_INFO("SQL error: %s\n", errMsg);
  1065. result = FAIL;
  1066. }
  1067. else
  1068. {
  1069. memset(sql, 0, ARRAY_SIZE(sql));
  1070. sprintf(sql, "UPDATE ocpp20_auth_local SET version=%d",listVersion);
  1071. if( sqlite3_exec(db, sql, NULL, NULL, &errMsg) != SQLITE_OK )
  1072. {
  1073. DEBUG_INFO("SQL error: %s\n", errMsg);
  1074. result = FAIL;
  1075. }
  1076. }
  1077. return result;
  1078. }
  1079. int DB_addLocalCache(struct IdTokenType *idToken, struct IdTokenInfoType *idTokenInfo)
  1080. {
  1081. int result = PASS;
  1082. char sql[512];
  1083. char* errMsg = NULL;
  1084. 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;",
  1085. idToken->idToken,
  1086. idToken->type,
  1087. idTokenInfo->status,
  1088. idTokenInfo->cacheExpiryDateTime,
  1089. idTokenInfo->chargingPriority,
  1090. idTokenInfo->language1,
  1091. idTokenInfo->language2,
  1092. idTokenInfo->groupIdToken.idToken,
  1093. idTokenInfo->groupIdToken.type);
  1094. //* Execute SQL statement */
  1095. if(sqlite3_exec(db, sql, DB_cbAddLocalListCache, 0, &errMsg) != SQLITE_OK)
  1096. {
  1097. DEBUG_INFO("SQL error: %s\n", errMsg);
  1098. result = FAIL;
  1099. }
  1100. return result;
  1101. }
  1102. int deleteIdTagcallback(void *para, int columnCount, char **columnValue, char **columnName)
  1103. {
  1104. // localversion = argv[5] ? atoi(columnValue[5]) : 0;
  1105. // printf("localversion=%d\n", localversion);
  1106. return 0;
  1107. }
  1108. void DB_deleteIdTag(char idTag[])
  1109. {
  1110. char sql[512];
  1111. char* errMsg = NULL;
  1112. sprintf(sql,"DELETE from ocpp20_auth_local where idToken='%s'; SELECT * from ocpp20_auth_local;", idTag);
  1113. //* Execute SQL statement */
  1114. if( sqlite3_exec(db, sql, deleteIdTagcallback, 0, &errMsg) != SQLITE_OK )
  1115. {
  1116. DEBUG_INFO("SQL error: %s", errMsg);
  1117. }
  1118. }
  1119. int DB_cleanLocalList()
  1120. {
  1121. int result = PASS;
  1122. char * sqlcleanLocalList = "delete from ocpp20_auth_local";
  1123. char *errMsg = 0;
  1124. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1125. {
  1126. DEBUG_INFO("%s\n", errMsg);
  1127. result = FAIL;
  1128. }
  1129. return result;
  1130. }
  1131. int DB_cleanLocalCache()
  1132. {
  1133. int result = PASS;
  1134. char * sqlcleanLocalList = "delete from ocpp20_auth_cache";
  1135. char *errMsg = 0;
  1136. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1137. {
  1138. DEBUG_INFO("%s\n", errMsg);
  1139. result = FAIL;
  1140. }
  1141. return result;
  1142. }
  1143. int BootTypecallback(void *para, int columnCount, char **columnValue, char **columnName)
  1144. {
  1145. sprintf((char*)ShmOCPP20Data->BootNotification.reason,"%s", columnValue[1] ? columnValue[1] : BootReasonEnumTypeStr[BootReasonEnumType_PowerUp]);
  1146. return 0;
  1147. }
  1148. void DB_getBooType()
  1149. {
  1150. char sql[256];
  1151. char* errMsg = NULL;
  1152. sprintf(sql,"select * from ocpp20_boot_type;");
  1153. /* Execute SQL statement */
  1154. if(sqlite3_exec(db, sql, BootTypecallback, 0, &errMsg) != SQLITE_OK )
  1155. {
  1156. DEBUG_INFO("SQL error: %s\n", errMsg);
  1157. }
  1158. }
  1159. int DB_cbUpdateBootType(void *para, int columnCount, char **columnValue, char **columnName)
  1160. {
  1161. for(int i = 0; i<columnCount; i++)
  1162. {
  1163. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1164. }
  1165. return 0;
  1166. }
  1167. int DB_updateBootType(BootReasonEnumType reason)
  1168. {
  1169. int result = PASS;
  1170. char sql[512];
  1171. char* errMsg = NULL;
  1172. sprintf(sql,"insert or replace into ocpp20_boot_type (idx, type) VALUES(1, '%s');", BootReasonEnumTypeStr[reason>BootReasonEnumType_Watchdog?BootReasonEnumType_PowerUp:reason]);
  1173. //* Execute SQL statement */
  1174. if(sqlite3_exec(db, sql, DB_cbUpdateBootType, 0, &errMsg) != SQLITE_OK)
  1175. {
  1176. DEBUG_INFO("SQL error: %s\n", errMsg);
  1177. result = FAIL;
  1178. }
  1179. return result;
  1180. }
  1181. int DB_variableClear()
  1182. {
  1183. int result = PASS;
  1184. char * sqlcleanLocalList = "delete from ocpp20_variable";
  1185. char *errMsg = 0;
  1186. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1187. {
  1188. DEBUG_INFO("%s\n", errMsg);
  1189. result = FAIL;
  1190. }
  1191. return result;
  1192. }
  1193. int DB_cbVariableSaveToDb(void *para, int columnCount, char **columnValue, char **columnName)
  1194. {
  1195. for(int i = 0; i<columnCount; i++)
  1196. {
  1197. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1198. }
  1199. return 0;
  1200. }
  1201. int DB_variableSaveToDb(struct ReportDataType *variable)
  1202. {
  1203. int result = FAIL;
  1204. char sql[4096];
  1205. char* errMsg = NULL;
  1206. 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;",
  1207. variable->component.name,
  1208. variable->component.instance,
  1209. variable->variable.name,
  1210. variable->variable.instance,
  1211. variable->variableCharacteristics.dataType,
  1212. variable->variableCharacteristics.unit,
  1213. variable->variableCharacteristics.maxLimit,
  1214. variable->variableAttribute[0].type,
  1215. variable->variableAttribute[0].mutability,
  1216. variable->variableAttribute[0].value,
  1217. variable->variableCharacteristics.minLimit);
  1218. //* Execute SQL statement */
  1219. if(sqlite3_exec(db, sql, DB_cbVariableSaveToDb, 0, &errMsg) != SQLITE_OK)
  1220. {
  1221. DEBUG_INFO("SQL error: %s\n", errMsg);
  1222. result = FAIL;
  1223. }
  1224. return result;
  1225. }
  1226. int DB_cbVariableIsCreate(void *para, int columnCount, char **columnValue, char **columnName)
  1227. {
  1228. memset(&ShmOCPP20Data->ControllerComponentVariable[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable));
  1229. if(atoi(columnValue[0]) == 0)
  1230. {
  1231. DB_updateBootType(BootReasonEnumType_PowerUp);
  1232. // Create variable table content
  1233. /* AlignedDataCtrlr Required item */
  1234. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].component.name, "AlignedDataCtrlr");
  1235. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variable.name, "Enabled");
  1236. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1237. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1238. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1239. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1240. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled]);
  1241. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].component.name, "AlignedDataCtrlr");
  1242. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variable.name, "Available");
  1243. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1244. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1245. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1246. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].value, "TRUE");
  1247. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available]);
  1248. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].component.name, "AlignedDataCtrlr");
  1249. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variable.name, "Measurands");
  1250. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1251. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableCharacteristics.maxLimit = 20;
  1252. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1253. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1254. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1255. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, "Current.Import,"
  1256. "Energy.Active.Import.Register,"
  1257. "Energy.Active.Import.Interval,"
  1258. "Power.Active.Import,"
  1259. "Voltage,"
  1260. "SoC,"
  1261. "Current.Offered,"
  1262. "Power.Offered");
  1263. else
  1264. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, "Current.Import,"
  1265. "Energy.Active.Import.Register,"
  1266. "Energy.Active.Import.Interval,"
  1267. "Power.Active.Import,"
  1268. "Voltage,"
  1269. "Current.Offered");
  1270. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands]);
  1271. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].component.name, "AlignedDataCtrlr");
  1272. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variable.name, "Interval");
  1273. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.unit, "Seconds");
  1274. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1275. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.minLimit = 5;
  1276. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1277. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1278. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value, "0");
  1279. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval]);
  1280. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].component.name, "AlignedDataCtrlr");
  1281. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variable.name, "SendDuringIdle");
  1282. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1283. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1284. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1285. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].value, "TRUE");
  1286. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle]);
  1287. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].component.name, "AlignedDataCtrlr");
  1288. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variable.name, "SignReadings");
  1289. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1290. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1291. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1292. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].value, "FALSE");
  1293. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings]);
  1294. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].component.name, "AlignedDataCtrlr");
  1295. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  1296. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1297. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableCharacteristics.maxLimit = 10;
  1298. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1299. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1300. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1301. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  1302. "Energy.Active.Import.Register,"
  1303. "Energy.Active.Import.Interval,"
  1304. "Power.Active.Import,"
  1305. "Voltage,"
  1306. "SoC");
  1307. else
  1308. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  1309. "Energy.Active.Import.Register,"
  1310. "Energy.Active.Import.Interval,"
  1311. "Power.Active.Import,"
  1312. "Voltage");
  1313. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands]);
  1314. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].component.name, "AlignedDataCtrlr");
  1315. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  1316. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableCharacteristics.unit, "Seconds");
  1317. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1318. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1319. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1320. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].value, "0");
  1321. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval]);
  1322. /* AuthCtrlrVariable Required item */
  1323. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].component.name, "AuthCtrlr");
  1324. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variable.name, "Enabled");
  1325. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1326. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1327. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1328. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1329. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled]);
  1330. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].component.name, "AlignedDataCtrlr");
  1331. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variable.name, "AdditionalInfoItemsPerMessage");
  1332. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1333. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1334. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1335. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].value, "0");
  1336. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage]);
  1337. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].component.name, "AuthCtrlr");
  1338. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variable.name, "OfflineTxForUnknownIdEnabled");
  1339. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1340. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1341. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1342. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].value, "FALSE");
  1343. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled]);
  1344. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].component.name, "AuthCtrlr");
  1345. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variable.name, "AuthorizeRemoteStart");
  1346. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1347. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1348. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1349. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].value, "FALSE");
  1350. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart]);
  1351. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].component.name, "AuthCtrlr");
  1352. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variable.name, "LocalAuthorizeOffline");
  1353. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1354. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1355. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1356. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "TRUE");
  1357. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline]);
  1358. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].component.name, "AuthCtrlr");
  1359. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variable.name, "LocalPreAuthorize");
  1360. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1361. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1362. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1363. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].value, "TRUE");
  1364. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize]);
  1365. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].component.name, "AuthCtrlr");
  1366. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variable.name, "MasterPassGroupId");
  1367. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1368. ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableCharacteristics.maxLimit = 36;
  1369. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1370. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1371. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].value, " ");
  1372. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId]);
  1373. /* AuthCacheCtrlr Variable Required item*/
  1374. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].component.name, "AuthCacheCtrlr");
  1375. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variable.name, "Enabled");
  1376. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1377. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1378. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1379. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1380. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled]);
  1381. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].component.name, "AuthCacheCtrlr");
  1382. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variable.name, "Available");
  1383. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1384. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1385. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1386. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].value, "TRUE");
  1387. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available]);
  1388. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].component.name, "AuthCacheCtrlr");
  1389. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variable.name, "LifeTime");
  1390. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableCharacteristics.unit, "Seconds");
  1391. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1392. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1393. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1394. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].value, "TRUE");
  1395. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime]);
  1396. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].component.name, "AuthCacheCtrlr");
  1397. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variable.name, "Storage");
  1398. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1399. ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableCharacteristics.maxLimit = (1024*10);
  1400. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1401. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1402. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].value, "TRUE");
  1403. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage]);
  1404. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].component.name, "AuthCacheCtrlr");
  1405. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variable.name, "Policy");
  1406. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1407. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1408. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1409. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].value, "LRU,LFU");
  1410. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy]);
  1411. /* ClockCtrlr Variable Required item */
  1412. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].component.name, "ClockCtrlr");
  1413. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variable.name, "DateTime");
  1414. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_dateTime]);
  1415. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1416. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1417. getNowDatetime(ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].value);
  1418. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime]);
  1419. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].component.name, "ClockCtrlr");
  1420. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variable.name, "NtpSource");
  1421. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1422. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1423. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1424. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].value, "DHCP, manual");
  1425. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource]);
  1426. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].component.name, "ClockCtrlr");
  1427. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.name, "NtpServerUri");
  1428. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.instance, "1");
  1429. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1430. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1431. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1432. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].value, " ");
  1433. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri]);
  1434. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].component.name, "ClockCtrlr");
  1435. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variable.name, "TimeOffset");
  1436. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1437. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1438. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1439. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].value, "+00:00");
  1440. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset]);
  1441. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].component.name, "ClockCtrlr");
  1442. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variable.name, "NextTimeOffsetTransitionDateTime");
  1443. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_dateTime]);
  1444. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1445. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1446. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].value, " ");
  1447. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime]);
  1448. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].component.name, "ClockCtrlr");
  1449. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.name, "TimeOffset");
  1450. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.instance, "NextTransition");
  1451. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1452. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1453. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1454. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].value, "+00:00");
  1455. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset]);
  1456. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].component.name, "ClockCtrlr");
  1457. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variable.name, "TimeSource");
  1458. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_SequenceList]);
  1459. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1460. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1461. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].value, "Heartbeat,RealTimeClock");
  1462. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource]);
  1463. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].component.name, "ClockCtrlr");
  1464. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variable.name, "TimeZone");
  1465. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1466. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1467. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1468. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].value, "UTC");
  1469. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone]);
  1470. /* ChargingStation Required item */
  1471. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].component.name, "ChargingStation");
  1472. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variable.name, "Available");
  1473. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1474. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1475. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1476. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].value, "FALSE");
  1477. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available]);
  1478. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].component.name, "ChargingStation");
  1479. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variable.name, "AvailabilityState");
  1480. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1481. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1482. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1483. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].value, "Available,Occupied,Reserved,Unavailable,Faulted");
  1484. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState]);
  1485. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].component.name, "ChargingStation");
  1486. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variable.name, "SupplyPhases");
  1487. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1488. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1489. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1490. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].value, "3");
  1491. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases]);
  1492. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].component.name, "ChargingStation");
  1493. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variable.name, "SystemUptimeSec");
  1494. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1495. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1496. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1497. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variableAttribute[0].value, "0");
  1498. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec]);
  1499. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].component.name, "ChargingStation");
  1500. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variable.name, "FreeVend");
  1501. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1502. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1503. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1504. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variableAttribute[0].value, (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  1505. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend]);
  1506. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].component.name, "ChargingStation");
  1507. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variable.name, "FreeVendIdtag");
  1508. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1509. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Actual]);
  1510. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1511. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variableAttribute[0].value, "FreeVendIdtag");
  1512. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag]);
  1513. /* Connector Required item */
  1514. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].component.name, "Connector");
  1515. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variable.name, "Available");
  1516. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1517. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1518. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1519. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].value, "FALSE");
  1520. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_Available]);
  1521. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].component.name, "Connector");
  1522. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variable.name, "ConnectorType");
  1523. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1524. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1525. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1526. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].value, " ");
  1527. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType]);
  1528. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].component.name, "Connector");
  1529. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variable.name, "SupplyPhases");
  1530. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1531. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1532. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1533. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].value, "3");
  1534. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases]);
  1535. /* CustomizationCtrlr Required item */
  1536. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].component.name, "CustomizationCtrlr");
  1537. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variable.name, "CustomImplementationEnabled");
  1538. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1539. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1540. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1541. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].value, "FALSE");
  1542. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled]);
  1543. /* DeviceDataCtrlr Required item */
  1544. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  1545. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.instance, "GetReport");
  1546. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1547. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1548. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1549. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1550. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].value, "10");
  1551. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage]);
  1552. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  1553. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.instance, "GetVariables");
  1554. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1555. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1556. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1557. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1558. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].value, "10");
  1559. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage]);
  1560. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].component.name, "DeviceDataCtrlr");
  1561. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.instance, "GetReport");
  1562. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.name, "BytesPerMessage");
  1563. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1564. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1565. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1566. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].value, "2048");
  1567. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage]);
  1568. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  1569. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.instance, "GetVariables");
  1570. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  1571. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1572. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1573. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1574. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].value, "2048");
  1575. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage]);
  1576. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].component.name, "DeviceDataCtrlr");
  1577. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variable.name, "ConfigurationValueSize");
  1578. ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableCharacteristics.maxLimit = 1000;
  1579. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1580. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1581. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1582. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].value, "10");
  1583. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize]);
  1584. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].component.name, "DeviceDataCtrlr");
  1585. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variable.name, "ReportingValueSize");
  1586. ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableCharacteristics.maxLimit = 2500;
  1587. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1588. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1589. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1590. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].value, "10");
  1591. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize]);
  1592. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  1593. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.instance, "SetVariables");
  1594. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1595. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1596. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1597. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1598. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].value, "10");
  1599. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage]);
  1600. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  1601. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.instance, "SetVariables");
  1602. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  1603. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1604. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1605. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1606. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].value, "2048");
  1607. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage]);
  1608. /* DisplayMessageCtrlr Required item */
  1609. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].component.name, "DisplayMessageCtrlr");
  1610. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variable.name, "Enabled");
  1611. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1612. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1613. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1614. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1615. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled]);
  1616. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].component.name, "DisplayMessageCtrlr");
  1617. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variable.name, "Available");
  1618. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1619. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1620. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1621. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].value, "FALSE");
  1622. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available]);
  1623. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].component.name, "DisplayMessageCtrlr");
  1624. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variable.name, "DisplayMessages");
  1625. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1626. ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableCharacteristics.maxLimit = 1;
  1627. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1628. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1629. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].value, "%s", "1");
  1630. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages]);
  1631. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].component.name, "DisplayMessageCtrlr");
  1632. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variable.name, "SupportedFormats");
  1633. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1634. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1635. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1636. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].value, " ");
  1637. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats]);
  1638. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].component.name, "DisplayMessageCtrlr");
  1639. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variable.name, "SupportedPriorities");
  1640. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1641. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1642. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1643. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].value, " ");
  1644. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities]);
  1645. /* EVSE Required item */
  1646. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].component.name, "EVSE");
  1647. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variable.name, "Available");
  1648. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1649. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1650. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1651. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].value, "FALSE");
  1652. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_Available]);
  1653. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].component.name, "EVSE");
  1654. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variable.name, "AvailabilityState");
  1655. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1656. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1657. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1658. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].value, "Available,Occupied,Reserved,Unavailable,Faulted");
  1659. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState]);
  1660. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].component.name, "EVSE");
  1661. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variable.name, "SupplyPhases");
  1662. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1663. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1664. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1665. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].value, "3");
  1666. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases]);
  1667. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].component.name, "EVSE");
  1668. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variable.name, "Power");
  1669. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_decimal]);
  1670. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1671. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1672. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].value, "7700");
  1673. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_Power]);
  1674. /* LocalAuthListCtrlr Required item */
  1675. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].component.name, "LocalAuthListCtrlr");
  1676. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variable.name, "Enabled");
  1677. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1678. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1679. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1680. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  1681. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled]);
  1682. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].component.name, "LocalAuthListCtrlr");
  1683. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variable.name, "Entries");
  1684. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1685. ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableCharacteristics.maxLimit = 5000;
  1686. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1687. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1688. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].value, "5000");
  1689. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries]);
  1690. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].component.name, "LocalAuthListCtrlr");
  1691. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variable.name, "Available");
  1692. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1693. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1694. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1695. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].value, "TRUE");
  1696. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available]);
  1697. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].component.name, "LocalAuthListCtrlr");
  1698. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1699. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.instance, "SendLocalList");
  1700. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1701. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1702. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1703. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].value, "500");
  1704. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage]);
  1705. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].component.name, "LocalAuthListCtrlr");
  1706. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.name, "BytesPerMessage");
  1707. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.instance, "SendLocalList");
  1708. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1709. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1710. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1711. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].value, "20480");
  1712. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage]);
  1713. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].component.name, "LocalAuthListCtrlr");
  1714. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variable.name, "Storage");
  1715. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1716. ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableCharacteristics.maxLimit = (1024*10);
  1717. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1718. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1719. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].value, "100000");
  1720. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage]);
  1721. /* MonitoringCtrlr Required item */
  1722. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].component.name, "MonitoringCtrlr");
  1723. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variable.instance, "Enabled");
  1724. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1725. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1726. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1727. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1728. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled]);
  1729. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].component.name, "MonitoringCtrlr");
  1730. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variable.instance, "Available");
  1731. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1732. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1733. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1734. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].value, "FALSE");
  1735. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available]);
  1736. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  1737. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.instance, "ClearVariableMonitoring");
  1738. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1739. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1740. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1741. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1742. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].value, "1");
  1743. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage]);
  1744. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  1745. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.instance, "SetVariableMonitoring");
  1746. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1747. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1748. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1749. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1750. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].value, "1");
  1751. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage]);
  1752. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  1753. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.instance, "ClearVariableMonitoring");
  1754. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  1755. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1756. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1757. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1758. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].value, "2048");
  1759. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage]);
  1760. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  1761. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.instance, "SetVariableMonitoring");
  1762. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  1763. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1764. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1765. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1766. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].value, "2048");
  1767. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage]);
  1768. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].component.name, "MonitoringCtrlr");
  1769. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variable.name, "OfflineQueuingSeverity");
  1770. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1771. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1772. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1773. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].value, "2048");
  1774. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity]);
  1775. /* OCPPCommCtrlr Required item */
  1776. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].component.name, "OCPPCommCtrlr");
  1777. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variable.name, "ActiveNetworkProfile");
  1778. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1779. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1780. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1781. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].value, "1");
  1782. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile]);
  1783. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].component.name, "OCPPCommCtrlr");
  1784. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.instance, "Default");
  1785. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.name, "MessageTimeout");
  1786. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableCharacteristics.unit, "Seconds");
  1787. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1788. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1789. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1790. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].value, "30");
  1791. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout]);
  1792. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].component.name, "OCPPCommCtrlr");
  1793. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variable.name, "FileTransferProtocols");
  1794. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1795. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1796. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1797. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].value, "FTP,FTPS,HTTP,HTTPS");
  1798. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols]);
  1799. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].component.name, "OCPPCommCtrlr");
  1800. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variable.name, "HeartbeatInterval");
  1801. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.unit, "Seconds");
  1802. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.minLimit = 10;
  1803. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1804. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1805. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1806. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value, "30");
  1807. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval]);
  1808. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].component.name, "OCPPCommCtrlr");
  1809. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variable.name, "NetworkConfigurationPriority");
  1810. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_SequenceList]);
  1811. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1812. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1813. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value, "[0]");
  1814. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority]);
  1815. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].component.name, "OCPPCommCtrlr");
  1816. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variable.name, "NetworkProfileConnectionAttempts");
  1817. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1818. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1819. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1820. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].value, "3");
  1821. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts]);
  1822. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].component.name, "OCPPCommCtrlr");
  1823. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variable.name, "OfflineThreshold");
  1824. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableCharacteristics.unit, "Seconds");
  1825. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1826. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1827. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1828. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].value, "30");
  1829. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold]);
  1830. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].component.name, "OCPPCommCtrlr");
  1831. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variable.name, "QueueAllMessages");
  1832. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1833. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1834. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1835. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].value, "FALSE");
  1836. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages]);
  1837. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].component.name, "OCPPCommCtrlr");
  1838. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.instance, "TransactionEvent");
  1839. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.name, "MessageAttempts");
  1840. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableCharacteristics.unit, "Seconds");
  1841. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1842. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1843. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1844. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].value, "3");
  1845. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts]);
  1846. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].component.name, "OCPPCommCtrlr");
  1847. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.instance, "TransactionEvent");
  1848. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.name, "MessageAttemptInterval");
  1849. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableCharacteristics.unit, "Seconds");
  1850. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1851. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1852. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1853. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].value, "30");
  1854. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval]);
  1855. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].component.name, "OCPPCommCtrlr");
  1856. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variable.name, "UnlockOnEVSideDisconnect");
  1857. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1858. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1859. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1860. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].value, "TRUE");
  1861. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect]);
  1862. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].component.name, "OCPPCommCtrlr");
  1863. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variable.name, "WebSocketPingInterval");
  1864. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.unit, "Seconds");
  1865. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.minLimit = 10;
  1866. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1867. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1868. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1869. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].value, "30");
  1870. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval]);
  1871. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].component.name, "OCPPCommCtrlr");
  1872. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variable.name, "ResetRetries");
  1873. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1874. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1875. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1876. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].value, "3");
  1877. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries]);
  1878. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].component.name, "OCPPCommCtrlr");
  1879. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variable.name, "PublicKeyWithSignedMeterValue");
  1880. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1881. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1882. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1883. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].value, "Never,OncePerTransaction,EveryMeterValue");
  1884. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue]);
  1885. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].component.name, "OCPPCommCtrlr");
  1886. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variable.name, "VariableVersion");
  1887. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1888. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1889. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1890. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].value, "%d", variableVersion);
  1891. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion]);
  1892. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].component.name, "OCPPCommCtrlr");
  1893. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variable.name, "StatusNotificationPeriodically");
  1894. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1895. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1896. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1897. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].value, "FALSE");
  1898. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically]);
  1899. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].component.name, "OCPPCommCtrlr");
  1900. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variable.name, "StatusNotificationInterval");
  1901. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableCharacteristics.unit, "Seconds");
  1902. ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableCharacteristics.minLimit = 10;
  1903. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1904. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1905. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1906. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].value, "120");
  1907. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval]);
  1908. /* ReservationCtrlr Required item */
  1909. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].component.name, "ReservationCtrlr");
  1910. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variable.name, "Enabled");
  1911. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1912. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1913. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1914. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  1915. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled]);
  1916. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].component.name, "ReservationCtrlr");
  1917. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variable.name, "Available");
  1918. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1919. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1920. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1921. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].value, "TRUE");
  1922. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available]);
  1923. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].component.name, "ReservationCtrlr");
  1924. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variable.name, "NonEvseSpecific");
  1925. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1926. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1927. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1928. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].value, "FALSE");
  1929. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific]);
  1930. /* SampledDataCtrlr Required item */
  1931. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].component.name, "SampledDataCtrlr");
  1932. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variable.name, "Enabled");
  1933. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1934. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1935. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1936. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  1937. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled]);
  1938. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].component.name, "SampledDataCtrlr");
  1939. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variable.name, "Available");
  1940. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1941. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1942. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1943. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].value, "TRUE");
  1944. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available]);
  1945. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].component.name, "SampledDataCtrlr");
  1946. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variable.name, "SignReadings");
  1947. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1948. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1949. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1950. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].value, "FALSE");
  1951. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings]);
  1952. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].component.name, "SampledDataCtrlr");
  1953. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  1954. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1955. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableCharacteristics.maxLimit = 10;
  1956. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1957. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1958. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1959. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  1960. "Energy.Active.Import.Register,"
  1961. "Energy.Active.Import.Interval,"
  1962. "Power.Active.Import,"
  1963. "Voltage,"
  1964. "SoC");
  1965. else
  1966. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,"
  1967. "Energy.Active.Import.Register,"
  1968. "Energy.Active.Import.Interval,"
  1969. "Power.Active.Import,"
  1970. "Voltage");
  1971. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands]);
  1972. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].component.name, "SampledDataCtrlr");
  1973. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  1974. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableCharacteristics.unit, "Seconds");
  1975. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1976. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1977. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1978. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].value, "0");
  1979. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval]);
  1980. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].component.name, "SampledDataCtrlr");
  1981. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variable.name, "TxStartedMeasurands");
  1982. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1983. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableCharacteristics.maxLimit = 10;
  1984. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1985. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1986. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].value, " ");
  1987. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands]);
  1988. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].component.name, "SampledDataCtrlr");
  1989. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variable.name, "TxUpdatedMeasurands");
  1990. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1991. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableCharacteristics.maxLimit = 10;
  1992. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1993. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1994. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1995. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, "Current.Import,"
  1996. "Energy.Active.Import.Register,"
  1997. "Energy.Active.Import.Interval,"
  1998. "Power.Active.Import,"
  1999. "Voltage,"
  2000. "SoC,"
  2001. "Current.Offered,"
  2002. "Power.Offered");
  2003. else
  2004. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, "Current.Import,"
  2005. "Energy.Active.Import.Register,"
  2006. "Energy.Active.Import.Interval,"
  2007. "Power.Active.Import,"
  2008. "Voltage,"
  2009. "Current.Offered");
  2010. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands]);
  2011. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].component.name, "SampledDataCtrlr");
  2012. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variable.name, "TxUpdatedInterval");
  2013. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.unit, "Seconds");
  2014. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2015. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.minLimit = 3;
  2016. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2017. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2018. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value, "30");
  2019. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval]);
  2020. /* SecurityCtrlr Required item */
  2021. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].component.name, "SecurityCtrlr");
  2022. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variable.name, "BasicAuthPassword");
  2023. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2024. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableCharacteristics.maxLimit = 40;
  2025. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2026. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_WriteOnly]);
  2027. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].value, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  2028. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword]);
  2029. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].component.name, "SecurityCtrlr");
  2030. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variable.name, "Identity");
  2031. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2032. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableCharacteristics.maxLimit = 48;
  2033. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2034. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2035. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].value, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  2036. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity]);
  2037. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].component.name, "SecurityCtrlr");
  2038. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variable.name, "OrganizationName");
  2039. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2040. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2041. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2042. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].value, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2043. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName]);
  2044. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].component.name, "SecurityCtrlr");
  2045. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variable.name, "CertificateEntries");
  2046. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2047. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableCharacteristics.maxLimit = 1;
  2048. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2049. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2050. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].value, "1");
  2051. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries]);
  2052. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].component.name, "SecurityCtrlr");
  2053. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variable.name, "SecurityProfile");
  2054. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2055. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2056. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2057. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].value, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  2058. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile]);
  2059. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].component.name, "SecurityCtrlr");
  2060. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variable.name, "AdditionalRootCertificateCheck");
  2061. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2062. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2063. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2064. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].value, "FALSE");
  2065. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck]);
  2066. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].component.name, "SecurityCtrlr");
  2067. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variable.name, "MaxCertificateChainSize");
  2068. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2069. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableCharacteristics.maxLimit = 10000;
  2070. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2071. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2072. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].value, "10000");
  2073. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize]);
  2074. /* SmartChargingCtrlr Required item */
  2075. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].component.name, "SmartChargingCtrlr");
  2076. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variable.name, "Enabled");
  2077. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2078. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2079. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2080. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  2081. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled]);
  2082. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].component.name, "SmartChargingCtrlr");
  2083. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variable.name, "Available");
  2084. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2085. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2086. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2087. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].value, "TRUE");
  2088. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available]);
  2089. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].component.name, "SmartChargingCtrlr");
  2090. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variable.name, "ACPhaseSwitchingSupported");
  2091. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2092. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2093. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2094. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].value, "FALSE");
  2095. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported]);
  2096. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].component.name, "SmartChargingCtrlr");
  2097. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variable.name, "ProfileStackLevel");
  2098. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2099. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2100. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2101. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value, "0");
  2102. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel]);
  2103. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].component.name, "SmartChargingCtrlr");
  2104. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variable.name, "RateUnit");
  2105. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  2106. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2107. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2108. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].value, "A,W");
  2109. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit]);
  2110. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].component.name, "SmartChargingCtrlr");
  2111. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variable.name, "PeriodsPerSchedule");
  2112. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2113. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2114. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2115. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].value, "10");
  2116. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule]);
  2117. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].component.name, "SmartChargingCtrlr");
  2118. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variable.name, "ExternalControlSignalsEnabled");
  2119. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2120. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2121. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2122. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].value, "FALSE");
  2123. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled]);
  2124. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].component.name, "SmartChargingCtrlr");
  2125. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variable.name, "NotifyChargingLimitWithSchedules");
  2126. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2127. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2128. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2129. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].value, "FALSE");
  2130. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules]);
  2131. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].component.name, "SmartChargingCtrlr");
  2132. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variable.name, "Phases3to1");
  2133. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2134. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2135. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2136. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].value, "FALSE");
  2137. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1]);
  2138. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].component.name, "SmartChargingCtrlr");
  2139. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variable.name, "Entries");
  2140. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2141. ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableCharacteristics.maxLimit = 10;
  2142. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2143. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2144. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value, "10");
  2145. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries]);
  2146. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].component.name, "SmartChargingCtrlr");
  2147. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variable.name, "LimitChangeSignificance");
  2148. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_decimal]);
  2149. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2150. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2151. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].value, "1");
  2152. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance]);
  2153. /* TariffCostCtrlr Required item */
  2154. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].component.name, "TariffCostCtrlr");
  2155. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.instance, "Tariff");
  2156. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.name, "Enabled");
  2157. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2158. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2159. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2160. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].value, "FALSE");
  2161. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled]);
  2162. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].component.name, "TariffCostCtrlr");
  2163. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.instance, "Tariff");
  2164. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.name, "Available");
  2165. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2166. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2167. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2168. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].value, "FALSE");
  2169. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_Available]);
  2170. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].component.name, "TariffCostCtrlr");
  2171. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variable.name, "TariffFallbackMessage");
  2172. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2173. ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableCharacteristics.maxLimit = 255;
  2174. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2175. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2176. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].value, " ");
  2177. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage]);
  2178. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].component.name, "TariffCostCtrlr");
  2179. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.instance, "Cost");
  2180. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.name, "Enabled");
  2181. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2182. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2183. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2184. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].value, "FALSE");
  2185. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled]);
  2186. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].component.name, "TariffCostCtrlr");
  2187. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.instance, "Cost");
  2188. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.name, "Available");
  2189. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2190. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2191. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2192. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].value, "FALSE");
  2193. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Available]);
  2194. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].component.name, "TariffCostCtrlr");
  2195. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variable.name, "TotalCostFallbackMessage");
  2196. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2197. ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableCharacteristics.maxLimit = 255;
  2198. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2199. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2200. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].value, " ");
  2201. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage]);
  2202. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].component.name, "TariffCostCtrlr");
  2203. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variable.name, "Currency");
  2204. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2205. ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableCharacteristics.maxLimit = 3;
  2206. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2207. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2208. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].value, "NTD");
  2209. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Currency]);
  2210. /* TxCtrlr Required item */
  2211. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2212. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variable.name, "ChargingBeforeAcceptedEnabled");
  2213. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2214. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2215. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2216. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].value, "FALSE");
  2217. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled]);
  2218. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].component.name, "TxCtrlr");
  2219. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variable.name, "EVConnectionTimeOut");
  2220. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableCharacteristics.unit, "Seconds");
  2221. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2222. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2223. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2224. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value, "180");
  2225. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut]);
  2226. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].component.name, "TxCtrlr");
  2227. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variable.name, "StopTxOnEVSideDisconnect");
  2228. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2229. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2230. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2231. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].value, "TRUE");
  2232. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect]);
  2233. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2234. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variable.name, "TxBeforeAcceptedEnabled");
  2235. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2236. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2237. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2238. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].value, "FALSE");
  2239. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled]);
  2240. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].component.name, "TxCtrlr");
  2241. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variable.name, "TxStartPoint");
  2242. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2243. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2244. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2245. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].value, "PowerPathClosed");
  2246. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint]);
  2247. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].component.name, "TxCtrlr");
  2248. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variable.name, "TxStopPoint");
  2249. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2250. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2251. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2252. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].value, "PowerPathClosed");
  2253. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint]);
  2254. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].component.name, "TxCtrlr");
  2255. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variable.name, "MaxEnergyOnInvalidId");
  2256. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2257. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableCharacteristics.unit, "Wh");
  2258. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2259. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2260. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].value, "0");
  2261. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId]);
  2262. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].component.name, "TxCtrlr");
  2263. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variable.name, "StopTxOnInvalidId");
  2264. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2265. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2266. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2267. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].value, "FALSE");
  2268. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId]);
  2269. }
  2270. else
  2271. {
  2272. // Variable name init
  2273. /* AlignedDataCtrlr Required item */
  2274. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].component.name, "AlignedDataCtrlr");
  2275. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variable.name, "Enabled");
  2276. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].component.name, "AlignedDataCtrlr");
  2277. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variable.name, "Available");
  2278. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].component.name, "AlignedDataCtrlr");
  2279. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variable.name, "Measurands");
  2280. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].component.name, "AlignedDataCtrlr");
  2281. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variable.name, "Interval");
  2282. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].component.name, "AlignedDataCtrlr");
  2283. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variable.name, "SendDuringIdle");
  2284. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].component.name, "AlignedDataCtrlr");
  2285. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variable.name, "SignReadings");
  2286. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].component.name, "AlignedDataCtrlr");
  2287. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2288. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].component.name, "AlignedDataCtrlr");
  2289. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2290. /* AuthCtrlrVariable Required item */
  2291. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].component.name, "AuthCtrlr");
  2292. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variable.name, "Enabled");
  2293. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].component.name, "AlignedDataCtrlr");
  2294. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variable.name, "AdditionalInfoItemsPerMessage");
  2295. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].component.name, "AuthCtrlr");
  2296. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variable.name, "OfflineTxForUnknownIdEnabled");
  2297. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].component.name, "AuthCtrlr");
  2298. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variable.name, "AuthorizeRemoteStart");
  2299. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].component.name, "AuthCtrlr");
  2300. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variable.name, "LocalAuthorizeOffline");
  2301. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].component.name, "AuthCtrlr");
  2302. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variable.name, "LocalPreAuthorize");
  2303. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].component.name, "AuthCtrlr");
  2304. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variable.name, "MasterPassGroupId");
  2305. /* AuthCacheCtrlr Variable Required item */
  2306. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].component.name, "AuthCacheCtrlr");
  2307. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variable.name, "Enabled");
  2308. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].component.name, "AuthCacheCtrlr");
  2309. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variable.name, "Available");
  2310. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].component.name, "AuthCacheCtrlr");
  2311. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variable.name, "LifeTime");
  2312. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].component.name, "AuthCacheCtrlr");
  2313. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variable.name, "Storage");
  2314. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].component.name, "AuthCacheCtrlr");
  2315. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variable.name, "Policy");
  2316. /* ClockCtrlr Variable Required item */
  2317. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].component.name, "ClockCtrlr");
  2318. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variable.name, "DateTime");
  2319. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].component.name, "ClockCtrlr");
  2320. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variable.name, "NtpSource");
  2321. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].component.name, "ClockCtrlr");
  2322. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.name, "NtpServerUri");
  2323. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.instance, "1");
  2324. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].component.name, "ClockCtrlr");
  2325. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variable.name, "TimeOffset");
  2326. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].component.name, "ClockCtrlr");
  2327. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variable.name, "NextTimeOffsetTransitionDateTime");
  2328. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].component.name, "ClockCtrlr");
  2329. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.name, "TimeOffset");
  2330. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.instance, "NextTransition");
  2331. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].component.name, "ClockCtrlr");
  2332. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variable.name, "TimeSource");
  2333. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].component.name, "ClockCtrlr");
  2334. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variable.name, "TimeZone");
  2335. /* ChargingStation Required item */
  2336. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].component.name, "ChargingStation");
  2337. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variable.name, "Available");
  2338. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].component.name, "ChargingStation");
  2339. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variable.name, "AvailabilityState");
  2340. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].component.name, "ChargingStation");
  2341. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variable.name, "SupplyPhases");
  2342. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].component.name, "ChargingStation");
  2343. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SystemUptimeSec].variable.name, "SystemUptimeSec");
  2344. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].component.name, "ChargingStation");
  2345. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVend].variable.name, "FreeVend");
  2346. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].component.name, "ChargingStation");
  2347. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_FreeVendIdtag].variable.name, "FreeVendIdtag");
  2348. /* Connector Required item */
  2349. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].component.name, "Connector");
  2350. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variable.name, "Available");
  2351. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].component.name, "Connector");
  2352. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variable.name, "ConnectorType");
  2353. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].component.name, "Connector");
  2354. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variable.name, "SupplyPhases");
  2355. /* CustomizationCtrlr Required item */
  2356. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].component.name, "CustomizationCtrlr");
  2357. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variable.name, "CustomImplementationEnabled");
  2358. /* DeviceDataCtrlr Required item */
  2359. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2360. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.instance, "GetReport");
  2361. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2362. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2363. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.instance, "GetVariables");
  2364. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2365. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2366. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.instance, "GetReport");
  2367. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.name, "BytesPerMessage");
  2368. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2369. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.instance, "GetVariables");
  2370. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2371. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].component.name, "DeviceDataCtrlr");
  2372. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variable.name, "ConfigurationValueSize");
  2373. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].component.name, "DeviceDataCtrlr");
  2374. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variable.name, "ReportingValueSize");
  2375. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2376. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.instance, "SetVariables");
  2377. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2378. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2379. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.instance, "SetVariables");
  2380. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2381. /* DisplayMessageCtrlr Required item */
  2382. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].component.name, "DisplayMessageCtrlr");
  2383. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variable.name, "Enabled");
  2384. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].component.name, "DisplayMessageCtrlr");
  2385. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variable.name, "Available");
  2386. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].component.name, "DisplayMessageCtrlr");
  2387. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variable.name, "DisplayMessages");
  2388. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].component.name, "DisplayMessageCtrlr");
  2389. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variable.name, "SupportedFormats");
  2390. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].component.name, "DisplayMessageCtrlr");
  2391. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variable.name, "SupportedPriorities");
  2392. /* EVSE Required item */
  2393. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].component.name, "EVSE");
  2394. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variable.name, "Available");
  2395. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].component.name, "EVSE");
  2396. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variable.name, "AvailabilityState");
  2397. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].component.name, "EVSE");
  2398. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variable.name, "SupplyPhases");
  2399. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].component.name, "EVSE");
  2400. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variable.name, "Power");
  2401. /* LocalAuthListCtrlr Required item */
  2402. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].component.name, "LocalAuthListCtrlr");
  2403. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variable.name, "Enabled");
  2404. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].component.name, "LocalAuthListCtrlr");
  2405. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variable.name, "Entries");
  2406. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].component.name, "LocalAuthListCtrlr");
  2407. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variable.name, "Available");
  2408. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].component.name, "LocalAuthListCtrlr");
  2409. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2410. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.instance, "SendLocalList");
  2411. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].component.name, "LocalAuthListCtrlr");
  2412. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.name, "BytesPerMessage");
  2413. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.instance, "SendLocalList");
  2414. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].component.name, "LocalAuthListCtrlr");
  2415. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variable.name, "Storage");
  2416. /* MonitoringCtrlr Required item */
  2417. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].component.name, "MonitoringCtrlr");
  2418. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variable.instance, "Enabled");
  2419. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].component.name, "MonitoringCtrlr");
  2420. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variable.instance, "Available");
  2421. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2422. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.instance, "ClearVariableMonitoring");
  2423. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2424. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2425. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.instance, "SetVariableMonitoring");
  2426. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2427. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2428. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.instance, "ClearVariableMonitoring");
  2429. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2430. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2431. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.instance, "SetVariableMonitoring");
  2432. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2433. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].component.name, "MonitoringCtrlr");
  2434. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variable.name, "OfflineQueuingSeverity");
  2435. /* OCPPCommCtrlr Required item */
  2436. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].component.name, "OCPPCommCtrlr");
  2437. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variable.name, "ActiveNetworkProfile");
  2438. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].component.name, "OCPPCommCtrlr");
  2439. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.instance, "Default");
  2440. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.name, "MessageTimeout");
  2441. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].component.name, "OCPPCommCtrlr");
  2442. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variable.name, "FileTransferProtocols");
  2443. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].component.name, "OCPPCommCtrlr");
  2444. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variable.name, "HeartbeatInterval");
  2445. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].component.name, "OCPPCommCtrlr");
  2446. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variable.name, "NetworkConfigurationPriority");
  2447. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].component.name, "OCPPCommCtrlr");
  2448. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variable.name, "NetworkProfileConnectionAttempts");
  2449. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].component.name, "OCPPCommCtrlr");
  2450. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variable.name, "OfflineThreshold");
  2451. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].component.name, "OCPPCommCtrlr");
  2452. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variable.name, "QueueAllMessages");
  2453. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].component.name, "OCPPCommCtrlr");
  2454. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.instance, "TransactionEvent");
  2455. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.name, "MessageAttempts");
  2456. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].component.name, "OCPPCommCtrlr");
  2457. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.instance, "TransactionEvent");
  2458. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.name, "MessageAttemptInterval");
  2459. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].component.name, "OCPPCommCtrlr");
  2460. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variable.name, "UnlockOnEVSideDisconnect");
  2461. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].component.name, "OCPPCommCtrlr");
  2462. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variable.name, "WebSocketPingInterval");
  2463. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].component.name, "OCPPCommCtrlr");
  2464. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variable.name, "ResetRetries");
  2465. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].component.name, "OCPPCommCtrlr");
  2466. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variable.name, "PublicKeyWithSignedMeterValue");
  2467. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].component.name, "OCPPCommCtrlr");
  2468. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variable.name, "VariableVersion");
  2469. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].component.name, "OCPPCommCtrlr");
  2470. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variable.name, "StatusNotificationPeriodically");
  2471. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].component.name, "OCPPCommCtrlr");
  2472. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variable.name, "StatusNotificationInterval");
  2473. /* ReservationCtrlr Required item */
  2474. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].component.name, "ReservationCtrlr");
  2475. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variable.name, "Enabled");
  2476. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].component.name, "ReservationCtrlr");
  2477. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variable.name, "Available");
  2478. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].component.name, "ReservationCtrlr");
  2479. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variable.name, "NonEvseSpecific");
  2480. /* SampledDataCtrlr Required item */
  2481. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].component.name, "SampledDataCtrlr");
  2482. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variable.name, "Enabled");
  2483. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].component.name, "SampledDataCtrlr");
  2484. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variable.name, "Available");
  2485. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].component.name, "SampledDataCtrlr");
  2486. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variable.name, "SignReadings");
  2487. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].component.name, "SampledDataCtrlr");
  2488. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2489. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].component.name, "SampledDataCtrlr");
  2490. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2491. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].component.name, "SampledDataCtrlr");
  2492. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variable.name, "TxStartedMeasurands");
  2493. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].component.name, "SampledDataCtrlr");
  2494. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variable.name, "TxUpdatedMeasurands");
  2495. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].component.name, "SampledDataCtrlr");
  2496. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variable.name, "TxUpdatedInterval");
  2497. /* SecurityCtrlr Required item */
  2498. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].component.name, "SecurityCtrlr");
  2499. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variable.name, "BasicAuthPassword");
  2500. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].component.name, "SecurityCtrlr");
  2501. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variable.name, "Identity");
  2502. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].component.name, "SecurityCtrlr");
  2503. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variable.name, "OrganizationName");
  2504. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].component.name, "SecurityCtrlr");
  2505. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variable.name, "CertificateEntries");
  2506. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].component.name, "SecurityCtrlr");
  2507. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variable.name, "SecurityProfile");
  2508. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].component.name, "SecurityCtrlr");
  2509. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variable.name, "AdditionalRootCertificateCheck");
  2510. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].component.name, "SecurityCtrlr");
  2511. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variable.name, "MaxCertificateChainSize");
  2512. /* SmartChargingCtrlr Required item */
  2513. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].component.name, "SmartChargingCtrlr");
  2514. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variable.name, "Enabled");
  2515. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].component.name, "SmartChargingCtrlr");
  2516. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variable.name, "Available");
  2517. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].component.name, "SmartChargingCtrlr");
  2518. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variable.name, "ACPhaseSwitchingSupported");
  2519. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].component.name, "SmartChargingCtrlr");
  2520. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variable.name, "ProfileStackLevel");
  2521. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].component.name, "SmartChargingCtrlr");
  2522. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variable.name, "RateUnit");
  2523. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].component.name, "SmartChargingCtrlr");
  2524. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variable.name, "PeriodsPerSchedule");
  2525. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].component.name, "SmartChargingCtrlr");
  2526. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variable.name, "ExternalControlSignalsEnabled");
  2527. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].component.name, "SmartChargingCtrlr");
  2528. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variable.name, "NotifyChargingLimitWithSchedules");
  2529. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].component.name, "SmartChargingCtrlr");
  2530. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variable.name, "Phases3to1");
  2531. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].component.name, "SmartChargingCtrlr");
  2532. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variable.name, "Entries");
  2533. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].component.name, "SmartChargingCtrlr");
  2534. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variable.name, "LimitChangeSignificance");
  2535. /* TariffCostCtrlr Required item */
  2536. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].component.name, "TariffCostCtrlr");
  2537. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.instance, "Tariff");
  2538. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.name, "Enabled");
  2539. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].component.name, "TariffCostCtrlr");
  2540. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.instance, "Tariff");
  2541. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.name, "Available");
  2542. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].component.name, "TariffCostCtrlr");
  2543. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variable.name, "TariffFallbackMessage");
  2544. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].component.name, "TariffCostCtrlr");
  2545. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.instance, "Cost");
  2546. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.name, "Enabled");
  2547. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].component.name, "TariffCostCtrlr");
  2548. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.instance, "Cost");
  2549. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.name, "Available");
  2550. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].component.name, "TariffCostCtrlr");
  2551. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variable.name, "TotalCostFallbackMessage");
  2552. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].component.name, "TariffCostCtrlr");
  2553. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variable.name, "Currency");
  2554. /* TxCtrlr Required item */
  2555. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2556. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variable.name, "ChargingBeforeAcceptedEnabled");
  2557. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].component.name, "TxCtrlr");
  2558. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variable.name, "EVConnectionTimeOut");
  2559. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].component.name, "TxCtrlr");
  2560. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variable.name, "StopTxOnEVSideDisconnect");
  2561. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2562. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variable.name, "TxBeforeAcceptedEnabled");
  2563. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].component.name, "TxCtrlr");
  2564. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variable.name, "TxStartPoint");
  2565. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].component.name, "TxCtrlr");
  2566. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variable.name, "TxStopPoint");
  2567. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].component.name, "TxCtrlr");
  2568. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variable.name, "MaxEnergyOnInvalidId");
  2569. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].component.name, "TxCtrlr");
  2570. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variable.name, "StopTxOnInvalidId");
  2571. }
  2572. return 0;
  2573. }
  2574. void DB_variableIsCreate()
  2575. {
  2576. char sql[512];
  2577. char* errMsg = NULL;
  2578. sprintf(sql,"select count(idx) as quantity from ocpp20_variable;");
  2579. /* Execute SQL statement */
  2580. if(sqlite3_exec(db, sql, DB_cbVariableIsCreate, 0, &errMsg) != SQLITE_OK )
  2581. {
  2582. DEBUG_INFO("SQL error: %s\n", errMsg);
  2583. }
  2584. }
  2585. int DB_cbVariableLoadFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  2586. {
  2587. for(int idx=0;idx<CtrlrVariable_CNT;idx++)
  2588. {
  2589. if((strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].component.name, columnValue[1]) == 0) &&
  2590. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].component.instance, columnValue[2]) == 0) &&
  2591. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variable.name, columnValue[3]) == 0) &&
  2592. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variable.instance, columnValue[4]) == 0))
  2593. {
  2594. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.dataType, "%s", columnValue[5]);
  2595. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.unit, "%s", columnValue[6]);
  2596. ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.maxLimit = strlen(columnValue[7])>0?atoi(columnValue[7]):255;
  2597. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].type, "%s", columnValue[8]);
  2598. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].mutability, "%s", columnValue[9]);
  2599. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].value, "%s", columnValue[10]);
  2600. ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.minLimit = strlen(columnValue[11])>=0?atoi(columnValue[11]):0;
  2601. }
  2602. }
  2603. return 0;
  2604. }
  2605. void DB_variableLoadFromDb()
  2606. {
  2607. char sql[512];
  2608. char* errMsg = NULL;
  2609. sprintf(sql,"select * from ocpp20_variable order by idx;");
  2610. /* Execute SQL statement */
  2611. if(sqlite3_exec(db, sql, DB_cbVariableLoadFromDb, 0, &errMsg) != SQLITE_OK )
  2612. {
  2613. DEBUG_INFO("SQL error: %s\n", errMsg);
  2614. }
  2615. }
  2616. int DB_cbGetNetworkProfileFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  2617. {
  2618. memset(&ShmOCPP20Data->NetworkConnectionProfile[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile));
  2619. if(columnCount > 0)
  2620. {
  2621. for(int idx=0;idx<columnCount;idx++)
  2622. {
  2623. json_object *SetNetworkProfile;
  2624. SetNetworkProfile = json_tokener_parse(columnValue[2]);
  2625. if(!is_error(SetNetworkProfile))
  2626. {
  2627. // Required data
  2628. if(json_object_object_get(SetNetworkProfile, "ocppVersion") != NULL)
  2629. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppVersion, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppVersion")));
  2630. if(json_object_object_get(SetNetworkProfile, "ocppTransport") != NULL)
  2631. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppTransport")));
  2632. if(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl") != NULL)
  2633. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl")));
  2634. if(json_object_object_get(SetNetworkProfile, "messageTimeout") != NULL)
  2635. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.messageTimeout = json_object_get_int(json_object_object_get(SetNetworkProfile, "messageTimeout"));
  2636. if(json_object_object_get(SetNetworkProfile, "ocppInterface") != NULL)
  2637. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppInterface, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppInterface")));
  2638. if(json_object_object_get(SetNetworkProfile, "vpn") != NULL)
  2639. {
  2640. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server") != NULL)
  2641. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.server, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server")));
  2642. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user") != NULL)
  2643. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.user, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user")));
  2644. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group") != NULL)
  2645. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.group, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group")));
  2646. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password") != NULL)
  2647. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.password, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password")));
  2648. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key") != NULL)
  2649. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.key, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key")));
  2650. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type") != NULL)
  2651. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type")));
  2652. }
  2653. if(json_object_object_get(SetNetworkProfile, "apn") != NULL)
  2654. {
  2655. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn") != NULL)
  2656. {
  2657. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn));
  2658. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn")));
  2659. }
  2660. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName") != NULL)
  2661. {
  2662. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName));
  2663. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName")));
  2664. }
  2665. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword") != NULL)
  2666. {
  2667. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword));
  2668. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword")));
  2669. }
  2670. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin") != NULL)
  2671. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.simPin = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin"));
  2672. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork") != NULL)
  2673. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.preferredNetwork, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork")));
  2674. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork") != NULL)
  2675. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.useOnlyPreferredNetwork = json_object_get_boolean(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork"));
  2676. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication") != NULL)
  2677. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnAuthentication, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication")));
  2678. }
  2679. }
  2680. json_object_put(SetNetworkProfile);
  2681. ShmOCPP20Data->NetworkConnectionProfile[idx].slot = atoi(columnValue[1]);
  2682. }
  2683. }
  2684. return 0;
  2685. }
  2686. void DB_getNetworkProfileFromDb()
  2687. {
  2688. char sql[512];
  2689. char* errMsg = NULL;
  2690. sprintf(sql,"select * from ocpp20_networkprofile order by slot;");
  2691. /* Execute SQL statement */
  2692. if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
  2693. {
  2694. DEBUG_INFO("SQL error: %s\n", errMsg);
  2695. }
  2696. }
  2697. int DB_addNetworkProfile(int slot, char *data)
  2698. {
  2699. int result = PASS;
  2700. char sql[512];
  2701. char* errMsg = NULL;
  2702. sprintf(sql,"insert or replace into ocpp20_networkprofile (slot, connectionData) VALUES('%d', '%s'); SELECT * from ocpp20_networkprofile order by slot;",
  2703. slot,
  2704. data);
  2705. //* Execute SQL statement */
  2706. if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK)
  2707. {
  2708. DEBUG_INFO("SQL error: %s\n", errMsg);
  2709. result = FAIL;
  2710. }
  2711. return result;
  2712. }
  2713. int DB_deleteNetworkProfile(int slot)
  2714. {
  2715. int result = PASS;
  2716. char sql[512];
  2717. char* errMsg = NULL;
  2718. sprintf(sql,"DELETE from ocpp20_networkprofile where slot=%d; SELECT * from ocpp20_networkprofile order by slot;", slot);
  2719. //* Execute SQL statement */
  2720. if( sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
  2721. {
  2722. DEBUG_INFO("SQL error: %s", errMsg);
  2723. result = FAIL;
  2724. }
  2725. return result;
  2726. }
  2727. int getCurrentYear()
  2728. {
  2729. int result = 0;
  2730. time_t CurrentTime;
  2731. struct tm *tm;
  2732. CurrentTime = time(NULL);
  2733. tm=localtime(&CurrentTime);
  2734. result = (tm->tm_year + 1900);
  2735. return result;
  2736. }
  2737. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  2738. {
  2739. int result = PASS;
  2740. char* errMsg = NULL;
  2741. char sqlStr[8192];
  2742. sprintf(sqlStr, "insert into ocpp20_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  2743. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  2744. {
  2745. result = FAIL;
  2746. DEBUG_WARN( "Insert local transaction record error message: %s\n", errMsg);
  2747. }
  2748. 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));
  2749. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  2750. {
  2751. result = FAIL;
  2752. DEBUG_WARN( "delete local transaction record error message: %s\n", errMsg);
  2753. }
  2754. return result;
  2755. }
  2756. //==========================================
  2757. // Check time passed since today
  2758. //==========================================
  2759. long long DiffTimebWithNow(struct timeb ST)
  2760. {
  2761. //return milli-second
  2762. struct timeb ET;
  2763. long long StartTime,StopTime;
  2764. ftime(&ET);
  2765. StartTime=(long long)ST.time;
  2766. StopTime=(long long)ET.time;
  2767. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  2768. }
  2769. int getTimePassSinceToday(uint8_t gun_index)
  2770. {
  2771. int result = -1;
  2772. static time_t lastTime[4];
  2773. time_t t;
  2774. struct tm *tmStartToday;
  2775. struct timeb tbStartToday;
  2776. t=time(NULL);
  2777. if(difftime(t, lastTime[gun_index])>0)
  2778. {
  2779. tmStartToday=localtime(&t);
  2780. tmStartToday->tm_hour = 0;
  2781. tmStartToday->tm_min = 0;
  2782. tmStartToday->tm_sec = 0;
  2783. tbStartToday.time = mktime(tmStartToday);
  2784. tbStartToday.millitm = 0;
  2785. result = DiffTimebWithNow(tbStartToday)/1000;
  2786. lastTime[gun_index] = t;
  2787. }
  2788. return result;
  2789. }
  2790. int syncDateTimeRTC(uint8_t *data)
  2791. {
  2792. struct ParsingResult
  2793. {
  2794. int result;
  2795. int scanedElement;
  2796. int year;
  2797. int month;
  2798. int mday;
  2799. int hour;
  2800. int min;
  2801. int sec;
  2802. int tz_hour;
  2803. int tz_min;
  2804. float minSec;
  2805. }result;
  2806. struct tm tmOrg;
  2807. struct tm *tmTarget;
  2808. struct timeb tbTarget;
  2809. char buf[128];
  2810. memset(&result, 0x00, sizeof(struct ParsingResult));
  2811. result.result = PASS;
  2812. if(strstr((char*)data, ".") != NULL)
  2813. {
  2814. // Original data with mini second
  2815. if(strstr((char*)data, "Z") != NULL)
  2816. {
  2817. // Original data with Z
  2818. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  2819. &result.year,
  2820. &result.month,
  2821. &result.mday,
  2822. &result.hour,
  2823. &result.min,
  2824. &result.sec,
  2825. &result.minSec);
  2826. }
  2827. else
  2828. {
  2829. // Original data without Z
  2830. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  2831. &result.year,
  2832. &result.month,
  2833. &result.mday,
  2834. &result.hour,
  2835. &result.min,
  2836. &result.sec,
  2837. &result.minSec,
  2838. &result.tz_hour,
  2839. &result.tz_min);
  2840. }
  2841. }
  2842. else
  2843. {
  2844. // Original data without mini second
  2845. if(strstr((char*)data, "Z") != NULL)
  2846. {
  2847. // Original data with Z
  2848. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  2849. &result.year,
  2850. &result.month,
  2851. &result.mday,
  2852. &result.hour,
  2853. &result.min,
  2854. &result.sec);
  2855. }
  2856. else
  2857. {
  2858. // Original data without Z
  2859. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  2860. &result.year,
  2861. &result.month,
  2862. &result.mday,
  2863. &result.hour,
  2864. &result.min,
  2865. &result.sec,
  2866. &result.tz_hour,
  2867. &result.tz_min);
  2868. }
  2869. }
  2870. tmOrg.tm_year = result.year - 1900;
  2871. tmOrg.tm_mon = result.month - 1;
  2872. tmOrg.tm_mday = result.mday;
  2873. tmOrg.tm_hour = result.hour;
  2874. tmOrg.tm_min = result.min;
  2875. tmOrg.tm_sec = result.sec;
  2876. tmOrg.tm_gmtoff = 0;
  2877. tbTarget.time = mktime(&tmOrg);
  2878. tbTarget.timezone = 0;
  2879. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  2880. tmTarget = gmtime(&tbTarget.time);
  2881. 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);
  2882. //DEBUG_INFO(" org date time: %s\n", data);
  2883. //DEBUG_INFO("parse date time: %s\n", buf);
  2884. system(buf);
  2885. system("/sbin/hwclock -w --systohc");
  2886. if(result.scanedElement < 6)
  2887. result.result = FAIL;
  2888. return result.result;
  2889. }
  2890. //==========================================
  2891. // GetCompositeSchedule logic related function
  2892. //==========================================
  2893. int DiffTimebSec(struct timeb ST, struct timeb ET)
  2894. {
  2895. //return milli-second
  2896. unsigned int StartTime,StopTime;
  2897. StartTime=(unsigned int)ST.time;
  2898. StopTime=(unsigned int)ET.time;
  2899. return (StopTime-StartTime);
  2900. }
  2901. int DiffTimebWithNowSec(struct timeb ST)
  2902. {
  2903. //return milli-second
  2904. struct timeb ET;
  2905. unsigned int StartTime,StopTime;
  2906. ftime(&ET);
  2907. StartTime=(unsigned int)ST.time;
  2908. StopTime=(unsigned int)ET.time;
  2909. return (StopTime-StartTime);
  2910. }
  2911. int getStartStop(uint8_t *start, uint8_t *stop)
  2912. {
  2913. int result = -1;
  2914. struct tm tmStart;
  2915. struct timeb tbStart;
  2916. struct tm tmStop;
  2917. struct timeb tbStop;
  2918. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  2919. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  2920. {
  2921. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  2922. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  2923. tmStart.tm_year -= 1900;
  2924. tmStart.tm_mon -= 1;
  2925. tbStart.time = mktime(&tmStart);
  2926. tbStart.millitm = 0;
  2927. tmStop.tm_year -= 1900;
  2928. tmStop.tm_mon -= 1;
  2929. tbStop.time = mktime(&tmStop);
  2930. tbStop.millitm = 0;
  2931. result = DiffTimebSec(tbStart, tbStop);
  2932. //DEBUG_INFO("getStartStop(): %d\n", result);
  2933. }
  2934. else
  2935. {
  2936. DEBUG_WARN("Start or stop date parsing error.\r\n");
  2937. }
  2938. return result;
  2939. }
  2940. int isOvertNow(uint8_t *start)
  2941. {
  2942. int result = NO;
  2943. struct ParsingResult
  2944. {
  2945. int result;
  2946. int scanedElement;
  2947. int year;
  2948. int month;
  2949. int mday;
  2950. int hour;
  2951. int min;
  2952. int sec;
  2953. int tz_hour;
  2954. int tz_min;
  2955. float minSec;
  2956. }parsingResult;
  2957. struct tm tmStart;
  2958. struct timeb tbStart;
  2959. memset(&parsingResult, 0x00, sizeof(struct ParsingResult));
  2960. if(strstr((char*)start, ".") != NULL)
  2961. {
  2962. // Original data with mini second
  2963. if(strstr((char*)start, "Z") != NULL)
  2964. {
  2965. // Original data with Z
  2966. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%fZ",
  2967. &parsingResult.year,
  2968. &parsingResult.month,
  2969. &parsingResult.mday,
  2970. &parsingResult.hour,
  2971. &parsingResult.min,
  2972. &parsingResult.sec,
  2973. &parsingResult.minSec);
  2974. }
  2975. else
  2976. {
  2977. // Original data without Z
  2978. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  2979. &parsingResult.year,
  2980. &parsingResult.month,
  2981. &parsingResult.mday,
  2982. &parsingResult.hour,
  2983. &parsingResult.min,
  2984. &parsingResult.sec,
  2985. &parsingResult.minSec,
  2986. &parsingResult.tz_hour,
  2987. &parsingResult.tz_min);
  2988. }
  2989. }
  2990. else
  2991. {
  2992. // Original data without mini second
  2993. if(strstr((char*)start, "Z") != NULL)
  2994. {
  2995. // Original data with Z
  2996. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%dZ",
  2997. &parsingResult.year,
  2998. &parsingResult.month,
  2999. &parsingResult.mday,
  3000. &parsingResult.hour,
  3001. &parsingResult.min,
  3002. &parsingResult.sec);
  3003. }
  3004. else
  3005. {
  3006. // Original data without Z
  3007. parsingResult.scanedElement = sscanf((char*)start, "%d-%d-%dT%d:%d:%d%d:%d",
  3008. &parsingResult.year,
  3009. &parsingResult.month,
  3010. &parsingResult.mday,
  3011. &parsingResult.hour,
  3012. &parsingResult.min,
  3013. &parsingResult.sec,
  3014. &parsingResult.tz_hour,
  3015. &parsingResult.tz_min);
  3016. }
  3017. }
  3018. if(parsingResult.scanedElement >= 6)
  3019. {
  3020. tmStart.tm_year = parsingResult.year - 1900;
  3021. tmStart.tm_mon = parsingResult.month - 1;
  3022. tmStart.tm_mday = parsingResult.mday;
  3023. tmStart.tm_hour = parsingResult.hour;
  3024. tmStart.tm_min = parsingResult.min;
  3025. tmStart.tm_sec = parsingResult.sec;
  3026. tmStart.tm_gmtoff = 0;
  3027. tbStart.time = mktime(&tmStart);
  3028. tbStart.timezone = 0;
  3029. tbStart.millitm = 0;
  3030. tbStart.time -= (parsingResult.tz_hour*3600) + (parsingResult.tz_min*60*(parsingResult.tz_hour>=0?1:-1));
  3031. if(DiffTimebWithNowSec(tbStart) <= 0)
  3032. result = NO;
  3033. else
  3034. result = YES;
  3035. }
  3036. else
  3037. {
  3038. DEBUG_WARN("Start date parsing error.\n");
  3039. }
  3040. return result;
  3041. }
  3042. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  3043. {
  3044. int result = -1;
  3045. struct tm tmStart;
  3046. struct timeb tbStart;
  3047. struct tm tmStop;
  3048. struct timeb tbStop;
  3049. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  3050. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  3051. {
  3052. tmStart.tm_year -= 1900;
  3053. tmStart.tm_mon -= 1;
  3054. tbStart.time = mktime(&tmStart);
  3055. tbStart.millitm = 0;
  3056. tmStop.tm_year -= 1900;
  3057. tmStop.tm_mon -= 1;
  3058. tbStop.time = mktime(&tmStop);
  3059. tbStop.millitm = 0;
  3060. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  3061. }
  3062. return result;
  3063. }
  3064. void checkChargePointMaxProfile(uint32_t durationReq, struct ChargingProfileType *compositeProfile, uint8_t idxSchedule, uint8_t isUnitA)
  3065. {
  3066. FILE *fp;
  3067. char profileFileName[128];
  3068. char *line = NULL;
  3069. size_t len = 0;
  3070. time_t CurrentTime;
  3071. struct tm *tmComposite;
  3072. struct ChargingProfileType maxProfile;
  3073. uint8_t limitMax=0;
  3074. int compositePeriodIdx = 0;
  3075. CurrentTime = time(NULL);
  3076. tmComposite=localtime(&CurrentTime);
  3077. 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);
  3078. if(isUnitA)
  3079. sprintf((char*)compositeProfile->chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3080. else
  3081. sprintf((char*)compositeProfile->chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3082. compositeProfile->chargingSchedule[idxSchedule].duration = durationReq;
  3083. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3084. {
  3085. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3086. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3087. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3088. }
  3089. compositeProfile->id = 0;
  3090. compositeProfile->stackLevel = 99 ;
  3091. sprintf((char*)compositeProfile->chargingProfileKind ,"Absolute");
  3092. maxProfile.id = -1;
  3093. maxProfile.chargingSchedule[idxSchedule].duration = -1;
  3094. system("rm -f /tmp/*.json");
  3095. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  3096. // Search max profile
  3097. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  3098. if((access(profileFileName, F_OK))!=-1)
  3099. {
  3100. fp = fopen(profileFileName, "r");
  3101. while(getline(&line, &len, fp) != -1)
  3102. {
  3103. json_object *obj = NULL;
  3104. obj = json_tokener_parse(line);
  3105. if(is_error(obj))
  3106. {
  3107. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  3108. }
  3109. else
  3110. {
  3111. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != maxProfile.id) &&
  3112. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= maxProfile.stackLevel)
  3113. )
  3114. {
  3115. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  3116. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  3117. )
  3118. {
  3119. struct tm tmFrom, tmTo;
  3120. struct timeb tbFrom, tbTo;
  3121. 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) &&
  3122. (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))
  3123. {
  3124. tmFrom.tm_year -= 1900;
  3125. tmFrom.tm_mon -= 1;
  3126. tbFrom.time = mktime(&tmFrom);
  3127. tmTo.tm_year -= 1900;
  3128. tmTo.tm_mon -= 1;
  3129. tbTo.time = mktime(&tmTo);
  3130. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3131. {
  3132. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3133. {
  3134. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3135. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3136. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3137. }
  3138. maxProfile.id = -1;
  3139. maxProfile.stackLevel = -1;
  3140. if(maxProfile.id == -1)
  3141. DEBUG_INFO("MaxProfile found.\n");
  3142. else
  3143. DEBUG_INFO("MaxProfile updated.\n");
  3144. // Required item
  3145. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  3146. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  3147. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  3148. if(isUnitA)
  3149. {
  3150. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3151. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3152. {
  3153. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3154. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3155. 3:
  3156. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3157. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3158. }
  3159. }
  3160. else
  3161. {
  3162. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3163. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3164. {
  3165. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3166. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3167. 3:
  3168. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3169. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  3170. }
  3171. }
  3172. // Optional item
  3173. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  3174. {
  3175. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  3176. }
  3177. else
  3178. {
  3179. sprintf((char*)maxProfile.validFrom, " ");
  3180. }
  3181. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  3182. {
  3183. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  3184. }
  3185. else
  3186. {
  3187. sprintf((char*)maxProfile.validTo, " ");
  3188. }
  3189. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  3190. {
  3191. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  3192. }
  3193. else
  3194. {
  3195. sprintf((char*)maxProfile.recurrencyKind, " ");
  3196. }
  3197. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  3198. {
  3199. sprintf((char*)maxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  3200. }
  3201. else
  3202. {
  3203. sprintf((char*)maxProfile.transactionId, " ");
  3204. }
  3205. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  3206. {
  3207. maxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "duration"));
  3208. }
  3209. else
  3210. {
  3211. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  3212. }
  3213. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  3214. {
  3215. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  3216. }
  3217. else
  3218. {
  3219. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", compositeProfile->chargingSchedule[idxSchedule].startSchedule);
  3220. }
  3221. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  3222. {
  3223. maxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  3224. }
  3225. else
  3226. {
  3227. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3228. }
  3229. }
  3230. }
  3231. }
  3232. else
  3233. {
  3234. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3235. {
  3236. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3237. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3238. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3239. }
  3240. maxProfile.id = -1;
  3241. maxProfile.stackLevel = -1;
  3242. if(maxProfile.id == -1)
  3243. DEBUG_INFO("MaxProfile found.\n");
  3244. else
  3245. DEBUG_INFO("MaxProfile updated.\n");
  3246. // Required item
  3247. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  3248. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  3249. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  3250. if(isUnitA)
  3251. {
  3252. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3253. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3254. {
  3255. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3256. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3257. 3:
  3258. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3259. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3260. }
  3261. }
  3262. else
  3263. {
  3264. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3265. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3266. {
  3267. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3268. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3269. 3:
  3270. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3271. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  3272. }
  3273. }
  3274. // Optional item
  3275. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  3276. {
  3277. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  3278. }
  3279. else
  3280. {
  3281. sprintf((char*)maxProfile.validFrom, " ");
  3282. }
  3283. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  3284. {
  3285. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  3286. }
  3287. else
  3288. {
  3289. sprintf((char*)maxProfile.validTo, " ");
  3290. }
  3291. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  3292. {
  3293. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  3294. }
  3295. else
  3296. {
  3297. sprintf((char*)maxProfile.recurrencyKind, " ");
  3298. }
  3299. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  3300. {
  3301. sprintf((char*)maxProfile.transactionId,"%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  3302. }
  3303. else
  3304. {
  3305. sprintf((char*)maxProfile.transactionId, " ");
  3306. }
  3307. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  3308. {
  3309. maxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "duration"));
  3310. }
  3311. else
  3312. {
  3313. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  3314. }
  3315. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  3316. {
  3317. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  3318. }
  3319. else
  3320. {
  3321. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", compositeProfile->chargingSchedule[idxSchedule].startSchedule);
  3322. }
  3323. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  3324. {
  3325. maxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  3326. }
  3327. else
  3328. {
  3329. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3330. }
  3331. }
  3332. }
  3333. }
  3334. json_object_put(obj);
  3335. }
  3336. fclose(fp);
  3337. /*
  3338. if(maxProfile.id !=-1)
  3339. {
  3340. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  3341. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3342. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3343. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3344. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3345. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3346. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  3347. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.chargingSchedule[idxSchedule].StartSchedule);
  3348. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  3349. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  3350. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  3351. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  3352. {
  3353. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3354. {
  3355. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3356. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  3357. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3358. }
  3359. }
  3360. }
  3361. else
  3362. DEBUG_INFO("MaxProfile not found.\n");
  3363. DEBUG_INFO("------------------------------------\n");*/
  3364. }
  3365. if(maxProfile.id != -1)
  3366. {
  3367. if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  3368. {
  3369. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3370. {
  3371. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  3372. 0:
  3373. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  3374. }
  3375. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3376. {
  3377. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3378. {
  3379. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  3380. 0:
  3381. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  3382. if(idxPeriod > 0)
  3383. {
  3384. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3385. {
  3386. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3387. }
  3388. }
  3389. }
  3390. }
  3391. }
  3392. else if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  3393. {
  3394. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3395. {
  3396. maxProfile.chargingSchedule[idxSchedule].duration = maxProfile.chargingSchedule[idxSchedule].duration;
  3397. }
  3398. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3399. {
  3400. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3401. {
  3402. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod;
  3403. if(idxPeriod > 0)
  3404. {
  3405. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3406. {
  3407. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3408. }
  3409. }
  3410. }
  3411. }
  3412. }
  3413. else
  3414. {
  3415. if(strstr((char*)maxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  3416. {
  3417. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3418. {
  3419. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  3420. 0:
  3421. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  3422. }
  3423. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3424. {
  3425. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3426. {
  3427. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  3428. 0:
  3429. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  3430. if(idxPeriod > 0)
  3431. {
  3432. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3433. {
  3434. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3435. }
  3436. }
  3437. }
  3438. }
  3439. }
  3440. else
  3441. {
  3442. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3443. {
  3444. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  3445. 0:
  3446. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  3447. }
  3448. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3449. {
  3450. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3451. {
  3452. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  3453. 0:
  3454. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  3455. if(idxPeriod > 0)
  3456. {
  3457. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3458. {
  3459. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3460. }
  3461. }
  3462. }
  3463. }
  3464. }
  3465. }
  3466. /*
  3467. DEBUG_INFO("MaxProfile after align.\n");
  3468. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  3469. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3470. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3471. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3472. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3473. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3474. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  3475. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3476. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  3477. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  3478. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  3479. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  3480. {
  3481. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3482. {
  3483. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3484. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  3485. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3486. }
  3487. }
  3488. DEBUG_INFO("------------------------------------\n");*/
  3489. }
  3490. // Find each profile period quantity
  3491. for(int idx=0;idx<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  3492. {
  3493. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  3494. limitMax = idx+1;
  3495. }
  3496. if(maxProfile.id != -1)
  3497. {
  3498. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3499. {
  3500. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  3501. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  3502. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  3503. {
  3504. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  3505. {
  3506. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct ChargingSchedulePeriodType));
  3507. compositePeriodIdx++;
  3508. }
  3509. else
  3510. {
  3511. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct ChargingSchedulePeriodType));
  3512. }
  3513. }
  3514. }
  3515. }
  3516. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  3517. DEBUG_INFO("Schedule start: %s\n", compositeProfile->chargingSchedule[idxSchedule].startSchedule);
  3518. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->chargingSchedule[idxSchedule].duration);
  3519. DEBUG_INFO("Rate unit: %s\n", compositeProfile->chargingSchedule[idxSchedule].chargingRateUnit);
  3520. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3521. {
  3522. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod >= 0)
  3523. {
  3524. compositeProfile->id = 1;
  3525. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  3526. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit);
  3527. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases);
  3528. }
  3529. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit == -1)
  3530. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit =0;
  3531. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod == -1)
  3532. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod =0;
  3533. }
  3534. if(line)
  3535. free(line);
  3536. }
  3537. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct ChargingProfileType *compositeProfile, uint8_t idxSchedule, uint8_t isUnitA)
  3538. {
  3539. FILE *fp;
  3540. char profileFileName[128];
  3541. char *line = NULL;
  3542. size_t len = 0;
  3543. time_t CurrentTime;
  3544. struct tm *tmComposite;
  3545. struct ChargingProfileType maxProfile;
  3546. struct ChargingProfileType defaultTxProfile;
  3547. struct ChargingProfileType txProfile;
  3548. struct ChargingSchedulePeriodType tmpPeriod;
  3549. uint8_t limitMax=0;
  3550. uint8_t limitDef=0;
  3551. uint8_t limitTx=0;
  3552. int compositePeriodIdx = 0;
  3553. CurrentTime = time(NULL);
  3554. tmComposite=localtime(&CurrentTime);
  3555. 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);
  3556. if(isUnitA)
  3557. sprintf((char*)compositeProfile->chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3558. else
  3559. sprintf((char*)compositeProfile->chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3560. compositeProfile->chargingSchedule[idxSchedule].duration = durationReq;
  3561. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3562. {
  3563. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3564. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3565. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3566. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 0;
  3567. }
  3568. compositeProfile->id = 0;
  3569. compositeProfile->stackLevel = 99 ;
  3570. sprintf((char*)compositeProfile->chargingProfileKind ,ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]);
  3571. maxProfile.id = -1;
  3572. defaultTxProfile.id = -1;
  3573. txProfile.id = -1;
  3574. maxProfile.chargingSchedule[idxSchedule].duration = -1;
  3575. defaultTxProfile.chargingSchedule[idxSchedule].duration = -1;
  3576. txProfile.chargingSchedule[idxSchedule].duration = -1;
  3577. system("rm -f /tmp/*.json");
  3578. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  3579. /*
  3580. * Search valid charging profile
  3581. */
  3582. //DEBUG_INFO("====================================\n");
  3583. // Search tx profile
  3584. sprintf(profileFileName, "/tmp/TxProfile_%d_OCPP20.json", connectorId);
  3585. if((access(profileFileName, F_OK))!=-1)
  3586. {
  3587. fp = fopen(profileFileName, "r");
  3588. while(getline(&line, &len, fp) != -1)
  3589. {
  3590. json_object *obj = NULL;
  3591. obj = json_tokener_parse(line);
  3592. if(is_error(obj))
  3593. {
  3594. DEBUG_ERROR("Parse txProfile from file error.\n");
  3595. }
  3596. else
  3597. {
  3598. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != txProfile.id) &&
  3599. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= txProfile.stackLevel)
  3600. )
  3601. {
  3602. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  3603. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  3604. )
  3605. {
  3606. struct tm tmFrom, tmTo;
  3607. struct timeb tbFrom, tbTo;
  3608. 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) &&
  3609. (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))
  3610. {
  3611. tmFrom.tm_year -= 1900;
  3612. tmFrom.tm_mon -= 1;
  3613. tbFrom.time = mktime(&tmFrom);
  3614. tmTo.tm_year -= 1900;
  3615. tmTo.tm_mon -= 1;
  3616. tbTo.time = mktime(&tmTo);
  3617. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3618. {
  3619. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3620. {
  3621. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3622. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3623. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3624. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  3625. }
  3626. txProfile.id = -1;
  3627. txProfile.stackLevel = -1;
  3628. if(txProfile.id == -1)
  3629. DEBUG_INFO("TxProfile found.\n");
  3630. else
  3631. DEBUG_INFO("TxProfile updated.\n");
  3632. // Required item
  3633. txProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  3634. txProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  3635. sprintf((char*)txProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  3636. if(isUnitA)
  3637. {
  3638. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3639. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3640. {
  3641. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3642. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3643. 3:
  3644. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3645. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3646. }
  3647. }
  3648. else
  3649. {
  3650. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3651. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3652. {
  3653. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3654. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3655. 3:
  3656. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3657. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  3658. }
  3659. }
  3660. // Optional item
  3661. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  3662. {
  3663. sprintf((char*)txProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  3664. }
  3665. else
  3666. {
  3667. sprintf((char*)txProfile.validFrom, " ");
  3668. }
  3669. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  3670. {
  3671. sprintf((char*)txProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  3672. }
  3673. else
  3674. {
  3675. sprintf((char*)txProfile.validTo, " ");
  3676. }
  3677. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  3678. {
  3679. sprintf((char*)txProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  3680. }
  3681. else
  3682. {
  3683. sprintf((char*)txProfile.recurrencyKind, " ");
  3684. }
  3685. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  3686. {
  3687. sprintf((char*)txProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  3688. }
  3689. else
  3690. {
  3691. sprintf((char*)txProfile.transactionId, " ");
  3692. }
  3693. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  3694. {
  3695. txProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "duration"));
  3696. }
  3697. else
  3698. {
  3699. txProfile.chargingSchedule[idxSchedule].duration = 86400;
  3700. }
  3701. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  3702. {
  3703. sprintf((char*)txProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  3704. }
  3705. else
  3706. {
  3707. sprintf((char*)txProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp));
  3708. }
  3709. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  3710. {
  3711. txProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  3712. }
  3713. else
  3714. {
  3715. txProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3716. }
  3717. }
  3718. }
  3719. }
  3720. else
  3721. {
  3722. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3723. {
  3724. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3725. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3726. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3727. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  3728. }
  3729. txProfile.id = -1;
  3730. txProfile.stackLevel = -1;
  3731. if(txProfile.id == -1)
  3732. DEBUG_INFO("TxProfile found.\n");
  3733. else
  3734. DEBUG_INFO("TxProfile updated.\n");
  3735. // Required item
  3736. txProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  3737. txProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  3738. sprintf((char*)txProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  3739. if(isUnitA)
  3740. {
  3741. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3742. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3743. {
  3744. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3745. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3746. 3:
  3747. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3748. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3749. }
  3750. }
  3751. else
  3752. {
  3753. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3754. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3755. {
  3756. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3757. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3758. 3:
  3759. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3760. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  3761. }
  3762. }
  3763. // Optional item
  3764. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  3765. {
  3766. sprintf((char*)txProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  3767. }
  3768. else
  3769. {
  3770. sprintf((char*)txProfile.validFrom, " ");
  3771. }
  3772. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  3773. {
  3774. sprintf((char*)txProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  3775. }
  3776. else
  3777. {
  3778. sprintf((char*)txProfile.validTo, " ");
  3779. }
  3780. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  3781. {
  3782. sprintf((char*)txProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  3783. }
  3784. else
  3785. {
  3786. sprintf((char*)txProfile.recurrencyKind, " ");
  3787. }
  3788. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  3789. {
  3790. sprintf((char*)txProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  3791. }
  3792. else
  3793. {
  3794. sprintf((char*)txProfile.transactionId, " ");
  3795. }
  3796. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  3797. {
  3798. txProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "duration"));
  3799. }
  3800. else
  3801. {
  3802. txProfile.chargingSchedule[idxSchedule].duration = 86400;
  3803. }
  3804. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  3805. {
  3806. sprintf((char*)txProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  3807. }
  3808. else
  3809. {
  3810. sprintf((char*)txProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp));
  3811. }
  3812. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  3813. {
  3814. txProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  3815. }
  3816. else
  3817. {
  3818. txProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3819. }
  3820. }
  3821. }
  3822. }
  3823. json_object_put(obj);
  3824. }
  3825. fclose(fp);
  3826. /*
  3827. if(txProfile.id != -1)
  3828. {
  3829. DEBUG_INFO("Profile ID: %d\n", txProfile.id);
  3830. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3831. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3832. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3833. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3834. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3835. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.recurrencyKind);
  3836. DEBUG_INFO("Profile start schedule: %s\n", txProfile.chargingSchedule[idxSchedule].StartSchedule);
  3837. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.chargingSchedule[idxSchedule].Duration);
  3838. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  3839. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.chargingSchedule[idxSchedule].MinChargingRate);
  3840. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  3841. {
  3842. if(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3843. {
  3844. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3845. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  3846. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3847. }
  3848. }
  3849. }
  3850. else
  3851. DEBUG_INFO("TxProfile not found.\n");*/
  3852. }
  3853. // Search default tx profile
  3854. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d_OCPP20.json", connectorId);
  3855. if((access(profileFileName, F_OK))==-1)
  3856. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  3857. if((access(profileFileName, F_OK))!=-1)
  3858. {
  3859. fp = fopen(profileFileName, "r");
  3860. while(getline(&line, &len, fp) != -1)
  3861. {
  3862. json_object *obj = NULL;
  3863. obj = json_tokener_parse(line);
  3864. if(is_error(obj))
  3865. {
  3866. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  3867. }
  3868. else
  3869. {
  3870. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != defaultTxProfile.id) &&
  3871. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= defaultTxProfile.stackLevel)
  3872. )
  3873. {
  3874. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  3875. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  3876. )
  3877. {
  3878. struct tm tmFrom, tmTo;
  3879. struct timeb tbFrom, tbTo;
  3880. 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) &&
  3881. (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))
  3882. {
  3883. tmFrom.tm_year -= 1900;
  3884. tmFrom.tm_mon -= 1;
  3885. tbFrom.time = mktime(&tmFrom);
  3886. tmTo.tm_year -= 1900;
  3887. tmTo.tm_mon -= 1;
  3888. tbTo.time = mktime(&tmTo);
  3889. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3890. {
  3891. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3892. {
  3893. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3894. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3895. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3896. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  3897. }
  3898. defaultTxProfile.id = -1;
  3899. defaultTxProfile.stackLevel = -1;
  3900. if(defaultTxProfile.id == -1)
  3901. DEBUG_INFO("TxDefaultProfile found.\n");
  3902. else
  3903. DEBUG_INFO("TxDefaultProfile updated.\n");
  3904. // Required item
  3905. defaultTxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  3906. defaultTxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  3907. sprintf((char*)defaultTxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  3908. if(isUnitA)
  3909. {
  3910. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3911. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3912. {
  3913. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3914. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3915. 3:
  3916. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3917. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3918. }
  3919. }
  3920. else
  3921. {
  3922. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3923. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3924. {
  3925. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3926. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3927. 3:
  3928. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3929. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  3930. }
  3931. }
  3932. // Optional item
  3933. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  3934. {
  3935. sprintf((char*)defaultTxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  3936. }
  3937. else
  3938. {
  3939. sprintf((char*)defaultTxProfile.validFrom, " ");
  3940. }
  3941. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  3942. {
  3943. sprintf((char*)defaultTxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  3944. }
  3945. else
  3946. {
  3947. sprintf((char*)defaultTxProfile.validTo, " ");
  3948. }
  3949. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  3950. {
  3951. sprintf((char*)defaultTxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  3952. }
  3953. else
  3954. {
  3955. sprintf((char*)defaultTxProfile.recurrencyKind, " ");
  3956. }
  3957. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  3958. {
  3959. sprintf((char*)defaultTxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  3960. }
  3961. else
  3962. {
  3963. sprintf((char*)defaultTxProfile.transactionId, " ");
  3964. }
  3965. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  3966. {
  3967. defaultTxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "duration"));
  3968. }
  3969. else
  3970. {
  3971. defaultTxProfile.chargingSchedule[idxSchedule].duration = 86400;
  3972. }
  3973. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  3974. {
  3975. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  3976. }
  3977. else
  3978. {
  3979. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp));
  3980. }
  3981. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  3982. {
  3983. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  3984. }
  3985. else
  3986. {
  3987. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3988. }
  3989. }
  3990. }
  3991. }
  3992. else
  3993. {
  3994. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3995. {
  3996. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3997. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3998. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3999. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  4000. }
  4001. defaultTxProfile.id = -1;
  4002. defaultTxProfile.stackLevel = -1;
  4003. if(defaultTxProfile.id == -1)
  4004. DEBUG_INFO("TxDefaultProfile found.\n");
  4005. else
  4006. DEBUG_INFO("TxDefaultProfile updated.\n");
  4007. // Required item
  4008. defaultTxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4009. defaultTxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4010. sprintf((char*)defaultTxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4011. if(isUnitA)
  4012. {
  4013. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4014. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  4015. {
  4016. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4017. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  4018. 3:
  4019. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  4020. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  4021. }
  4022. }
  4023. else
  4024. {
  4025. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4026. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  4027. {
  4028. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4029. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  4030. 3:
  4031. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  4032. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  4033. }
  4034. }
  4035. // Optional item
  4036. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4037. {
  4038. sprintf((char*)defaultTxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4039. }
  4040. else
  4041. {
  4042. sprintf((char*)defaultTxProfile.validFrom, " ");
  4043. }
  4044. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4045. {
  4046. sprintf((char*)defaultTxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4047. }
  4048. else
  4049. {
  4050. sprintf((char*)defaultTxProfile.validTo, " ");
  4051. }
  4052. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4053. {
  4054. sprintf((char*)defaultTxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4055. }
  4056. else
  4057. {
  4058. sprintf((char*)defaultTxProfile.recurrencyKind, " ");
  4059. }
  4060. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4061. {
  4062. sprintf((char*)defaultTxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4063. }
  4064. else
  4065. {
  4066. sprintf((char*)defaultTxProfile.transactionId, " ");
  4067. }
  4068. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  4069. {
  4070. defaultTxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "duration"));
  4071. }
  4072. else
  4073. {
  4074. defaultTxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4075. }
  4076. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  4077. {
  4078. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  4079. }
  4080. else
  4081. {
  4082. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp));
  4083. }
  4084. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  4085. {
  4086. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  4087. }
  4088. else
  4089. {
  4090. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4091. }
  4092. }
  4093. }
  4094. }
  4095. json_object_put(obj);
  4096. }
  4097. fclose(fp);
  4098. /*
  4099. if(defaultTxProfile.id != -1)
  4100. {
  4101. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.id);
  4102. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  4103. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  4104. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  4105. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  4106. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  4107. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.recurrencyKind);
  4108. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].StartSchedule);
  4109. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.chargingSchedule[idxSchedule].Duration);
  4110. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4111. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4112. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4113. {
  4114. if(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4115. {
  4116. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4117. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4118. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4119. }
  4120. }
  4121. }
  4122. else
  4123. DEBUG_INFO("TxDefaultProfile not found.\n");
  4124. DEBUG_INFO("------------------------------------\n");*/
  4125. }
  4126. // Search max profile
  4127. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  4128. if((access(profileFileName, F_OK))!=-1)
  4129. {
  4130. fp = fopen(profileFileName, "r");
  4131. while(getline(&line, &len, fp) != -1)
  4132. {
  4133. json_object *obj = NULL;
  4134. obj = json_tokener_parse(line);
  4135. if(is_error(obj))
  4136. {
  4137. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  4138. }
  4139. else
  4140. {
  4141. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id")) != maxProfile.id) &&
  4142. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel")) >= maxProfile.stackLevel)
  4143. )
  4144. {
  4145. if((json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL) &&
  4146. (json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4147. )
  4148. {
  4149. struct tm tmFrom, tmTo;
  4150. struct timeb tbFrom, tbTo;
  4151. 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) &&
  4152. (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))
  4153. {
  4154. tmFrom.tm_year -= 1900;
  4155. tmFrom.tm_mon -= 1;
  4156. tbFrom.time = mktime(&tmFrom);
  4157. tmTo.tm_year -= 1900;
  4158. tmTo.tm_mon -= 1;
  4159. tbTo.time = mktime(&tmTo);
  4160. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  4161. {
  4162. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4163. {
  4164. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4165. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4166. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4167. }
  4168. maxProfile.id = -1;
  4169. maxProfile.stackLevel = -1;
  4170. if(maxProfile.id == -1)
  4171. DEBUG_INFO("MaxProfile found.\n");
  4172. else
  4173. DEBUG_INFO("MaxProfile updated.\n");
  4174. // Required item
  4175. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4176. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4177. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4178. if(isUnitA)
  4179. {
  4180. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4181. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  4182. {
  4183. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4184. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  4185. 3:
  4186. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  4187. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  4188. }
  4189. }
  4190. else
  4191. {
  4192. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4193. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  4194. {
  4195. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4196. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  4197. 3:
  4198. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  4199. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  4200. }
  4201. }
  4202. // Optional item
  4203. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4204. {
  4205. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4206. }
  4207. else
  4208. {
  4209. sprintf((char*)maxProfile.validFrom, " ");
  4210. }
  4211. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4212. {
  4213. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4214. }
  4215. else
  4216. {
  4217. sprintf((char*)maxProfile.validTo, " ");
  4218. }
  4219. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4220. {
  4221. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4222. }
  4223. else
  4224. {
  4225. sprintf((char*)maxProfile.recurrencyKind, " ");
  4226. }
  4227. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4228. {
  4229. sprintf((char*)maxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4230. }
  4231. else
  4232. {
  4233. sprintf((char*)maxProfile.transactionId, " ");
  4234. }
  4235. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  4236. {
  4237. maxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "duration"));
  4238. }
  4239. else
  4240. {
  4241. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4242. }
  4243. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  4244. {
  4245. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  4246. }
  4247. else
  4248. {
  4249. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp));
  4250. }
  4251. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  4252. {
  4253. maxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  4254. }
  4255. else
  4256. {
  4257. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4258. }
  4259. }
  4260. }
  4261. }
  4262. else
  4263. {
  4264. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4265. {
  4266. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  4267. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  4268. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  4269. }
  4270. maxProfile.id = -1;
  4271. maxProfile.stackLevel = -1;
  4272. if(maxProfile.id == -1)
  4273. DEBUG_INFO("MaxProfile found.\n");
  4274. else
  4275. DEBUG_INFO("MaxProfile updated.\n");
  4276. // Required item
  4277. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "id"));
  4278. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "stackLevel"));
  4279. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingProfileKind")));
  4280. if(isUnitA)
  4281. {
  4282. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4283. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  4284. {
  4285. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4286. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  4287. 3:
  4288. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  4289. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  4290. }
  4291. }
  4292. else
  4293. {
  4294. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4295. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  4296. {
  4297. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4298. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  4299. 3:
  4300. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  4301. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  4302. }
  4303. }
  4304. // Optional item
  4305. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom") != NULL)
  4306. {
  4307. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validFrom")));
  4308. }
  4309. else
  4310. {
  4311. sprintf((char*)maxProfile.validFrom, " ");
  4312. }
  4313. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo") != NULL)
  4314. {
  4315. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "validTo")));
  4316. }
  4317. else
  4318. {
  4319. sprintf((char*)maxProfile.validTo, " ");
  4320. }
  4321. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind") != NULL)
  4322. {
  4323. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "recurrencyKind")));
  4324. }
  4325. else
  4326. {
  4327. sprintf((char*)maxProfile.recurrencyKind, " ");
  4328. }
  4329. if(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId") != NULL)
  4330. {
  4331. sprintf((char*)maxProfile.transactionId,"%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "transactionId")));
  4332. }
  4333. else
  4334. {
  4335. sprintf((char*)maxProfile.transactionId, " ");
  4336. }
  4337. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  4338. {
  4339. maxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "duration"));
  4340. }
  4341. else
  4342. {
  4343. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4344. }
  4345. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  4346. {
  4347. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  4348. }
  4349. else
  4350. {
  4351. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", (!cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging ? compositeProfile->chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp));
  4352. }
  4353. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  4354. {
  4355. maxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  4356. }
  4357. else
  4358. {
  4359. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4360. }
  4361. }
  4362. }
  4363. }
  4364. json_object_put(obj);
  4365. }
  4366. fclose(fp);
  4367. /*
  4368. if(maxProfile.id !=-1)
  4369. {
  4370. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  4371. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  4372. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  4373. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  4374. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  4375. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  4376. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  4377. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.chargingSchedule[idxSchedule].StartSchedule);
  4378. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  4379. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4380. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4381. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4382. {
  4383. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4384. {
  4385. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4386. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4387. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4388. }
  4389. }
  4390. }
  4391. else
  4392. DEBUG_INFO("MaxProfile not found.\n");
  4393. DEBUG_INFO("------------------------------------\n");*/
  4394. }
  4395. /*
  4396. * Align found profile start schedule & periods
  4397. */
  4398. //DEBUG_INFO("====================================\n");
  4399. /*
  4400. // For local test usage, force modify found profile start schedule info
  4401. 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);
  4402. 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);
  4403. 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);
  4404. */
  4405. if(txProfile.id != -1)
  4406. {
  4407. if(strstr((char*)txProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  4408. {
  4409. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  4410. {
  4411. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4412. 0:
  4413. (txProfile.chargingSchedule[idxSchedule].duration-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4414. }
  4415. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4416. {
  4417. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4418. {
  4419. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4420. 0:
  4421. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4422. if(idxPeriod > 0)
  4423. {
  4424. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4425. {
  4426. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4427. }
  4428. }
  4429. }
  4430. }
  4431. }
  4432. else if(strstr((char*)txProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  4433. {
  4434. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  4435. {
  4436. txProfile.chargingSchedule[idxSchedule].duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.chargingSchedule[idxSchedule].duration:((txProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4437. 0:
  4438. (txProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4439. }
  4440. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4441. {
  4442. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4443. {
  4444. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod:((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4445. 0:
  4446. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4447. if(idxPeriod > 0)
  4448. {
  4449. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4450. {
  4451. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4452. }
  4453. }
  4454. }
  4455. }
  4456. }
  4457. else
  4458. {
  4459. if(strstr((char*)txProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  4460. {
  4461. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  4462. {
  4463. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4464. 0:
  4465. (txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4466. }
  4467. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4468. {
  4469. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4470. {
  4471. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4472. 0:
  4473. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4474. if(idxPeriod > 0)
  4475. {
  4476. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4477. {
  4478. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4479. }
  4480. }
  4481. }
  4482. }
  4483. }
  4484. else
  4485. {
  4486. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  4487. {
  4488. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4489. 0:
  4490. (txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4491. }
  4492. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4493. {
  4494. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4495. {
  4496. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4497. 0:
  4498. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4499. if(idxPeriod > 0)
  4500. {
  4501. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4502. {
  4503. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4504. }
  4505. }
  4506. }
  4507. }
  4508. }
  4509. }
  4510. /*
  4511. DEBUG_INFO("txProfile after align.\n");
  4512. DEBUG_INFO("Profile ID: %d\n", txProfile.id);
  4513. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  4514. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  4515. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  4516. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  4517. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  4518. DEBUG_INFO("Profile recurrencyKind: %s\n", txProfile.recurrencyKind);
  4519. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  4520. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.chargingSchedule[idxSchedule].Duration);
  4521. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4522. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4523. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4524. {
  4525. if(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4526. {
  4527. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4528. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4529. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4530. }
  4531. }*/
  4532. }
  4533. if(defaultTxProfile.id != -1)
  4534. {
  4535. if(strstr((char*)defaultTxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  4536. {
  4537. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  4538. {
  4539. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4540. 0:
  4541. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4542. }
  4543. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4544. {
  4545. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4546. {
  4547. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4548. 0:
  4549. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4550. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod < txProfile.chargingSchedule[idxSchedule].duration)
  4551. {
  4552. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod += (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  4553. }
  4554. if(idxPeriod > 0)
  4555. {
  4556. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4557. {
  4558. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4559. }
  4560. }
  4561. }
  4562. }
  4563. }
  4564. else if(strstr((char*)defaultTxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  4565. {
  4566. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  4567. {
  4568. defaultTxProfile.chargingSchedule[idxSchedule].duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.chargingSchedule[idxSchedule].duration:((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4569. 0:
  4570. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4571. }
  4572. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4573. {
  4574. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4575. {
  4576. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod:((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4577. 0:
  4578. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4579. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod < txProfile.chargingSchedule[idxSchedule].duration)
  4580. {
  4581. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod += (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  4582. }
  4583. if(idxPeriod > 0)
  4584. {
  4585. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4586. {
  4587. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4588. }
  4589. }
  4590. }
  4591. }
  4592. }
  4593. else
  4594. {
  4595. if(strstr((char*)defaultTxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  4596. {
  4597. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  4598. {
  4599. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4600. 0:
  4601. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4602. }
  4603. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4604. {
  4605. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4606. {
  4607. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4608. 0:
  4609. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4610. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod < txProfile.chargingSchedule[idxSchedule].duration)
  4611. {
  4612. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod += (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  4613. }
  4614. if(idxPeriod > 0)
  4615. {
  4616. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4617. {
  4618. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4619. }
  4620. }
  4621. }
  4622. }
  4623. }
  4624. else
  4625. {
  4626. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  4627. {
  4628. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4629. 0:
  4630. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4631. }
  4632. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4633. {
  4634. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4635. {
  4636. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4637. 0:
  4638. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4639. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod < txProfile.chargingSchedule[idxSchedule].duration)
  4640. {
  4641. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod += (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  4642. }
  4643. if(idxPeriod > 0)
  4644. {
  4645. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4646. {
  4647. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4648. }
  4649. }
  4650. }
  4651. }
  4652. }
  4653. }
  4654. /*
  4655. DEBUG_INFO("defaultTxProfile after align.\n");
  4656. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.id);
  4657. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  4658. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  4659. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  4660. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  4661. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  4662. DEBUG_INFO("Profile recurrencyKind: %s\n", defaultTxProfile.recurrencyKind);
  4663. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  4664. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.chargingSchedule[idxSchedule].Duration);
  4665. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4666. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4667. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4668. {
  4669. if(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4670. {
  4671. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4672. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4673. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4674. }
  4675. }
  4676. DEBUG_INFO("------------------------------------\n");*/
  4677. }
  4678. if(maxProfile.id != -1)
  4679. {
  4680. if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  4681. {
  4682. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4683. {
  4684. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4685. 0:
  4686. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4687. }
  4688. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4689. {
  4690. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4691. {
  4692. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4693. 0:
  4694. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4695. if(idxPeriod > 0)
  4696. {
  4697. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4698. {
  4699. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4700. }
  4701. }
  4702. }
  4703. }
  4704. }
  4705. else if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  4706. {
  4707. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4708. {
  4709. maxProfile.chargingSchedule[idxSchedule].duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.chargingSchedule[idxSchedule].duration:((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4710. 0:
  4711. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[9].startSchedule)));
  4712. }
  4713. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4714. {
  4715. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4716. {
  4717. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod:((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4718. 0:
  4719. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4720. if(idxPeriod > 0)
  4721. {
  4722. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4723. {
  4724. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4725. }
  4726. }
  4727. }
  4728. }
  4729. }
  4730. else
  4731. {
  4732. if(strstr((char*)maxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  4733. {
  4734. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4735. {
  4736. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4737. 0:
  4738. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4739. }
  4740. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4741. {
  4742. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4743. {
  4744. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4745. 0:
  4746. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4747. if(idxPeriod > 0)
  4748. {
  4749. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4750. {
  4751. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4752. }
  4753. }
  4754. }
  4755. }
  4756. }
  4757. else
  4758. {
  4759. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4760. {
  4761. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4762. 0:
  4763. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4764. }
  4765. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4766. {
  4767. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4768. {
  4769. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4770. 0:
  4771. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4772. if(idxPeriod > 0)
  4773. {
  4774. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4775. {
  4776. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4777. }
  4778. }
  4779. }
  4780. }
  4781. }
  4782. }
  4783. /*
  4784. DEBUG_INFO("MaxProfile after align.\n");
  4785. DEBUG_INFO("Profile ID: %d\n", maxProfile.id);
  4786. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  4787. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  4788. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  4789. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  4790. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  4791. DEBUG_INFO("Profile recurrencyKind: %s\n", maxProfile.recurrencyKind);
  4792. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  4793. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  4794. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4795. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4796. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4797. {
  4798. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4799. {
  4800. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4801. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4802. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4803. }
  4804. }
  4805. DEBUG_INFO("------------------------------------\n");*/
  4806. }
  4807. /*
  4808. * Merge to conposite schedule
  4809. */
  4810. //DEBUG_INFO("====================================\n");
  4811. // Find each profile period quantity
  4812. for(int idx=0;idx<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  4813. {
  4814. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  4815. limitMax = idx+1;
  4816. }
  4817. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  4818. {
  4819. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  4820. limitDef = idx+1;
  4821. }
  4822. for(int idx=0;idx<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  4823. {
  4824. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  4825. limitTx = idx+1;
  4826. }
  4827. // TxProfile found, composite schedule based on it
  4828. if(txProfile.id != -1)
  4829. {
  4830. compositeProfile->chargingSchedule[idxSchedule].duration = txProfile.chargingSchedule[idxSchedule].duration;
  4831. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  4832. {
  4833. if((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit != -1) &&
  4834. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod < durationReq) &&
  4835. (txProfile.chargingSchedule[idxSchedule].duration > 0))
  4836. {
  4837. if(maxProfile.id != -1)
  4838. {
  4839. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4840. {
  4841. if((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod))
  4842. {
  4843. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  4844. {
  4845. tmpPeriod.startPeriod = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod;
  4846. tmpPeriod.numberPhases = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].numberPhases;
  4847. 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);
  4848. }
  4849. else
  4850. {
  4851. tmpPeriod.startPeriod = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod;
  4852. tmpPeriod.numberPhases = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].numberPhases;
  4853. tmpPeriod.limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit;
  4854. }
  4855. }
  4856. if(idxMaxPeriod == (limitMax-1))
  4857. {
  4858. if(tmpPeriod.limit != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  4859. {
  4860. if(tmpPeriod.startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4861. {
  4862. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4863. compositePeriodIdx++;
  4864. }
  4865. else
  4866. {
  4867. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4868. }
  4869. }
  4870. }
  4871. }
  4872. }
  4873. else
  4874. {
  4875. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4876. {
  4877. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod],sizeof(struct ChargingSchedulePeriodType));
  4878. compositePeriodIdx++;
  4879. }
  4880. else
  4881. {
  4882. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod],sizeof(struct ChargingSchedulePeriodType));
  4883. }
  4884. }
  4885. }
  4886. if(idxTxPeriod == (limitTx-1))
  4887. {
  4888. if(defaultTxProfile.id != -1)
  4889. {
  4890. compositeProfile->chargingSchedule[idxSchedule].duration = (defaultTxProfile.chargingSchedule[idxSchedule].duration>compositeProfile->chargingSchedule[idxSchedule].duration)?defaultTxProfile.chargingSchedule[idxSchedule].duration:compositeProfile->chargingSchedule[idxSchedule].duration;
  4891. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  4892. {
  4893. if((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod + (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod))) &&
  4894. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod < durationReq) &&
  4895. (defaultTxProfile.chargingSchedule[idxSchedule].duration>0))
  4896. {
  4897. if(maxProfile.id != -1)
  4898. {
  4899. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4900. {
  4901. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod)
  4902. {
  4903. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  4904. {
  4905. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  4906. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  4907. 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);
  4908. }
  4909. else
  4910. {
  4911. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  4912. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  4913. tmpPeriod.limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit;
  4914. }
  4915. if(tmpPeriod.limit != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  4916. {
  4917. if(tmpPeriod.startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4918. {
  4919. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4920. compositePeriodIdx++;
  4921. }
  4922. else
  4923. {
  4924. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4925. }
  4926. }
  4927. // Delete duplicate period
  4928. if(compositePeriodIdx > 1)
  4929. {
  4930. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  4931. {
  4932. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  4933. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  4934. compositePeriodIdx -= 1;
  4935. }
  4936. }
  4937. }
  4938. else
  4939. {
  4940. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4941. {
  4942. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  4943. compositePeriodIdx++;
  4944. }
  4945. else
  4946. {
  4947. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  4948. }
  4949. break;
  4950. }
  4951. }
  4952. }
  4953. else
  4954. {
  4955. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4956. {
  4957. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  4958. compositePeriodIdx++;
  4959. }
  4960. else
  4961. {
  4962. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  4963. }
  4964. }
  4965. }
  4966. }
  4967. }
  4968. }
  4969. }
  4970. }
  4971. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  4972. else if(defaultTxProfile.id != -1)
  4973. {
  4974. compositeProfile->chargingSchedule[idxSchedule].duration = defaultTxProfile.chargingSchedule[idxSchedule].duration;
  4975. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  4976. {
  4977. if((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit != -1) &&
  4978. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod < durationReq) &&
  4979. (defaultTxProfile.chargingSchedule[idxSchedule].duration > 0))
  4980. {
  4981. if(maxProfile.id != -1)
  4982. {
  4983. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4984. {
  4985. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod)
  4986. {
  4987. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  4988. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  4989. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  4990. {
  4991. 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);
  4992. }
  4993. else
  4994. {
  4995. tmpPeriod.limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit;
  4996. }
  4997. if(tmpPeriod.limit != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  4998. {
  4999. if(tmpPeriod.startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5000. {
  5001. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5002. compositePeriodIdx++;
  5003. }
  5004. else
  5005. {
  5006. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5007. }
  5008. }
  5009. // Delete duplicate period
  5010. if(compositePeriodIdx > 1)
  5011. {
  5012. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  5013. {
  5014. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  5015. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  5016. compositePeriodIdx -= 1;
  5017. }
  5018. }
  5019. }
  5020. else
  5021. {
  5022. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5023. {
  5024. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5025. compositePeriodIdx++;
  5026. }
  5027. else
  5028. {
  5029. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5030. }
  5031. break;
  5032. }
  5033. }
  5034. }
  5035. else
  5036. {
  5037. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5038. {
  5039. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5040. compositePeriodIdx++;
  5041. }
  5042. else
  5043. {
  5044. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  5045. }
  5046. }
  5047. }
  5048. }
  5049. }
  5050. // Fill other period by MaxProfile
  5051. if(maxProfile.id != -1)
  5052. {
  5053. if(compositePeriodIdx==0)
  5054. {
  5055. compositeProfile->chargingSchedule[idxSchedule].duration = maxProfile.chargingSchedule[idxSchedule].duration;
  5056. for(int idxMaxPeriod=0;idxMaxPeriod<limitDef;idxMaxPeriod++)
  5057. {
  5058. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  5059. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  5060. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  5061. {
  5062. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  5063. {
  5064. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  5065. compositePeriodIdx++;
  5066. }
  5067. else
  5068. {
  5069. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct StructChargingSchedulePeriod));
  5070. }
  5071. }
  5072. }
  5073. }
  5074. else
  5075. {
  5076. int lastCompositePeriodIdx = compositePeriodIdx;
  5077. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  5078. {
  5079. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  5080. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  5081. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  5082. {
  5083. if((maxProfile.chargingSchedule[idxSchedule].duration >= compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod))
  5084. {
  5085. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit > compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[lastCompositePeriodIdx-1].limit)
  5086. {
  5087. tmpPeriod.startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod;
  5088. tmpPeriod.numberPhases = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].numberPhases;
  5089. tmpPeriod.limit = compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[lastCompositePeriodIdx-1].limit;
  5090. }
  5091. else
  5092. {
  5093. tmpPeriod.startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod;
  5094. tmpPeriod.numberPhases = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].numberPhases;
  5095. tmpPeriod.limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit;
  5096. }
  5097. }
  5098. if(tmpPeriod.limit != -1)
  5099. {
  5100. if(tmpPeriod.limit != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx-1)].limit)
  5101. {
  5102. if(tmpPeriod.startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx-1)].startPeriod)
  5103. {
  5104. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5105. compositePeriodIdx++;
  5106. }
  5107. else
  5108. {
  5109. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  5110. }
  5111. }
  5112. // Delete duplicate period
  5113. if(compositePeriodIdx > 1)
  5114. {
  5115. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  5116. {
  5117. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  5118. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  5119. compositePeriodIdx -= 1;
  5120. }
  5121. }
  5122. }
  5123. }
  5124. }
  5125. }
  5126. }
  5127. compositeProfile->chargingSchedule[idxSchedule].duration = durationReq;
  5128. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  5129. DEBUG_INFO("Schedule start: %s\n", compositeProfile->chargingSchedule[idxSchedule].startSchedule);
  5130. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->chargingSchedule[idxSchedule].duration);
  5131. DEBUG_INFO("Rate unit: %s\n", compositeProfile->chargingSchedule[idxSchedule].chargingRateUnit);
  5132. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  5133. {
  5134. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod >= 0)
  5135. {
  5136. compositeProfile->id = 1;
  5137. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  5138. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit);
  5139. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases);
  5140. }
  5141. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit == -1)
  5142. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit =0;
  5143. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod == -1)
  5144. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod =0;
  5145. }
  5146. if(line)
  5147. free(line);
  5148. checkChargePointMaxProfile(durationReq, &ShmOCPP20Data->MaxChargingProfile, idxSchedule, isUnitA);
  5149. ShmOCPP20Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = ON;
  5150. }
  5151. //==========================================
  5152. // Init all share memory
  5153. //==========================================
  5154. int InitShareMemory()
  5155. {
  5156. int result = PASS;
  5157. int MeterSMId;
  5158. //creat ShmSysConfigAndInfo
  5159. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  5160. {
  5161. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  5162. result = FAIL;
  5163. }
  5164. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  5165. {
  5166. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  5167. result = FAIL;
  5168. }
  5169. else
  5170. {}
  5171. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  5172. {
  5173. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  5174. result = FAIL;
  5175. }
  5176. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  5177. {
  5178. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  5179. result = FAIL;
  5180. }
  5181. else
  5182. {}
  5183. //creat ShmPsuData
  5184. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  5185. {
  5186. DEBUG_ERROR("shmget ShmPsuData NG\n");
  5187. result = FAIL;
  5188. }
  5189. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  5190. {
  5191. DEBUG_ERROR("shmat ShmPsuData NG\n");
  5192. result = FAIL;
  5193. }
  5194. else
  5195. {}
  5196. //creat ShmOCPP20Data
  5197. if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), 0777)) < 0)
  5198. {
  5199. DEBUG_ERROR("shmget ShmOCPP20Data NG\n");
  5200. result = FAIL;
  5201. }
  5202. else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  5203. {
  5204. DEBUG_ERROR("shmat ShmOCPP20Data NG\n");
  5205. result = FAIL;
  5206. }
  5207. else
  5208. {}
  5209. /****************************** For Initial Settings************************************************/
  5210. /*
  5211. DEBUG_INFO("Authorize_20 size: %d\n", sizeof(struct Authorize_20));
  5212. DEBUG_INFO("BootNotification_20 size: %d\n", sizeof(struct BootNotification_20));
  5213. DEBUG_INFO("CancelReservation_20 size: %d\n", sizeof(struct CancelReservation_20));
  5214. DEBUG_INFO("CertificateSigned_20 size: %d\n", sizeof(struct CertificateSigned_20));
  5215. DEBUG_INFO("ChangeAvailability_20 size: %d\n", sizeof(struct ChangeAvailability_20));
  5216. DEBUG_INFO("ClearCache_20 size: %d\n", sizeof(struct ClearCache_20));
  5217. DEBUG_INFO("ClearChargingProfile_20 size: %d\n", sizeof(struct ClearChargingProfile_20));
  5218. DEBUG_INFO("ClearDisplayMessage_20 size: %d\n", sizeof(struct ClearDisplayMessage_20));
  5219. DEBUG_INFO("ClearedChargingLimit_20 size: %d\n", sizeof(struct ClearedChargingLimit_20));
  5220. DEBUG_INFO("ClearVariableMonitoring_20 size: %d\n", sizeof(struct ClearVariableMonitoring_20));
  5221. DEBUG_INFO("CostUpdated_20 size: %d\n", sizeof(struct CostUpdated_20));
  5222. DEBUG_INFO("CustomerInformation_20 size: %d\n", sizeof(struct CustomerInformation_20));
  5223. DEBUG_INFO("DeleteCertificate_20 size: %d\n", sizeof(struct DeleteCertificate_20));
  5224. DEBUG_INFO("FirmwareStatusNotification_20 size: %d\n", sizeof(struct FirmwareStatusNotification_20));
  5225. DEBUG_INFO("Get15118EVCertificate_20 size: %d\n", sizeof(struct Get15118EVCertificate_20));
  5226. DEBUG_INFO("GetBaseReport_20 size: %d\n", sizeof(struct GetBaseReport_20));
  5227. DEBUG_INFO("GetCertificateStatus_20 size: %d\n", sizeof(struct GetCertificateStatus_20));
  5228. DEBUG_INFO("GetChargingProfiles_20 size: %d\n", sizeof(struct GetChargingProfiles_20));
  5229. DEBUG_INFO("GetCompositeSchedule_20 size: %d\n", sizeof(struct GetCompositeSchedule_20));
  5230. DEBUG_INFO("GetDisplayMessages_20 size: %d\n", sizeof(struct GetDisplayMessages_20));
  5231. DEBUG_INFO("GetInstalledCertificateIds_20 size: %d\n", sizeof(struct GetInstalledCertificateIds_20));
  5232. DEBUG_INFO("GetLog_20 size: %d\n", sizeof(struct GetLog_20));
  5233. DEBUG_INFO("GetMonitoringReport_20 size: %d\n", sizeof(struct GetMonitoringReport_20));
  5234. DEBUG_INFO("GetReport_20 size: %d\n", sizeof(struct GetReport_20));
  5235. DEBUG_INFO("GetTransactionStatus_20 size: %d\n", sizeof(struct GetTransactionStatus_20));
  5236. DEBUG_INFO("GetVariables_20 size: %d\n", sizeof(struct GetVariables_20));
  5237. DEBUG_INFO("InstallCertificate_20 size: %d\n", sizeof(struct InstallCertificate_20));
  5238. DEBUG_INFO("LogStatusNotification_20 size: %d\n", sizeof(struct LogStatusNotification_20));
  5239. DEBUG_INFO("MeterValues_20 size: %d\n", sizeof(struct MeterValues_20));
  5240. DEBUG_INFO("NotifyChargingLimit_20 size: %d\n", sizeof(struct NotifyChargingLimit_20));
  5241. DEBUG_INFO("NotifyCustomerInformation_20 size: %d\n", sizeof(struct NotifyCustomerInformation_20));
  5242. DEBUG_INFO("NotifyDisplayMessages_20 size: %d\n", sizeof(struct NotifyDisplayMessages_20));
  5243. DEBUG_INFO("NotifyEVChargingNeeds_20 size: %d\n", sizeof(struct NotifyEVChargingNeeds_20));
  5244. DEBUG_INFO("NotifyEVChargingSchedule_20 size: %d\n", sizeof(struct NotifyEVChargingSchedule_20));
  5245. DEBUG_INFO("NotifyEvent_20 size: %d\n", sizeof(struct NotifyEvent_20));
  5246. DEBUG_INFO("NotifyMonitoringReport_20 size: %d\n", sizeof(struct NotifyMonitoringReport_20));
  5247. DEBUG_INFO("NotifyReport_20 size: %d\n", sizeof(struct NotifyReport_20));
  5248. DEBUG_INFO("PublishFirmware_20 size: %d\n", sizeof(struct PublishFirmware_20));
  5249. DEBUG_INFO("PublishFirmwareStatusNotification_20 size: %d\n", sizeof(struct PublishFirmwareStatusNotification_20));
  5250. DEBUG_INFO("ReportChargingProfiles_20 size: %d\n", sizeof(struct ReportChargingProfiles_20));
  5251. DEBUG_INFO("RequestStartTransaction_20 size: %d\n", sizeof(struct RequestStartTransaction_20));
  5252. DEBUG_INFO("RequestStopTransaction_20 size: %d\n", sizeof(struct RequestStopTransaction_20));
  5253. DEBUG_INFO("ReservationStatusUpdate_20 size: %d\n", sizeof(struct ReservationStatusUpdate_20));
  5254. DEBUG_INFO("ReserveNow_20 size: %d\n", sizeof(struct ReserveNow_20));
  5255. DEBUG_INFO("Reset_20 size: %d\n", sizeof(struct Reset_20));
  5256. DEBUG_INFO("SecurityEventNotification_20 size: %d\n", sizeof(struct SecurityEventNotification_20));
  5257. DEBUG_INFO("SendLocalList_20 size: %d\n", sizeof(struct SendLocalList_20));
  5258. DEBUG_INFO("SetChargingProfile_20 size: %d\n", sizeof(struct SetChargingProfile_20));
  5259. DEBUG_INFO("SetDisplayMessage_20 size: %d\n", sizeof(struct SetDisplayMessage_20));
  5260. DEBUG_INFO("SetMonitoringBase_20 size: %d\n", sizeof(struct SetMonitoringBase_20));
  5261. DEBUG_INFO("SetMonitoringLevel_20 size: %d\n", sizeof(struct SetMonitoringLevel_20));
  5262. DEBUG_INFO("SetNetworkProfile_20 size: %d\n", sizeof(struct SetNetworkProfile_20));
  5263. DEBUG_INFO("SetVariableMonitoring_20 size: %d\n", sizeof(struct SetVariableMonitoring_20));
  5264. DEBUG_INFO("SetVariables_20 size: %d\n", sizeof(struct SetVariables_20));
  5265. DEBUG_INFO("SignCertificate_20 size: %d\n", sizeof(struct SignCertificate_20));
  5266. DEBUG_INFO("StatusNotification_20 size: %d\n", sizeof(struct StatusNotification_20));
  5267. DEBUG_INFO("TransactionEvent_20 size: %d\n", sizeof(struct TransactionEvent_20));
  5268. DEBUG_INFO("TriggerMessage_20 size: %d\n", sizeof(struct TriggerMessage_20));
  5269. DEBUG_INFO("UnlockConnector_20 size: %d\n", sizeof(struct UnlockConnector_20));
  5270. DEBUG_INFO("UnpublishFirmware_20 size: %d\n", sizeof(struct UnpublishFirmware_20));
  5271. DEBUG_INFO("UpdateFirmware_20 size: %d\n", sizeof(struct UpdateFirmware_20));
  5272. DEBUG_INFO("ChargingProfileType size: %d\n", sizeof(struct ChargingProfileType));
  5273. */
  5274. return result;
  5275. }
  5276. int ProcessShareMemory()
  5277. {
  5278. int result = PASS;
  5279. if(InitShareMemory() == FAIL)
  5280. {
  5281. DEBUG_ERROR("InitShareMemory NG\n");
  5282. if(ShmStatusCodeData!=NULL)
  5283. {
  5284. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  5285. }
  5286. result = FAIL;
  5287. }
  5288. if(RatedCurrentParsing((char*)ShmSysConfigAndInfo->SysConfig.ModelName, &modelnameInfo) != -1)
  5289. {
  5290. DEBUG_INFO("Model name rated power: %d\n", modelnameInfo.ratedPower);
  5291. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  5292. ((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  5293. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  5294. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  5295. ) // 'D' means DC
  5296. {
  5297. // DO series
  5298. for(int gun_index=0; gun_index<GENERAL_GUN_QUANTITY ; gun_index++)
  5299. {
  5300. SystemInitial += 1;
  5301. gunTotalNumber += 1;
  5302. gunType[gun_index] = GUN_TYPE_DO;
  5303. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  5304. {
  5305. case Gun_Type_Chademo:
  5306. DEBUG_INFO("Gun-%02d type: Cabinet CHAdeMO\n", gun_index);
  5307. break;
  5308. case Gun_Type_CCS_2:
  5309. DEBUG_INFO("Gun-%02d type: Cabinet CCS\n", gun_index);
  5310. break;
  5311. case Gun_Type_GB:
  5312. DEBUG_INFO("Gun-%02d type: Cabinet GBT\n", gun_index);
  5313. break;
  5314. case Gun_Type_AC:
  5315. DEBUG_INFO("Gun-%02d type: Cabinet AC\n", gun_index);
  5316. break;
  5317. default:
  5318. DEBUG_WARN("Gun-%02d type: Cabinet unknown\n", gun_index);
  5319. break;
  5320. }
  5321. }
  5322. }
  5323. else
  5324. {
  5325. for(int gun_index=0;gun_index<modelnameInfo.GetGunCount;gun_index++)
  5326. {
  5327. SystemInitial += 1;
  5328. gunTotalNumber += 1;
  5329. switch(modelnameInfo.ParsingInfo[gun_index].GunType)
  5330. {
  5331. case Gun_Type_Chademo:
  5332. gunType[gun_index] = GUN_TYPE_CHAdeMO;
  5333. DEBUG_INFO("Gun-%02d type: CHAdeMO\n", gun_index);
  5334. break;
  5335. case Gun_Type_CCS_2:
  5336. gunType[gun_index] = GUN_TYPE_CCS;
  5337. DEBUG_INFO("Gun-%02d type: CCS\n", gun_index);
  5338. break;
  5339. case Gun_Type_GB:
  5340. gunType[gun_index] = GUN_TYPE_GBT;
  5341. DEBUG_INFO("Gun-%02d type: GBT\n", gun_index);
  5342. break;
  5343. case Gun_Type_AC:
  5344. gunType[gun_index] = GUN_TYPE_AC;
  5345. DEBUG_INFO("Gun-%02d type: AC\n", gun_index);
  5346. break;
  5347. default:
  5348. DEBUG_WARN("Gun-%02d type: Unknown\n", gun_index);
  5349. break;
  5350. }
  5351. }
  5352. }
  5353. }
  5354. else
  5355. {
  5356. DEBUG_ERROR("Model name parsing fail.\n");
  5357. result = FAIL;
  5358. }
  5359. if(result != PASS)sleep(5);
  5360. return result;
  5361. }
  5362. //---------------------common routine---------------------------//
  5363. void checkNetworkProfile(void)
  5364. {
  5365. memcpy(ShmOCPP20Data->OcppServerURL, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmOCPP20Data->OcppServerURL));
  5366. json_object *priority;
  5367. priority = json_tokener_parse((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value);
  5368. if(!is_error(priority))
  5369. {
  5370. for(uint8_t idxPriority=0;idxPriority<json_object_array_length(priority);idxPriority++)
  5371. {
  5372. for(uint8_t idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile);idx++)
  5373. {
  5374. if((ShmOCPP20Data->NetworkConnectionProfile[idx].slot == json_object_get_int(json_object_array_get_idx(priority, idxPriority))) &&
  5375. (strlen((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl) > 0) &&
  5376. (ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount < 3))
  5377. {
  5378. memcpy(ShmOCPP20Data->OcppServerURL, ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl));
  5379. ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount++;
  5380. break;
  5381. }
  5382. }
  5383. }
  5384. }
  5385. json_object_put(priority);
  5386. DEBUG_INFO("Get network profile URL: %s\n", ShmOCPP20Data->OcppServerURL);
  5387. }
  5388. void checkRemoteStart(uint8_t connectorIdx)
  5389. {
  5390. uint8_t tempIndex;
  5391. int isAllowStart = TRUE;
  5392. char cmdBuf[512];
  5393. //check Transaction active
  5394. if(gunType[connectorIdx-1] == GUN_TYPE_CHAdeMO)
  5395. {
  5396. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5397. {
  5398. tempIndex = ((connectorIdx-1) == 2) ? 1: 0;
  5399. }
  5400. else
  5401. {
  5402. tempIndex = (connectorIdx-1);
  5403. }
  5404. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5405. {
  5406. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  5407. {
  5408. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) == 0))
  5409. {
  5410. //Reserved
  5411. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  5412. }
  5413. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) != 0))
  5414. {
  5415. //Reserved
  5416. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  5417. isAllowStart = FALSE;
  5418. }
  5419. else
  5420. {
  5421. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  5422. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  5423. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  5424. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  5425. {
  5426. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  5427. isAllowStart = FALSE;
  5428. }
  5429. }//END FOR ELSE
  5430. }
  5431. }// END FOR CHAdeMO_QUANTITY
  5432. }
  5433. else if(gunType[connectorIdx-1] == GUN_TYPE_CCS)
  5434. {
  5435. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5436. {
  5437. tempIndex = ((connectorIdx-1) == 2) ? 1: 0;
  5438. }
  5439. else
  5440. {
  5441. tempIndex = (connectorIdx-1);
  5442. }
  5443. for (int index = 0; index < CCS_QUANTITY; index++)
  5444. {
  5445. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5446. {
  5447. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) == 0))
  5448. {
  5449. //Reserved
  5450. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  5451. }
  5452. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) != 0))
  5453. {
  5454. //Reserved
  5455. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  5456. isAllowStart = FALSE;
  5457. }
  5458. else
  5459. {
  5460. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  5461. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  5462. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  5463. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  5464. {
  5465. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  5466. isAllowStart = FALSE;
  5467. }
  5468. }// END FOR ELSE
  5469. }
  5470. }// END FOR CCS_QUANTITY
  5471. }
  5472. else if(gunType[connectorIdx-1] == GUN_TYPE_GBT)
  5473. {
  5474. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5475. {
  5476. tempIndex = ((connectorIdx-1) == 2) ? 1: 0;
  5477. }
  5478. else
  5479. {
  5480. tempIndex = (connectorIdx-1);
  5481. }
  5482. for (int index = 0; index < GB_QUANTITY; index++)
  5483. {
  5484. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  5485. {
  5486. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) == 0))
  5487. {
  5488. //Reserved
  5489. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  5490. }
  5491. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) != 0))
  5492. {
  5493. //Reserved
  5494. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  5495. isAllowStart = FALSE;
  5496. }
  5497. else
  5498. {
  5499. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  5500. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  5501. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  5502. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  5503. {
  5504. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  5505. isAllowStart = FALSE;
  5506. }
  5507. }// END FOR ELSE
  5508. }
  5509. } // END FOR GB_QUANTITY
  5510. }
  5511. else if(gunType[connectorIdx-1] == GUN_TYPE_DO)
  5512. {
  5513. tempIndex = (connectorIdx-1);
  5514. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5515. {
  5516. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  5517. {
  5518. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) == 0))
  5519. {
  5520. //Reserved
  5521. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  5522. }
  5523. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) != 0))
  5524. {
  5525. //Reserved
  5526. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  5527. isAllowStart = FALSE;
  5528. }
  5529. else
  5530. {
  5531. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  5532. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  5533. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  5534. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  5535. {
  5536. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  5537. isAllowStart = FALSE;
  5538. }
  5539. }// END FOR ELSE
  5540. }
  5541. } // END FOR GB_QUANTITY
  5542. }
  5543. else
  5544. {
  5545. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5546. {
  5547. tempIndex = 2;
  5548. }
  5549. else
  5550. {
  5551. tempIndex = (connectorIdx-1);
  5552. }
  5553. for (int index = 0; index < AC_QUANTITY; index++)
  5554. {
  5555. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  5556. {
  5557. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) == 0))
  5558. {
  5559. //Reserved
  5560. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  5561. }
  5562. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) != 0))
  5563. {
  5564. //Reserved
  5565. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  5566. isAllowStart = FALSE;
  5567. }
  5568. else
  5569. {
  5570. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  5571. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  5572. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  5573. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  5574. {
  5575. DEBUG_WARN("AC connector not allow start cause busy.\n");
  5576. isAllowStart = FALSE;
  5577. }
  5578. }//END FOR ELSE
  5579. }
  5580. }// END FOR AC_QUANTITY
  5581. }
  5582. if(isAllowStart == TRUE)
  5583. {
  5584. if(ShmOCPP20Data->RequestStartTransaction[connectorIdx -1].chargingProfile.id > 0)
  5585. {
  5586. if((access("/Storage/OCPP/TxProfile_Tmp_OCPP20.json", F_OK))!=-1)
  5587. {
  5588. sprintf(cmdBuf, "mv /Storage/OCPP/TxProfile_Tmp_OCPP20.json /Storage/OCPP/TxProfile_%d_OCPP20.json", connectorIdx);
  5589. system(cmdBuf);
  5590. }
  5591. }
  5592. ShmOCPP20Data->CsMsg.bits[connectorIdx-1].RequestStartTransactionReq = ON;
  5593. }
  5594. }
  5595. void CheckSystemValue(void)
  5596. {
  5597. char filenmae[100]={0};
  5598. char str[100]={0};
  5599. int tempIndex = 0;
  5600. //===============================
  5601. // EVSE operation check
  5602. //===============================
  5603. //===============================
  5604. // Heartbeat check
  5605. //===============================
  5606. if((server_sign == TRUE) && (getDiffSecNow(clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  5607. {
  5608. //parameter for test
  5609. sendHeartbeatRequest(0);
  5610. //==============================================
  5611. // Reset Waiting Time
  5612. //==============================================
  5613. HeartBeatWithNOResponse += 1;
  5614. }
  5615. //===============================
  5616. // CSU Trigger Authorize Request
  5617. //===============================
  5618. if(isWebsocketSendable &&
  5619. (server_sign == TRUE) &&
  5620. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON) &&
  5621. (authorizeRetryTimes < 3))
  5622. {
  5623. sendAuthorizeRequest(0);
  5624. authorizeRetryTimes = authorizeRetryTimes + 1;
  5625. if(authorizeRetryTimes < 3)
  5626. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  5627. }
  5628. else if((server_sign == TRUE) &&
  5629. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON) &&
  5630. (authorizeRetryTimes >= 3))
  5631. {
  5632. authorizeRetryTimes = 0;
  5633. SetOcppConnStatus(FALSE);
  5634. server_sign = FALSE;
  5635. }
  5636. else if((server_sign == FALSE) &&
  5637. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "TRUE") == 0) &&
  5638. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].value, "TRUE") == 0) &&
  5639. (ShmOCPP20Data->OcppConnStatus == OFF) &&
  5640. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON))
  5641. {
  5642. sendAuthorizeRequest(0);
  5643. }
  5644. if(isWebsocketSendable &&
  5645. (server_sign == TRUE) &&
  5646. (ShmOCPP20Data->GetMonitoringReport.requestId > 0))
  5647. {
  5648. for(uint8_t idxCriterion=0;idxCriterion<ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.monitoringCriteria);idxCriterion++)
  5649. {
  5650. if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_ThresholdMonitoring]) == 0)
  5651. {
  5652. /*
  5653. * TODO:
  5654. * 1. Report component that are ThresholdMonitoring
  5655. */
  5656. }
  5657. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_DeltaMonitoring]) == 0)
  5658. {
  5659. /*
  5660. * TODO:
  5661. * 1. Report component that are DeltaMonitoring
  5662. */
  5663. }
  5664. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_PeriodicMonitoring]) == 0)
  5665. {
  5666. /*
  5667. * TODO:
  5668. * 1. Report component that are PeriodicMonitoring
  5669. */
  5670. }
  5671. else
  5672. {
  5673. /*
  5674. * TODO:
  5675. * 1. Process unknown criteria condition
  5676. */
  5677. }
  5678. }
  5679. ShmOCPP20Data->GetMonitoringReport.requestId = 0;
  5680. }
  5681. if(isWebsocketSendable &&
  5682. (server_sign == TRUE) &&
  5683. (ShmOCPP20Data->GetReport.requestId > 0))
  5684. {
  5685. for(uint8_t idxCriterion=0;idxCriterion<ARRAY_SIZE(ShmOCPP20Data->GetReport.componentCriteria);idxCriterion++)
  5686. {
  5687. if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Active]) == 0)
  5688. {
  5689. /*
  5690. * TODO:
  5691. * 1. Report component that are active
  5692. */
  5693. }
  5694. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Available]) == 0)
  5695. {
  5696. /*
  5697. * TODO:
  5698. * 1. Report component that are available
  5699. */
  5700. }
  5701. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Enabled]) == 0)
  5702. {
  5703. /*
  5704. * TODO:
  5705. * 1. Report component that are enable
  5706. */
  5707. }
  5708. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Problem]) == 0)
  5709. {
  5710. /*
  5711. * TODO:
  5712. * 1. Report component that are problem
  5713. */
  5714. }
  5715. else
  5716. {
  5717. /*
  5718. * TODO:
  5719. * 1. Process unknown criteria condition
  5720. */
  5721. }
  5722. }
  5723. ShmOCPP20Data->GetReport.requestId = 0;
  5724. }
  5725. if(isWebsocketSendable &&
  5726. (server_sign == TRUE) &&
  5727. (ShmOCPP20Data->GetBaseReport.requestId > 0))
  5728. {
  5729. uint8_t reportIdx = 0;
  5730. ShmOCPP20Data->NotifyReport.requestId = ShmOCPP20Data->GetBaseReport.requestId;
  5731. if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_ConfigurationInventory]) == 0)
  5732. {
  5733. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  5734. {
  5735. if(reportIdx < ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData))
  5736. {
  5737. 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))
  5738. {
  5739. memcpy(&ShmOCPP20Data->NotifyReport.reportData[reportIdx], &ShmOCPP20Data->ControllerComponentVariable[idx_var], sizeof(struct ReportDataType));
  5740. reportIdx++;
  5741. }
  5742. }
  5743. else
  5744. {
  5745. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  5746. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  5747. ShmOCPP20Data->NotifyReport.seqNo += 1;
  5748. else
  5749. ShmOCPP20Data->NotifyReport.seqNo = 0;
  5750. sendNotifyReportRequest();
  5751. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  5752. reportIdx = 0;
  5753. }
  5754. }
  5755. }
  5756. else if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_FullInventory]) == 0)
  5757. {
  5758. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  5759. {
  5760. if(reportIdx < ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData))
  5761. {
  5762. memcpy(&ShmOCPP20Data->NotifyReport.reportData[reportIdx], &ShmOCPP20Data->ControllerComponentVariable[idx_var], sizeof(struct ReportDataType));
  5763. reportIdx++;
  5764. }
  5765. else
  5766. {
  5767. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  5768. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  5769. ShmOCPP20Data->NotifyReport.seqNo += 1;
  5770. else
  5771. ShmOCPP20Data->NotifyReport.seqNo = 0;
  5772. sendNotifyReportRequest();
  5773. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  5774. reportIdx = 0;
  5775. }
  5776. }
  5777. }
  5778. else
  5779. {
  5780. /*
  5781. * TODO:
  5782. * 1. Fill out summary inventory to response message, currently not support
  5783. */
  5784. }
  5785. if(reportIdx > 0)
  5786. {
  5787. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  5788. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  5789. ShmOCPP20Data->NotifyReport.seqNo += 1;
  5790. else
  5791. ShmOCPP20Data->NotifyReport.seqNo = 0;
  5792. sendNotifyReportRequest();
  5793. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  5794. reportIdx = 0;
  5795. }
  5796. ShmOCPP20Data->GetBaseReport.requestId = 0;
  5797. }
  5798. if(isWebsocketSendable &&
  5799. (server_sign == TRUE) &&
  5800. ShmOCPP20Data->SpMsg.bits.NotifyEventReq)
  5801. {
  5802. getNowDatetime(ShmOCPP20Data->NotifyEvent.generatedAt);
  5803. ShmOCPP20Data->NotifyEvent.tbc = FALSE;
  5804. if(ShmOCPP20Data->NotifyEvent.seqNo < INT_MAX)
  5805. ShmOCPP20Data->NotifyEvent.seqNo += 1;
  5806. else
  5807. ShmOCPP20Data->NotifyEvent.seqNo = 0;
  5808. sendNotifyEventRequest();
  5809. memset(&ShmOCPP20Data->NotifyEvent.eventData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)* sizeof(struct EventDataType ));
  5810. ShmOCPP20Data->SpMsg.bits.NotifyEventReq = OFF;
  5811. }
  5812. if(isWebsocketSendable &&
  5813. (server_sign == TRUE) &&
  5814. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq)
  5815. {
  5816. if(strcmp((char*)ShmOCPP20Data->Get15118EVCertificate.action, CertificateActionEnumTypeStr[CertificateActionEnumType_Install]) == 0)
  5817. {
  5818. /*
  5819. * TODO:
  5820. * 1.
  5821. */
  5822. }
  5823. else if(strcmp((char*)ShmOCPP20Data->Get15118EVCertificate.action, CertificateActionEnumTypeStr[CertificateActionEnumType_Update]) == 0)
  5824. {
  5825. /*
  5826. * TODO:
  5827. * 1.
  5828. */
  5829. }
  5830. else
  5831. {
  5832. /*
  5833. * TODO:
  5834. * 1.
  5835. */
  5836. }
  5837. sendGet15118EVCertificateRequest();
  5838. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq = OFF;
  5839. }
  5840. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  5841. {
  5842. // ClockAlign MeterValue
  5843. 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))
  5844. {
  5845. //check Transaction active
  5846. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5847. {
  5848. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5849. {
  5850. tempIndex = ((gun_index==2) ? 1: 0);
  5851. }
  5852. else
  5853. {
  5854. tempIndex = gun_index;
  5855. }
  5856. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5857. {
  5858. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5859. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5860. {
  5861. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  5862. }
  5863. }// End for CHAdeMO
  5864. }
  5865. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5866. {
  5867. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5868. {
  5869. tempIndex = ((gun_index==2) ? 1: 0);
  5870. }
  5871. else
  5872. {
  5873. tempIndex = gun_index;
  5874. }
  5875. for (int index = 0; index < CCS_QUANTITY; index++)
  5876. {
  5877. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5878. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5879. {
  5880. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  5881. }
  5882. } // End for CCS
  5883. }
  5884. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5885. {
  5886. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5887. {
  5888. tempIndex = ((gun_index==2) ? 1: 0);
  5889. }
  5890. else
  5891. {
  5892. tempIndex = gun_index;
  5893. }
  5894. for (int index = 0; index < GB_QUANTITY; index++)
  5895. {
  5896. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5897. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5898. {
  5899. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  5900. }
  5901. }// End for GB
  5902. }
  5903. else if(gunType[gun_index] == GUN_TYPE_DO)
  5904. {
  5905. tempIndex = gun_index;
  5906. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5907. {
  5908. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5909. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5910. {
  5911. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  5912. }
  5913. }
  5914. }
  5915. else
  5916. {
  5917. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5918. {
  5919. tempIndex = 2;
  5920. }
  5921. else
  5922. {
  5923. tempIndex = gun_index;
  5924. }
  5925. for (int index = 0; index < AC_QUANTITY; index++)
  5926. {
  5927. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5928. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5929. {
  5930. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  5931. }
  5932. }//End for AC
  5933. }
  5934. }
  5935. }
  5936. //===============================
  5937. // Each connector operation check
  5938. //===============================
  5939. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  5940. {
  5941. //==========================================
  5942. // Check remote start without connector id
  5943. //==========================================
  5944. if(ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq)
  5945. {
  5946. int connectorIdInt = -1;
  5947. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  5948. {
  5949. if(!cpinitateMsg.bits[gun_index].isOnCharging && (strstr((char*)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[ConnectorStatusEnumType_Occupied]) != NULL))
  5950. {
  5951. connectorIdInt = (gun_index+1);
  5952. DEBUG_INFO("Detect connector-%02d connected ready to start.\n", connectorIdInt);
  5953. checkRemoteStart(connectorIdInt);
  5954. ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = OFF;
  5955. break;
  5956. }
  5957. }
  5958. if(getDiffSecNow(clientTime.RemoteStartWait) > atoi((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value))
  5959. {
  5960. DEBUG_WARN("Remote start request without connector id wait link over %s seconds.\n", (char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value);
  5961. ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = OFF;
  5962. }
  5963. }
  5964. //==========================================
  5965. // csu trigger DataTransferReq
  5966. //==========================================
  5967. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].DataTransferReq == ON))
  5968. {
  5969. sendDataTransferRequest(gun_index);
  5970. ShmOCPP20Data->CsMsg.bits[gun_index].DataTransferReq = OFF;
  5971. }
  5972. //==============================================
  5973. // Charger status notification & Transaction event report
  5974. //==============================================
  5975. //--- Check Mode Change ---//
  5976. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5977. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5978. {
  5979. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5980. {
  5981. tempIndex = ((gun_index==2) ? 1: 0);
  5982. }
  5983. else
  5984. {
  5985. tempIndex = gun_index;
  5986. }
  5987. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5988. {
  5989. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5990. {
  5991. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  5992. {
  5993. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  5994. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  5995. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  5996. if((SystemInitial == 0) &&
  5997. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  5998. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_COMPLETE))
  5999. {
  6000. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  6001. }
  6002. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  6003. {
  6004. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  6005. if((access(filenmae,F_OK))!=-1)
  6006. {
  6007. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  6008. sprintf(str,"rm -f %s",filenmae);
  6009. system(str);
  6010. }
  6011. }
  6012. }
  6013. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  6014. #if 1 // for TempStopTransaction
  6015. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  6016. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  6017. {
  6018. checkTempStopTransaction(gun_index);
  6019. }
  6020. #endif
  6021. }
  6022. }
  6023. }
  6024. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6025. {
  6026. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6027. {
  6028. tempIndex = ((gun_index==2) ? 1: 0);
  6029. }
  6030. else
  6031. {
  6032. tempIndex = gun_index;
  6033. }
  6034. for (int index = 0; index < CCS_QUANTITY; index++)
  6035. {
  6036. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6037. {
  6038. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn != CcsPreviousConnectorPlugIn[index]) )//if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != CcsPreviousSystemStatus[index]/*PRE_SYS_MODE[gun_index]*/ )
  6039. {
  6040. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  6041. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  6042. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  6043. if((SystemInitial == 0) &&
  6044. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  6045. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_COMPLETE))
  6046. {
  6047. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  6048. }
  6049. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  6050. {
  6051. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  6052. if((access(filenmae,F_OK))!=-1)
  6053. {
  6054. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  6055. sprintf(str,"rm -f %s",filenmae);
  6056. system(str);
  6057. }
  6058. }
  6059. }
  6060. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  6061. #if 1 // for TempStopTransaction
  6062. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  6063. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  6064. {
  6065. checkTempStopTransaction(gun_index);
  6066. }
  6067. #endif
  6068. }
  6069. }
  6070. }
  6071. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6072. {
  6073. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6074. {
  6075. tempIndex = ((gun_index==2) ? 1: 0);
  6076. }
  6077. else
  6078. {
  6079. tempIndex = gun_index;
  6080. }
  6081. for (int index = 0; index < GB_QUANTITY; index++)
  6082. {
  6083. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6084. {
  6085. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  6086. {
  6087. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  6088. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  6089. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  6090. if((SystemInitial == 0) &&
  6091. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  6092. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_COMPLETE))
  6093. {
  6094. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  6095. }
  6096. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  6097. {
  6098. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  6099. if((access(filenmae,F_OK))!=-1)
  6100. {
  6101. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  6102. sprintf(str,"rm -f %s",filenmae);
  6103. system(str);
  6104. }
  6105. }
  6106. }
  6107. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  6108. #if 1 // for TempStopTransaction
  6109. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  6110. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  6111. {
  6112. checkTempStopTransaction(gun_index);
  6113. }
  6114. #endif
  6115. }
  6116. }
  6117. }
  6118. else if(gunType[gun_index] == GUN_TYPE_DO)
  6119. {
  6120. tempIndex = gun_index;
  6121. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6122. {
  6123. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6124. {
  6125. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  6126. {
  6127. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  6128. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  6129. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  6130. if((SystemInitial == 0) &&
  6131. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CHARGING) &&
  6132. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_COMPLETE))
  6133. {
  6134. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  6135. }
  6136. 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
  6137. {
  6138. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  6139. if((access(filenmae,F_OK))!=-1)
  6140. {
  6141. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  6142. sprintf(str,"rm -f %s",filenmae);
  6143. system(str);
  6144. }
  6145. }
  6146. }
  6147. 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);
  6148. #if 1 // for TempStopTransaction
  6149. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  6150. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  6151. {
  6152. checkTempStopTransaction(gun_index);
  6153. }
  6154. #endif
  6155. }
  6156. }
  6157. }
  6158. else
  6159. {
  6160. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6161. {
  6162. tempIndex = 2;
  6163. }
  6164. else
  6165. {
  6166. tempIndex = gun_index;
  6167. }
  6168. for (int index = 0; index < AC_QUANTITY; index++)
  6169. {
  6170. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6171. {
  6172. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  6173. {
  6174. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  6175. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  6176. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  6177. if((SystemInitial == 0) &&
  6178. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_CHARGING) &&
  6179. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_COMPLETE))
  6180. {
  6181. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  6182. }
  6183. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_IDLE))) // complete
  6184. {
  6185. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d_OCPP20.json",(gun_index+1));
  6186. if((access(filenmae,F_OK))!=-1)
  6187. {
  6188. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  6189. sprintf(str,"rm -f %s",filenmae);
  6190. system(str);
  6191. }
  6192. }
  6193. }
  6194. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  6195. #if 1 // for TempStopTransaction
  6196. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  6197. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  6198. {
  6199. checkTempStopTransaction(gun_index);
  6200. }
  6201. #endif
  6202. }
  6203. }// END
  6204. }
  6205. if(isWebsocketSendable && (server_sign == TRUE) && (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= 5) &&
  6206. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == ON) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == ON) ||
  6207. ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].value, "TRUE") == 0) &&
  6208. (getDiffSecNow(clientTime.StatusNotification[gun_index]) >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationInterval].variableAttribute[0].value)))))
  6209. {
  6210. if(SystemInitial > 0)
  6211. SystemInitial -= 1;
  6212. sendStatusNotificationRequest(gun_index);
  6213. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  6214. }
  6215. //==============================================
  6216. // CSU Trigger Smart Charging Profile
  6217. //==============================================
  6218. if(ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq == ON)
  6219. {
  6220. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP20Data->SmartChargingProfile[gun_index], 0, TRUE);
  6221. ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq = OFF;
  6222. }
  6223. //==============================================
  6224. // CSU transaction event
  6225. //==============================================
  6226. if(ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == ON)
  6227. {
  6228. sendTransactionEventRequest(gun_index);
  6229. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = OFF;
  6230. //storeTempStopTransaction(gun_index);
  6231. //memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0], 0x00, sizeof(struct MeterValueType));
  6232. }
  6233. //==============================================
  6234. // Meter report
  6235. //==============================================
  6236. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValueReq)
  6237. {
  6238. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Trigger);
  6239. cpinitateMsg.bits[gun_index].TriggerMeterValueReq = OFF;
  6240. }
  6241. if(isWebsocketSendable && (cpinitateMsg.bits[gun_index].ClockAlignMeterReq == ON))
  6242. {
  6243. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Clock);
  6244. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = OFF;
  6245. }
  6246. // Sample period MeterValue
  6247. if(getDiffSecNow(clientTime.MeterValues[gun_index]) >= ((atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value)>3)?(atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value)- 1):3))
  6248. {
  6249. //check Transaction active
  6250. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6251. {
  6252. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6253. {
  6254. tempIndex = ((gun_index==2) ? 1: 0);
  6255. }
  6256. else
  6257. {
  6258. tempIndex = gun_index;
  6259. }
  6260. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6261. {
  6262. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6263. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6264. {
  6265. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6266. {
  6267. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  6268. }
  6269. }
  6270. }// End for CHAdeMO
  6271. }
  6272. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6273. {
  6274. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6275. {
  6276. tempIndex = ((gun_index==2) ? 1: 0);
  6277. }
  6278. else
  6279. {
  6280. tempIndex = gun_index;
  6281. }
  6282. for (int index = 0; index < CCS_QUANTITY; index++)
  6283. {
  6284. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6285. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6286. {
  6287. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6288. {
  6289. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  6290. }
  6291. }
  6292. } // End for CCS
  6293. }
  6294. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6295. {
  6296. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6297. {
  6298. tempIndex = ((gun_index==2) ? 1: 0);
  6299. }
  6300. else
  6301. {
  6302. tempIndex = gun_index;
  6303. }
  6304. for (int index = 0; index < GB_QUANTITY; index++)
  6305. {
  6306. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6307. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6308. {
  6309. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6310. {
  6311. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  6312. }
  6313. }
  6314. }// End for GB
  6315. }
  6316. else if(gunType[gun_index] == GUN_TYPE_DO)
  6317. {
  6318. tempIndex = gun_index;
  6319. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6320. {
  6321. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6322. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6323. {
  6324. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  6325. {
  6326. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  6327. }
  6328. }
  6329. }
  6330. }
  6331. else
  6332. {
  6333. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6334. {
  6335. tempIndex = 2;
  6336. }
  6337. else
  6338. {
  6339. tempIndex = gun_index;
  6340. }
  6341. for (int index = 0; index < AC_QUANTITY; index++)
  6342. {
  6343. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  6344. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6345. {
  6346. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  6347. {
  6348. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  6349. }
  6350. }
  6351. }//End for AC
  6352. }
  6353. if(cpinitateMsg.bits[gun_index].SampleMeterReq == ON)
  6354. {
  6355. if(atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value) > 0)
  6356. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic);
  6357. cpinitateMsg.bits[gun_index].SampleMeterReq = OFF;
  6358. }
  6359. refreshStartTimer(&clientTime.MeterValues[gun_index]);
  6360. }
  6361. //==============================================
  6362. // Check Connector reserved
  6363. //==============================================
  6364. //===============================
  6365. // Check if Reserve is expired
  6366. //===============================
  6367. if((server_sign == TRUE) && (ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime[0] != 0))
  6368. {
  6369. if(isOvertNow(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime))
  6370. {
  6371. DEBUG_INFO("reserve expired.\n");
  6372. ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationId = ShmOCPP20Data->ReserveNow[gun_index].id;
  6373. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Expired]);
  6374. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = ON;
  6375. memset(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime,0,ARRAY_SIZE(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime));
  6376. }
  6377. }//END OF Check if Reserve is expired
  6378. //==========================================
  6379. // csu trigger FirmwareStatusNotificationReq
  6380. //==========================================
  6381. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq == ON))
  6382. {
  6383. sendFirmwareStatusNotificationRequest((char *)ShmOCPP20Data->FirmwareStatusNotification.status);
  6384. }
  6385. //==========================================
  6386. // csu cleared charging limit request
  6387. //==========================================
  6388. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq == ON))
  6389. {
  6390. sendClearedChargingLimitRequest(gun_index);
  6391. }
  6392. //==========================================
  6393. // csu trigger CancelReservationConf
  6394. //==========================================
  6395. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationConf == ON))
  6396. {
  6397. sendCancelReservationConfirmation((char *)ShmOCPP20Data->CancelReservation[gun_index].guid, gun_index);
  6398. }
  6399. //==========================================
  6400. // csu notify EV charging need request
  6401. //==========================================
  6402. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsReq == ON))
  6403. {
  6404. sendNotifyEVChargingNeedsRequest(gun_index);
  6405. }
  6406. //==========================================
  6407. // csu trigger ChangeAvailabilityConf
  6408. //==========================================
  6409. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == ON))
  6410. {
  6411. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP20Data->ChangeAvailability[gun_index].ResponseStatus);
  6412. }
  6413. //==========================================
  6414. // csu trigger UnlockConnectorConf
  6415. //==========================================
  6416. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf == ON))
  6417. {
  6418. sendUnlockConnectorConfirmation((char *)ShmOCPP20Data->UnlockConnector[gun_index].guid, gun_index);
  6419. }
  6420. //==========================================
  6421. // csu trigger ReserveNowConf
  6422. //==========================================
  6423. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf == ON))
  6424. {
  6425. sendReserveNowConfirmation((char *)ShmOCPP20Data->ReserveNow[gun_index].guid, gun_index);
  6426. }
  6427. //==========================================
  6428. // csu trigger ReserveNowConf
  6429. //==========================================
  6430. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq == ON))
  6431. {
  6432. sendReservationStatusUpdateRequest(gun_index);
  6433. }
  6434. //==========================================
  6435. // csu trigger LogStatusNotificationReq
  6436. //==========================================
  6437. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq == ON))
  6438. {
  6439. sendLogStatusNotificationRequest((char *)ShmOCPP20Data->LogStatusNotification.status);
  6440. }
  6441. //==========================================
  6442. // csu trigger SignCertificateReq
  6443. //==========================================
  6444. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.SignCertificateReq == ON))
  6445. {
  6446. if((access("/Storage/OCPP/certCP.csr",F_OK) != -1) &&
  6447. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) == 0) )
  6448. {
  6449. sendSignCertificateRequest(CertificateSignedStatusEnumType_ChargingStationCertificate);
  6450. }
  6451. else if((access("/Storage/OCPP/certV2G.csr",F_OK) != -1) &&
  6452. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0))
  6453. {
  6454. sendSignCertificateRequest(CertificateSignedStatusEnumType_V2GCertificate);
  6455. }
  6456. }
  6457. }
  6458. }
  6459. //==========================================
  6460. // send request routine
  6461. //==========================================
  6462. int sendAuthorizeRequest(int gun_index)
  6463. {
  6464. mtrace();
  6465. int result = FAIL;
  6466. char message[4096]={0};
  6467. char guid[37];
  6468. char tempdata[128]={0};
  6469. json_object *Authorize = json_object_new_object();
  6470. json_object *idToken = json_object_new_object();
  6471. DEBUG_INFO("sendAuthorizeRequest...\n");
  6472. memset(&(ShmOCPP20Data->Authorize.Response_idTokenInfo),0,sizeof(struct IdTokenInfoType));
  6473. //Local Authorize
  6474. if ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].value, "TRUE")==0) && (ShmOCPP20Data->OcppConnStatus == 0))
  6475. {
  6476. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  6477. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "");
  6478. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, "");
  6479. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]);
  6480. result = PASS;
  6481. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  6482. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  6483. authorizeRetryTimes = 0;
  6484. return result;
  6485. }
  6486. 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)) ||
  6487. ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].value, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "TRUE") == 0)))
  6488. {
  6489. // Query idtag from cache
  6490. DB_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId, TRUE);
  6491. // Query idtag from list
  6492. if((strcmp((char*)idTagQuery.idToken.idToken,"") == 0) || (strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0) )
  6493. DB_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId, FALSE);
  6494. if((strcmp((char*)idTagQuery.idToken.idToken,"") == 0) || (strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0) )
  6495. {
  6496. if(strcmp((char*)idTagQuery.idToken.idToken,"") == 0)
  6497. {
  6498. DEBUG_INFO("Card %s does not find in list or cache\n", ShmSysConfigAndInfo->SysConfig.UserId);
  6499. }
  6500. if(strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0)
  6501. {
  6502. DEBUG_INFO("Card %s does not accepted in list and cache\n", ShmSysConfigAndInfo->SysConfig.UserId);
  6503. }
  6504. // Return authorize result if does not connect to server
  6505. if(!ShmOCPP20Data->OcppConnStatus)
  6506. {
  6507. DEBUG_INFO("Local Authorization Fail.\n");
  6508. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "");
  6509. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  6510. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Invalid]);
  6511. DEBUG_INFO("ShmOCPP20Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
  6512. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  6513. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  6514. authorizeRetryTimes = 0;
  6515. return result;
  6516. }
  6517. }
  6518. else
  6519. {
  6520. DEBUG_INFO("Local Authorization get result.\n");
  6521. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, (char*)idTagQuery.idTokenInfo.cacheExpiryDateTime);
  6522. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
  6523. if(isOvertNow((uint8_t*)&idTagQuery.idTokenInfo.cacheExpiryDateTime[0]))
  6524. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Expired]);
  6525. else
  6526. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, (char*)idTagQuery.idTokenInfo.status);
  6527. DEBUG_INFO("ShmOCPP20Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
  6528. result = PASS;
  6529. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  6530. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  6531. authorizeRetryTimes = 0;
  6532. return result;
  6533. }
  6534. }
  6535. //get data from shared memory
  6536. strcpy((char *)ShmOCPP20Data->Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  6537. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.idToken));
  6538. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.type));
  6539. json_object_object_add(Authorize, "idToken", idToken);
  6540. random_uuid(guid);
  6541. sprintf(message,"[%d,\"%s\",\"Authorize\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(Authorize, JSON_C_TO_STRING_PLAIN));
  6542. json_object_put(Authorize);
  6543. LWS_Send(message);
  6544. sprintf(tempdata, "Authorize,%d", gun_index);
  6545. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6546. {
  6547. result = PASS;
  6548. }
  6549. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  6550. return result;
  6551. }
  6552. int sendBootNotificationRequest()
  6553. {
  6554. mtrace();
  6555. int result = FAIL;
  6556. char message[4096]={0};
  6557. char guid[37]={0};
  6558. char tempdata[128]={0};
  6559. json_object *BootNotification = json_object_new_object();
  6560. json_object *chargingStation = json_object_new_object();
  6561. json_object *modem = json_object_new_object();
  6562. DEBUG_INFO("sendBootNotificationRequest...\n");
  6563. // Fill BootNotification fields
  6564. DB_getBooType();
  6565. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.model, "%s", ShmSysConfigAndInfo->SysConfig.ModelName);
  6566. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.vendorName, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  6567. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.serialNumber, "%s", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  6568. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.firmwareVersion, "%s", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  6569. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.modem.iccid, "%s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  6570. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.modem.imsi, "%s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  6571. if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
  6572. {
  6573. json_object_object_add(modem, "iccid", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.modem.iccid));
  6574. json_object_object_add(modem, "imsi", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.modem.imsi));
  6575. json_object_object_add(chargingStation, "modem", modem);
  6576. }
  6577. json_object_object_add(chargingStation, "model", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.model));
  6578. json_object_object_add(chargingStation, "vendorName", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.vendorName));
  6579. json_object_object_add(chargingStation, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.serialNumber));
  6580. json_object_object_add(chargingStation, "firmwareVersion", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.firmwareVersion));
  6581. json_object_object_add(BootNotification, "chargingStation", chargingStation);
  6582. json_object_object_add(BootNotification, "reason", json_object_new_string((char*)ShmOCPP20Data->BootNotification.reason));
  6583. random_uuid(guid);
  6584. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", json_object_to_json_string_ext(BootNotification, JSON_C_TO_STRING_PLAIN));
  6585. json_object_put(BootNotification);
  6586. LWS_Send(message);
  6587. sprintf(tempdata, "BootNotification,0");
  6588. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6589. {
  6590. result = PASS;
  6591. }
  6592. return result;
  6593. }
  6594. int sendClearedChargingLimitRequest(int gun_index)
  6595. {
  6596. mtrace();
  6597. int result = FAIL;
  6598. char message[4096]={0};
  6599. char guid[37]={0};
  6600. char tempdata[128]={0};
  6601. json_object *ClearedChargingLimit = json_object_new_object();
  6602. DEBUG_INFO("sendClearedChargingLimitRequest...\n");
  6603. json_object_object_add(ClearedChargingLimit, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->ClearedChargingLimit[gun_index].chargingLimitSource));
  6604. json_object_object_add(ClearedChargingLimit, "evseId", json_object_new_int(ShmOCPP20Data->ClearedChargingLimit[gun_index].evseId));
  6605. random_uuid(guid);
  6606. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ClearedChargingLimit", json_object_to_json_string_ext(ClearedChargingLimit, JSON_C_TO_STRING_PLAIN));
  6607. json_object_put(ClearedChargingLimit);
  6608. LWS_Send(message);
  6609. sprintf(tempdata, "ClearedChargingLimit,%d", gun_index);
  6610. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6611. {
  6612. result = PASS;
  6613. }
  6614. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq = OFF;
  6615. return result;
  6616. }
  6617. int sendDataTransferRequest(int gun_index)
  6618. {
  6619. mtrace();
  6620. char message[1000]={0};
  6621. char guid[37]={0};
  6622. char tempdata[65]={0};
  6623. int result = FAIL;
  6624. DEBUG_INFO("sendDataTransferRequest...\n");
  6625. random_uuid(guid);
  6626. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  6627. MESSAGE_TYPE_CALL,
  6628. guid,
  6629. ShmOCPP20Data->DataTransfer[gun_index].vendorId,
  6630. ShmOCPP20Data->DataTransfer[gun_index].messageId,
  6631. ShmOCPP20Data->DataTransfer[gun_index].data);
  6632. LWS_Send(message);
  6633. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  6634. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6635. {
  6636. result = PASS;
  6637. }
  6638. return result;
  6639. }
  6640. int sendFirmwareStatusNotificationRequest(char *status)
  6641. {
  6642. mtrace();
  6643. int result = FAIL;
  6644. char message[110]={0};
  6645. char guid[37]={0};
  6646. char tempdata[65]={0};
  6647. json_object *FirmwareStatusNotification = json_object_new_object();
  6648. DEBUG_INFO("sendFirmwareStatusNotificationRequest...\n");
  6649. sprintf((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", (const char *)status);
  6650. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  6651. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->FirmwareStatusNotification.status));
  6652. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->FirmwareStatusNotification.requestId));
  6653. random_uuid(guid);
  6654. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6655. json_object_put(FirmwareStatusNotification);
  6656. LWS_SendNow(message);
  6657. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6658. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6659. {
  6660. result = PASS;
  6661. }
  6662. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = OFF;
  6663. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationConf = OFF;
  6664. //record status
  6665. if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded])==0)
  6666. {
  6667. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Downloaded;
  6668. }
  6669. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed])==0)
  6670. {
  6671. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadFailed;
  6672. }
  6673. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading])==0)
  6674. {
  6675. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Downloading;
  6676. }
  6677. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadScheduled])==0)
  6678. {
  6679. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadScheduled;
  6680. }
  6681. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadPaused])==0)
  6682. {
  6683. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadPaused;
  6684. }
  6685. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle])==0)
  6686. {
  6687. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle;
  6688. }
  6689. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallationFailed])==0)
  6690. {
  6691. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallationFailed;
  6692. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  6693. }
  6694. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Installing])==0)
  6695. {
  6696. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Installing;
  6697. }
  6698. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Installed])==0)
  6699. {
  6700. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Installed;
  6701. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  6702. }
  6703. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallRebooting])==0)
  6704. {
  6705. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallRebooting;
  6706. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  6707. }
  6708. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallScheduled])==0)
  6709. {
  6710. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallScheduled;
  6711. }
  6712. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallVerificationFailed])==0)
  6713. {
  6714. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallVerificationFailed;
  6715. }
  6716. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InvalidSignature])==0)
  6717. {
  6718. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InvalidSignature;
  6719. }
  6720. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_SignatureVerified])==0)
  6721. {
  6722. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_SignatureVerified;
  6723. }
  6724. return result;
  6725. }
  6726. int sendGet15118EVCertificateRequest()
  6727. {
  6728. mtrace();
  6729. int result = FAIL;
  6730. char message[4096]={0};
  6731. char guid[37]={0};
  6732. char tempdata[128]={0};
  6733. json_object *Get15118EVCertificate = json_object_new_object();
  6734. DEBUG_INFO("sendGet15118EVCertificateRequest...\n");
  6735. json_object_object_add(Get15118EVCertificate, "iso15118SchemaVersion", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.iso15118SchemaVersion));
  6736. json_object_object_add(Get15118EVCertificate, "action", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.action));
  6737. json_object_object_add(Get15118EVCertificate, "exiRequest", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.exiRequest));
  6738. random_uuid(guid);
  6739. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "Get15118EVCertificate", json_object_to_json_string_ext(Get15118EVCertificate, JSON_C_TO_STRING_PLAIN));
  6740. json_object_put(Get15118EVCertificate);
  6741. LWS_Send(message);
  6742. sprintf(tempdata, "Get15118EVCertificate,0");
  6743. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6744. {
  6745. result = PASS;
  6746. }
  6747. return result;
  6748. }
  6749. int sendGetCertificateStatusRequest()
  6750. {
  6751. mtrace();
  6752. int result = FAIL;
  6753. char message[4096]={0};
  6754. char guid[37]={0};
  6755. char tempdata[128]={0};
  6756. json_object *GetCertificateStatus = json_object_new_object();
  6757. json_object *ocspRequestData = json_object_new_object();
  6758. DEBUG_INFO("sendGetCertificateStatusRequest...\n");
  6759. json_object_object_add(ocspRequestData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.hashAlgorithm));
  6760. json_object_object_add(ocspRequestData, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.issuerNameHash));
  6761. json_object_object_add(ocspRequestData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.issuerKeyHash));
  6762. json_object_object_add(ocspRequestData, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.serialNumber));
  6763. json_object_object_add(ocspRequestData, "responderURL", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.responderURL));
  6764. json_object_object_add(GetCertificateStatus, "ocspRequestData", ocspRequestData);
  6765. random_uuid(guid);
  6766. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "GetCertificateStatus", json_object_to_json_string_ext(GetCertificateStatus, JSON_C_TO_STRING_PLAIN));
  6767. json_object_put(GetCertificateStatus);
  6768. LWS_Send(message);
  6769. sprintf(tempdata, "GetCertificateStatus,0");
  6770. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6771. {
  6772. result = PASS;
  6773. }
  6774. return result;
  6775. }
  6776. int sendHeartbeatRequest()
  6777. {
  6778. mtrace();
  6779. int result = FAIL;
  6780. char message[40096]={0};
  6781. char guid[37]={0};
  6782. char tempdata[128]={0};
  6783. DEBUG_INFO("sendHeartbeatRequest...\n");
  6784. random_uuid(guid);
  6785. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  6786. , MESSAGE_TYPE_CALL
  6787. , guid );
  6788. LWS_Send(message);
  6789. sprintf(tempdata, "Heartbeat,%d", 0);
  6790. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6791. {
  6792. result = PASS;
  6793. }
  6794. return result;
  6795. }
  6796. int sendLogStatusNotificationRequest(char *status)
  6797. {
  6798. mtrace();
  6799. int result = FAIL;
  6800. char message[4096]={0};
  6801. char guid[37]={0};
  6802. char tempdata[128]={0};
  6803. json_object *LogStatusNotification = json_object_new_object();
  6804. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6805. ShmOCPP20Data->LogStatusNotification.requestId = ShmOCPP20Data->GetLog.requestId;
  6806. sprintf((char *)ShmOCPP20Data->LogStatusNotification.status,"%s",(const char *)status);
  6807. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->LogStatusNotification.status));
  6808. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->LogStatusNotification.requestId));
  6809. random_uuid(guid);
  6810. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6811. json_object_put(LogStatusNotification);
  6812. LWS_SendNow(message);
  6813. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6814. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6815. {
  6816. result = PASS;
  6817. }
  6818. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  6819. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationConf = OFF;
  6820. //record status
  6821. if(strcmp(status,"BadMessage")==0)
  6822. {
  6823. LogStatusNotificationStatus = UploadLogStatusEnumType_BadMessage;
  6824. }
  6825. else if(strcmp(status,"Idle")==0)
  6826. {
  6827. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle;
  6828. }
  6829. else if(strcmp(status,"NotSupportedOperation")==0)
  6830. {
  6831. LogStatusNotificationStatus = UploadLogStatusEnumType_NotSupportedOperation;
  6832. }
  6833. else if(strcmp(status,"PermissionDenied")==0)
  6834. {
  6835. LogStatusNotificationStatus = UploadLogStatusEnumType_PermissionDenied;
  6836. }
  6837. else if(strcmp(status,"Uploaded")==0)
  6838. {
  6839. LogStatusNotificationStatus = UploadLogStatusEnumType_Uploaded;
  6840. }
  6841. else if(strcmp(status,"UploadFailure")==0)
  6842. {
  6843. LogStatusNotificationStatus = UploadLogStatusEnumType_UploadFailure;
  6844. }
  6845. else if(strcmp(status,"Uploading")==0)
  6846. {
  6847. LogStatusNotificationStatus = UploadLogStatusEnumType_Uploading;
  6848. }
  6849. return result;
  6850. }
  6851. int sendMeterValuesRequest(int gun_index, ReadingContextEnumType dataType)
  6852. {
  6853. mtrace();
  6854. int result = FAIL;
  6855. char guid[37]={0};
  6856. char tempdata[65]={0};
  6857. int tempIndex = 0;
  6858. json_object *MeterValueReq = json_object_new_object();
  6859. json_object *meterValues = json_object_new_array();
  6860. json_object *sampledValues = json_object_new_array();
  6861. DEBUG_INFO("sendMeterValuesRequest...\n");
  6862. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6863. memset(&ShmOCPP20Data->MeterValues[gun_index], 0, sizeof(struct MeterValues_20));
  6864. //set value
  6865. ShmOCPP20Data->MeterValues[gun_index].evseId = gun_index + 1; // gun start from 1~
  6866. //UTC Date time
  6867. struct timeval tmnow;
  6868. struct tm *tm;
  6869. char buf[28];//, usec_buf[6];
  6870. gettimeofday(&tmnow, NULL);
  6871. time_t t;
  6872. t = time(NULL);
  6873. /*UTC time and date*/
  6874. tm = gmtime(&t);
  6875. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6876. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].timestamp, buf);
  6877. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6878. //idx_sample=0;
  6879. //********************************(1)Current.Import L1************************************************/
  6880. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  6881. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  6882. (dataType == ReadingContextEnumType_Trigger))
  6883. {
  6884. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6885. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6886. {
  6887. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6888. {
  6889. tempIndex = ((gun_index==2) ? 1: 0);
  6890. }
  6891. else
  6892. {
  6893. tempIndex = gun_index;
  6894. }
  6895. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6896. {
  6897. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6898. {
  6899. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent*100))/100.0;
  6900. }
  6901. }
  6902. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6903. }
  6904. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6905. {
  6906. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6907. {
  6908. tempIndex = ((gun_index==2) ? 1: 0);
  6909. }
  6910. else
  6911. {
  6912. tempIndex = gun_index;
  6913. }
  6914. for (int index = 0; index < CCS_QUANTITY; index++)
  6915. {
  6916. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6917. {
  6918. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent*100))/100.0;
  6919. }
  6920. }
  6921. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6922. }
  6923. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6924. {
  6925. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6926. {
  6927. tempIndex = ((gun_index==2) ? 1: 0);
  6928. }
  6929. else
  6930. {
  6931. tempIndex = gun_index;
  6932. }
  6933. for (int index = 0; index < GB_QUANTITY; index++)
  6934. {
  6935. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6936. {
  6937. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent*100))/100.0;
  6938. }
  6939. }
  6940. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6941. }
  6942. else if(gunType[gun_index] == GUN_TYPE_DO)
  6943. {
  6944. tempIndex = gun_index;
  6945. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6946. {
  6947. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6948. {
  6949. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent*100))/100.0;
  6950. }
  6951. }
  6952. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6953. }
  6954. else
  6955. {
  6956. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6957. {
  6958. tempIndex = 2;
  6959. }
  6960. else
  6961. {
  6962. tempIndex = gun_index;
  6963. }
  6964. for (int index = 0; index < AC_QUANTITY; index++)
  6965. {
  6966. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6967. {
  6968. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent*100))/100.0;
  6969. }
  6970. }
  6971. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  6972. }
  6973. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].context, ReadingContextEnumTypeStr[dataType]);
  6974. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  6975. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  6976. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].unitOfMeasure.uint , "A");
  6977. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].unitOfMeasure.multiplier = 0;
  6978. }
  6979. //idx_sample=1;
  6980. //********************************(2)Energy.Active.Import.Register ************************************************/
  6981. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]) != NULL)) ||
  6982. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]) != NULL)) ||
  6983. (dataType == ReadingContextEnumType_Trigger))
  6984. {
  6985. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6986. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6987. {
  6988. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6989. {
  6990. tempIndex = ((gun_index==2) ? 1: 0);
  6991. }
  6992. else
  6993. {
  6994. tempIndex = gun_index;
  6995. }
  6996. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6997. {
  6998. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6999. {
  7000. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*100))/100.0;
  7001. }
  7002. }
  7003. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7004. }
  7005. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7006. {
  7007. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7008. {
  7009. tempIndex = ((gun_index==2) ? 1: 0);
  7010. }
  7011. else
  7012. {
  7013. tempIndex = gun_index;
  7014. }
  7015. for (int index = 0; index < CCS_QUANTITY; index++)
  7016. {
  7017. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7018. {
  7019. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*100))/100.0;
  7020. }
  7021. }
  7022. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7023. }
  7024. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7025. {
  7026. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7027. {
  7028. tempIndex = ((gun_index==2) ? 1: 0);
  7029. }
  7030. else
  7031. {
  7032. tempIndex = gun_index;
  7033. }
  7034. for (int index = 0; index < GB_QUANTITY; index++)
  7035. {
  7036. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7037. {
  7038. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*100))/100.0;
  7039. }
  7040. }
  7041. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7042. }
  7043. else if(gunType[gun_index] == GUN_TYPE_DO)
  7044. {
  7045. tempIndex = gun_index;
  7046. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7047. {
  7048. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7049. {
  7050. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*100))/100.0;
  7051. }
  7052. }
  7053. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7054. }
  7055. else
  7056. {
  7057. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7058. {
  7059. tempIndex = 2;
  7060. }
  7061. else
  7062. {
  7063. tempIndex = gun_index;
  7064. }
  7065. for (int index = 0; index < AC_QUANTITY; index++)
  7066. {
  7067. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7068. {
  7069. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*100))/100.0;
  7070. }
  7071. }
  7072. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  7073. }
  7074. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].context, ReadingContextEnumTypeStr[dataType]);
  7075. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]);
  7076. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7077. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].unitOfMeasure.uint , "kWh");
  7078. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.multiplier = 0;
  7079. }
  7080. //idx_sample=2;
  7081. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  7082. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]) != NULL)) ||
  7083. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]) != NULL)) ||
  7084. (dataType == ReadingContextEnumType_Trigger))
  7085. {
  7086. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7087. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7088. {
  7089. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7090. {
  7091. tempIndex = ((gun_index==2) ? 1: 0);
  7092. }
  7093. else
  7094. {
  7095. tempIndex = gun_index;
  7096. }
  7097. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7098. {
  7099. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7100. {
  7101. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy*100))/100.0;
  7102. }
  7103. } // END OF FOR CHAdeMO_QUANTITY
  7104. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7105. }
  7106. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7107. {
  7108. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7109. {
  7110. tempIndex = ((gun_index==2) ? 1: 0);
  7111. }
  7112. else
  7113. {
  7114. tempIndex = gun_index;
  7115. }
  7116. for (int index = 0; index < CCS_QUANTITY; index++)
  7117. {
  7118. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7119. {
  7120. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy*100))/100.0;
  7121. }
  7122. } // END OF CCS_QUANTITY
  7123. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7124. }
  7125. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7126. {
  7127. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7128. {
  7129. tempIndex = ((gun_index==2) ? 1: 0);
  7130. }
  7131. else
  7132. {
  7133. tempIndex = gun_index;
  7134. }
  7135. for (int index = 0; index < GB_QUANTITY; index++)
  7136. {
  7137. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7138. {
  7139. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy*100))/100.0;
  7140. }
  7141. } // END OF GB_QUANTITY
  7142. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7143. }
  7144. else if(gunType[gun_index] == GUN_TYPE_DO)
  7145. {
  7146. tempIndex = gun_index;
  7147. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7148. {
  7149. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7150. {
  7151. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy*100))/100.0;
  7152. }
  7153. }
  7154. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7155. }
  7156. else
  7157. {
  7158. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7159. {
  7160. tempIndex = 2;
  7161. }
  7162. else
  7163. {
  7164. tempIndex = gun_index;
  7165. }
  7166. for (int index = 0; index < AC_QUANTITY; index++)
  7167. {
  7168. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7169. {
  7170. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy*100))/100.0;
  7171. }
  7172. }
  7173. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  7174. }
  7175. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].context, ReadingContextEnumTypeStr[dataType]);
  7176. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]);
  7177. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7178. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.uint , "kWh");
  7179. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.multiplier = 0;
  7180. }
  7181. //idx_sample=3;
  7182. //********************************(4)Power.Active.Import************************************************/
  7183. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]) != NULL)) ||
  7184. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]) != NULL)) ||
  7185. (dataType == ReadingContextEnumType_Trigger))
  7186. {
  7187. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7188. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7189. {
  7190. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7191. {
  7192. tempIndex = ((gun_index==2) ? 1: 0);
  7193. }
  7194. else
  7195. {
  7196. tempIndex = gun_index;
  7197. }
  7198. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7199. {
  7200. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7201. {
  7202. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower*100))/100.0;
  7203. }
  7204. } // END OF FOR
  7205. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7206. }
  7207. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7208. {
  7209. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7210. {
  7211. tempIndex = ((gun_index==2) ? 1: 0);
  7212. }
  7213. else
  7214. {
  7215. tempIndex = gun_index;
  7216. }
  7217. for (int index = 0; index < CCS_QUANTITY; index++)
  7218. {
  7219. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7220. {
  7221. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower*100))/100.0;
  7222. }
  7223. }
  7224. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7225. }
  7226. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7227. {
  7228. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7229. {
  7230. tempIndex = ((gun_index==2) ? 1: 0);
  7231. }
  7232. else
  7233. {
  7234. tempIndex = gun_index;
  7235. }
  7236. for (int index = 0; index < GB_QUANTITY; index++)
  7237. {
  7238. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7239. {
  7240. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7241. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower*100))/100.0;
  7242. }
  7243. }
  7244. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7245. }
  7246. else if(gunType[gun_index] == GUN_TYPE_DO)
  7247. {
  7248. tempIndex = gun_index;
  7249. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7250. {
  7251. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7252. {
  7253. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7254. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower*100))/100.0;
  7255. }
  7256. }
  7257. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7258. }
  7259. else
  7260. {
  7261. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7262. {
  7263. tempIndex = 2;
  7264. }
  7265. else
  7266. {
  7267. tempIndex = gun_index;
  7268. }
  7269. for (int index = 0; index < AC_QUANTITY; index++)
  7270. {
  7271. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7272. {
  7273. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower*100))/100.0;
  7274. }
  7275. }
  7276. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  7277. }
  7278. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].context, ReadingContextEnumTypeStr[dataType]);
  7279. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]);
  7280. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7281. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].unitOfMeasure.uint , "kW");
  7282. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].unitOfMeasure.multiplier = 0;
  7283. }
  7284. //idx_sample=4;
  7285. //***********************************************(5)VOLTAGE L1******************************************************/
  7286. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  7287. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  7288. (dataType == ReadingContextEnumType_Trigger))
  7289. {
  7290. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7291. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7292. {
  7293. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7294. {
  7295. tempIndex = ((gun_index==2) ? 1: 0);
  7296. }
  7297. else
  7298. {
  7299. tempIndex = gun_index;
  7300. }
  7301. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7302. {
  7303. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7304. {
  7305. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage*100))/100.0;
  7306. }
  7307. }
  7308. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7309. }
  7310. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7311. {
  7312. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7313. {
  7314. tempIndex = ((gun_index==2) ? 1: 0);
  7315. }
  7316. else
  7317. {
  7318. tempIndex = gun_index;
  7319. }
  7320. for (int index = 0; index < CCS_QUANTITY; index++)
  7321. {
  7322. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7323. {
  7324. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage*100))/100.0;
  7325. }
  7326. }
  7327. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7328. }
  7329. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7330. {
  7331. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7332. {
  7333. tempIndex = ((gun_index==2) ? 1: 0);
  7334. }
  7335. else
  7336. {
  7337. tempIndex = gun_index;
  7338. }
  7339. for (int index = 0; index < GB_QUANTITY; index++)
  7340. {
  7341. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7342. {
  7343. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage*100))/100.0;
  7344. }
  7345. }
  7346. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7347. }
  7348. else if(gunType[gun_index] == GUN_TYPE_DO)
  7349. {
  7350. tempIndex = gun_index;
  7351. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7352. {
  7353. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7354. {
  7355. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage*100))/100.0;
  7356. }
  7357. }
  7358. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7359. }
  7360. else
  7361. {
  7362. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7363. {
  7364. tempIndex = 2;
  7365. }
  7366. else
  7367. {
  7368. tempIndex = gun_index;
  7369. }
  7370. for (int index = 0; index < AC_QUANTITY; index++)
  7371. {
  7372. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7373. {
  7374. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage*100))/100.0;
  7375. }
  7376. }
  7377. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  7378. }
  7379. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].context, ReadingContextEnumTypeStr[dataType]);
  7380. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  7381. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7382. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].unitOfMeasure.uint , "V");
  7383. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].unitOfMeasure.multiplier = 0;
  7384. }
  7385. //***********************************************(6)SOC******************************************************/
  7386. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) != NULL)) ||
  7387. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) != NULL)) ||
  7388. (dataType == ReadingContextEnumType_Trigger))
  7389. {
  7390. 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))
  7391. {
  7392. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  7393. {
  7394. tempIndex = ((gun_index==2) ? 1: 0);
  7395. }
  7396. else
  7397. {
  7398. tempIndex = gun_index;
  7399. }
  7400. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7401. {
  7402. //tempIndex = ((gun_index==2) ? 1: 0);
  7403. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7404. {
  7405. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7406. {
  7407. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  7408. }
  7409. }
  7410. }
  7411. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7412. {
  7413. //tempIndex = ((gun_index==2) ? 1: 0);
  7414. for (int index = 0; index < CCS_QUANTITY; index++)
  7415. {
  7416. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7417. {
  7418. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  7419. }
  7420. }
  7421. }
  7422. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7423. {
  7424. //tempIndex = ((gun_index==2) ? 1: 0);
  7425. for (int index = 0; index < GB_QUANTITY; index++)
  7426. {
  7427. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7428. {
  7429. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  7430. }
  7431. }
  7432. }
  7433. else if(gunType[gun_index] == GUN_TYPE_DO)
  7434. {
  7435. //tempIndex = ((gun_index==2) ? 1: 0);
  7436. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7437. {
  7438. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7439. {
  7440. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  7441. }
  7442. }
  7443. }
  7444. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].context, ReadingContextEnumTypeStr[dataType]);
  7445. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].measurand, MeasurandEnumTypeStr[MeasurandEnumType_SoC]);
  7446. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7447. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].location, LocationEnumTypeStr[LocationEnumType_EV]);
  7448. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].unitOfMeasure.uint , "Percent");
  7449. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].unitOfMeasure.multiplier = 0;
  7450. }
  7451. }
  7452. //********************************(7)Current.Import L2************************************************/
  7453. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  7454. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  7455. (dataType == ReadingContextEnumType_Trigger))
  7456. {
  7457. // Only for AC 3 phase
  7458. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  7459. {
  7460. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7461. {
  7462. tempIndex = 2;
  7463. }
  7464. else
  7465. {
  7466. tempIndex = gun_index;
  7467. }
  7468. for (int index = 0; index < AC_QUANTITY; index++)
  7469. {
  7470. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7471. {
  7472. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2*100))/100.0;
  7473. }
  7474. }
  7475. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].phase, PhaseEnumTypeStr[PhaseEnumType_L2_N]);
  7476. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].context, ReadingContextEnumTypeStr[dataType]);
  7477. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  7478. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7479. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].unitOfMeasure.uint , "A");
  7480. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].unitOfMeasure.multiplier = 0;
  7481. }
  7482. }
  7483. //********************************(8)Current.Import L3************************************************/
  7484. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  7485. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]) != NULL)) ||
  7486. (dataType == ReadingContextEnumType_Trigger))
  7487. {
  7488. // Only for AC 3 phase
  7489. if( (gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  7490. {
  7491. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7492. {
  7493. tempIndex = 2;
  7494. }
  7495. else
  7496. {
  7497. tempIndex = gun_index;
  7498. }
  7499. for (int index = 0; index < AC_QUANTITY; index++)
  7500. {
  7501. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7502. {
  7503. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3*100))/100.0;
  7504. }
  7505. }
  7506. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7507. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].context, ReadingContextEnumTypeStr[dataType]);
  7508. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  7509. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7510. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].unitOfMeasure.uint , "A");
  7511. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].unitOfMeasure.multiplier = 0;
  7512. }
  7513. }
  7514. //***********************************************(9)VOLTAGE L2******************************************************/
  7515. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  7516. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  7517. (dataType == ReadingContextEnumType_Trigger))
  7518. {
  7519. if( (gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  7520. {
  7521. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7522. {
  7523. tempIndex = 2;
  7524. }
  7525. else
  7526. {
  7527. tempIndex = gun_index;
  7528. }
  7529. for (int index = 0; index < AC_QUANTITY; index++)
  7530. {
  7531. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7532. {
  7533. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2*100))/100.0;
  7534. }
  7535. }
  7536. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].phase, PhaseEnumTypeStr[PhaseEnumType_L2_N]);
  7537. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].context, ReadingContextEnumTypeStr[dataType]);
  7538. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  7539. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7540. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].unitOfMeasure.uint , "V");
  7541. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].unitOfMeasure.multiplier = 0;
  7542. }
  7543. }
  7544. //***********************************************(10)VOLTAGE L3******************************************************/
  7545. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  7546. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]) != NULL)) ||
  7547. (dataType == ReadingContextEnumType_Trigger))
  7548. {
  7549. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  7550. {
  7551. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7552. {
  7553. tempIndex = 2;
  7554. }
  7555. else
  7556. {
  7557. tempIndex = gun_index;
  7558. }
  7559. for (int index = 0; index < AC_QUANTITY; index++)
  7560. {
  7561. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7562. {
  7563. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].value = ((uint32_t)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3*100))/100.0;
  7564. }
  7565. }
  7566. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  7567. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].context, ReadingContextEnumTypeStr[dataType]);
  7568. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  7569. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7570. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].unitOfMeasure.uint , "V");
  7571. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].unitOfMeasure.multiplier = 0;
  7572. }
  7573. }
  7574. //***********************************************(11)Current.Offered******************************************************/
  7575. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) != NULL)) ||
  7576. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) != NULL)) ||
  7577. (dataType == ReadingContextEnumType_Trigger))
  7578. {
  7579. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7580. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7581. {
  7582. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7583. {
  7584. tempIndex = ((gun_index==2) ? 1: 0);
  7585. }
  7586. else
  7587. {
  7588. tempIndex = gun_index;
  7589. }
  7590. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7591. {
  7592. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7593. {
  7594. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingCurrent/10);
  7595. }
  7596. } // END OF FOR
  7597. }
  7598. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7599. {
  7600. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7601. {
  7602. tempIndex = ((gun_index==2) ? 1: 0);
  7603. }
  7604. else
  7605. {
  7606. tempIndex = gun_index;
  7607. }
  7608. for (int index = 0; index < CCS_QUANTITY; index++)
  7609. {
  7610. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7611. {
  7612. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingCurrent/10);
  7613. }
  7614. }
  7615. }
  7616. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7617. {
  7618. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7619. {
  7620. tempIndex = ((gun_index==2) ? 1: 0);
  7621. }
  7622. else
  7623. {
  7624. tempIndex = gun_index;
  7625. }
  7626. for (int index = 0; index < GB_QUANTITY; index++)
  7627. {
  7628. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7629. {
  7630. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7631. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingCurrent/10);;
  7632. }
  7633. }
  7634. }
  7635. else if(gunType[gun_index] == GUN_TYPE_DO)
  7636. {
  7637. tempIndex = gun_index;
  7638. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7639. {
  7640. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7641. {
  7642. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7643. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingCurrent/10);;
  7644. }
  7645. }
  7646. }
  7647. else
  7648. {
  7649. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7650. {
  7651. tempIndex = 2;
  7652. }
  7653. else
  7654. {
  7655. tempIndex = gun_index;
  7656. }
  7657. for (int index = 0; index < AC_QUANTITY; index++)
  7658. {
  7659. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7660. {
  7661. uint16_t currentOffer;
  7662. if(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent == 0)
  7663. {
  7664. currentOffer = ShmSysConfigAndInfo->SysConfig.RatingCurrent;
  7665. }
  7666. else
  7667. {
  7668. currentOffer = ((ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent>ShmSysConfigAndInfo->SysConfig.RatingCurrent)?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  7669. }
  7670. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].value = currentOffer;
  7671. }
  7672. }
  7673. }
  7674. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].context, ReadingContextEnumTypeStr[dataType]);
  7675. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]);
  7676. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7677. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].unitOfMeasure.uint , "A");
  7678. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[10].unitOfMeasure.multiplier = 0;
  7679. }
  7680. //***********************************************(12)Power.Offered******************************************************/
  7681. if(((dataType == ReadingContextEnumType_Sample_Clock) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) != NULL)) ||
  7682. ((dataType == ReadingContextEnumType_Sample_Periodic) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) != NULL)) ||
  7683. (dataType == ReadingContextEnumType_Trigger))
  7684. {
  7685. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  7686. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7687. {
  7688. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7689. {
  7690. tempIndex = ((gun_index==2) ? 1: 0);
  7691. }
  7692. else
  7693. {
  7694. tempIndex = gun_index;
  7695. }
  7696. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7697. {
  7698. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7699. {
  7700. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].AvailableChargingPower*100);
  7701. }
  7702. } // END OF FOR
  7703. }
  7704. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7705. {
  7706. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7707. {
  7708. tempIndex = ((gun_index==2) ? 1: 0);
  7709. }
  7710. else
  7711. {
  7712. tempIndex = gun_index;
  7713. }
  7714. for (int index = 0; index < CCS_QUANTITY; index++)
  7715. {
  7716. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7717. {
  7718. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].AvailableChargingPower*100);
  7719. }
  7720. }
  7721. }
  7722. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7723. {
  7724. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7725. {
  7726. tempIndex = ((gun_index==2) ? 1: 0);
  7727. }
  7728. else
  7729. {
  7730. tempIndex = gun_index;
  7731. }
  7732. for (int index = 0; index < GB_QUANTITY; index++)
  7733. {
  7734. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7735. {
  7736. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7737. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].AvailableChargingPower*100);
  7738. }
  7739. }
  7740. }
  7741. else if(gunType[gun_index] == GUN_TYPE_DO)
  7742. {
  7743. tempIndex = gun_index;
  7744. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7745. {
  7746. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7747. {
  7748. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  7749. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].value = (uint16_t) (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.AvailableChargingPower*100);
  7750. }
  7751. }
  7752. }
  7753. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].context, ReadingContextEnumTypeStr[dataType]);
  7754. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]);
  7755. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  7756. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].unitOfMeasure.uint , "W");
  7757. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[11].unitOfMeasure.multiplier = 0;
  7758. }
  7759. // Message create ====================================================================================================
  7760. random_uuid(guid);
  7761. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->MeterValues[gun_index].meterValue);idxMeter++)
  7762. {
  7763. json_object *meterValue = json_object_new_object();
  7764. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  7765. {
  7766. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  7767. {
  7768. json_object *sampledValue = json_object_new_object();
  7769. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  7770. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  7771. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  7772. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  7773. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  7774. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  7775. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  7776. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  7777. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  7778. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  7779. {
  7780. json_object *unitOfMeasure = json_object_new_object();
  7781. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  7782. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  7783. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  7784. }
  7785. json_object_array_add(sampledValues, sampledValue);
  7786. }
  7787. }
  7788. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].timestamp));
  7789. json_object_object_add(meterValue, "sampledValue", sampledValues);
  7790. json_object_array_add(meterValues, meterValue);
  7791. idxMeter++;
  7792. }
  7793. json_object_object_add(MeterValueReq, "meterValue", meterValues);
  7794. json_object_object_add(MeterValueReq, "evseId", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].evseId));
  7795. sprintf(queuedata,"[%d,\"%s\",\"MeterValues\",%s]"
  7796. ,MESSAGE_TYPE_CALL
  7797. ,guid
  7798. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7799. json_object_put(MeterValueReq);
  7800. if((dataType != ReadingContextEnumType_Trigger) &&
  7801. (dataType != ReadingContextEnumType_Sample_Clock))
  7802. {
  7803. // Transaction meter value send by TransactionEvent message
  7804. memcpy(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0], &ShmOCPP20Data->MeterValues[gun_index].meterValue[0], sizeof(struct MeterValueType));
  7805. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = ON;
  7806. result = PASS;
  7807. }
  7808. else
  7809. {
  7810. // Put request guid to hash map
  7811. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7812. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7813. {
  7814. result = PASS;
  7815. }
  7816. if((dataType != ReadingContextEnumType_Trigger) &&
  7817. (dataType != ReadingContextEnumType_Sample_Clock))
  7818. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  7819. else
  7820. {
  7821. if(FirstHeartBeat)
  7822. LWS_Send(queuedata +2);
  7823. }
  7824. }
  7825. return result;
  7826. }
  7827. int sendNotifyChargingLimitRequest(int gun_index)
  7828. {
  7829. mtrace();
  7830. int result = FAIL;
  7831. char message[4096]={0};
  7832. char guid[37]={0};
  7833. char tempdata[128]={0};
  7834. json_object *NotifyChargingLimit = json_object_new_object();
  7835. json_object *chargingLimit = json_object_new_object();
  7836. DEBUG_INFO("sendNotifyChargingLimitRequest...\n");
  7837. json_object_object_add(NotifyChargingLimit, "evseId", json_object_new_int(ShmOCPP20Data->NotifyChargingLimit[gun_index].evseId));
  7838. json_object_object_add(chargingLimit, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->NotifyChargingLimit[gun_index].chargingLimit.chargingLimitSource));
  7839. json_object_object_add(chargingLimit, "chargingLimitSource", json_object_new_boolean(ShmOCPP20Data->NotifyChargingLimit[gun_index].chargingLimit.isGridCritical));
  7840. json_object_object_add(NotifyChargingLimit, "chargingLimit", NotifyChargingLimit);
  7841. random_uuid(guid);
  7842. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyChargingLimit", json_object_to_json_string_ext(NotifyChargingLimit, JSON_C_TO_STRING_PLAIN));
  7843. json_object_put(NotifyChargingLimit);
  7844. LWS_Send(message);
  7845. sprintf(tempdata, "NotifyChargingLimit,%d", gun_index);
  7846. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7847. {
  7848. result = PASS;
  7849. }
  7850. return result;
  7851. }
  7852. int sendNotifyCustomerInformationRequest()
  7853. {
  7854. mtrace();
  7855. int result = FAIL;
  7856. char message[4096]={0};
  7857. char guid[37]={0};
  7858. char tempdata[128]={0};
  7859. json_object *NotifyCustomerInformation = json_object_new_object();
  7860. DEBUG_INFO("sendNotifyCustomerInformationRequest...\n");
  7861. json_object_object_add(NotifyCustomerInformation, "data", json_object_new_string((char*)ShmOCPP20Data->NotifyCustomerInformation.data));
  7862. json_object_object_add(NotifyCustomerInformation, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyCustomerInformation.tbc));
  7863. json_object_object_add(NotifyCustomerInformation, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyCustomerInformation.seqNo));
  7864. json_object_object_add(NotifyCustomerInformation, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyCustomerInformation.generatedAt));
  7865. json_object_object_add(NotifyCustomerInformation, "requestId", json_object_new_int(ShmOCPP20Data->NotifyCustomerInformation.requestId));
  7866. random_uuid(guid);
  7867. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyCustomerInformation", json_object_to_json_string_ext(NotifyCustomerInformation, JSON_C_TO_STRING_PLAIN));
  7868. json_object_put(NotifyCustomerInformation);
  7869. LWS_Send(message);
  7870. sprintf(tempdata, "NotifyCustomerInformation,0");
  7871. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7872. {
  7873. result = PASS;
  7874. }
  7875. return result;
  7876. }
  7877. int sendNotifyDisplayMessagesRequest()
  7878. {
  7879. mtrace();
  7880. int result = FAIL;
  7881. char message[4096]={0};
  7882. char guid[37]={0};
  7883. char tempdata[128]={0};
  7884. json_object *NotifyDisplayMessages = json_object_new_object();
  7885. json_object *messageInfos = json_object_new_array();
  7886. DEBUG_INFO("sendNotifyDisplayMessagesRequest...\n");
  7887. json_object_object_add(NotifyDisplayMessages, "requestId", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.requestId));
  7888. json_object_object_add(NotifyDisplayMessages, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyDisplayMessages.tbc));
  7889. for(int idxMsg=0;idxMsg<ARRAY_SIZE(ShmOCPP20Data->NotifyDisplayMessages.messageInfo);idxMsg++)
  7890. {
  7891. if(strlen((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.content) > 0)
  7892. {
  7893. json_object *messageInfo = json_object_new_object();
  7894. json_object *message = json_object_new_object();
  7895. json_object *display = json_object_new_object();
  7896. json_object *evse = json_object_new_object();
  7897. json_object_object_add(messageInfo, "id", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].id));
  7898. json_object_object_add(messageInfo, "priority", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].priority));
  7899. json_object_object_add(messageInfo, "state", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].state));
  7900. json_object_object_add(messageInfo, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].startDateTime));
  7901. json_object_object_add(messageInfo, "endDateTime", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].endDateTime));
  7902. json_object_object_add(messageInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].transactionId));
  7903. json_object_object_add(message, "format", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.format));
  7904. json_object_object_add(message, "language", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.language));
  7905. json_object_object_add(message, "content", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.content));
  7906. json_object_object_add(messageInfo, "message", message);
  7907. json_object_object_add(display, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.name));
  7908. json_object_object_add(display, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.instance));
  7909. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.evse.id));
  7910. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.evse.connectorId));
  7911. json_object_object_add(display, "evse",evse);
  7912. json_object_object_add(messageInfo, "evse", display);
  7913. json_object_array_add(messageInfos, messageInfo);
  7914. }
  7915. }
  7916. json_object_object_add(NotifyDisplayMessages, "messageInfo", messageInfos);
  7917. random_uuid(guid);
  7918. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyDisplayMessages", json_object_to_json_string_ext(NotifyDisplayMessages, JSON_C_TO_STRING_PLAIN));
  7919. json_object_put(NotifyDisplayMessages);
  7920. LWS_Send(message);
  7921. sprintf(tempdata, "NotifyDisplayMessages,0");
  7922. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7923. {
  7924. result = PASS;
  7925. }
  7926. return result;
  7927. }
  7928. int sendNotifyEVChargingNeedsRequest(int gun_index)
  7929. {
  7930. mtrace();
  7931. int result = FAIL;
  7932. char message[4096]={0};
  7933. char guid[37]={0};
  7934. char tempdata[128]={0};
  7935. json_object *NotifyEVChargingNeeds = json_object_new_object();
  7936. json_object *chargingNeeds = json_object_new_object();
  7937. json_object *acChargingParameters = json_object_new_object();
  7938. json_object *dcChargingParameters = json_object_new_object();
  7939. DEBUG_INFO("sendNotifyEVChargingNeedsRequest...\n");
  7940. json_object_object_add(NotifyEVChargingNeeds, "maxScheduleTuples", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].maxScheduleTuples));
  7941. json_object_object_add(NotifyEVChargingNeeds, "evseId", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].evseId));
  7942. json_object_object_add(chargingNeeds, "requestedEnergyTransfer", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.requestedEnergyTransfer));
  7943. json_object_object_add(chargingNeeds, "departureTime", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.departureTime));
  7944. json_object_object_add(acChargingParameters, "energyAmount", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.energyAmount));
  7945. json_object_object_add(acChargingParameters, "evMinCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMinCurrent));
  7946. json_object_object_add(acChargingParameters, "evMaxCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMaxCurrent));
  7947. json_object_object_add(acChargingParameters, "evMaxVoltage", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMaxVoltage));
  7948. json_object_object_add(chargingNeeds, "acChargingParameters", acChargingParameters);
  7949. json_object_object_add(dcChargingParameters, "evMaxCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxCurrent));
  7950. json_object_object_add(dcChargingParameters, "evMaxVoltage", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxVoltage));
  7951. json_object_object_add(dcChargingParameters, "energyAmount", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.energyAmount));
  7952. json_object_object_add(dcChargingParameters, "evMaxPower", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxPower));
  7953. json_object_object_add(dcChargingParameters, "stateOfCharge", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.stateOfCharge));
  7954. json_object_object_add(dcChargingParameters, "evEnergyCapacity", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evEnergyCapacity));
  7955. json_object_object_add(dcChargingParameters, "fullSoC", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.fullSoC));
  7956. json_object_object_add(dcChargingParameters, "bulkSoC", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.bulkSoC));
  7957. json_object_object_add(chargingNeeds, "dcChargingParameters", dcChargingParameters);
  7958. json_object_object_add(NotifyEVChargingNeeds, "chargingNeeds", chargingNeeds);
  7959. random_uuid(guid);
  7960. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEVChargingNeeds", json_object_to_json_string_ext(NotifyEVChargingNeeds, JSON_C_TO_STRING_PLAIN));
  7961. json_object_put(NotifyEVChargingNeeds);
  7962. LWS_Send(message);
  7963. sprintf(tempdata, "NotifyEVChargingNeeds,%d", gun_index);
  7964. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7965. {
  7966. result = PASS;
  7967. }
  7968. return result;
  7969. }
  7970. int sendNotifyEVChargingScheduleRequest(int gun_index)
  7971. {
  7972. mtrace();
  7973. int result = FAIL;
  7974. char message[4096]={0};
  7975. char guid[37]={0};
  7976. char tempdata[128]={0};
  7977. json_object *NotifyEVChargingSchedule = json_object_new_object();
  7978. json_object *chargingSchedule = json_object_new_object();
  7979. json_object *periods = json_object_new_array();
  7980. DEBUG_INFO("sendNotifyEVChargingScheduleRequest...\n");
  7981. json_object_object_add(NotifyEVChargingSchedule, "timeBase", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].timeBase));
  7982. json_object_object_add(NotifyEVChargingSchedule, "evseId", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].evseId));
  7983. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.startSchedule));
  7984. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.duration));
  7985. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingRateUnit));
  7986. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.minChargingRate));
  7987. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.id));
  7988. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  7989. {
  7990. if(((ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  7991. (ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  7992. {
  7993. json_object *Period = json_object_new_object();
  7994. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  7995. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  7996. if(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  7997. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  7998. if(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  7999. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  8000. json_object_array_add(periods, Period);
  8001. }
  8002. }
  8003. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", periods);
  8004. json_object_object_add(NotifyEVChargingSchedule, "chargingSchedule", chargingSchedule);
  8005. random_uuid(guid);
  8006. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEVChargingSchedule", json_object_to_json_string_ext(NotifyEVChargingSchedule, JSON_C_TO_STRING_PLAIN));
  8007. json_object_put(NotifyEVChargingSchedule);
  8008. LWS_Send(message);
  8009. sprintf(tempdata, "NotifyEVChargingSchedule,%d", gun_index);
  8010. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8011. {
  8012. result = PASS;
  8013. }
  8014. return result;
  8015. }
  8016. int sendNotifyEventRequest()
  8017. {
  8018. mtrace();
  8019. int result = FAIL;
  8020. char message[4096]={0};
  8021. char guid[37]={0};
  8022. char tempdata[128]={0};
  8023. json_object *NotifyEvent = json_object_new_object();
  8024. json_object *eventDatas = json_object_new_array();
  8025. DEBUG_INFO("sendNotifyEventRequest...\n");
  8026. json_object_object_add(NotifyEvent, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.generatedAt));
  8027. json_object_object_add(NotifyEvent, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyEvent.tbc));
  8028. json_object_object_add(NotifyEvent, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyEvent.seqNo));
  8029. for(int idxEvent=0;idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData);idxEvent++)
  8030. {
  8031. if(strlen((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp) > 0)
  8032. {
  8033. json_object *eventData = json_object_new_object();
  8034. json_object *component = json_object_new_object();
  8035. json_object *evse = json_object_new_object();
  8036. json_object *variable = json_object_new_object();
  8037. json_object_object_add(eventData, "eventId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId));
  8038. json_object_object_add(eventData, "timestamp", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp));
  8039. json_object_object_add(eventData, "trigger", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger));
  8040. json_object_object_add(eventData, "cause", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cause));
  8041. json_object_object_add(eventData, "actualValue", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue));
  8042. json_object_object_add(eventData, "techCode", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode));
  8043. json_object_object_add(eventData, "techInfo", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo));
  8044. json_object_object_add(eventData, "cleared", json_object_new_boolean(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared));
  8045. json_object_object_add(eventData, "transactionId", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].transactionId));
  8046. json_object_object_add(eventData, "variableMonitoringId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variableMonitoringId));
  8047. json_object_object_add(eventData, "eventNotificationType", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType));
  8048. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name));
  8049. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.instance));
  8050. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.id));
  8051. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId));
  8052. json_object_object_add(component, "evse",evse);
  8053. json_object_object_add(eventData, "component", component);
  8054. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name));
  8055. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.instance));
  8056. json_object_object_add(eventData, "variable", variable);
  8057. json_object_array_add(eventDatas, eventData);
  8058. }
  8059. }
  8060. json_object_object_add(NotifyEvent, "eventData", eventDatas);
  8061. random_uuid(guid);
  8062. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEvent", json_object_to_json_string_ext(NotifyEvent, JSON_C_TO_STRING_PLAIN));
  8063. json_object_put(NotifyEvent);
  8064. LWS_Send(message);
  8065. sprintf(tempdata, "NotifyEvent,0");
  8066. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8067. {
  8068. result = PASS;
  8069. }
  8070. return result;
  8071. }
  8072. int sendNotifyMonitoringReportRequest()
  8073. {
  8074. mtrace();
  8075. int result = FAIL;
  8076. char message[4096]={0};
  8077. char guid[37]={0};
  8078. char tempdata[128]={0};
  8079. json_object *NotifyMonitoringReport = json_object_new_object();
  8080. json_object *monitors = json_object_new_array();
  8081. DEBUG_INFO("sendNotifyMonitoringReportRequest...\n");
  8082. json_object_object_add(NotifyMonitoringReport, "requestId", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.requestId));
  8083. json_object_object_add(NotifyMonitoringReport, "tbc", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.tbc));
  8084. json_object_object_add(NotifyMonitoringReport, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.seqNo));
  8085. json_object_object_add(NotifyMonitoringReport, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.generatedAt));
  8086. for(int idxMonitor=0;idxMonitor<ARRAY_SIZE(ShmOCPP20Data->NotifyMonitoringReport.monitor);idxMonitor++)
  8087. {
  8088. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.name) > 0)
  8089. {
  8090. json_object *monitor = json_object_new_object();
  8091. json_object *component = json_object_new_object();
  8092. json_object *evse = json_object_new_object();
  8093. json_object *variable = json_object_new_object();
  8094. json_object *variableMonitorings = json_object_new_array();
  8095. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.name));
  8096. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.instance));
  8097. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.evse.id));
  8098. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.evse.connectorId));
  8099. json_object_object_add(component, "evse",evse);
  8100. json_object_object_add(monitor, "component", component);
  8101. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variable.name));
  8102. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variable.instance));
  8103. json_object_object_add(monitor, "variable", variable);
  8104. for(int idxVar=0;idxVar<ARRAY_SIZE(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring);idxVar++)
  8105. {
  8106. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].type) > 0)
  8107. {
  8108. json_object *variableMonitoring = json_object_new_object();
  8109. json_object_object_add(variableMonitoring, "id", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].id));
  8110. json_object_object_add(variableMonitoring, "value", json_object_new_double(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].value));
  8111. json_object_object_add(variableMonitoring, "type", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].type));
  8112. json_object_object_add(variableMonitoring, "severity", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].severity));
  8113. json_object_object_add(variableMonitoring, "transaction", json_object_new_boolean(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].transaction));
  8114. json_object_array_add(variableMonitorings, variableMonitoring);
  8115. }
  8116. }
  8117. json_object_object_add(monitor, "variableMonitoring", variableMonitorings);
  8118. json_object_array_add(monitors, monitor);
  8119. }
  8120. }
  8121. json_object_object_add(NotifyMonitoringReport, "monitor", monitors);
  8122. random_uuid(guid);
  8123. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyMonitoringReport", json_object_to_json_string_ext(NotifyMonitoringReport, JSON_C_TO_STRING_PLAIN));
  8124. json_object_put(NotifyMonitoringReport);
  8125. LWS_Send(message);
  8126. sprintf(tempdata, "NotifyMonitoringReport,0");
  8127. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8128. {
  8129. result = PASS;
  8130. }
  8131. return result;
  8132. }
  8133. int sendNotifyReportRequest()
  8134. {
  8135. mtrace();
  8136. int result = FAIL;
  8137. char message[4096]={0};
  8138. char guid[37]={0};
  8139. char tempdata[128]={0};
  8140. json_object *NotifyReport = json_object_new_object();
  8141. json_object *reportDatas = json_object_new_array();
  8142. DEBUG_INFO("sendNotifyReportRequest...\n");
  8143. json_object_object_add(NotifyReport, "requestId", json_object_new_int(ShmOCPP20Data->NotifyReport.requestId));
  8144. json_object_object_add(NotifyReport, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.generatedAt));
  8145. json_object_object_add(NotifyReport, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyReport.tbc));
  8146. json_object_object_add(NotifyReport, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyReport.seqNo));
  8147. for(int idxReport=0;idxReport<ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData);idxReport++)
  8148. {
  8149. if(strlen((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.name) > 0)
  8150. {
  8151. json_object *reportData = json_object_new_object();
  8152. json_object *component = json_object_new_object();
  8153. json_object *evse = json_object_new_object();
  8154. json_object *variable = json_object_new_object();
  8155. json_object *variableAttributes = json_object_new_array();
  8156. json_object *variableCharacteristics = json_object_new_object();
  8157. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.name));
  8158. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.instance));
  8159. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyReport.reportData[idxReport].component.evse.id));
  8160. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyReport.reportData[idxReport].component.evse.connectorId));
  8161. json_object_object_add(component, "evse",evse);
  8162. json_object_object_add(reportData, "component", component);
  8163. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variable.name));
  8164. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variable.instance));
  8165. json_object_object_add(reportData, "variable",variable);
  8166. json_object_object_add(variableCharacteristics, "unit", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.unit));
  8167. json_object_object_add(variableCharacteristics, "dataType", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.dataType));
  8168. json_object_object_add(variableCharacteristics, "minLimit", json_object_new_double(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.minLimit));
  8169. json_object_object_add(variableCharacteristics, "maxLimit", json_object_new_double(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.maxLimit));
  8170. json_object_object_add(reportData, "variableCharacteristics",variableCharacteristics);
  8171. for(int idxAttr=0;idxAttr<ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute);idxAttr++)
  8172. {
  8173. if(strlen((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].value) > 0)
  8174. {
  8175. json_object *variableAttribute = json_object_new_object();
  8176. json_object_object_add(variableAttribute, "type", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].type));
  8177. json_object_object_add(variableAttribute, "value", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].value));
  8178. json_object_object_add(variableAttribute, "mutability", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].mutability));
  8179. json_object_object_add(variableAttribute, "persistent", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].persistent));
  8180. json_object_object_add(variableAttribute, "constant", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].constant));
  8181. json_object_array_add(variableAttributes, variableAttribute);
  8182. }
  8183. }
  8184. json_object_object_add(reportData, "variableAttribute", variableAttributes);
  8185. json_object_array_add(reportDatas, reportData);
  8186. }
  8187. }
  8188. json_object_object_add(NotifyReport, "reportData", reportDatas);
  8189. random_uuid(guid);
  8190. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyReport", json_object_to_json_string_ext(NotifyReport, JSON_C_TO_STRING_PLAIN));
  8191. json_object_put(NotifyReport);
  8192. LWS_SendNow(message);
  8193. sprintf(tempdata, "NotifyReport,0");
  8194. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8195. {
  8196. result = PASS;
  8197. }
  8198. return result;
  8199. }
  8200. int sendPublishFirmwareStatusNotificationRequest()
  8201. {
  8202. mtrace();
  8203. int result = FAIL;
  8204. char message[4096]={0};
  8205. char guid[37]={0};
  8206. char tempdata[128]={0};
  8207. json_object *PublishFirmwareStatusNotification = json_object_new_object();
  8208. json_object *locations = json_object_new_array();
  8209. DEBUG_INFO("sendPublishFirmwareStatusNotificationRequest...\n");
  8210. json_object_object_add(PublishFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->PublishFirmwareStatusNotificatio.status));
  8211. json_object_object_add(PublishFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->PublishFirmwareStatusNotificatio.requestId));
  8212. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->PublishFirmwareStatusNotificatio.location);idx++)
  8213. {
  8214. json_object_array_add(locations, json_object_new_string((char*)ShmOCPP20Data->PublishFirmwareStatusNotificatio.location[idx]));
  8215. }
  8216. json_object_object_add(PublishFirmwareStatusNotification, "location", locations);
  8217. random_uuid(guid);
  8218. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "PublishFirmwareStatusNotification", json_object_to_json_string_ext(PublishFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  8219. json_object_put(PublishFirmwareStatusNotification);
  8220. LWS_Send(message);
  8221. sprintf(tempdata, "PublishFirmwareStatusNotification,0");
  8222. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8223. {
  8224. result = PASS;
  8225. }
  8226. return result;
  8227. }
  8228. int sendReportChargingProfilesRequest(int gun_index)
  8229. {
  8230. mtrace();
  8231. int result = FAIL;
  8232. char message[4096]={0};
  8233. char guid[37]={0};
  8234. char tempdata[128]={0};
  8235. json_object *ReportChargingProfiles = json_object_new_object();
  8236. json_object *chargingProfiles = json_object_new_array();
  8237. DEBUG_INFO("sendReportChargingProfilesRequest...\n");
  8238. json_object_object_add(ReportChargingProfiles, "requestId", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].requestId));
  8239. json_object_object_add(ReportChargingProfiles, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingLimitSource));
  8240. json_object_object_add(ReportChargingProfiles, "tbc", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].tbc));
  8241. json_object_object_add(ReportChargingProfiles, "evseId", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].evseId));
  8242. for(int idxProfile=0;idxProfile<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile);idxProfile++)
  8243. {
  8244. json_object *chargingProfile = json_object_new_object();
  8245. json_object *chargingSchedules = json_object_new_array();
  8246. json_object_object_add(chargingProfile, "id", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].id));
  8247. json_object_object_add(chargingProfile, "stackLevel", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].stackLevel));
  8248. json_object_object_add(chargingProfile, "chargingProfilePurpose", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingProfilePurpose));
  8249. json_object_object_add(chargingProfile, "chargingProfileKind", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingProfileKind));
  8250. json_object_object_add(chargingProfile, "recurrencyKind", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].recurrencyKind));
  8251. json_object_object_add(chargingProfile, "validFrom", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].validFrom));
  8252. json_object_object_add(chargingProfile, "validTo", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].validTo));
  8253. json_object_object_add(chargingProfile, "transactionId", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].transactionId));
  8254. for(int idxSchedule=0;idxSchedule<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule);idxSchedule++)
  8255. {
  8256. json_object *chargingSchedule = json_object_new_object();
  8257. json_object *chargingSchedulePeriods = json_object_new_array();
  8258. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].startSchedule));
  8259. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].duration));
  8260. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingRateUnit));
  8261. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].minChargingRate));
  8262. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].id));
  8263. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  8264. {
  8265. json_object *chargingSchedulePeriod = json_object_new_object();
  8266. json_object_object_add(chargingSchedulePeriod, "startPeriod", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod));
  8267. json_object_object_add(chargingSchedulePeriod, "limit", json_object_new_double(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit));
  8268. json_object_object_add(chargingSchedulePeriod, "numberPhases", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  8269. json_object_object_add(chargingSchedulePeriod, "phaseToUse", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse));
  8270. json_object_array_add(chargingSchedulePeriods, chargingSchedulePeriod);
  8271. }
  8272. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriods);
  8273. json_object_array_add(chargingSchedules, chargingSchedule);
  8274. }
  8275. json_object_object_add(chargingProfile, "chargingSchedule", chargingSchedules);
  8276. json_object_array_add(chargingProfiles, chargingProfile);
  8277. }
  8278. json_object_object_add(ReportChargingProfiles, "chargingProfile", chargingProfiles);
  8279. random_uuid(guid);
  8280. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ReportChargingProfiles", json_object_to_json_string_ext(ReportChargingProfiles, JSON_C_TO_STRING_PLAIN));
  8281. json_object_put(ReportChargingProfiles);
  8282. LWS_Send(message);
  8283. sprintf(tempdata, "ReportChargingProfiles,%d", gun_index);
  8284. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8285. {
  8286. result = PASS;
  8287. }
  8288. return result;
  8289. }
  8290. int sendReservationStatusUpdateRequest(int gun_index)
  8291. {
  8292. mtrace();
  8293. int result = FAIL;
  8294. char message[4096]={0};
  8295. char guid[37]={0};
  8296. char tempdata[128]={0};
  8297. json_object *ReservationStatusUpdate = json_object_new_object();
  8298. DEBUG_INFO("sendReservationStatusUpdateRequest...\n");
  8299. json_object_object_add(ReservationStatusUpdate, "reservationId", json_object_new_int(ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationId));
  8300. json_object_object_add(ReservationStatusUpdate, "reservationUpdateStatus", json_object_new_string((char*)ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationUpdateStatus));
  8301. random_uuid(guid);
  8302. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ReservationStatusUpdate", json_object_to_json_string_ext(ReservationStatusUpdate, JSON_C_TO_STRING_PLAIN));
  8303. json_object_put(ReservationStatusUpdate);
  8304. LWS_Send(message);
  8305. sprintf(tempdata, "ReservationStatusUpdate,%d", gun_index);
  8306. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8307. {
  8308. result = PASS;
  8309. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = OFF;
  8310. }
  8311. return result;
  8312. }
  8313. int sendSecurityEventNotificationRequest()
  8314. {
  8315. mtrace();
  8316. int result = FAIL;
  8317. char message[4096]={0};
  8318. char guid[37]={0};
  8319. char tempdata[128]={0};
  8320. json_object *SecurityEventNotification = json_object_new_object();
  8321. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  8322. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.type));
  8323. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.timestamp));
  8324. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.techInfo));
  8325. random_uuid(guid);
  8326. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  8327. json_object_put(SecurityEventNotification);
  8328. LWS_Send(message);
  8329. sprintf(tempdata, "SecurityEventNotification,0");
  8330. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8331. {
  8332. result = PASS;
  8333. }
  8334. return result;
  8335. }
  8336. int sendSignCertificateRequest(CertificateSigningUseEnumType certType)
  8337. {
  8338. mtrace();
  8339. int result = FAIL;
  8340. char message[4096]={0};
  8341. char guid[37]={0};
  8342. char tempdata[128]={0};
  8343. json_object *SignCertificate = json_object_new_object();
  8344. DEBUG_INFO("sendSignCertificateRequest...\n");
  8345. // Read csr file content
  8346. memset(ShmOCPP20Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP20Data->SignCertificate.csr));
  8347. FILE *fp=fopen(((certType == CertificateSignedStatusEnumType_V2GCertificate)?"/Storage/OCPP/certV2G.csr":"/Storage/OCPP/certCP.csr"),"r");
  8348. char *line = NULL;
  8349. size_t len = 0;
  8350. while(getline(&line, &len, fp) != -1)
  8351. {
  8352. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  8353. {
  8354. memcpy(&ShmOCPP20Data->SignCertificate.csr[strlen((char*)ShmOCPP20Data->SignCertificate.csr)], line, (strlen(line)-1));
  8355. }
  8356. }
  8357. fclose(fp);
  8358. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP20Data->SignCertificate.csr));
  8359. sprintf((char*)ShmOCPP20Data->SignCertificate.certificateType, CertificateSigningUseEnumTypeStr[certType]);
  8360. json_object_object_add(SignCertificate, "certificateType", json_object_new_string((char*)ShmOCPP20Data->SignCertificate.certificateType));
  8361. random_uuid(guid);
  8362. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  8363. json_object_put(SignCertificate);
  8364. LWS_Send(message);
  8365. sprintf(tempdata, "SignCertificate,0");
  8366. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8367. {
  8368. result = PASS;
  8369. }
  8370. return result;
  8371. }
  8372. int sendStatusNotificationRequest(int gun_index)
  8373. {
  8374. mtrace();
  8375. int result = FAIL;
  8376. char message[600]={0};
  8377. char guid[37];
  8378. int currentStatus = 0;
  8379. struct timeval tmnow;
  8380. struct tm *tm;
  8381. char buf[28];//, usec_buf[6];
  8382. char tempdata[65]={0};
  8383. int tempIndex = 0;
  8384. uint8_t isStateChanged = TRUE;
  8385. DEBUG_INFO("sendStatusNotificationRequest...\n");
  8386. gettimeofday(&tmnow, NULL);
  8387. time_t t;
  8388. t = time(NULL);
  8389. /*UTC time and date*/
  8390. tm = gmtime(&t);
  8391. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  8392. #if 0 // remove temporally
  8393. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  8394. strcat(buf,".");
  8395. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  8396. strcat(buf,usec_buf);
  8397. #endif
  8398. printf("%s",buf);
  8399. ShmOCPP20Data->StatusNotification[gun_index].evseId = (gun_index + 1);
  8400. ShmOCPP20Data->StatusNotification[gun_index].connectorId = (gun_index + 1);
  8401. strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].timestamp, buf);
  8402. //strcpy(ShmOCPP20Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  8403. /*
  8404. enum _SYSTEM_STATUS
  8405. {
  8406. S_BOOTING = 0,
  8407. S_IDLE, = 1
  8408. S_AUTHORIZING, =2
  8409. S_REASSIGN_CHECK, =3
  8410. S_REASSIGN, =4
  8411. S_PRECHARGE, =5
  8412. S_PREPARING_FOR_EV, =6
  8413. S_PREPARING_FOR_EVSE, =7
  8414. S_CHARGING, =8
  8415. S_TERMINATING, =9
  8416. S_COMPLETE, =10
  8417. S_ALARM, =11
  8418. S_FAULT =12
  8419. }
  8420. */
  8421. //check Transaction active
  8422. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  8423. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8424. {
  8425. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8426. {
  8427. tempIndex = ((gun_index==2) ? 1: 0);
  8428. }
  8429. else
  8430. {
  8431. tempIndex = gun_index;
  8432. }
  8433. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8434. {
  8435. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  8436. {
  8437. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  8438. {
  8439. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  8440. {
  8441. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  8442. }
  8443. else
  8444. {
  8445. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  8446. }
  8447. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  8448. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  8449. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  8450. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  8451. }
  8452. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  8453. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  8454. ) //S_PRECHARGE
  8455. {
  8456. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  8457. }
  8458. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  8459. {
  8460. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  8461. }
  8462. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  8463. {
  8464. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  8465. }
  8466. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  8467. {
  8468. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  8469. }
  8470. 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
  8471. {
  8472. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  8473. }
  8474. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  8475. {
  8476. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  8477. }
  8478. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  8479. {
  8480. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  8481. }
  8482. } //end of the same index
  8483. }//end of for CHAdeMO_QUANTITY
  8484. }
  8485. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8486. {
  8487. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8488. {
  8489. tempIndex = ((gun_index==2) ? 1: 0);
  8490. }
  8491. else
  8492. {
  8493. tempIndex = gun_index;
  8494. }
  8495. for (int index = 0; index < CCS_QUANTITY; index++)
  8496. {
  8497. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8498. {
  8499. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8500. {
  8501. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  8502. {
  8503. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  8504. }
  8505. else
  8506. {
  8507. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  8508. }
  8509. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  8510. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  8511. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  8512. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  8513. }
  8514. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  8515. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  8516. ) //S_PRECHARGE
  8517. {
  8518. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  8519. }
  8520. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  8521. {
  8522. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  8523. }
  8524. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  8525. {
  8526. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  8527. }
  8528. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  8529. {
  8530. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  8531. }
  8532. 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
  8533. {
  8534. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status : Unavailable
  8535. }
  8536. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  8537. {
  8538. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  8539. }
  8540. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  8541. {
  8542. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  8543. }
  8544. } //end of the same index
  8545. } // end of for CCS_QUANTITY
  8546. }
  8547. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8548. {
  8549. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8550. {
  8551. tempIndex = ((gun_index==2) ? 1: 0);
  8552. }
  8553. else
  8554. {
  8555. tempIndex = gun_index;
  8556. }
  8557. for (int index = 0; index < GB_QUANTITY; index++)
  8558. {
  8559. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8560. {
  8561. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8562. {
  8563. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  8564. {
  8565. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  8566. }
  8567. else
  8568. {
  8569. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  8570. }
  8571. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  8572. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  8573. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  8574. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  8575. }
  8576. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  8577. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  8578. ) //S_PRECHARGE
  8579. {
  8580. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  8581. }
  8582. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  8583. {
  8584. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  8585. }
  8586. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  8587. {
  8588. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  8589. }
  8590. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  8591. {
  8592. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  8593. }
  8594. 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
  8595. {
  8596. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  8597. }
  8598. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  8599. {
  8600. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  8601. }
  8602. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  8603. {
  8604. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  8605. }
  8606. } //end of the same index
  8607. } // end of for GB_QUANTITY
  8608. }
  8609. else if(gunType[gun_index] == GUN_TYPE_DO)
  8610. {
  8611. tempIndex = gun_index;
  8612. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8613. {
  8614. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8615. {
  8616. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8617. {
  8618. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  8619. {
  8620. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  8621. }
  8622. else
  8623. {
  8624. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  8625. }
  8626. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  8627. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  8628. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  8629. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  8630. }
  8631. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  8632. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  8633. ) //S_PRECHARGE
  8634. {
  8635. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  8636. }
  8637. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  8638. {
  8639. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  8640. }
  8641. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  8642. {
  8643. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  8644. }
  8645. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  8646. {
  8647. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  8648. }
  8649. 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
  8650. {
  8651. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  8652. }
  8653. 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
  8654. {
  8655. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  8656. }
  8657. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  8658. {
  8659. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  8660. }
  8661. } //end of the same index
  8662. }
  8663. }
  8664. else
  8665. {
  8666. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8667. {
  8668. tempIndex = 2;
  8669. }
  8670. else
  8671. {
  8672. tempIndex = gun_index;
  8673. }
  8674. for (int index = 0; index < AC_QUANTITY; index++)
  8675. {
  8676. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8677. {
  8678. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  8679. {
  8680. 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))
  8681. {
  8682. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  8683. }
  8684. else
  8685. {
  8686. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  8687. }
  8688. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  8689. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  8690. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  8691. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  8692. }
  8693. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  8694. {
  8695. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  8696. }
  8697. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  8698. {
  8699. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  8700. }
  8701. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  8702. {
  8703. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  8704. }
  8705. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  8706. {
  8707. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  8708. }
  8709. 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
  8710. {
  8711. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  8712. }
  8713. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  8714. {
  8715. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  8716. }
  8717. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  8718. {
  8719. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  8720. }
  8721. }//end of the same index
  8722. }//end of for AC_QUANTITY
  8723. }
  8724. //it's option
  8725. if((strstr((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]) != NULL) &&
  8726. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq &&
  8727. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_StatusNotificationPeriodically].variableAttribute[0].value, "TRUE") != 0))
  8728. {
  8729. isStateChanged = FALSE;
  8730. }
  8731. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  8732. strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]);
  8733. random_uuid(guid);
  8734. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"evseId\":%d,\"connectorStatus\":\"%s\",\"timestamp\":\"%s\"}]"
  8735. , MESSAGE_TYPE_CALL
  8736. , guid
  8737. , ShmOCPP20Data->StatusNotification[gun_index].connectorId
  8738. , ShmOCPP20Data->StatusNotification[gun_index].evseId
  8739. , ShmOCPP20Data->StatusNotification[gun_index].connectorStatus
  8740. , ShmOCPP20Data->StatusNotification[gun_index].timestamp);
  8741. if((server_sign == TRUE) && isStateChanged)
  8742. {
  8743. LWS_Send(message);
  8744. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  8745. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8746. {
  8747. result = PASS;
  8748. }
  8749. }
  8750. else
  8751. {
  8752. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  8753. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  8754. result = PASS;
  8755. }
  8756. return result;
  8757. }
  8758. int sendTransactionEventRequest(int gun_index)
  8759. {
  8760. mtrace();
  8761. int result = FAIL;
  8762. char message[1024*20]={0};
  8763. char guid[37]={0};
  8764. char tempdata[128]={0};
  8765. uint8_t tempIndex;
  8766. json_object *TransactionEvent = json_object_new_object();
  8767. json_object *transactionInfo = json_object_new_object();
  8768. json_object *idToken = json_object_new_object();
  8769. json_object *evse = json_object_new_object();
  8770. json_object *meterValues = json_object_new_array();
  8771. char TempStopTransaction[256];
  8772. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  8773. DEBUG_INFO("sendTransactionEventRequest...\n");
  8774. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  8775. {
  8776. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8777. {
  8778. tempIndex = ((gun_index==2) ? 1: 0);
  8779. }
  8780. else
  8781. {
  8782. tempIndex = gun_index;
  8783. }
  8784. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8785. {
  8786. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  8787. {
  8788. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  8789. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  8790. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  8791. else
  8792. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  8793. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  8794. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  8795. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  8796. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  8797. {
  8798. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8799. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  8800. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  8801. {
  8802. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  8803. }
  8804. else
  8805. {
  8806. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  8807. }
  8808. }
  8809. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  8810. {
  8811. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8812. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  8813. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  8814. }
  8815. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  8816. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  8817. ) //S_PRECHARGE
  8818. {
  8819. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  8820. {
  8821. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  8822. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartUserId);
  8823. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartIdType]);
  8824. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8825. }
  8826. else
  8827. {
  8828. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8829. }
  8830. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  8831. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8832. }
  8833. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  8834. {
  8835. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  8836. {
  8837. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  8838. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartUserId);
  8839. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartIdType]);
  8840. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8841. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8842. }
  8843. else
  8844. {
  8845. storeTempStopTransaction(gun_index);
  8846. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8847. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  8848. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  8849. }
  8850. }
  8851. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  8852. {
  8853. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  8854. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8855. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8856. if((access(TempStopTransaction,F_OK))!=-1)
  8857. {
  8858. remove(TempStopTransaction); // remove file "TempStopTransaction"
  8859. }
  8860. }
  8861. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  8862. {
  8863. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8864. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  8865. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8866. }
  8867. 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
  8868. {
  8869. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8870. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8871. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8872. }
  8873. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  8874. {
  8875. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8876. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8877. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8878. }
  8879. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  8880. {
  8881. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8882. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8883. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8884. }
  8885. } //end of the same index
  8886. }//end of for CHAdeMO_QUANTITY
  8887. }
  8888. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8889. {
  8890. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8891. {
  8892. tempIndex = ((gun_index==2) ? 1: 0);
  8893. }
  8894. else
  8895. {
  8896. tempIndex = gun_index;
  8897. }
  8898. for (int index = 0; index < CCS_QUANTITY; index++)
  8899. {
  8900. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8901. {
  8902. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  8903. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  8904. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  8905. else
  8906. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  8907. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  8908. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  8909. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  8910. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8911. {
  8912. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8913. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  8914. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  8915. {
  8916. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  8917. }
  8918. else
  8919. {
  8920. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  8921. }
  8922. }
  8923. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  8924. {
  8925. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8926. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  8927. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  8928. }
  8929. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  8930. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  8931. ) //S_PRECHARGE
  8932. {
  8933. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  8934. {
  8935. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  8936. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartUserId);
  8937. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartIdType]);
  8938. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8939. }
  8940. else
  8941. {
  8942. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8943. }
  8944. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  8945. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8946. }
  8947. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  8948. {
  8949. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  8950. {
  8951. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  8952. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartUserId);
  8953. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartIdType]);
  8954. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8955. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8956. }
  8957. else
  8958. {
  8959. storeTempStopTransaction(gun_index);
  8960. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8961. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  8962. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  8963. }
  8964. }
  8965. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  8966. {
  8967. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  8968. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8969. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8970. if((access(TempStopTransaction,F_OK))!=-1)
  8971. {
  8972. remove(TempStopTransaction); // remove file "TempStopTransaction"
  8973. }
  8974. }
  8975. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  8976. {
  8977. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8978. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  8979. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8980. }
  8981. 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
  8982. {
  8983. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8984. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8985. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8986. }
  8987. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  8988. {
  8989. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8990. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8991. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8992. }
  8993. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  8994. {
  8995. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8996. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8997. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8998. }
  8999. } //end of the same index
  9000. } // end of for CCS_QUANTITY
  9001. }
  9002. else if(gunType[gun_index] == GUN_TYPE_GBT)
  9003. {
  9004. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9005. {
  9006. tempIndex = ((gun_index==2) ? 1: 0);
  9007. }
  9008. else
  9009. {
  9010. tempIndex = gun_index;
  9011. }
  9012. for (int index = 0; index < GB_QUANTITY; index++)
  9013. {
  9014. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  9015. {
  9016. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9017. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9018. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9019. else
  9020. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9021. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9022. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9023. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  9024. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9025. {
  9026. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9027. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9028. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  9029. {
  9030. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9031. }
  9032. else
  9033. {
  9034. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9035. }
  9036. }
  9037. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9038. {
  9039. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9040. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9041. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9042. }
  9043. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9044. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9045. ) //S_PRECHARGE
  9046. {
  9047. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9048. {
  9049. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9050. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartUserId);
  9051. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartIdType]);
  9052. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9053. }
  9054. else
  9055. {
  9056. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9057. }
  9058. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9059. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9060. }
  9061. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9062. {
  9063. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9064. {
  9065. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9066. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartUserId);
  9067. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartIdType]);
  9068. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9069. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9070. }
  9071. else
  9072. {
  9073. storeTempStopTransaction(gun_index);
  9074. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9075. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9076. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9077. }
  9078. }
  9079. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9080. {
  9081. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9082. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9083. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9084. if((access(TempStopTransaction,F_OK))!=-1)
  9085. {
  9086. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9087. }
  9088. }
  9089. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9090. {
  9091. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9092. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9093. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9094. }
  9095. 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
  9096. {
  9097. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9098. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9099. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9100. }
  9101. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9102. {
  9103. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9104. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9105. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9106. }
  9107. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9108. {
  9109. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9110. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9111. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9112. }
  9113. } //end of the same index
  9114. } // end of for GB_QUANTITY
  9115. }
  9116. else if(gunType[gun_index] == GUN_TYPE_DO)
  9117. {
  9118. tempIndex = gun_index;
  9119. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9120. {
  9121. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  9122. {
  9123. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9124. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9125. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9126. else
  9127. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9128. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9129. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9130. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  9131. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  9132. {
  9133. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9134. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9135. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  9136. {
  9137. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9138. }
  9139. else
  9140. {
  9141. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9142. }
  9143. }
  9144. else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9145. {
  9146. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9147. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9148. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9149. }
  9150. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9151. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9152. ) //S_PRECHARGE
  9153. {
  9154. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9155. {
  9156. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9157. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartUserId);
  9158. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartIdType]);
  9159. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9160. }
  9161. else
  9162. {
  9163. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9164. }
  9165. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9166. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9167. }
  9168. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9169. {
  9170. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9171. {
  9172. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9173. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartUserId);
  9174. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartIdType]);
  9175. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9176. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9177. }
  9178. else
  9179. {
  9180. storeTempStopTransaction(gun_index);
  9181. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9182. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9183. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9184. }
  9185. }
  9186. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9187. {
  9188. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9189. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9190. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9191. if((access(TempStopTransaction,F_OK))!=-1)
  9192. {
  9193. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9194. }
  9195. }
  9196. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9197. {
  9198. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9199. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9200. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9201. }
  9202. 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
  9203. {
  9204. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9205. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9206. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9207. }
  9208. 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
  9209. {
  9210. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9211. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9212. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9213. }
  9214. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9215. {
  9216. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9217. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9218. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9219. }
  9220. } //end of the same index
  9221. }
  9222. }
  9223. else
  9224. {
  9225. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9226. {
  9227. tempIndex = 2;
  9228. }
  9229. else
  9230. {
  9231. tempIndex = gun_index;
  9232. }
  9233. for (int index = 0; index < AC_QUANTITY; index++)
  9234. {
  9235. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  9236. {
  9237. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  9238. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  9239. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  9240. else
  9241. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  9242. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  9243. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  9244. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  9245. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  9246. {
  9247. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9248. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9249. 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))
  9250. {
  9251. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  9252. }
  9253. else
  9254. {
  9255. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  9256. }
  9257. }
  9258. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  9259. {
  9260. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9261. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  9262. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  9263. }
  9264. else if ( ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  9265. ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  9266. ) //S_PRECHARGE
  9267. {
  9268. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9269. {
  9270. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9271. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartUserId);
  9272. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartIdType]);
  9273. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9274. }
  9275. else
  9276. {
  9277. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9278. }
  9279. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  9280. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9281. }
  9282. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  9283. {
  9284. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  9285. {
  9286. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  9287. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartUserId);
  9288. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", IdTokenEnumTypeStr[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartIdType]);
  9289. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9290. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9291. }
  9292. else
  9293. {
  9294. storeTempStopTransaction(gun_index);
  9295. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9296. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  9297. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_MeterValuePeriodic]);
  9298. }
  9299. }
  9300. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  9301. {
  9302. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  9303. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9304. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9305. if((access(TempStopTransaction,F_OK))!=-1)
  9306. {
  9307. remove(TempStopTransaction); // remove file "TempStopTransaction"
  9308. }
  9309. }
  9310. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  9311. {
  9312. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9313. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  9314. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  9315. }
  9316. 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
  9317. {
  9318. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9319. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9320. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9321. }
  9322. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  9323. {
  9324. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  9325. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9326. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9327. }
  9328. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  9329. {
  9330. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  9331. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  9332. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  9333. }
  9334. }//end of the same index
  9335. }//end of for AC_QUANTITY
  9336. }
  9337. // Message
  9338. json_object_object_add(TransactionEvent, "eventType", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  9339. json_object_object_add(TransactionEvent, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].timestamp));
  9340. json_object_object_add(TransactionEvent, "triggerReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason));
  9341. json_object_object_add(TransactionEvent, "seqNo", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].seqNo));
  9342. json_object_object_add(TransactionEvent, "offline", json_object_new_boolean(ShmOCPP20Data->TransactionEvent[gun_index].offline));
  9343. if(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed > 0)
  9344. json_object_object_add(TransactionEvent, "numberOfPhasesUsed", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed));
  9345. if(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent > 0)
  9346. json_object_object_add(TransactionEvent, "cableMaxCurrent", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent));
  9347. if(ShmOCPP20Data->TransactionEvent[gun_index].reservationId > 0)
  9348. json_object_object_add(TransactionEvent, "reservationId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].reservationId));
  9349. json_object_object_add(transactionInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId));
  9350. json_object_object_add(transactionInfo, "chargingState", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState));
  9351. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging > 0)
  9352. json_object_object_add(transactionInfo, "timeSpentCharging", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging));
  9353. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason) > 0) && (strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL))
  9354. json_object_object_add(transactionInfo, "stoppedReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason));
  9355. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId > 0)
  9356. json_object_object_add(transactionInfo, "remoteStartId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId));
  9357. json_object_object_add(TransactionEvent, "transactionInfo", transactionInfo);
  9358. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken) > 0)
  9359. {
  9360. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
  9361. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type));
  9362. json_object_object_add(TransactionEvent, "idToken", idToken);
  9363. }
  9364. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.id));
  9365. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId));
  9366. json_object_object_add(TransactionEvent, "evse", evse);
  9367. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0].timestamp) > 0)
  9368. {
  9369. for(int idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue);idxMeter++)
  9370. {
  9371. json_object *meterValue = json_object_new_object();
  9372. json_object *sampledValues = json_object_new_array();
  9373. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].timestamp));
  9374. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  9375. {
  9376. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0) &&
  9377. ((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0) || (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) == 0) || (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) == 0) || (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) == 0)))
  9378. {
  9379. if(((strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL) && (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, (char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) != NULL)) ||
  9380. (strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) == NULL))
  9381. {
  9382. json_object *sampledValue = json_object_new_object();
  9383. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  9384. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  9385. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  9386. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  9387. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  9388. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  9389. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  9390. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  9391. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  9392. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  9393. {
  9394. json_object *unitOfMeasure = json_object_new_object();
  9395. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  9396. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  9397. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  9398. }
  9399. json_object_array_add(sampledValues, sampledValue);
  9400. }
  9401. }
  9402. }
  9403. json_object_object_add(meterValue, "sampledValue", sampledValues);
  9404. json_object_array_add(meterValues, meterValue);
  9405. }
  9406. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  9407. }
  9408. random_uuid(guid);
  9409. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "TransactionEvent", json_object_to_json_string_ext(TransactionEvent, JSON_C_TO_STRING_PLAIN));
  9410. json_object_put(TransactionEvent);
  9411. sprintf(tempdata, "TransactionEvent,%d", gun_index);
  9412. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  9413. {
  9414. result = PASS;
  9415. }
  9416. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  9417. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Started]) != NULL)
  9418. OCPP_insert_transaction_msg(YES, message);
  9419. else if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL)
  9420. {
  9421. OCPP_insert_transaction_msg(NO, message);
  9422. memset(&ShmOCPP20Data->SessionTarget[gun_index], 0x00, sizeof(struct StructSessionTarget));
  9423. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  9424. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  9425. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  9426. }
  9427. return result;
  9428. }
  9429. //==========================================
  9430. // send confirm routine
  9431. //==========================================
  9432. int sendCancelReservationConfirmation(char *uuid, unsigned char gun_index)
  9433. {
  9434. mtrace();
  9435. int result = FAIL;
  9436. char message[4096]={0};
  9437. json_object *CancelReservation = json_object_new_object();
  9438. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  9439. json_object_object_add(CancelReservation, "status", json_object_new_string((char*)ShmOCPP20Data->CancelReservation[gun_index].Response_status));
  9440. sprintf(message,"[%d,\"%s\",%s]"
  9441. ,MESSAGE_TYPE_CALLRESULT
  9442. ,uuid
  9443. ,json_object_to_json_string_ext(CancelReservation, JSON_C_TO_STRING_PLAIN));
  9444. json_object_put(CancelReservation);
  9445. ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationConf = OFF;
  9446. LWS_Send(message);
  9447. result = TRUE;
  9448. return result;
  9449. }
  9450. int sendCertificateSignedConfirmation(char *uuid)
  9451. {
  9452. mtrace();
  9453. int result = FAIL;
  9454. char message[4096]={0};
  9455. json_object *CertificateSigned = json_object_new_object();
  9456. json_object *statusInfo = json_object_new_object();
  9457. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  9458. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_status));
  9459. if(strlen((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.reasonCode) > 0)
  9460. {
  9461. json_object_object_add(statusInfo, "reasonCode", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.reasonCode));
  9462. if(strlen((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.additionalInfo) > 0)
  9463. json_object_object_add(statusInfo, "statadditionalInfous", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.additionalInfo));
  9464. }
  9465. json_object_object_add(CertificateSigned, "statusInfo", statusInfo);
  9466. sprintf(message,"[%d,\"%s\",%s]"
  9467. ,MESSAGE_TYPE_CALLRESULT
  9468. ,uuid
  9469. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  9470. json_object_put(CertificateSigned);
  9471. LWS_Send(message);
  9472. result = TRUE;
  9473. return result;
  9474. }
  9475. int sendChangeAvailabilityConfirmation(char *uuid, unsigned char gun_index)
  9476. {
  9477. mtrace();
  9478. int result = FAIL;
  9479. char message[4096]={0};
  9480. json_object *ChangeAvailability = json_object_new_object();
  9481. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  9482. json_object_object_add(ChangeAvailability, "status", json_object_new_string((char*)ShmOCPP20Data->ChangeAvailability[gun_index].Response_status));
  9483. sprintf(message,"[%d,\"%s\",%s]"
  9484. ,MESSAGE_TYPE_CALLRESULT
  9485. ,uuid
  9486. ,json_object_to_json_string_ext(ChangeAvailability, JSON_C_TO_STRING_PLAIN));
  9487. json_object_put(ChangeAvailability);
  9488. LWS_Send(message);
  9489. result = TRUE;
  9490. return result;
  9491. }
  9492. int sendClearCacheConfirmation(char *uuid)
  9493. {
  9494. mtrace();
  9495. int result = FAIL;
  9496. char message[4096]={0};
  9497. json_object *ClearCache = json_object_new_object();
  9498. DEBUG_INFO("sendClearCacheConfirmation...\n");
  9499. json_object_object_add(ClearCache, "status", json_object_new_string((char*)ShmOCPP20Data->ClearCache.Response_status));
  9500. sprintf(message,"[%d,\"%s\",%s]"
  9501. ,MESSAGE_TYPE_CALLRESULT
  9502. ,uuid
  9503. ,json_object_to_json_string_ext(ClearCache, JSON_C_TO_STRING_PLAIN));
  9504. json_object_put(ClearCache);
  9505. LWS_Send(message);
  9506. result = TRUE;
  9507. return result;
  9508. }
  9509. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  9510. {
  9511. mtrace();
  9512. int result = FAIL;
  9513. char message[500]={0};
  9514. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  9515. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  9516. LWS_Send(message);
  9517. return result;
  9518. }
  9519. int sendClearDisplayMessageConfirmation(char *uuid)
  9520. {
  9521. mtrace();
  9522. int result = FAIL;
  9523. char message[4096]={0};
  9524. json_object *ClearDisplayMessage = json_object_new_object();
  9525. DEBUG_INFO("sendClearDisplayMessageConfirmation...\n");
  9526. json_object_object_add(ClearDisplayMessage, "status", json_object_new_string((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status));
  9527. sprintf(message,"[%d,\"%s\",%s]"
  9528. ,MESSAGE_TYPE_CALLRESULT
  9529. ,uuid
  9530. ,json_object_to_json_string_ext(ClearDisplayMessage, JSON_C_TO_STRING_PLAIN));
  9531. json_object_put(ClearDisplayMessage);
  9532. LWS_Send(message);
  9533. result = TRUE;
  9534. return result;
  9535. }
  9536. int sendClearVariableMonitoringConfirmation(char *uuid, unsigned char variableQuantity)
  9537. {
  9538. mtrace();
  9539. int result = FAIL;
  9540. char message[4096]={0};
  9541. json_object *ClearVariableMonitoring = json_object_new_object();
  9542. json_object *clearMonitoringResults = json_object_new_array();
  9543. DEBUG_INFO("sendClearVariableMonitoringConfirmation...\n");
  9544. for(int idx=0;idx<variableQuantity;idx++)
  9545. {
  9546. json_object *clearMonitoringResult = json_object_new_object();
  9547. json_object_object_add(clearMonitoringResult, "id", json_object_new_int(ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].id));
  9548. json_object_object_add(clearMonitoringResult, "status", json_object_new_string((char*)ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].status));
  9549. json_object_array_add(clearMonitoringResults, clearMonitoringResult);
  9550. }
  9551. json_object_object_add(ClearVariableMonitoring, "clearMonitoringResult", clearMonitoringResults);
  9552. sprintf(message,"[%d,\"%s\",%s]"
  9553. ,MESSAGE_TYPE_CALLRESULT
  9554. ,uuid
  9555. ,json_object_to_json_string_ext(ClearVariableMonitoring, JSON_C_TO_STRING_PLAIN));
  9556. json_object_put(ClearVariableMonitoring);
  9557. LWS_Send(message);
  9558. result = TRUE;
  9559. return result;
  9560. }
  9561. int sendCostUpdatedConfirmation(char *uuid)
  9562. {
  9563. mtrace();
  9564. int result = FAIL;
  9565. char message[4096]={0};
  9566. DEBUG_INFO("sendCostUpdatedConfirmation...\n");
  9567. sprintf(message,"[%d,\"%s\",{}]"
  9568. ,MESSAGE_TYPE_CALLRESULT
  9569. ,uuid);
  9570. LWS_Send(message);
  9571. result = TRUE;
  9572. return result;
  9573. }
  9574. int sendCustomerInformationConfirmation(char *uuid)
  9575. {
  9576. mtrace();
  9577. int result = FAIL;
  9578. char message[4096]={0};
  9579. json_object *CustomerInformation = json_object_new_object();
  9580. DEBUG_INFO("sendCustomerInformationConfirmation...\n");
  9581. json_object_object_add(CustomerInformation, "status", json_object_new_string((char*)ShmOCPP20Data->CustomerInformation.Response_status));
  9582. sprintf(message,"[%d,\"%s\",%s]"
  9583. ,MESSAGE_TYPE_CALLRESULT
  9584. ,uuid
  9585. ,json_object_to_json_string_ext(CustomerInformation, JSON_C_TO_STRING_PLAIN));
  9586. json_object_put(CustomerInformation);
  9587. LWS_Send(message);
  9588. result = TRUE;
  9589. return result;
  9590. }
  9591. int sendDataTransferConfirmation(char *uuid, unsigned char gun_index)
  9592. {
  9593. mtrace();
  9594. int result = FAIL;
  9595. char message[4096]={0};
  9596. json_object *DataTransfer = json_object_new_object();
  9597. DEBUG_INFO("sendDataTransferConfirmation...\n");
  9598. json_object_object_add(DataTransfer, "status", json_object_new_string((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_status));
  9599. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_data));
  9600. sprintf(message,"[%d,\"%s\",%s]"
  9601. ,MESSAGE_TYPE_CALLRESULT
  9602. ,uuid
  9603. ,json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  9604. json_object_put(DataTransfer);
  9605. LWS_Send(message);
  9606. result = TRUE;
  9607. return result;
  9608. }
  9609. int sendDeleteCertificateConfirmation(char *uuid)
  9610. {
  9611. mtrace();
  9612. int result = FAIL;
  9613. char message[4096]={0};
  9614. json_object *DeleteCertificate = json_object_new_object();
  9615. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  9616. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP20Data->DeleteCertificate.Response_status));
  9617. sprintf(message,"[%d,\"%s\",%s]"
  9618. ,MESSAGE_TYPE_CALLRESULT
  9619. ,uuid
  9620. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  9621. json_object_put(DeleteCertificate);
  9622. LWS_Send(message);
  9623. result = TRUE;
  9624. return result;
  9625. }
  9626. int sendGetBaseReportConfirmation(char *uuid)
  9627. {
  9628. mtrace();
  9629. int result = FAIL;
  9630. char message[4096]={0};
  9631. json_object *GetBaseReport = json_object_new_object();
  9632. DEBUG_INFO("sendGetBaseReportConfirmation...\n");
  9633. json_object_object_add(GetBaseReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetBaseReport.Response_status));
  9634. sprintf(message,"[%d,\"%s\",%s]"
  9635. ,MESSAGE_TYPE_CALLRESULT
  9636. ,uuid
  9637. ,json_object_to_json_string_ext(GetBaseReport, JSON_C_TO_STRING_PLAIN));
  9638. json_object_put(GetBaseReport);
  9639. LWS_Send(message);
  9640. result = TRUE;
  9641. return result;
  9642. }
  9643. int sendGetChargingProfilesConfirmation(char *uuid, unsigned char gun_index)
  9644. {
  9645. mtrace();
  9646. int result = FAIL;
  9647. char message[4096]={0};
  9648. json_object *GetChargingProfiles = json_object_new_object();
  9649. DEBUG_INFO("sendGetChargingProfilesConfirmation...\n");
  9650. json_object_object_add(GetChargingProfiles, "status", json_object_new_string((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status));
  9651. sprintf(message,"[%d,\"%s\",%s]"
  9652. ,MESSAGE_TYPE_CALLRESULT
  9653. ,uuid
  9654. ,json_object_to_json_string_ext(GetChargingProfiles, JSON_C_TO_STRING_PLAIN));
  9655. json_object_put(GetChargingProfiles);
  9656. LWS_Send(message);
  9657. result = TRUE;
  9658. return result;
  9659. }
  9660. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  9661. {
  9662. mtrace();
  9663. int result = FAIL;
  9664. char message[4096]={0};
  9665. int CompositeScheduleIndex = 0;
  9666. json_object *GetCompositeSchedule = json_object_new_object();
  9667. json_object *schedule = json_object_new_object();
  9668. json_object *chargingSchedule = json_object_new_object();
  9669. json_object *chargingSchedulePeriod = json_object_new_array();
  9670. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  9671. json_object_object_add(GetCompositeSchedule, "status", json_object_new_string(payload));
  9672. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  9673. if(nPeriod == 0)
  9674. {
  9675. if(strcmp((const char *)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime,"")!=0)
  9676. {
  9677. if(strlen((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule))
  9678. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule));
  9679. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration > 0)
  9680. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration));
  9681. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit));
  9682. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate > 0)
  9683. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate));
  9684. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.id));
  9685. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  9686. {
  9687. if(((ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  9688. (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  9689. {
  9690. json_object *Period = json_object_new_object();
  9691. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  9692. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  9693. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  9694. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  9695. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  9696. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  9697. json_object_array_add(chargingSchedulePeriod, Period);
  9698. }
  9699. }
  9700. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriod);
  9701. json_object_object_add(schedule, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime));
  9702. json_object_object_add(schedule, "chargingSchedule", chargingSchedule);
  9703. json_object_object_add(GetCompositeSchedule, "schedule", schedule);
  9704. }
  9705. }
  9706. else
  9707. {
  9708. if(strlen((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule))
  9709. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule));
  9710. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration > 0)
  9711. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration));
  9712. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit));
  9713. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate > 0)
  9714. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate));
  9715. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.id));
  9716. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  9717. {
  9718. if(((ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  9719. (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  9720. {
  9721. json_object *Period = json_object_new_object();
  9722. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  9723. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  9724. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  9725. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  9726. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  9727. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  9728. json_object_array_add(chargingSchedulePeriod, Period);
  9729. }
  9730. }
  9731. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriod);
  9732. json_object_object_add(schedule, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime));
  9733. json_object_object_add(schedule, "chargingSchedule", chargingSchedule);
  9734. json_object_object_add(GetCompositeSchedule, "schedule", schedule);
  9735. }
  9736. sprintf(message,"[%d,\"%s\",%s]"
  9737. ,MESSAGE_TYPE_CALLRESULT
  9738. ,uuid
  9739. ,json_object_to_json_string_ext(GetCompositeSchedule, JSON_C_TO_STRING_PLAIN));
  9740. json_object_put(GetCompositeSchedule);
  9741. LWS_Send(message);
  9742. result = TRUE;
  9743. return result;
  9744. }
  9745. int sendGetGetDisplayMessagesConfirmation(char *uuid)
  9746. {
  9747. mtrace();
  9748. int result = FAIL;
  9749. char message[4096]={0};
  9750. json_object *GetGetDisplayMessages = json_object_new_object();
  9751. DEBUG_INFO("sendGetGetDisplayMessagesConfirmation...\n");
  9752. json_object_object_add(GetGetDisplayMessages, "status", json_object_new_string((char*)ShmOCPP20Data->GetDisplayMessages.Response_status));
  9753. sprintf(message,"[%d,\"%s\",%s]"
  9754. ,MESSAGE_TYPE_CALLRESULT
  9755. ,uuid
  9756. ,json_object_to_json_string_ext(GetGetDisplayMessages, JSON_C_TO_STRING_PLAIN));
  9757. json_object_put(GetGetDisplayMessages);
  9758. LWS_Send(message);
  9759. result = TRUE;
  9760. return result;
  9761. }
  9762. int sendGetInstalledCertificateIdsConfirmation(char *uuid, unsigned char certQuantity)
  9763. {
  9764. mtrace();
  9765. int result = FAIL;
  9766. char message[4096]={0};
  9767. json_object *GetInstalledCertificateIds = json_object_new_object();
  9768. json_object *certificateHashDataChains = json_object_new_array();
  9769. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  9770. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status));
  9771. for(int idx=0;idx<certQuantity;idx++)
  9772. {
  9773. json_object *cert = json_object_new_object();
  9774. json_object *certificateHashData = json_object_new_object();
  9775. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.hashAlgorithm));
  9776. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.issuerNameHash));
  9777. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.issuerKeyHash));
  9778. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.serialNumber));
  9779. json_object_object_add(cert, "certificateHashData", certificateHashData);
  9780. json_object_object_add(cert, "certificateType", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateType));
  9781. json_object_array_add(certificateHashDataChains, cert);
  9782. }
  9783. json_object_object_add(GetInstalledCertificateIds , "certificateHashDataChain", certificateHashDataChains);
  9784. sprintf(message,"[%d,\"%s\",%s]"
  9785. ,MESSAGE_TYPE_CALLRESULT
  9786. ,uuid
  9787. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  9788. json_object_put(GetInstalledCertificateIds);
  9789. LWS_Send(message);
  9790. result = TRUE;
  9791. return result;
  9792. }
  9793. int sendGetLocalListVersionConfirmation(char *uuid)
  9794. {
  9795. mtrace();
  9796. int result = FAIL;
  9797. char message[4096]={0};
  9798. json_object *GetLocalListVersion = json_object_new_object();
  9799. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  9800. json_object_object_add(GetLocalListVersion, "versionNumber", json_object_new_int(ShmOCPP20Data->GetLocalListVersion.Response_versionNumber));
  9801. sprintf(message,"[%d,\"%s\",%s]"
  9802. ,MESSAGE_TYPE_CALLRESULT
  9803. ,uuid
  9804. ,json_object_to_json_string_ext(GetLocalListVersion, JSON_C_TO_STRING_PLAIN));
  9805. json_object_put(GetLocalListVersion);
  9806. LWS_Send(message);
  9807. result = TRUE;
  9808. return result;
  9809. }
  9810. int sendGetLogConfirmation(char *uuid)
  9811. {
  9812. mtrace();
  9813. int result = FAIL;
  9814. char message[4096]={0};
  9815. json_object *GetLog = json_object_new_object();
  9816. DEBUG_INFO("sendGetLogConfirmation...\n");
  9817. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP20Data->GetLog.Response_status));
  9818. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP20Data->GetLog.Response_filename));
  9819. sprintf(message,"[%d,\"%s\",%s]"
  9820. ,MESSAGE_TYPE_CALLRESULT
  9821. ,uuid
  9822. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  9823. json_object_put(GetLog);
  9824. LWS_Send(message);
  9825. result = TRUE;
  9826. return result;
  9827. }
  9828. int sendGetMonitoringReportConfirmation(char *uuid)
  9829. {
  9830. mtrace();
  9831. int result = FAIL;
  9832. char message[4096]={0};
  9833. json_object *GetMonitoringReport = json_object_new_object();
  9834. DEBUG_INFO("sendGetMonitoringReportConfirmation...\n");
  9835. json_object_object_add(GetMonitoringReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetMonitoringReport.Response_status));
  9836. sprintf(message,"[%d,\"%s\",%s]"
  9837. ,MESSAGE_TYPE_CALLRESULT
  9838. ,uuid
  9839. ,json_object_to_json_string_ext(GetMonitoringReport, JSON_C_TO_STRING_PLAIN));
  9840. json_object_put(GetMonitoringReport);
  9841. LWS_Send(message);
  9842. result = TRUE;
  9843. return result;
  9844. }
  9845. int sendGetReportConfirmation(char *uuid)
  9846. {
  9847. mtrace();
  9848. int result = FAIL;
  9849. char message[4096]={0};
  9850. json_object *GetReport = json_object_new_object();
  9851. DEBUG_INFO("sendGetReportConfirmation...\n");
  9852. json_object_object_add(GetReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetReport.Response_status));
  9853. sprintf(message,"[%d,\"%s\",%s]"
  9854. ,MESSAGE_TYPE_CALLRESULT
  9855. ,uuid
  9856. ,json_object_to_json_string_ext(GetReport, JSON_C_TO_STRING_PLAIN));
  9857. json_object_put(GetReport);
  9858. LWS_Send(message);
  9859. result = TRUE;
  9860. return result;
  9861. }
  9862. int sendGetTransactionStatusConfirmation(char *uuid, unsigned char gun_index)
  9863. {
  9864. mtrace();
  9865. int result = FAIL;
  9866. char message[4096]={0};
  9867. json_object *GetTransactionStatus = json_object_new_object();
  9868. DEBUG_INFO("sendGetTransactionStatusConfirmation...\n");
  9869. json_object_object_add(GetTransactionStatus, "ongoingIndicator", json_object_new_boolean(ShmOCPP20Data->GetTransactionStatus[gun_index].Response_ongoingIndicator));
  9870. json_object_object_add(GetTransactionStatus, "messagesInQueue", json_object_new_boolean(ShmOCPP20Data->GetTransactionStatus[gun_index].Response_messagesInQueue));
  9871. sprintf(message,"[%d,\"%s\",%s]"
  9872. ,MESSAGE_TYPE_CALLRESULT
  9873. ,uuid
  9874. ,json_object_to_json_string_ext(GetTransactionStatus, JSON_C_TO_STRING_PLAIN));
  9875. json_object_put(GetTransactionStatus);
  9876. LWS_Send(message);
  9877. result = TRUE;
  9878. return result;
  9879. }
  9880. int sendGetVariablesConfirmation(char *uuid, unsigned char variableQuantity)
  9881. {
  9882. mtrace();
  9883. int result = FAIL;
  9884. char message[4096]={0};
  9885. json_object *GetVariables = json_object_new_object();
  9886. json_object *getVariableResults = json_object_new_array();
  9887. DEBUG_INFO("sendGetVariablesConfirmation...\n");
  9888. for(int idx=0;idx<variableQuantity;idx++)
  9889. {
  9890. json_object *variableResult = json_object_new_object();
  9891. json_object *component = json_object_new_object();
  9892. json_object *variable = json_object_new_object();
  9893. json_object *evse = json_object_new_object();
  9894. json_object_object_add(variableResult, "attributeType", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType));
  9895. json_object_object_add(variableResult, "attributeStatus", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus));
  9896. json_object_object_add(variableResult, "attributeValue", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue));
  9897. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.id));
  9898. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.connectorId));
  9899. json_object_object_add(component, "evse", evse);
  9900. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.name));
  9901. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.instance));
  9902. json_object_object_add(variableResult, "component", component);
  9903. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.name));
  9904. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.instance));
  9905. json_object_object_add(variableResult, "variable", variable);
  9906. json_object_array_add(getVariableResults, variableResult);
  9907. }
  9908. json_object_object_add(GetVariables , "getVariableResult", getVariableResults);
  9909. sprintf(message,"[%d,\"%s\",%s]"
  9910. ,MESSAGE_TYPE_CALLRESULT
  9911. ,uuid
  9912. ,json_object_to_json_string_ext(GetVariables, JSON_C_TO_STRING_PLAIN));
  9913. json_object_put(GetVariables);
  9914. LWS_Send(message);
  9915. result = TRUE;
  9916. return result;
  9917. }
  9918. int sendInstallCertificateConfirmation(char *uuid)
  9919. {
  9920. mtrace();
  9921. int result = FAIL;
  9922. char message[4096]={0};
  9923. json_object *InstallCertificate = json_object_new_object();
  9924. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  9925. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP20Data->InstallCertificate.Response_status));
  9926. sprintf(message,"[%d,\"%s\",%s]"
  9927. ,MESSAGE_TYPE_CALLRESULT
  9928. ,uuid
  9929. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  9930. json_object_put(InstallCertificate);
  9931. LWS_Send(message);
  9932. result = TRUE;
  9933. return result;
  9934. }
  9935. int sendPublishFirmwareConfirmation(char *uuid)
  9936. {
  9937. mtrace();
  9938. int result = FAIL;
  9939. char message[4096]={0};
  9940. json_object *PublishFirmware = json_object_new_object();
  9941. json_object_object_add(PublishFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->PublishFirmware.Response_status));
  9942. DEBUG_INFO("sendPublishFirmwareConfirmation...\n");
  9943. sprintf(message,"[%d,\"%s\",%s]"
  9944. ,MESSAGE_TYPE_CALLRESULT
  9945. ,uuid
  9946. ,json_object_to_json_string_ext(PublishFirmware, JSON_C_TO_STRING_PLAIN));
  9947. json_object_put(PublishFirmware);
  9948. LWS_Send(message);
  9949. result = TRUE;
  9950. return result;
  9951. }
  9952. int sendRemoteStartTransactionConfirmation(char *uuid, unsigned char gun_index)
  9953. {
  9954. mtrace();
  9955. int result = FAIL;
  9956. char message[4096]={0};
  9957. json_object *RemoteStartTransaction = json_object_new_object();
  9958. json_object_object_add(RemoteStartTransaction, "status", json_object_new_string((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status));
  9959. if((strstr((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]) != NULL) &&
  9960. (strlen((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId) > 0))
  9961. json_object_object_add(RemoteStartTransaction, "transactionId", json_object_new_string((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId));
  9962. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  9963. sprintf(message,"[%d,\"%s\",%s]"
  9964. ,MESSAGE_TYPE_CALLRESULT
  9965. ,uuid
  9966. ,json_object_to_json_string_ext(RemoteStartTransaction, JSON_C_TO_STRING_PLAIN));
  9967. json_object_put(RemoteStartTransaction);
  9968. LWS_Send(message);
  9969. result = TRUE;
  9970. return result;
  9971. }
  9972. int sendRemoteStopTransactionConfirmation(char *uuid, unsigned char gun_index)
  9973. {
  9974. mtrace();
  9975. int result = FAIL;
  9976. char message[4096]={0};
  9977. json_object *RemoteStopTransaction = json_object_new_object();
  9978. json_object_object_add(RemoteStopTransaction, "status", json_object_new_string((char*)ShmOCPP20Data->RequestStopTransaction[gun_index].Response_status));
  9979. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  9980. sprintf(message,"[%d,\"%s\",%s]"
  9981. ,MESSAGE_TYPE_CALLRESULT
  9982. ,uuid
  9983. ,json_object_to_json_string_ext(RemoteStopTransaction, JSON_C_TO_STRING_PLAIN));
  9984. json_object_put(RemoteStopTransaction);
  9985. LWS_Send(message);
  9986. result = TRUE;
  9987. return result;
  9988. }
  9989. int sendReserveNowConfirmation(char *uuid, unsigned char gun_index)
  9990. {
  9991. mtrace();
  9992. int result = FAIL;
  9993. char message[4096]={0};
  9994. json_object *ReserveNow = json_object_new_object();
  9995. json_object_object_add(ReserveNow, "status", json_object_new_string((char*)ShmOCPP20Data->ReserveNow[gun_index].Response_status));
  9996. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  9997. sprintf(message,"[%d,\"%s\",%s]"
  9998. ,MESSAGE_TYPE_CALLRESULT
  9999. ,uuid
  10000. ,json_object_to_json_string_ext(ReserveNow, JSON_C_TO_STRING_PLAIN));
  10001. json_object_put(ReserveNow);
  10002. LWS_Send(message);
  10003. result = TRUE;
  10004. ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf = OFF;
  10005. return result;
  10006. }
  10007. int sendResetConfirmation(char *uuid)
  10008. {
  10009. mtrace();
  10010. int result = FAIL;
  10011. char message[4096]={0};
  10012. json_object *Reset = json_object_new_object();
  10013. DEBUG_INFO("sendResetConfirmation...\n");
  10014. ShmOCPP20Data->MsMsg.bits.ResetConf = OFF;
  10015. json_object_object_add(Reset, "status", json_object_new_string((char*)ShmOCPP20Data->Reset.Response_status));
  10016. sprintf(message,"[%d,\"%s\",%s]"
  10017. ,MESSAGE_TYPE_CALLRESULT
  10018. ,uuid
  10019. ,json_object_to_json_string_ext(Reset, JSON_C_TO_STRING_PLAIN));
  10020. json_object_put(Reset);
  10021. LWS_Send(message);
  10022. if(strcmp((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]) == 0)
  10023. {
  10024. DB_updateBootType(BootReasonEnumType_RemoteReset);
  10025. }
  10026. else if(strcmp((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Scheduled]) == 0)
  10027. {
  10028. DB_updateBootType(BootReasonEnumType_ScheduledReset);
  10029. }
  10030. result = TRUE;
  10031. return result;
  10032. }
  10033. int sendSendLocalListConfirmation(char *uuid)
  10034. {
  10035. mtrace();
  10036. int result = FAIL;
  10037. char message[4096]={0};
  10038. json_object *SendLocalList = json_object_new_object();
  10039. json_object_object_add(SendLocalList, "status", json_object_new_string((char*)ShmOCPP20Data->SendLocalList.Response_status));
  10040. sprintf(message,"[%d,\"%s\",%s]"
  10041. ,MESSAGE_TYPE_CALLRESULT
  10042. ,uuid
  10043. ,json_object_to_json_string_ext(SendLocalList, JSON_C_TO_STRING_PLAIN));
  10044. json_object_put(SendLocalList);
  10045. LWS_Send(message);
  10046. result = TRUE;
  10047. return result;
  10048. }
  10049. int sendSetChargingProfileConfirmation(char *uuid, unsigned char gun_index)
  10050. {
  10051. mtrace();
  10052. int result = FAIL;
  10053. char message[4096]={0};
  10054. json_object *SetChargingProfile = json_object_new_object();
  10055. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  10056. json_object_object_add(SetChargingProfile, "status", json_object_new_string((char*)ShmOCPP20Data->SetChargingProfile[gun_index].Response_status));
  10057. sprintf(message,"[%d,\"%s\",%s]"
  10058. ,MESSAGE_TYPE_CALLRESULT
  10059. ,uuid
  10060. ,json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  10061. json_object_put(SetChargingProfile);
  10062. LWS_Send(message);
  10063. result = TRUE;
  10064. return result;
  10065. }
  10066. int sendSetDisplayMessagesConfirmation(char *uuid)
  10067. {
  10068. mtrace();
  10069. int result = FAIL;
  10070. char message[4096]={0};
  10071. json_object *SetDisplayMessage = json_object_new_object();
  10072. DEBUG_INFO("sendSetDisplayMessageConfirmation...\n");
  10073. json_object_object_add(SetDisplayMessage, "status", json_object_new_string((char*)ShmOCPP20Data->SetDisplayMessage.Response_status));
  10074. sprintf(message,"[%d,\"%s\",%s]"
  10075. ,MESSAGE_TYPE_CALLRESULT
  10076. ,uuid
  10077. ,json_object_to_json_string_ext(SetDisplayMessage, JSON_C_TO_STRING_PLAIN));
  10078. json_object_put(SetDisplayMessage);
  10079. LWS_Send(message);
  10080. result = TRUE;
  10081. return result;
  10082. }
  10083. int sendSetMonitoringBaseConfirmation(char *uuid)
  10084. {
  10085. mtrace();
  10086. int result = FAIL;
  10087. char message[4096]={0};
  10088. json_object *SetMonitoringBase = json_object_new_object();
  10089. DEBUG_INFO("sendSetMonitoringBaseConfirmation...\n");
  10090. json_object_object_add(SetMonitoringBase, "status", json_object_new_string((char*)ShmOCPP20Data->SetMonitoringBase.Response_status));
  10091. sprintf(message,"[%d,\"%s\",%s]"
  10092. ,MESSAGE_TYPE_CALLRESULT
  10093. ,uuid
  10094. ,json_object_to_json_string_ext(SetMonitoringBase, JSON_C_TO_STRING_PLAIN));
  10095. json_object_put(SetMonitoringBase);
  10096. LWS_Send(message);
  10097. result = TRUE;
  10098. return result;
  10099. }
  10100. int sendSetMonitoringLevelConfirmation(char *uuid)
  10101. {
  10102. mtrace();
  10103. int result = FAIL;
  10104. char message[4096]={0};
  10105. json_object *SetMonitoringLevel = json_object_new_object();
  10106. DEBUG_INFO("sendSetMonitoringLevelConfirmation...\n");
  10107. json_object_object_add(SetMonitoringLevel, "status", json_object_new_string((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status));
  10108. sprintf(message,"[%d,\"%s\",%s]"
  10109. ,MESSAGE_TYPE_CALLRESULT
  10110. ,uuid
  10111. ,json_object_to_json_string_ext(SetMonitoringLevel, JSON_C_TO_STRING_PLAIN));
  10112. json_object_put(SetMonitoringLevel);
  10113. LWS_Send(message);
  10114. result = TRUE;
  10115. return result;
  10116. }
  10117. int sendSetNetworkProfileConfirmation(char *uuid)
  10118. {
  10119. mtrace();
  10120. int result = FAIL;
  10121. char message[4096]={0};
  10122. json_object *SetNetworkProfile = json_object_new_object();
  10123. DEBUG_INFO("sendSetNetworkProfileConfirmation...\n");
  10124. json_object_object_add(SetNetworkProfile, "status", json_object_new_string((char*)ShmOCPP20Data->SetNetworkProfile.Response_status));
  10125. sprintf(message,"[%d,\"%s\",%s]"
  10126. ,MESSAGE_TYPE_CALLRESULT
  10127. ,uuid
  10128. ,json_object_to_json_string_ext(SetNetworkProfile, JSON_C_TO_STRING_PLAIN));
  10129. json_object_put(SetNetworkProfile);
  10130. LWS_Send(message);
  10131. result = TRUE;
  10132. return result;
  10133. }
  10134. int sendSetVariableMonitoringConfirmation(char *uuid, unsigned char variableQuantity)
  10135. {
  10136. mtrace();
  10137. int result = FAIL;
  10138. char message[4096]={0};
  10139. json_object *SetVariableMonitoring = json_object_new_object();
  10140. json_object *setMonitoringResults = json_object_new_array();
  10141. DEBUG_INFO("sendSetVariableMonitoringConfirmation...\n");
  10142. for(int idx=0;idx<variableQuantity;idx++)
  10143. {
  10144. json_object *variableMonitorResult = json_object_new_object();
  10145. json_object *component = json_object_new_object();
  10146. json_object *variable = json_object_new_object();
  10147. json_object *evse = json_object_new_object();
  10148. json_object_object_add(variableMonitorResult, "id", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].id));
  10149. json_object_object_add(variableMonitorResult, "type", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type));
  10150. json_object_object_add(variableMonitorResult, "severity", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].severity));
  10151. json_object_object_add(variableMonitorResult, "status", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status));
  10152. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.id));
  10153. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.connectorId));
  10154. json_object_object_add(component, "component", evse);
  10155. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.name));
  10156. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.instance));
  10157. json_object_object_add(variableMonitorResult, "component", component);
  10158. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.name));
  10159. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.instance));
  10160. json_object_object_add(variableMonitorResult, "variable", variable);
  10161. json_object_array_add(setMonitoringResults, variableMonitorResult);
  10162. }
  10163. json_object_object_add(SetVariableMonitoring , "setMonitoringResult", setMonitoringResults);
  10164. sprintf(message,"[%d,\"%s\",%s]"
  10165. ,MESSAGE_TYPE_CALLRESULT
  10166. ,uuid
  10167. ,json_object_to_json_string_ext(SetVariableMonitoring, JSON_C_TO_STRING_PLAIN));
  10168. json_object_put(SetVariableMonitoring);
  10169. LWS_Send(message);
  10170. result = TRUE;
  10171. return result;
  10172. }
  10173. int sendSetVariableConfirmation(char *uuid, unsigned char variableQuantity)
  10174. {
  10175. mtrace();
  10176. int result = FAIL;
  10177. char message[4096]={0};
  10178. json_object *SetVariable = json_object_new_object();
  10179. json_object *setVariableResults = json_object_new_array();
  10180. DEBUG_INFO("sendSetVariableConfirmation...\n");
  10181. for(int idx=0;idx<variableQuantity;idx++)
  10182. {
  10183. json_object *variableResult = json_object_new_object();
  10184. json_object *component = json_object_new_object();
  10185. json_object *variable = json_object_new_object();
  10186. json_object *evse = json_object_new_object();
  10187. json_object_object_add(variableResult, "attributeType", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType));
  10188. json_object_object_add(variableResult, "attributeStatus", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus));
  10189. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.id));
  10190. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.connectorId));
  10191. json_object_object_add(component, "evse", evse);
  10192. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.name));
  10193. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.instance));
  10194. json_object_object_add(variableResult, "component", component);
  10195. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.name));
  10196. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.instance));
  10197. json_object_object_add(variableResult, "variable", variable);
  10198. json_object_array_add(setVariableResults, variableResult);
  10199. }
  10200. json_object_object_add(SetVariable , "setVariableResult", setVariableResults);
  10201. sprintf(message,"[%d,\"%s\",%s]"
  10202. ,MESSAGE_TYPE_CALLRESULT
  10203. ,uuid
  10204. ,json_object_to_json_string_ext(SetVariable, JSON_C_TO_STRING_PLAIN));
  10205. json_object_put(SetVariable);
  10206. LWS_Send(message);
  10207. result = TRUE;
  10208. return result;
  10209. }
  10210. int sendTriggerMessageConfirmation(char *uuid)
  10211. {
  10212. mtrace();
  10213. int result = FAIL;
  10214. char message[4096]={0};
  10215. json_object *TriggerMessage = json_object_new_object();
  10216. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  10217. json_object_object_add(TriggerMessage, "status", json_object_new_string((char*)ShmOCPP20Data->TriggerMessage.Response_status));
  10218. sprintf(message,"[%d,\"%s\",%s]",
  10219. MESSAGE_TYPE_CALLRESULT,
  10220. uuid,
  10221. json_object_to_json_string_ext(TriggerMessage, JSON_C_TO_STRING_PLAIN));
  10222. json_object_put(TriggerMessage);
  10223. LWS_Send(message);
  10224. result = TRUE;
  10225. return result;
  10226. }
  10227. int sendUnlockConnectorConfirmation(char *uuid, unsigned char gun_index)
  10228. {
  10229. mtrace();
  10230. int result = FAIL;
  10231. char message[4096]={0};
  10232. json_object *UnlockConnector = json_object_new_object();
  10233. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  10234. json_object_object_add(UnlockConnector, "status", json_object_new_string((char*)ShmOCPP20Data->UnlockConnector[gun_index].Response_status));
  10235. sprintf(message,"[%d,\"%s\",%s]",
  10236. MESSAGE_TYPE_CALLRESULT,
  10237. uuid,
  10238. json_object_to_json_string_ext(UnlockConnector, JSON_C_TO_STRING_PLAIN));
  10239. json_object_put(UnlockConnector);
  10240. LWS_Send(message);
  10241. result = TRUE;
  10242. ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf = OFF;
  10243. return result;
  10244. }
  10245. int sendUnpublishFirmwareConfirmation(char *uuid)
  10246. {
  10247. mtrace();
  10248. int result = FAIL;
  10249. char message[4096]={0};
  10250. json_object *UnpublishFirmware = json_object_new_object();
  10251. DEBUG_INFO("sendUnpublishFirmwareConfirmation...\n");
  10252. json_object_object_add(UnpublishFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->UnpublishFirmware.Response_status));
  10253. sprintf(message,"[%d,\"%s\",%s]"
  10254. ,MESSAGE_TYPE_CALLRESULT
  10255. ,uuid
  10256. ,json_object_to_json_string_ext(UnpublishFirmware, JSON_C_TO_STRING_PLAIN));
  10257. json_object_put(UnpublishFirmware);
  10258. LWS_Send(message);
  10259. result = TRUE;
  10260. return result;
  10261. }
  10262. int sendUpdateFirmwareConfirmation(char *uuid)
  10263. {
  10264. mtrace();
  10265. int result = FAIL;
  10266. char message[4096]={0};
  10267. json_object *UpdateFirmware = json_object_new_object();
  10268. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  10269. sprintf((char*)ShmOCPP20Data->UpdateFirmware.Response_status, "%s", UpdateFirmwareStatusEnumTypeStr[UpdateFirmwareStatusEnumType_Accepted]);
  10270. json_object_object_add(UpdateFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->UpdateFirmware.Response_status));
  10271. sprintf(message,"[%d,\"%s\",%s]"
  10272. ,MESSAGE_TYPE_CALLRESULT
  10273. ,uuid
  10274. ,json_object_to_json_string_ext(UpdateFirmware, JSON_C_TO_STRING_PLAIN));
  10275. json_object_put(UpdateFirmware);
  10276. LWS_Send(message);
  10277. result = TRUE;
  10278. return result;
  10279. }
  10280. int sendUnknownConfirmation(char *uuid)
  10281. {
  10282. mtrace();
  10283. int result = FAIL;
  10284. char message[256]={0};
  10285. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  10286. DEBUG_INFO("sendUnknownConfirmation...\n");
  10287. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  10288. LWS_Send(message);
  10289. result = TRUE;
  10290. return result;
  10291. }
  10292. //==========================================
  10293. // send CallError routine
  10294. //==========================================
  10295. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  10296. {
  10297. mtrace();
  10298. char message[220]={0};
  10299. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  10300. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  10301. LWS_Send(message);
  10302. }
  10303. //==========================================
  10304. // Handle server request routine Start
  10305. //==========================================
  10306. int handleCancelReservationRequest(char *uuid, char *payload)
  10307. {
  10308. mtrace();
  10309. int result = FAIL;
  10310. int gunNO = 0;
  10311. int reservationIdInt = -1;
  10312. DEBUG_INFO("handleCancelReservationRequest...\n");
  10313. json_object *CancelReservation;
  10314. CancelReservation = json_tokener_parse(payload);
  10315. if(!is_error(CancelReservation))
  10316. {
  10317. // Required data
  10318. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  10319. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  10320. }
  10321. json_object_put(CancelReservation);
  10322. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  10323. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->CancelReservation);idx++)
  10324. sprintf((char*)ShmOCPP20Data->CancelReservation[idx].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Rejected]);
  10325. if(reservationIdInt != -1)
  10326. {
  10327. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  10328. //check Transaction active
  10329. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  10330. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10331. {
  10332. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  10333. {
  10334. sprintf((char*)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  10335. if(gunType[2] == GUN_TYPE_CHAdeMO)
  10336. {
  10337. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  10338. }
  10339. else
  10340. {
  10341. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  10342. }
  10343. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  10344. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  10345. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  10346. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  10347. goto end;
  10348. }
  10349. }
  10350. for (int index = 0; index < CCS_QUANTITY; index++)
  10351. {
  10352. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  10353. {
  10354. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  10355. if(gunType[2] == GUN_TYPE_CCS)
  10356. {
  10357. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  10358. }
  10359. else
  10360. {
  10361. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  10362. }
  10363. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  10364. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  10365. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  10366. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  10367. goto end;
  10368. }
  10369. }
  10370. for (int index = 0; index < GB_QUANTITY; index++)
  10371. {
  10372. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  10373. {
  10374. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  10375. if(gunType[2] == GUN_TYPE_GBT)
  10376. {
  10377. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  10378. }
  10379. else
  10380. {
  10381. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  10382. }
  10383. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  10384. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  10385. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  10386. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  10387. goto end;
  10388. }
  10389. }
  10390. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10391. {
  10392. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  10393. {
  10394. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  10395. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  10396. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  10397. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  10398. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  10399. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  10400. goto end;
  10401. }
  10402. }
  10403. for (int index = 0; index < AC_QUANTITY; index++)
  10404. {
  10405. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  10406. {
  10407. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  10408. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10409. {
  10410. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  10411. }
  10412. else
  10413. {
  10414. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  10415. }
  10416. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  10417. ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationId = reservationIdInt;
  10418. sprintf((char*)ShmOCPP20Data->ReservationStatusUpdate[gunNO].reservationUpdateStatus, ReservationUpdateStatusEnumTypeStr[ReservationUpdateStatusEnumType_Removed]);
  10419. ShmOCPP20Data->CpMsg.bits[gunNO].ReservationStatusUpdateReq = ON;
  10420. goto end;
  10421. }
  10422. }
  10423. }
  10424. //The reservationId does NOT match the reservationId
  10425. sendCancelReservationConfirmation(uuid, gunNO);
  10426. end:
  10427. // Fill in ocpp packet uuid
  10428. strcpy((char *)ShmOCPP20Data->CancelReservation[gunNO].guid, uuid);
  10429. return result;
  10430. }
  10431. int handleCertificateSignedRequest(char *uuid, char *payload)
  10432. {
  10433. mtrace();
  10434. int result = FAIL;
  10435. json_object *CertificateSigned;
  10436. DEBUG_INFO("handleCertificateSignedRequest...\n");
  10437. CertificateSigned = json_tokener_parse(payload);
  10438. if(!is_error(CertificateSigned))
  10439. {
  10440. memset(&ShmOCPP20Data->CertificateSigned, 0, sizeof(struct CertificateSigned_20));
  10441. memcpy(&ShmOCPP20Data->CertificateSigned.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->CertificateSigned.guid));
  10442. // Required data
  10443. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  10444. // Optional data
  10445. if(json_object_object_get(CertificateSigned, "certificateType") != NULL)
  10446. {
  10447. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateType, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateType")));
  10448. if(strcmp((char*)ShmOCPP20Data->CertificateSigned.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_ChargingStationCertificate]) == 0)
  10449. {
  10450. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  10451. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  10452. fclose(fp);
  10453. }
  10454. else if(strcmp((char*)ShmOCPP20Data->CertificateSigned.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0)
  10455. {
  10456. FILE *fp = fopen("/Storage/OCPP/certV2G.crt", "w");
  10457. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  10458. fclose(fp);
  10459. }
  10460. }
  10461. else
  10462. {
  10463. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  10464. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  10465. fclose(fp);
  10466. fp = fopen("/Storage/OCPP/certV2G.crt", "w");
  10467. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  10468. fclose(fp);
  10469. }
  10470. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10471. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Accepted]);
  10472. }
  10473. else
  10474. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Rejected]);
  10475. json_object_put(CertificateSigned);
  10476. sendCertificateSignedConfirmation(uuid);
  10477. return result;
  10478. }
  10479. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  10480. {
  10481. mtrace();
  10482. int result = FAIL;
  10483. int evseId = 0, gunIndex = 0;
  10484. char operationalStatus[16]={0};
  10485. char comfirmstr[20];
  10486. int specificId = FALSE;
  10487. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  10488. json_object *ChangeAvailability;
  10489. ChangeAvailability = json_tokener_parse(payload);
  10490. if(!is_error(ChangeAvailability))
  10491. {
  10492. // Required data
  10493. if(json_object_object_get(ChangeAvailability, "operationalStatus") != NULL)
  10494. sprintf((char*)operationalStatus, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "operationalStatus")));
  10495. if(json_object_object_get(ChangeAvailability, "evse") != NULL)
  10496. {
  10497. evseId = json_object_get_int(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "id"));
  10498. if(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "connectorId") != NULL)
  10499. gunIndex = json_object_get_int(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "connectorId"));
  10500. }
  10501. }
  10502. json_object_put(ChangeAvailability);
  10503. if((evseId != 0) && (evseId <= gunTotalNumber))
  10504. {
  10505. ShmOCPP20Data->ChangeAvailability[evseId - 1].evse.connectorId = evseId;
  10506. sprintf((char *)ShmOCPP20Data->ChangeAvailability[evseId - 1].operationalStatus, "%s", operationalStatus);
  10507. }
  10508. else if(evseId == 0)
  10509. {
  10510. for(int i=0; i < gunTotalNumber; i++)
  10511. {
  10512. ShmOCPP20Data->ChangeAvailability[i].evse.connectorId = evseId;
  10513. sprintf((char *)ShmOCPP20Data->ChangeAvailability[i].operationalStatus, "%s", operationalStatus);
  10514. }
  10515. }
  10516. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  10517. {
  10518. ShmOCPP20Data->ChangeAvailability[gunIndex - 1].evse.connectorId = gunIndex;
  10519. sprintf((char *)ShmOCPP20Data->ChangeAvailability[gunIndex - 1].operationalStatus, "%s", operationalStatus);
  10520. }
  10521. else if(gunIndex == 0)
  10522. {
  10523. for(int i=0; i < gunTotalNumber; i++)
  10524. {
  10525. ShmOCPP20Data->ChangeAvailability[i].evse.connectorId = gunIndex;
  10526. sprintf((char *)ShmOCPP20Data->ChangeAvailability[i].operationalStatus, "%s", operationalStatus);
  10527. }
  10528. }
  10529. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  10530. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10531. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  10532. {
  10533. specificId = TRUE;
  10534. }
  10535. if(specificId == FALSE)
  10536. goto end;
  10537. if(strcmp((const char *)operationalStatus, OperationalStatusEnumTypeStr[OperationalStatusEnumType_Inoperative]) == 0)
  10538. {
  10539. //----------------------gunIndex is 0 ------------------------------------------------//
  10540. if(gunIndex == 0)
  10541. {
  10542. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10543. {
  10544. for(int i=0; i < gunTotalNumber; i++)
  10545. {
  10546. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10547. {
  10548. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  10549. {
  10550. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  10551. {
  10552. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10553. goto end;
  10554. }
  10555. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  10556. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  10557. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10558. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  10559. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  10560. {
  10561. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  10562. goto end;
  10563. }
  10564. }
  10565. }//END FOR CHAdeMO_QUANTITY
  10566. for (int index = 0; index < CCS_QUANTITY; index++)
  10567. {
  10568. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  10569. {
  10570. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  10571. {
  10572. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10573. goto end;
  10574. }
  10575. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  10576. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  10577. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10578. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  10579. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  10580. {
  10581. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  10582. goto end;
  10583. }
  10584. }
  10585. }//END FOR CCS_QUANTITY
  10586. for (int index = 0; index < GB_QUANTITY; index++)
  10587. {
  10588. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  10589. {
  10590. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  10591. {
  10592. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10593. goto end;
  10594. }
  10595. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  10596. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  10597. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10598. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  10599. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  10600. {
  10601. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  10602. goto end;
  10603. }
  10604. }
  10605. }// END FOR GB_QUANTITY
  10606. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10607. {
  10608. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  10609. {
  10610. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  10611. {
  10612. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10613. goto end;
  10614. }
  10615. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  10616. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  10617. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  10618. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  10619. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  10620. {
  10621. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  10622. goto end;
  10623. }
  10624. }
  10625. }// END FOR DO_QUANTITY
  10626. for (int index = 0; index < AC_QUANTITY; index++)
  10627. {
  10628. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  10629. {
  10630. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  10631. {
  10632. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10633. goto end;
  10634. }
  10635. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  10636. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  10637. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10638. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  10639. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  10640. {
  10641. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  10642. goto end;
  10643. }
  10644. }
  10645. }//END FOR AC_QUANTITY
  10646. }// END FOR gunTotalNumber
  10647. }
  10648. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  10649. {
  10650. for(int i=0; i < gunTotalNumber; i++)
  10651. {
  10652. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  10653. {
  10654. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10655. goto end;
  10656. }
  10657. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  10658. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  10659. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  10660. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  10661. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  10662. {
  10663. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  10664. goto end;
  10665. }
  10666. }
  10667. }
  10668. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  10669. goto end;
  10670. }
  10671. //----------------------gunIndex is not 0 ------------------------------------------------//
  10672. //check Transaction active
  10673. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10674. {
  10675. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  10676. {
  10677. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  10678. {
  10679. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10680. goto end;
  10681. }
  10682. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  10683. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  10684. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10685. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  10686. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  10687. {
  10688. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  10689. goto end;
  10690. }
  10691. else
  10692. {
  10693. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  10694. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  10695. goto end;
  10696. }
  10697. }
  10698. }//END FOR CHAdeMO_QUANTITY
  10699. for (int index = 0; index < CCS_QUANTITY; index++)
  10700. {
  10701. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  10702. {
  10703. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  10704. {
  10705. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10706. goto end;
  10707. }
  10708. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  10709. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  10710. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10711. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  10712. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  10713. {
  10714. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  10715. goto end;
  10716. }
  10717. else
  10718. {
  10719. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  10720. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  10721. goto end;
  10722. }
  10723. }
  10724. }//END FOR CCS_QUANTITY
  10725. for (int index = 0; index < GB_QUANTITY; index++)
  10726. {
  10727. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  10728. {
  10729. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  10730. {
  10731. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10732. goto end;
  10733. }
  10734. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  10735. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  10736. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10737. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  10738. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  10739. {
  10740. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  10741. goto end;
  10742. }
  10743. else
  10744. {
  10745. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  10746. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  10747. goto end;
  10748. }
  10749. }
  10750. }// END FOR GB_QUANTITY
  10751. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10752. {
  10753. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  10754. {
  10755. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  10756. {
  10757. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10758. goto end;
  10759. }
  10760. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  10761. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  10762. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  10763. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  10764. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  10765. {
  10766. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  10767. goto end;
  10768. }
  10769. else
  10770. {
  10771. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  10772. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  10773. goto end;
  10774. }
  10775. }
  10776. }// END FOR DO_QUANTITY
  10777. for (int index = 0; index < AC_QUANTITY; index++)
  10778. {
  10779. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC))
  10780. {
  10781. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  10782. {
  10783. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10784. goto end;
  10785. }
  10786. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  10787. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  10788. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  10789. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  10790. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  10791. {
  10792. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  10793. goto end;
  10794. }
  10795. else
  10796. {
  10797. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  10798. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  10799. goto end;
  10800. }
  10801. }
  10802. }//END FOR AC_QUANTITY
  10803. }//END FOR AvailabilityEnumTypeStr[Inoperative]
  10804. if(strcmp((const char *)operationalStatus, OperationalStatusEnumTypeStr[OperationalStatusEnumType_Operative]) == 0)
  10805. {
  10806. //----------------------gunIndex is 0 ------------------------------------------------//
  10807. if(gunIndex == 0)
  10808. {
  10809. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  10810. {
  10811. for(int i=0; i < gunTotalNumber; i++)
  10812. {
  10813. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10814. {
  10815. 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
  10816. {
  10817. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10818. goto end;
  10819. }
  10820. }//END FOR CHAdeMO_QUANTITY
  10821. for (int index = 0; index < CCS_QUANTITY; index++)
  10822. {
  10823. 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
  10824. {
  10825. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10826. goto end;
  10827. }
  10828. }//END FOR CCS_QUANTITY
  10829. for (int index = 0; index < GB_QUANTITY; index++)
  10830. {
  10831. 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
  10832. {
  10833. //ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  10834. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10835. goto end;
  10836. }
  10837. }// END FOR GB_QUANTITY
  10838. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10839. {
  10840. 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
  10841. {
  10842. //ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  10843. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10844. goto end;
  10845. }
  10846. }// END FOR DO_QUANTITY
  10847. for (int index = 0; index < AC_QUANTITY; index++)
  10848. {
  10849. 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
  10850. {
  10851. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10852. goto end;
  10853. }
  10854. }//END FOR CHAdeMO_QUANTITY
  10855. }// END FOR gunTotalNumber
  10856. }
  10857. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  10858. {
  10859. for(int i=0; i < gunTotalNumber; i++)
  10860. {
  10861. for (int index = 0; index < AC_QUANTITY; index++)
  10862. {
  10863. 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
  10864. {
  10865. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10866. goto end;
  10867. }
  10868. }//END FOR CHAdeMO_QUANTITY
  10869. } // END FOR gunTotalNumber
  10870. }
  10871. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  10872. goto end;
  10873. }
  10874. //----------------------gunIndex is not 0 ------------------------------------------------//
  10875. //check Transaction active
  10876. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10877. {
  10878. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  10879. {
  10880. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  10881. goto end;
  10882. }
  10883. }//END FOR CHAdeMO_QUANTITY
  10884. for (int index = 0; index < CCS_QUANTITY; index++)
  10885. {
  10886. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  10887. {
  10888. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  10889. goto end;
  10890. }
  10891. }//END FOR CCS_QUANTITY
  10892. for (int index = 0; index < GB_QUANTITY; index++)
  10893. {
  10894. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  10895. {
  10896. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  10897. goto end;
  10898. }
  10899. }// END FOR GB_QUANTITY
  10900. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10901. {
  10902. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  10903. {
  10904. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  10905. goto end;
  10906. }
  10907. }// END FOR DO_QUANTITY
  10908. for (int index = 0; index < AC_QUANTITY; index++)
  10909. {
  10910. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  10911. {
  10912. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  10913. goto end;
  10914. }
  10915. }//END FOR AC_QUANTITY
  10916. }//END FOR AvailabilityEnumTypeStr[Operative]
  10917. end:
  10918. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  10919. {
  10920. sprintf((char *)ShmOCPP20Data->ChangeAvailability[gunIndex - 1].Response_status, "%s", comfirmstr );
  10921. }
  10922. else
  10923. {
  10924. sprintf((char *)ShmOCPP20Data->ChangeAvailability[0].Response_status, "%s", comfirmstr );
  10925. }
  10926. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  10927. {
  10928. if(strstr(comfirmstr, ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected]) == NULL)
  10929. ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  10930. }
  10931. else if(gunIndex == 0)
  10932. {
  10933. if(strstr(comfirmstr, ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected]) == NULL)
  10934. {
  10935. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  10936. ShmOCPP20Data->CsMsg.bits[i].ChangeAvailabilityReq = ON;
  10937. }
  10938. }
  10939. sendChangeAvailabilityConfirmation(uuid, (gunIndex==0?gunIndex:gunIndex-1));
  10940. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10941. return result;
  10942. }
  10943. int handleClearCacheRequest(char *uuid, char *payload)
  10944. {
  10945. mtrace();
  10946. int result = FAIL;
  10947. char rmFileCmd[100]={0};
  10948. struct stat stats;
  10949. DEBUG_INFO("handleClearCacheRequest...\n");
  10950. stat("/Storage/OCPP", &stats);
  10951. // Check for directory existence
  10952. if (S_ISDIR(stats.st_mode) == 1)
  10953. {}
  10954. else
  10955. {
  10956. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  10957. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  10958. system(rmFileCmd);
  10959. }
  10960. if(DB_cleanLocalCache() != PASS)
  10961. {
  10962. DEBUG_INFO("open AuthorizationCache file failed\n");
  10963. sprintf((char*)ShmOCPP20Data->ClearCache.Response_status, "%s", ClearCacheStatusEnumTypeStr[ClearCacheStatusEnumType_Rejected] );
  10964. }
  10965. else
  10966. {
  10967. DEBUG_INFO("open AuthorizationCache file successful\n");
  10968. sprintf((char*)ShmOCPP20Data->ClearCache.Response_status, "%s", ClearCacheStatusEnumTypeStr[ClearCacheStatusEnumType_Accepted] );
  10969. }
  10970. sendClearCacheConfirmation(uuid);
  10971. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10972. return result;
  10973. }
  10974. int handleClearChargingProfileRequest(char *uuid, char *payload)
  10975. {
  10976. mtrace();
  10977. int result = FAIL;
  10978. int resultRename;
  10979. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  10980. char chargingProfilePurposeStr[26]={0};
  10981. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  10982. char tempchargingProfilePurposeStr[26]={0};
  10983. char sstr[160]={0};
  10984. char str[100]={0};
  10985. int c = 0;
  10986. char *loc;
  10987. char fname[200]={0};
  10988. char comfirmstr[20]={0};
  10989. char word[1600]={0};
  10990. int clearflag = FALSE;
  10991. int chargingProfileIdIsNULL = FALSE;
  10992. int connectorIsNULL = FALSE;
  10993. int chargingProfilePurposeIsNULL = FALSE;
  10994. int stackLevelIsNULL = FALSE;
  10995. //int GotoEnd = FALSE;
  10996. FILE *fptr1, *fptr2;
  10997. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  10998. int n_chargingProfile=0;
  10999. int isEmptyFile = FALSE;
  11000. char sLineWord[1600]={0};
  11001. char chargingProfiles[10][100]={0};
  11002. int ChargeProfileCount = 0;
  11003. int ch;
  11004. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  11005. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  11006. json_object *ClearChargingProfile;
  11007. ClearChargingProfile = json_tokener_parse(payload);
  11008. if(!is_error(ClearChargingProfile))
  11009. {
  11010. // Optional data
  11011. if(json_object_object_get(ClearChargingProfile, "chargingProfileId") != NULL)
  11012. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "chargingProfileId"));
  11013. else
  11014. chargingProfileIdIsNULL = TRUE;
  11015. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "evseId") != NULL)
  11016. connectorIdInt = json_object_get_int(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "evseId"));
  11017. else
  11018. connectorIsNULL = TRUE;
  11019. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "chargingProfilePurpose") != NULL)
  11020. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "chargingProfilePurpose")));
  11021. else
  11022. chargingProfilePurposeIsNULL = TRUE;
  11023. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "stackLevel") != NULL)
  11024. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "stackLevel"));
  11025. else
  11026. stackLevelIsNULL = TRUE;
  11027. }
  11028. json_object_put(ClearChargingProfile);
  11029. if(connectorIsNULL == FALSE)
  11030. {
  11031. switch(connectorIdInt)
  11032. {
  11033. case 0:
  11034. if(chargingProfilePurposeIsNULL == TRUE)
  11035. {
  11036. int l = 0;
  11037. strcpy(fname, ChargePointMaxProfile_JSON);
  11038. if((access(fname,F_OK))!=-1)
  11039. {
  11040. strcpy(chargingProfiles[l], fname);
  11041. l = l + 1;
  11042. }
  11043. strcpy(fname, TxDefaultProfile_0_JSON);
  11044. if((access(fname,F_OK))!=-1)
  11045. {
  11046. strcpy(chargingProfiles[l], fname);
  11047. l = l + 1;
  11048. }
  11049. ChargeProfileCount = l;
  11050. }
  11051. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  11052. {
  11053. strcpy(fname, ChargePointMaxProfile_JSON);
  11054. if((access(fname,F_OK))!=-1)
  11055. {
  11056. strcpy(chargingProfiles[0], fname);
  11057. ChargeProfileCount = 1;
  11058. }
  11059. }
  11060. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  11061. {
  11062. strcpy(fname, TxDefaultProfile_0_JSON);
  11063. if((access(fname,F_OK))!=-1)
  11064. {
  11065. strcpy(chargingProfiles[0], fname);
  11066. ChargeProfileCount = 1;
  11067. }
  11068. }
  11069. break;
  11070. default:
  11071. if(chargingProfilePurposeIsNULL == TRUE)
  11072. {
  11073. int m = 0;
  11074. memset(fname, 0, ARRAY_SIZE(fname));
  11075. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", connectorIdInt);
  11076. if((access(fname,F_OK))!=-1)
  11077. {
  11078. strcpy(chargingProfiles[m], fname);
  11079. m = m + 1;
  11080. }
  11081. memset(fname, 0, ARRAY_SIZE(fname));
  11082. sprintf(fname, "/Storage/OCPP/TxProfile_%d_OCPP20.json", connectorIdInt);
  11083. if((access(fname,F_OK))!=-1)
  11084. {
  11085. strcpy(chargingProfiles[m], fname);
  11086. m = m + 1;
  11087. }
  11088. ChargeProfileCount = m;
  11089. }
  11090. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  11091. {
  11092. //strcpy(fname, TxDefaultProfile_1_JSON);
  11093. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", connectorIdInt);
  11094. if((access(fname,F_OK))!=-1)
  11095. {
  11096. strcpy(chargingProfiles[0], fname);
  11097. ChargeProfileCount = 1;
  11098. }
  11099. }
  11100. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  11101. {
  11102. sprintf(fname, "/Storage/OCPP/TxProfile_%d_OCPP20.json", connectorIdInt);
  11103. if((access(fname,F_OK))!=-1)
  11104. {
  11105. strcpy(chargingProfiles[0], fname);
  11106. ChargeProfileCount = 1;
  11107. }
  11108. }
  11109. //strcpy(fname, ChargePointMaxProfile_JSON );
  11110. break;
  11111. }
  11112. }
  11113. else // Check all Charging Profiles
  11114. {
  11115. int i = 0;
  11116. char fnametemp[200]={0};
  11117. ChargeProfileCount = 0;
  11118. //Check ChargePointMaxProfile.json exit
  11119. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  11120. {
  11121. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  11122. i = i + 1;
  11123. }
  11124. //Check TxDefaultProfile_%d.json
  11125. for(int j=1; j <= gunTotalNumber; j++)
  11126. {
  11127. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11128. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", j);
  11129. if((access(fnametemp,F_OK))!=-1)
  11130. {
  11131. strcpy(chargingProfiles[i], fnametemp);
  11132. i = i + 1;
  11133. }
  11134. }
  11135. //Check TxProfile_%d.json
  11136. for(int j=1; j <= gunTotalNumber; j++)
  11137. {
  11138. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  11139. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d_OCPP20.json", j);
  11140. if((access(fnametemp,F_OK))!=-1)
  11141. {
  11142. strcpy(chargingProfiles[i], fnametemp);
  11143. i = i + 1;
  11144. }
  11145. }
  11146. ChargeProfileCount = i;
  11147. }// End connectorIsNULL is TRUE
  11148. if(ChargeProfileCount == 0)
  11149. {
  11150. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  11151. goto end;
  11152. }
  11153. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  11154. {
  11155. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  11156. goto end;
  11157. }
  11158. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  11159. {
  11160. memset(str, 0, ARRAY_SIZE(str));
  11161. // clear temp file
  11162. sprintf(str,"rm -f %s",temp);
  11163. system(str);
  11164. for(int k=0; k < ChargeProfileCount; k++)
  11165. {
  11166. memset(str, 0, ARRAY_SIZE(str));
  11167. //clear file in C
  11168. sprintf(str,"rm -f %s",chargingProfiles[k]);
  11169. system(str);
  11170. }
  11171. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  11172. goto end;
  11173. }
  11174. else if(connectorIsNULL == TRUE)
  11175. {
  11176. for(int k=0; k < ChargeProfileCount; k++)
  11177. {
  11178. fptr1 = fopen(chargingProfiles[k], "r");
  11179. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  11180. //Check Charging Profile Count
  11181. while(fscanf(fptr1, "%s", word) != EOF)
  11182. {
  11183. //DEBUG_INFO("word=%s\n",word);
  11184. if(strstr(word, "id")!= NULL)
  11185. {
  11186. //DEBUG_INFO("test id \n");
  11187. n_chargingProfile = n_chargingProfile + 1;
  11188. //DEBUG_INFO("id Found\n");
  11189. }
  11190. }
  11191. rewind(fptr1);
  11192. //search Charging Profile Element
  11193. //int i= 0;
  11194. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  11195. {
  11196. //------------------------tempconnectorIdInt------------------------//
  11197. loc = strstr(sLineWord, "connectorId");
  11198. c = 0;
  11199. memset(sstr ,0, sizeof(sstr) );
  11200. while (loc[strlen("connectorId")+2+c] != ',')
  11201. {
  11202. sstr[c] = loc[strlen("connectorId")+2+c];
  11203. c++;
  11204. }
  11205. sstr[c] = '\0';
  11206. tempconnectorIdInt = atoi(sstr);
  11207. printf("file's gun number is %d\n", tempconnectorIdInt);
  11208. //--------------------------id--------------------//
  11209. c = 0;
  11210. loc = strstr(sLineWord, "id");
  11211. memset(sstr ,0, ARRAY_SIZE(sstr));
  11212. while (loc[strlen("id")+2+c] != ',')
  11213. {
  11214. sstr[c] = loc[strlen("id")+2+c];
  11215. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11216. c++;
  11217. }
  11218. sstr[c] = '\0';
  11219. tempchargingProfileIdInt = atoi(sstr);
  11220. //stackLevel
  11221. c = 0;
  11222. loc = strstr(sLineWord, "stackLevel");
  11223. memset(sstr ,0, ARRAY_SIZE(sstr));
  11224. while (loc[strlen("stackLevel")+2+c] != ',')
  11225. {
  11226. sstr[c] = loc[strlen("stackLevel")+2+c];
  11227. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11228. c++;
  11229. }
  11230. sstr[c] = '\0';
  11231. tempstackLevelInt = atoi(sstr);
  11232. c = 0;
  11233. loc = strstr(sLineWord, "chargingProfilePurpose");
  11234. memset(sstr ,0, ARRAY_SIZE(sstr));
  11235. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  11236. {
  11237. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  11238. c++;
  11239. }
  11240. sstr[c] = '\0';
  11241. strcpy(tempchargingProfilePurposeStr, sstr);
  11242. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  11243. {
  11244. //------- not write to fptr2-------//
  11245. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  11246. //clearflag = TRUE;
  11247. }
  11248. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  11249. {
  11250. //------- not write to fptr2-------//
  11251. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  11252. }
  11253. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  11254. {
  11255. //------- not write to fptr2-------//
  11256. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  11257. }
  11258. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  11259. {
  11260. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  11261. }
  11262. else
  11263. {
  11264. fprintf(fptr2, sLineWord);//writing data into file
  11265. }
  11266. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  11267. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  11268. if(clearflag == TRUE)
  11269. {
  11270. fclose(fptr1);
  11271. fclose(fptr2);
  11272. sprintf(str,"rm -f %s",chargingProfiles[k]);
  11273. system(str);
  11274. // clear temp file
  11275. sprintf(str,"rm -f %s",temp);
  11276. system(str);
  11277. }
  11278. else
  11279. {
  11280. fclose(fptr1);
  11281. fclose(fptr2);
  11282. memset(str, 0, ARRAY_SIZE(str));
  11283. sprintf(str,"rm -f %s",chargingProfiles[k]);
  11284. system(str);
  11285. resultRename = rename(temp, chargingProfiles[k]);
  11286. if(resultRename == 0)
  11287. {
  11288. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  11289. }
  11290. else
  11291. {
  11292. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  11293. }
  11294. if(comfirmstr[0]== 0)
  11295. {
  11296. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  11297. }
  11298. //Check chargingProfile is empty file
  11299. /*------ Read the file ----------------*/
  11300. fptr1=fopen(chargingProfiles[k],"r");
  11301. ch=fgetc(fptr1);
  11302. rewind(fptr1);
  11303. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  11304. if(ch!=EOF)
  11305. {
  11306. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  11307. {
  11308. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  11309. if(sLineWord[0]=='\0')
  11310. {
  11311. isEmptyFile = TRUE;
  11312. break;
  11313. }
  11314. else
  11315. {
  11316. isEmptyFile = FALSE;
  11317. break;
  11318. }
  11319. }
  11320. }
  11321. else
  11322. isEmptyFile = TRUE;
  11323. fclose(fptr1);
  11324. if(isEmptyFile == TRUE)
  11325. {
  11326. memset(str, 0, ARRAY_SIZE(str));
  11327. sprintf(str,"rm -f %s",chargingProfiles[k]);
  11328. system(str);
  11329. }
  11330. }
  11331. }// End of while(int k=0; k < ChargePointCount; k++)
  11332. }
  11333. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  11334. {
  11335. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  11336. for(int k=0; k < ChargeProfileCount; k++)
  11337. {
  11338. fptr1 = fopen(chargingProfiles[k], "r");
  11339. fptr2 = fopen(temp, "w+");
  11340. //Check Charging Profile Count
  11341. while(fscanf(fptr1, "%s", word) != EOF)
  11342. {
  11343. //DEBUG_INFO("word=%s\n",word);
  11344. if(strstr(word, "id")!= NULL)
  11345. {
  11346. n_chargingProfile = n_chargingProfile + 1;
  11347. }
  11348. }
  11349. rewind(fptr1);
  11350. //search Charging Profile Element
  11351. //int i= 0;
  11352. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  11353. {
  11354. //*************************tempconnectorIdInt*********************************/
  11355. loc = strstr(sLineWord, "connectorId");
  11356. c = 0;
  11357. memset(sstr ,0, ARRAY_SIZE(sstr));
  11358. while (loc[strlen("connectorId")+2+c] != ',')
  11359. {
  11360. sstr[c] = loc[strlen("connectorId")+2+c];
  11361. c++;
  11362. }
  11363. sstr[c] = '\0';
  11364. tempconnectorIdInt = atoi(sstr);
  11365. //id
  11366. c = 0;
  11367. loc = strstr(sLineWord, "id");
  11368. memset(sstr ,0, ARRAY_SIZE(sstr));
  11369. while (loc[strlen("id")+2+c] != ',')
  11370. {
  11371. sstr[c] = loc[strlen("id")+2+c];
  11372. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11373. c++;
  11374. }
  11375. sstr[c] = '\0';
  11376. tempchargingProfileIdInt = atoi(sstr);
  11377. //stackLevel
  11378. c = 0;
  11379. loc = strstr(sLineWord, "stackLevel");
  11380. memset(sstr ,0, ARRAY_SIZE(sstr));
  11381. while (loc[strlen("stackLevel")+2+c] != ',')
  11382. {
  11383. sstr[c] = loc[strlen("stackLevel")+2+c];
  11384. //printf("i=%d sstr=%c\n",c, sstr[c]);
  11385. c++;
  11386. }
  11387. sstr[c] = '\0';
  11388. tempstackLevelInt = atoi(sstr);
  11389. c = 0;
  11390. loc = strstr(sLineWord, "chargingProfilePurpose");
  11391. memset(sstr ,0, ARRAY_SIZE(sstr));
  11392. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  11393. {
  11394. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  11395. c++;
  11396. }
  11397. sstr[c] = '\0';
  11398. strcpy(tempchargingProfilePurposeStr, sstr);
  11399. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  11400. {
  11401. //------- not write to fptr2-------//
  11402. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  11403. //clearflag = TRUE;
  11404. }
  11405. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  11406. {
  11407. //------- not write to fptr2-------//
  11408. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  11409. }
  11410. else if(stackLevelIsNULL == TRUE)
  11411. {
  11412. //Clear Whole File
  11413. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  11414. clearflag = TRUE;
  11415. break;
  11416. }
  11417. else
  11418. {
  11419. fprintf(fptr2, sLineWord);//writing data into file
  11420. }
  11421. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  11422. }
  11423. if(clearflag == TRUE)
  11424. {
  11425. fclose(fptr1);
  11426. fclose(fptr2);
  11427. sprintf(str,"rm -f %s",chargingProfiles[k]);
  11428. system(str);
  11429. // clear temp file
  11430. sprintf(str,"rm -f %s",temp);
  11431. system(str);
  11432. }
  11433. else
  11434. {
  11435. fclose(fptr1);
  11436. fclose(fptr2);
  11437. sprintf(str,"rm -f %s",chargingProfiles[k]);
  11438. system(str);
  11439. resultRename = rename(temp, chargingProfiles[k]);
  11440. if(resultRename == 0)
  11441. {
  11442. DEBUG_INFO("File ChargingProfile renamed successfully");
  11443. }
  11444. else
  11445. {
  11446. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  11447. }
  11448. if(comfirmstr[0]== 0)
  11449. {
  11450. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  11451. }
  11452. //Check chargingProfile is empty file
  11453. /*------ Read the file ----------------*/
  11454. fptr1=fopen(chargingProfiles[k],"r");
  11455. ch=fgetc(fptr1);
  11456. rewind(fptr1);
  11457. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  11458. if(ch!=EOF)
  11459. {
  11460. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  11461. {
  11462. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  11463. if(sLineWord[0]=='\0')
  11464. {
  11465. isEmptyFile = TRUE;
  11466. break;
  11467. }
  11468. else
  11469. {
  11470. isEmptyFile = FALSE;
  11471. break;
  11472. }
  11473. }
  11474. }
  11475. else
  11476. isEmptyFile = TRUE;
  11477. fclose(fptr1);
  11478. if(isEmptyFile == TRUE)
  11479. {
  11480. memset(str, 0, ARRAY_SIZE(str));
  11481. sprintf(str,"rm -f %s",chargingProfiles[k]);
  11482. system(str);
  11483. }
  11484. /*------- End of reading ---------------*/
  11485. }
  11486. } // while(int k=0; k < ChargeProfileCount; k++)
  11487. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  11488. end:
  11489. if(strcmp(comfirmstr, ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted]) == 0)
  11490. {
  11491. if(connectorIdInt == 0)
  11492. {
  11493. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  11494. {
  11495. checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx], 0, TRUE);
  11496. }
  11497. }
  11498. else
  11499. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP20Data->SmartChargingProfile[connectorIdInt-1], 0, TRUE);
  11500. }
  11501. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  11502. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11503. return result;
  11504. }
  11505. int handleClearDisplayMessageRequest(char *uuid, char *payload)
  11506. {
  11507. mtrace();
  11508. int result = FAIL;
  11509. json_object *ClearDisplayMessage;
  11510. DEBUG_INFO("handleClearDisplayMessageRequest...\n");
  11511. sprintf((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status, ClearMessageStatusEnumTypeStr[ClearMessageStatusEnumType_Unknown]);
  11512. ClearDisplayMessage = json_tokener_parse(payload);
  11513. if(!is_error(ClearDisplayMessage))
  11514. {
  11515. // Required data
  11516. if(json_object_object_get(ClearDisplayMessage, "id") != NULL)
  11517. {
  11518. ShmOCPP20Data->ClearDisplayMessage.id = json_object_get_double(json_object_object_get(ClearDisplayMessage, "id"));
  11519. sprintf((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status, ClearMessageStatusEnumTypeStr[ClearMessageStatusEnumType_Accepted]);
  11520. }
  11521. }
  11522. json_object_put(ClearDisplayMessage);
  11523. sendCostUpdatedConfirmation(uuid);
  11524. return result;
  11525. }
  11526. int handleClearVariableMonitoringRequest(char *uuid, char *payload)
  11527. {
  11528. mtrace();
  11529. int result = FAIL;
  11530. json_object *ClearVariableMonitorin;
  11531. DEBUG_INFO("handleClearVariableMonitoringRequest...\n");
  11532. ClearVariableMonitorin = json_tokener_parse(payload);
  11533. if(!is_error(ClearVariableMonitorin))
  11534. {
  11535. // Required data
  11536. if(json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id")) <= ARRAY_SIZE(ShmOCPP20Data->ClearVariableMonitoring.id))
  11537. {
  11538. for(int idx=0;idx<json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id"));idx++)
  11539. {
  11540. ShmOCPP20Data->ClearVariableMonitoring.id[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(ClearVariableMonitorin, "id"), idx));
  11541. /*
  11542. * TODO:
  11543. * 1. Check response
  11544. */
  11545. ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].id = ShmOCPP20Data->ClearVariableMonitoring.id[idx];
  11546. strcpy((char*)ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].status, ClearMonitoringStatusEnumTypeStr[ClearMonitoringStatusEnumType_Accepted]);
  11547. }
  11548. sendClearVariableMonitoringConfirmation(uuid, json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id")));
  11549. }
  11550. }
  11551. json_object_put(ClearVariableMonitorin);
  11552. return result;
  11553. }
  11554. int handleCostUpdatedRequest(char *uuid, char *payload)
  11555. {
  11556. mtrace();
  11557. int result = FAIL;
  11558. json_object *CostUpdate;
  11559. DEBUG_INFO("handleCostUpdatedRequest...\n");
  11560. CostUpdate = json_tokener_parse(payload);
  11561. if(!is_error(CostUpdate))
  11562. {
  11563. // Required data
  11564. if(json_object_object_get(CostUpdate, "totalCost") != NULL)
  11565. {
  11566. ShmOCPP20Data->CostUpdated.totalCost = json_object_get_double(json_object_object_get(CostUpdate, "totalCost"));
  11567. }
  11568. if(json_object_object_get(CostUpdate, "transactionId") != NULL)
  11569. {
  11570. sprintf((char*)ShmOCPP20Data->CostUpdated.transactionId, "%s", json_object_get_string(json_object_object_get(CostUpdate, "transactionId")));
  11571. }
  11572. }
  11573. json_object_put(CostUpdate);
  11574. sendCostUpdatedConfirmation(uuid);
  11575. return result;
  11576. }
  11577. int handleCustomerInformationRequest(char *uuid, char *payload)
  11578. {
  11579. mtrace();
  11580. int result = FAIL;
  11581. json_object *CustomerInformation;
  11582. DEBUG_INFO("handleCustomerInformationRequest...\n");
  11583. CustomerInformation = json_tokener_parse(payload);
  11584. if(!is_error(CustomerInformation))
  11585. {
  11586. // Required data
  11587. if(json_object_object_get(CustomerInformation, "requestId") != NULL)
  11588. {
  11589. ShmOCPP20Data->CustomerInformation.requestId = json_object_get_int(json_object_object_get(CustomerInformation, "requestId"));
  11590. }
  11591. if(json_object_object_get(CustomerInformation, "report") != NULL)
  11592. {
  11593. ShmOCPP20Data->CustomerInformation.report = json_object_get_boolean(json_object_object_get(CustomerInformation, "report"));
  11594. }
  11595. if(json_object_object_get(CustomerInformation, "clear") != NULL)
  11596. {
  11597. ShmOCPP20Data->CustomerInformation.report = json_object_get_boolean(json_object_object_get(CustomerInformation, "clear"));
  11598. }
  11599. // Optional data
  11600. if(json_object_object_get(CustomerInformation, "idToken") != NULL)
  11601. {
  11602. if(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "idToken") != NULL)
  11603. {
  11604. sprintf((char*)ShmOCPP20Data->CustomerInformation.idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "idToken")));
  11605. }
  11606. if(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "type") != NULL)
  11607. {
  11608. sprintf((char*)ShmOCPP20Data->CustomerInformation.idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "type")));
  11609. }
  11610. }
  11611. if(json_object_object_get(CustomerInformation, "customerCertificate") != NULL)
  11612. {
  11613. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "hashAlgorithm") != NULL)
  11614. {
  11615. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "hashAlgorithm")));
  11616. }
  11617. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerNameHash") != NULL)
  11618. {
  11619. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerNameHash")));
  11620. }
  11621. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerKeyHash") != NULL)
  11622. {
  11623. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerKeyHash")));
  11624. }
  11625. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "serialNumber") != NULL)
  11626. {
  11627. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "serialNumber")));
  11628. }
  11629. }
  11630. strcpy((char*)ShmOCPP20Data->CustomerInformation.Response_status, CustomerInformationStatusEnumTypeStr[CustomerInformationStatusEnumType_Accepted]);
  11631. }
  11632. else
  11633. strcpy((char*)ShmOCPP20Data->CustomerInformation.Response_status, CustomerInformationStatusEnumTypeStr[CustomerInformationStatusEnumType_Rejected]);
  11634. json_object_put(CustomerInformation);
  11635. sendCustomerInformationConfirmation(uuid);
  11636. return result;
  11637. }
  11638. void createFirmwareVersionByDataTransfer(void)
  11639. {
  11640. json_object *FirmwareDataTransfer = json_object_new_object();
  11641. // AC & DC model
  11642. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  11643. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  11644. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  11645. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  11646. // DC model
  11647. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  11648. {
  11649. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  11650. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  11651. (gunType[3] != GUN_TYPE_UNKNOWN))
  11652. {
  11653. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  11654. }
  11655. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  11656. {
  11657. // DS DM DW
  11658. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  11659. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  11660. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  11661. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  11662. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  11663. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  11664. }
  11665. else
  11666. {
  11667. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  11668. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  11669. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  11670. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  11671. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  11672. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  11673. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  11674. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  11675. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  11676. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  11677. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  11678. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  11679. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  11680. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  11681. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  11682. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  11683. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  11684. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  11685. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  11686. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  11687. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  11688. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  11689. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  11690. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  11691. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  11692. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  11693. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  11694. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  11695. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  11696. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  11697. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  11698. }
  11699. }
  11700. // 4G model
  11701. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  11702. {
  11703. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  11704. }
  11705. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  11706. json_object_put(FirmwareDataTransfer);
  11707. }
  11708. int handleDataTransferRequest(char *uuid, char *payload)
  11709. {
  11710. mtrace();
  11711. int result = PASS;
  11712. DEBUG_INFO("handleDataTransferRequest...\n");
  11713. if((uuid != NULL) && (payload != NULL))
  11714. {
  11715. json_object *DataTransfer;
  11716. DataTransfer = json_tokener_parse(payload);
  11717. if(!is_error(DataTransfer))
  11718. {
  11719. // Required data
  11720. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  11721. sprintf((char*)ShmOCPP20Data->DataTransfer[0].vendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  11722. // Optional data
  11723. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  11724. sprintf((char*)ShmOCPP20Data->DataTransfer[0].messageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  11725. if(json_object_object_get(DataTransfer, "data") != NULL)
  11726. sprintf((char*)ShmOCPP20Data->DataTransfer[0].data, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  11727. result = PASS;
  11728. }
  11729. json_object_put(DataTransfer);
  11730. if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_FirmwareVersion") != NULL)
  11731. {
  11732. // Send all moudle firmware version on EVSE
  11733. createFirmwareVersionByDataTransfer();
  11734. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  11735. }
  11736. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_Tmate") != NULL)
  11737. {
  11738. system("/usr/bin/run_tmate_restart.sh &");
  11739. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  11740. }
  11741. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_ChargingPreference") != NULL)
  11742. {
  11743. json_object *data;
  11744. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  11745. if(!is_error(data))
  11746. {
  11747. 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))
  11748. {
  11749. DEBUG_INFO("ChargeingPreference connector id: %d\n", json_object_get_int(json_object_object_get(data, "ConnectorId")));
  11750. memset(&ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))], 0x00, sizeof(struct StructSessionTarget));
  11751. if(json_object_object_get(data, "SOC") != NULL)
  11752. {
  11753. ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetSoc = json_object_get_int(json_object_object_get(data, "SOC"));
  11754. DEBUG_INFO("ChargeingPreference target soc: %d\n", json_object_get_int(json_object_object_get(data, "SOC")));
  11755. }
  11756. if(json_object_object_get(data, "Energy") != NULL)
  11757. {
  11758. ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetEnergy = json_object_get_int(json_object_object_get(data, "Energy"));
  11759. DEBUG_INFO("ChargeingPreference target energy: %d KWH\n", json_object_get_int(json_object_object_get(data, "Energy")));
  11760. }
  11761. if(json_object_object_get(data, "Duration") != NULL)
  11762. {
  11763. ShmOCPP20Data->SessionTarget[json_object_get_int(json_object_object_get(data, "ConnectorId"))].targetDuration = json_object_get_int(json_object_object_get(data, "Duration"));
  11764. DEBUG_INFO("ChargeingPreference target duration: %d minutes\n", json_object_get_int(json_object_object_get(data, "Duration")));
  11765. }
  11766. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  11767. }
  11768. else
  11769. {
  11770. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  11771. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Connector id must > 0.");
  11772. }
  11773. }
  11774. else
  11775. {
  11776. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  11777. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  11778. }
  11779. json_object_put(data);
  11780. }
  11781. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "SetLEDBar") != NULL)
  11782. {
  11783. json_object *data;
  11784. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  11785. if(!is_error(data))
  11786. {
  11787. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  11788. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  11789. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  11790. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  11791. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  11792. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  11793. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  11794. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  11795. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  11796. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  11797. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  11798. }
  11799. else
  11800. {
  11801. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  11802. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  11803. }
  11804. json_object_put(data);
  11805. }
  11806. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_ConfigQR") != NULL)
  11807. {
  11808. json_object *data;
  11809. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  11810. if(!is_error(data))
  11811. {
  11812. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  11813. if(json_object_object_get(data, "Content_Type") != NULL)
  11814. {
  11815. 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))
  11816. {
  11817. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  11818. if(json_object_object_get(data, "Customization_Conent") != NULL)
  11819. {
  11820. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  11821. }
  11822. }
  11823. else
  11824. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  11825. }
  11826. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  11827. }
  11828. else
  11829. {
  11830. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  11831. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  11832. }
  11833. json_object_put(data);
  11834. }
  11835. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_DisplayLcdPage") != NULL)
  11836. {
  11837. json_object *data;
  11838. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  11839. if(!is_error(data))
  11840. {
  11841. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  11842. if(json_object_object_get(data, "ConnectorId") != NULL)
  11843. {
  11844. ShmSysConfigAndInfo->SysInfo.LcdOveride.connectorId = json_object_get_int(json_object_object_get(data, "ConnectorId"));
  11845. }
  11846. if(json_object_object_get(data, "Page_Index") != NULL)
  11847. {
  11848. ShmSysConfigAndInfo->SysInfo.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  11849. }
  11850. if(json_object_object_get(data, "Duration") != NULL)
  11851. {
  11852. ShmSysConfigAndInfo->SysInfo.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  11853. }
  11854. ShmSysConfigAndInfo->SysInfo.LcdOveride.isOverideReq = ON;
  11855. }
  11856. else
  11857. {
  11858. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  11859. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  11860. }
  11861. json_object_put(data);
  11862. }
  11863. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_CpConfiguration") != NULL)
  11864. {
  11865. json_object *data;
  11866. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  11867. if(!is_error(data))
  11868. {
  11869. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  11870. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, " ");
  11871. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  11872. {
  11873. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  11874. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  11875. else
  11876. {
  11877. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  11878. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  11879. }
  11880. }
  11881. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  11882. {
  11883. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  11884. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  11885. else
  11886. {
  11887. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  11888. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  11889. }
  11890. }
  11891. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  11892. {
  11893. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  11894. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  11895. else
  11896. {
  11897. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  11898. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  11899. }
  11900. }
  11901. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  11902. {
  11903. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  11904. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  11905. else
  11906. {
  11907. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  11908. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  11909. }
  11910. }
  11911. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  11912. {
  11913. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  11914. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  11915. else
  11916. {
  11917. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  11918. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  11919. }
  11920. }
  11921. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  11922. {
  11923. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  11924. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  11925. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  11926. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  11927. else
  11928. {
  11929. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  11930. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  11931. }
  11932. }
  11933. if(json_object_object_get(data, "isAuthentication") != NULL)
  11934. {
  11935. switch(json_object_get_int(json_object_object_get(data, "isAuthentication")))
  11936. {
  11937. case 0:
  11938. case 1:
  11939. ShmSysConfigAndInfo->SysConfig.AuthorisationMode = json_object_get_int(json_object_object_get(data, "isAuthentication"))^1;
  11940. break;
  11941. default:
  11942. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  11943. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  11944. break;
  11945. }
  11946. }
  11947. if(strstr((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]) != NULL)
  11948. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  11949. }
  11950. else
  11951. {
  11952. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  11953. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  11954. }
  11955. json_object_put(data);
  11956. }
  11957. else
  11958. {
  11959. // Can not find valid message id
  11960. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_UnknownMessageId]);
  11961. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data,"vendorId: %s messageId: %s data: %s"
  11962. ,ShmOCPP20Data->DataTransfer[0].vendorId
  11963. ,ShmOCPP20Data->DataTransfer[0].messageId
  11964. ,ShmOCPP20Data->DataTransfer[0].data);
  11965. }
  11966. }
  11967. else
  11968. {
  11969. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_UnknownMessageId]);
  11970. result = FAIL;
  11971. }
  11972. sendDataTransferConfirmation(uuid, 0);
  11973. return result;
  11974. }
  11975. int handleDeleteCertificateRequest(char *uuid, char *payload)
  11976. {
  11977. mtrace();
  11978. int result = FAIL;
  11979. json_object *DeleteCertificate;
  11980. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  11981. DeleteCertificate = json_tokener_parse(payload);
  11982. if(!is_error(DeleteCertificate))
  11983. {
  11984. memset(&ShmOCPP20Data->DeleteCertificate, 0, sizeof(struct DeleteCertificate_20));
  11985. memcpy(&ShmOCPP20Data->DeleteCertificate.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->DeleteCertificate.guid));
  11986. // Required data
  11987. if(json_object_object_get(DeleteCertificate, "certificateHashData") != NULL)
  11988. {
  11989. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm") != NULL)
  11990. {
  11991. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  11992. }
  11993. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash") != NULL)
  11994. {
  11995. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  11996. }
  11997. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash") != NULL)
  11998. {
  11999. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  12000. }
  12001. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber") != NULL)
  12002. {
  12003. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  12004. }
  12005. /*
  12006. * TODO:
  12007. * 1. Delete certification and response
  12008. */
  12009. if(strstr((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm, HashAlgorithmEnumTypeStr[HashAlgorithmEnumType_SHA256]) != NULL)
  12010. {
  12011. }
  12012. else if(strstr((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm, HashAlgorithmEnumTypeStr[HashAlgorithmEnumType_SHA384]) != NULL)
  12013. {
  12014. }
  12015. else
  12016. {
  12017. }
  12018. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, DeleteCertificateStatusEnumTypeStr[DeleteCertificateStatusEnumType_Accepted]);
  12019. }
  12020. }
  12021. else
  12022. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, DeleteCertificateStatusEnumTypeStr[DeleteCertificateStatusEnumType_Failed]);
  12023. json_object_put(DeleteCertificate);
  12024. sendDeleteCertificateConfirmation(uuid);
  12025. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12026. return result;
  12027. }
  12028. int handleGetBaseReportRequest(char *uuid, char *payload)
  12029. {
  12030. mtrace();
  12031. int result = FAIL;
  12032. json_object *GetBaseRepor;
  12033. DEBUG_INFO("handleGetBaseReportRequest...\n");
  12034. GetBaseRepor = json_tokener_parse(payload);
  12035. if(!is_error(GetBaseRepor))
  12036. {
  12037. memset(&ShmOCPP20Data->GetBaseReport, 0, sizeof(struct GetBaseReport_20));
  12038. memcpy(&ShmOCPP20Data->GetBaseReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetBaseReport.guid));
  12039. // Required data
  12040. if(json_object_object_get(GetBaseRepor, "requestId") != NULL)
  12041. {
  12042. ShmOCPP20Data->GetBaseReport.requestId = json_object_get_int(json_object_object_get(GetBaseRepor, "requestId"));
  12043. }
  12044. if(json_object_object_get(GetBaseRepor, "reportBase") != NULL)
  12045. {
  12046. sprintf((char*)ShmOCPP20Data->GetBaseReport.reportBase, "%s", json_object_get_string(json_object_object_get(GetBaseRepor, "reportBase")));
  12047. }
  12048. if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_SummaryInventory]) == 0)
  12049. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  12050. else
  12051. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  12052. }
  12053. else
  12054. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  12055. json_object_put(GetBaseRepor);
  12056. sendGetBaseReportConfirmation(uuid);
  12057. return result;
  12058. }
  12059. int handleGetChargingProfilesRequest(char *uuid, char *payload)
  12060. {
  12061. mtrace();
  12062. int result = FAIL;
  12063. int gun_index = -1;
  12064. json_object *GetChargingProfiles;
  12065. DEBUG_INFO("handleGetChargingProfilesRequest...\n");
  12066. GetChargingProfiles = json_tokener_parse(payload);
  12067. if(!is_error(GetChargingProfiles))
  12068. {
  12069. if(json_object_object_get(GetChargingProfiles, "evseId") != NULL)
  12070. {
  12071. 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;
  12072. }
  12073. if(gun_index >-1)
  12074. {
  12075. memset(&ShmOCPP20Data->GetChargingProfiles[gun_index], 0, sizeof(struct GetChargingProfiles_20));
  12076. memcpy(&ShmOCPP20Data->GetChargingProfiles[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetChargingProfiles[gun_index].guid));
  12077. // Required data
  12078. if(json_object_object_get(GetChargingProfiles, "requestId") != NULL)
  12079. {
  12080. ShmOCPP20Data->GetChargingProfiles[gun_index].requestId = json_object_get_int(json_object_object_get(GetChargingProfiles, "requestId"));
  12081. }
  12082. if(json_object_object_get(GetChargingProfiles, "chargingProfile") != NULL)
  12083. {
  12084. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfilePurpose") != NULL)
  12085. {
  12086. sprintf((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.chargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfilePurpose")));
  12087. }
  12088. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "stackLevel") != NULL)
  12089. {
  12090. ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "stackLevel"));
  12091. }
  12092. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingLimitSource") != NULL)
  12093. {
  12094. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingLimitSource"));idx++)
  12095. {
  12096. 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)));
  12097. }
  12098. }
  12099. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfileId") != NULL)
  12100. {
  12101. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfileId"));idx++)
  12102. {
  12103. 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));
  12104. }
  12105. }
  12106. }
  12107. strcpy((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status, GetChargingProfileStatusEnumTypeStr[GetChargingProfileStatusEnumType_Accepted]);
  12108. }
  12109. else
  12110. strcpy((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status, GetChargingProfileStatusEnumTypeStr[GetChargingProfileStatusEnumType_NoProfiles]);
  12111. }
  12112. json_object_put(GetChargingProfiles);
  12113. sendGetChargingProfilesConfirmation(uuid, gun_index);
  12114. return result;
  12115. }
  12116. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  12117. {
  12118. mtrace();
  12119. int result = FAIL;
  12120. int connectorIdInt, durationInt;
  12121. char chargingRateUnitStr[4]={0};
  12122. char comfirmstr[20];
  12123. int confirmPeriods = 0;
  12124. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  12125. json_object *GetCompositeSchedule;
  12126. GetCompositeSchedule = json_tokener_parse(payload);
  12127. if(!is_error(GetCompositeSchedule))
  12128. {
  12129. // Required data
  12130. if(json_object_object_get(GetCompositeSchedule, "evseId") != NULL)
  12131. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "evseId"));
  12132. else
  12133. connectorIdInt = -1;
  12134. if(json_object_object_get(GetCompositeSchedule, "duration"))
  12135. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  12136. else
  12137. durationInt = 86400;
  12138. // Optional data
  12139. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  12140. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  12141. }
  12142. json_object_put(GetCompositeSchedule);
  12143. memset(ShmOCPP20Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  12144. if((connectorIdInt == 0) ||
  12145. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  12146. {
  12147. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  12148. struct ChargingProfileType tmpProfile[1];
  12149. memset(&ShmOCPP20Data->GetCompositeSchedule[gun_index], 0, sizeof(struct GetCompositeSchedule_20));
  12150. memcpy(&ShmOCPP20Data->GetCompositeSchedule[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].guid));
  12151. if(strstr(chargingRateUnitStr, "W") != NULL)
  12152. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], 0, FALSE);
  12153. else
  12154. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], 0, TRUE);
  12155. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod);idx++)
  12156. {
  12157. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].chargingSchedule[0].chargingSchedulePeriod[idx].startPeriod);
  12158. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].chargingSchedule[0].chargingSchedulePeriod[idx].limit);
  12159. }
  12160. memcpy(&ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule, &tmpProfile[0].chargingSchedule[0], sizeof(struct CompositeScheduleType));
  12161. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod);idx++)
  12162. {
  12163. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].startPeriod);
  12164. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit);
  12165. if((ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].startPeriod==0) &&
  12166. (ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit==0) &&
  12167. (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))
  12168. {
  12169. confirmPeriods = idx;
  12170. break;
  12171. }
  12172. }
  12173. if((confirmPeriods == 0) && (tmpProfile[0].id > 0))
  12174. {
  12175. confirmPeriods += 1;
  12176. }
  12177. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  12178. }
  12179. else
  12180. {
  12181. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusEnumTypeStr[GenericStatusEnumType_Rejected]);
  12182. }
  12183. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  12184. return result;
  12185. }
  12186. int handleGetDisplayMessagesRequest(char *uuid, char *payload)
  12187. {
  12188. mtrace();
  12189. int result = FAIL;
  12190. json_object *GetDisplayMessages;
  12191. DEBUG_INFO("handleGetDisplayMessagesRequest...\n");
  12192. GetDisplayMessages = json_tokener_parse(payload);
  12193. if(!is_error(GetDisplayMessages))
  12194. {
  12195. memset(&ShmOCPP20Data->GetDisplayMessages, 0, sizeof(struct GetDisplayMessages_20));
  12196. memcpy(&ShmOCPP20Data->GetDisplayMessages.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetDisplayMessages.guid));
  12197. // Required data
  12198. if(json_object_object_get(GetDisplayMessages, "requestId") != NULL)
  12199. {
  12200. ShmOCPP20Data->GetDisplayMessages.requestId = json_object_get_int(json_object_object_get(GetDisplayMessages, "requestId"));
  12201. }
  12202. // Optional data
  12203. if(json_object_object_get(GetDisplayMessages, "priority") != NULL)
  12204. {
  12205. sprintf((char*)ShmOCPP20Data->GetDisplayMessages.priority, "%s", json_object_get_string(json_object_object_get(GetDisplayMessages, "priority")));
  12206. }
  12207. if(json_object_object_get(GetDisplayMessages, "state") != NULL)
  12208. {
  12209. sprintf((char*)ShmOCPP20Data->GetDisplayMessages.state, "%s", json_object_get_string(json_object_object_get(GetDisplayMessages, "state")));
  12210. }
  12211. if(json_object_array_length(json_object_object_get(GetDisplayMessages, "id")) <= ARRAY_SIZE(ShmOCPP20Data->GetDisplayMessages.id))
  12212. {
  12213. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetDisplayMessages, "id"));idx++)
  12214. {
  12215. ShmOCPP20Data->GetDisplayMessages.id[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(GetDisplayMessages, "id"), idx));
  12216. }
  12217. strcpy((char*)ShmOCPP20Data->GetDisplayMessages.Response_status, GetDisplayMessagesStatusEnumTypeStr[GetDisplayMessagesStatusEnumType_Accepted]);
  12218. ShmOCPP20Data->MsMsg.bits.GetDisplayMessagesReq = ON;
  12219. }
  12220. else
  12221. strcpy((char*)ShmOCPP20Data->GetDisplayMessages.Response_status, GetDisplayMessagesStatusEnumTypeStr[GetDisplayMessagesStatusEnumType_Unknown]);
  12222. }
  12223. json_object_put(GetDisplayMessages);
  12224. return result;
  12225. }
  12226. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  12227. {
  12228. mtrace();
  12229. int result = FAIL;
  12230. json_object *GetInstalledCertificateIds;
  12231. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  12232. GetInstalledCertificateIds = json_tokener_parse(payload);
  12233. if(!is_error(GetInstalledCertificateIds))
  12234. {
  12235. memset(&ShmOCPP20Data->GetInstalledCertificateIds, 0, sizeof(struct GetInstalledCertificateIds_20));
  12236. memcpy(&ShmOCPP20Data->GetInstalledCertificateIds.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetInstalledCertificateIds.guid));
  12237. // Optional data
  12238. if(json_object_array_length(json_object_object_get(GetInstalledCertificateIds, "certificateType")) <= ARRAY_SIZE(ShmOCPP20Data->GetInstalledCertificateIds.certificateType))
  12239. {
  12240. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetInstalledCertificateIds, "certificateType"));idx++)
  12241. {
  12242. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetInstalledCertificateIds, "certificateType"), idx)));
  12243. /*
  12244. * TODO:
  12245. * 1. Get installed certificate info for response
  12246. */
  12247. if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], GetCertificateIdUseEnumTypeStr[GetCertificateIdUseEnumType_V2GRootCertificate]) != NULL)
  12248. {
  12249. }
  12250. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], GetCertificateIdUseEnumTypeStr[GetCertificateIdUseEnumType_MORootCertificate]) != NULL)
  12251. {
  12252. }
  12253. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], GetCertificateIdUseEnumTypeStr[GetCertificateIdUseEnumType_CSMSRootCertificate]) != NULL)
  12254. {
  12255. }
  12256. else if(strstr((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], GetCertificateIdUseEnumTypeStr[GetCertificateIdUseEnumType_V2GCertificateChain]) != NULL)
  12257. {
  12258. }
  12259. else
  12260. {
  12261. }
  12262. }
  12263. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  12264. }
  12265. else
  12266. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_NotFound]);
  12267. }
  12268. json_object_put(GetInstalledCertificateIds);
  12269. sendInstallCertificateConfirmation(uuid);
  12270. return result;
  12271. }
  12272. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  12273. {
  12274. mtrace();
  12275. int result = FAIL;
  12276. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  12277. if(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "FALSE") == 0)
  12278. {
  12279. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  12280. localversion = -1;
  12281. }
  12282. else
  12283. {
  12284. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  12285. DB_getListVerion();
  12286. }
  12287. ShmOCPP20Data->GetLocalListVersion.Response_versionNumber = localversion;
  12288. sendGetLocalListVersionConfirmation(uuid);
  12289. return result;
  12290. }
  12291. static char fnamePlusPath[100]={0};
  12292. static char fnamePWithNoPath[60]={0};
  12293. void checkUploadLog(void)
  12294. {
  12295. FILE *fp;
  12296. /* Open the command for reading. */
  12297. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  12298. if (fp == NULL) {
  12299. printf("Failed to run command\n" );
  12300. exit(1);
  12301. }
  12302. int ftppathlen = 0;
  12303. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  12304. int i = 0;
  12305. /* Read the output a line at a time - output it. */
  12306. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  12307. if(i==0)
  12308. {
  12309. ftppathlen = strlen(fnamePlusPath);
  12310. printf("%s\n", fnamePlusPath);
  12311. fnamePlusPath[ftppathlen]='\0';
  12312. break;
  12313. }
  12314. i= i+1;
  12315. }
  12316. /* close */
  12317. pclose(fp);
  12318. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  12319. {
  12320. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  12321. {
  12322. fnamePlusPath[k]='\0';
  12323. }
  12324. }
  12325. i=1;
  12326. //char fname[60]={0};
  12327. while(i < ftppathlen)
  12328. {
  12329. int len=ftppathlen-i;
  12330. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  12331. {
  12332. printf("compare '/' all right\n");
  12333. break;
  12334. }
  12335. i=i+1;
  12336. }
  12337. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  12338. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  12339. fnamePWithNoPath[i+1] = '\0';
  12340. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  12341. {
  12342. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  12343. {
  12344. fnamePWithNoPath[j]='\0';
  12345. }
  12346. }
  12347. FILE* fp1 = fopen(fnamePlusPath, "r");
  12348. if (fp1)
  12349. {
  12350. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  12351. // file exists
  12352. fclose(fp1);
  12353. }
  12354. else
  12355. {
  12356. // file doesn't exist
  12357. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  12358. }
  12359. }
  12360. void* GetLogProcess(void* data)
  12361. {
  12362. pthread_detach(pthread_self());
  12363. mtrace();
  12364. int requestId, retriesInt=0, retryIntervalInt=0;
  12365. char logType[32], remoteLocation[1024]={0}, oldestTimestamp[30]={0}, latestTimestamp[30]={0};
  12366. 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};
  12367. int port=0;
  12368. int isSuccess = FALSE;
  12369. char ftpbuf[1024]={0};
  12370. char cmdBuf[2048];
  12371. struct tm *tmNow;
  12372. time_t CurrentTime;
  12373. struct tm tmStart;
  12374. struct tm tmStop;
  12375. CurrentTime = time(NULL);
  12376. tmNow=localtime(&CurrentTime);
  12377. uint16_t targetYear, targetMonth;
  12378. json_object *GetLog;
  12379. DEBUG_INFO("GetGetProcess...\n");
  12380. GetLog = json_tokener_parse(data);
  12381. if(!is_error(GetLog))
  12382. {
  12383. // Required data
  12384. if(json_object_object_get(GetLog, "requestId") != NULL)
  12385. requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  12386. if(json_object_object_get(GetLog, "logType") != NULL)
  12387. sprintf(logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  12388. if(json_object_object_get(GetLog, "log") != NULL)
  12389. {
  12390. if(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation") != NULL)
  12391. sprintf(remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  12392. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  12393. sprintf(oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  12394. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  12395. sprintf(latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  12396. }
  12397. // Optional data
  12398. if(json_object_object_get(GetLog, "retries") != NULL)
  12399. retriesInt = json_object_get_int(json_object_object_get(GetLog, "retries"));
  12400. else
  12401. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  12402. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  12403. retryIntervalInt = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  12404. else
  12405. retryIntervalInt = 30;
  12406. }
  12407. json_object_put(GetLog);
  12408. ShmOCPP20Data->GetLog.requestId = requestId;
  12409. if(strstr(logType, LogEnumTypeStr[LogEnumType_SecurityLog]))
  12410. {
  12411. /*
  12412. * TODO:
  12413. * 1. Pack security log
  12414. */
  12415. }
  12416. else
  12417. {
  12418. // Pack log to compress file
  12419. 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) &&
  12420. (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))
  12421. {
  12422. // Pack system log
  12423. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  12424. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  12425. targetYear = tmStart.tm_year;
  12426. targetMonth = tmStart.tm_mon;
  12427. do
  12428. {
  12429. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  12430. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*SystemLog*", cmdBuf, targetYear, targetMonth);
  12431. if(targetMonth+1>=13)
  12432. {
  12433. targetYear += 1;
  12434. targetMonth = 1;
  12435. }
  12436. else
  12437. {
  12438. targetMonth += 1;
  12439. }
  12440. }while((targetYear < (tmNow->tm_year+1900)) ||
  12441. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  12442. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  12443. system(cmdBuf);
  12444. // Pack charging & event log
  12445. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  12446. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  12447. targetYear = tmStart.tm_year;
  12448. targetMonth = tmStart.tm_mon;
  12449. do
  12450. {
  12451. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  12452. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*OcppMessageLog*", cmdBuf, targetYear, targetMonth);
  12453. if(targetMonth+1>=13)
  12454. {
  12455. targetYear += 1;
  12456. targetMonth = 1;
  12457. }
  12458. else
  12459. {
  12460. targetMonth += 1;
  12461. }
  12462. }while((targetYear < (tmNow->tm_year+1900)) ||
  12463. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  12464. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  12465. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  12466. system(cmdBuf);
  12467. // Combine log file
  12468. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  12469. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  12470. }
  12471. else
  12472. {
  12473. system("exec /root/logPackTools 'log' 6");
  12474. }
  12475. }
  12476. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP20Data->GetLog.Response_filename);
  12477. system(cmdBuf);
  12478. checkUploadLog();
  12479. //****************location*******************/
  12480. if(strcmp(remoteLocation,"")==0)
  12481. {
  12482. DEBUG_INFO("remoteLocation is <Empty>!\n");
  12483. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  12484. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  12485. goto end;
  12486. }
  12487. memset(protocol, 0, ARRAY_SIZE(protocol));
  12488. memset(user, 0, ARRAY_SIZE(user) );
  12489. memset(password, 0, ARRAY_SIZE(password));
  12490. memset(host, 0, ARRAY_SIZE(host));
  12491. memset(path, 0, ARRAY_SIZE(path));
  12492. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  12493. memset(host1, 0, ARRAY_SIZE(host1));
  12494. memset(path1, 0, ARRAY_SIZE(path1));
  12495. /*location: ftp://user:password@host:port/path*/
  12496. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  12497. if((access(fnamePlusPath,F_OK))!=-1)
  12498. {
  12499. DEBUG_INFO("fnamePlusPath exist.\n");
  12500. }
  12501. else
  12502. {
  12503. DEBUG_INFO("fnamePlusPath not exist!\n");
  12504. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  12505. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  12506. goto end;
  12507. }
  12508. if(strchr(remoteLocation,'@')==NULL)
  12509. {
  12510. sscanf(remoteLocation,
  12511. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12512. protocol, host, &port, path);
  12513. strcpy(user,"anonymous");
  12514. strcpy(password,"");
  12515. }
  12516. else
  12517. {
  12518. //DEBUG_INFO("pch=%s\n", pch);
  12519. sscanf(remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  12520. protocol, user, password, host, &port, path);
  12521. }
  12522. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  12523. {
  12524. DEBUG_INFO("protocol is not ftp/http ! \n");
  12525. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  12526. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  12527. goto end;
  12528. }
  12529. if(strncmp(remoteLocation,"http", 4) == 0)
  12530. {
  12531. sscanf(remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  12532. sprintf(ftppath,"/%s", path);
  12533. do
  12534. {
  12535. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploading]);
  12536. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  12537. sleep(3);
  12538. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, remoteLocation);
  12539. if(!isSuccess)
  12540. {
  12541. DEBUG_INFO("sendLogStatusNotificationRequest fail...retries: %d\n", retriesInt);
  12542. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  12543. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  12544. sleep(retryIntervalInt);
  12545. }
  12546. else
  12547. {
  12548. DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
  12549. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
  12550. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  12551. }
  12552. retriesInt--;
  12553. }while((isSuccess == 0)&&(retriesInt >= 0));
  12554. }
  12555. else
  12556. {
  12557. sscanf(host,"%[^/]%s",host1, path1);
  12558. if(strlen(path) > 0)
  12559. sprintf(ftppath,"/%s", path);
  12560. else
  12561. sprintf(ftppath,"/%s", path1);
  12562. int ftppathlen=strlen(ftppath);
  12563. int i=1;
  12564. char filenametemp[50];
  12565. while(i < ftppathlen)
  12566. {
  12567. int len=ftppathlen-i;
  12568. if(ftppath[len]== 47) // '/' ascll code: 47
  12569. {
  12570. DEBUG_INFO("find '/' all right\n");
  12571. break;
  12572. }
  12573. i=i+1;
  12574. }
  12575. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  12576. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  12577. filenametemp[i+1] = 0;
  12578. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12579. if(port == 0)
  12580. port = 21;
  12581. do
  12582. {
  12583. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploading]);
  12584. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  12585. sleep(3);
  12586. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  12587. if(!isSuccess)
  12588. {
  12589. DEBUG_INFO("sendLogStatusNotificationRequest fail...retries: %d\n", retriesInt);
  12590. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  12591. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  12592. sleep(retryIntervalInt);
  12593. }
  12594. else
  12595. {
  12596. DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
  12597. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
  12598. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  12599. }
  12600. retriesInt--;
  12601. }while((!isSuccess)&&(retriesInt >= 0));
  12602. }
  12603. end:
  12604. system("rm -f /mnt/*");
  12605. sleep(5);
  12606. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle;
  12607. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  12608. interLock.isGetLogGoing = OFF;
  12609. pthread_exit(NULL);
  12610. }
  12611. int handleGetLogRequest(char *uuid, char *payload)
  12612. {
  12613. mtrace();
  12614. int result = FAIL;
  12615. char fName[258];
  12616. time_t CurrentTime;
  12617. struct tm *tm;
  12618. pthread_t th_Status;
  12619. CurrentTime = time(NULL);
  12620. tm = localtime(&CurrentTime);
  12621. 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);
  12622. sprintf((char*)ShmOCPP20Data->GetLog.Response_filename, "%s", fName);
  12623. sprintf((char*)ShmOCPP20Data->GetLog.Response_status, "%s", LogStatusEnumTypeStr[LogStatusEnumType_Accepted]);
  12624. sendGetLogConfirmation(uuid);
  12625. if(!interLock.isGetLogGoing)
  12626. {
  12627. interLock.isGetLogGoing = ON;
  12628. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  12629. sleep(1);
  12630. }
  12631. else
  12632. DEBUG_WARN("Other GetDiagnostic request on going.\n");
  12633. return result;
  12634. }
  12635. int handleGetMonitoringReportRequest(char *uuid, char *payload)
  12636. {
  12637. mtrace();
  12638. int result = FAIL;
  12639. json_object *GetMonitoringReport;
  12640. DEBUG_INFO("handleGetMonitoringReportRequest...\n");
  12641. GetMonitoringReport = json_tokener_parse(payload);
  12642. if(!is_error(GetMonitoringReport))
  12643. {
  12644. memset(&ShmOCPP20Data->GetMonitoringReport, 0, sizeof(struct GetMonitoringReport_20));
  12645. memcpy(&ShmOCPP20Data->GetMonitoringReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.guid));
  12646. // Required data
  12647. if(json_object_object_get(GetMonitoringReport, "requestId") != NULL)
  12648. {
  12649. ShmOCPP20Data->GetMonitoringReport.requestId = json_object_get_int(json_object_object_get(GetMonitoringReport, "requestId"));
  12650. }
  12651. // Optional data
  12652. if(json_object_object_get(GetMonitoringReport, "monitoringCriteria") != NULL)
  12653. {
  12654. sprintf((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria, "%s", json_object_get_string(json_object_object_get(GetMonitoringReport, "monitoringCriteria")));
  12655. }
  12656. if(json_object_object_get(GetMonitoringReport, "componentVariable") != NULL)
  12657. {
  12658. if(json_object_array_length(json_object_object_get(GetMonitoringReport, "componentVariable")) <= ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.componentVariable))
  12659. {
  12660. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetMonitoringReport, "componentVariable"));idx++)
  12661. {
  12662. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component") != NULL)
  12663. {
  12664. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "name") != NULL)
  12665. {
  12666. 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")));
  12667. }
  12668. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "instance") != NULL)
  12669. {
  12670. 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")));
  12671. }
  12672. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "evse") != NULL)
  12673. {
  12674. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "getVariableData"), idx), "component"), "evse"), "id") != NULL)
  12675. {
  12676. 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"));
  12677. }
  12678. 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)
  12679. {
  12680. 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"));
  12681. }
  12682. }
  12683. }
  12684. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable") != NULL)
  12685. {
  12686. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "name") != NULL)
  12687. {
  12688. 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")));
  12689. }
  12690. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "instance") != NULL)
  12691. {
  12692. 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")));
  12693. }
  12694. }
  12695. }
  12696. }
  12697. }
  12698. }
  12699. json_object_put(GetMonitoringReport);
  12700. /*
  12701. * TODO:
  12702. * 1. Response result
  12703. */
  12704. strcpy((char*)ShmOCPP20Data->GetReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  12705. sendGetMonitoringReportConfirmation(uuid);
  12706. return result;
  12707. }
  12708. int handleGetReportRequest(char *uuid, char *payload)
  12709. {
  12710. mtrace();
  12711. int result = FAIL;
  12712. json_object *GetReport;
  12713. DEBUG_INFO("handleGetReportRequest...\n");
  12714. GetReport = json_tokener_parse(payload);
  12715. if(!is_error(GetReport))
  12716. {
  12717. memset(&ShmOCPP20Data->GetReport, 0, sizeof(struct GetReport_20));
  12718. memcpy(&ShmOCPP20Data->GetReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetReport.guid));
  12719. // Required data
  12720. if(json_object_object_get(GetReport, "requestId") != NULL)
  12721. {
  12722. ShmOCPP20Data->GetReport.requestId = json_object_get_int(json_object_object_get(GetReport, "requestId"));
  12723. }
  12724. // Optional data
  12725. if(json_object_object_get(GetReport, "componentCriteria") != NULL)
  12726. {
  12727. sprintf((char*)ShmOCPP20Data->GetReport.componentCriteria, "%s", json_object_get_string(json_object_object_get(GetReport, "componentCriteria")));
  12728. }
  12729. if(json_object_object_get(GetReport, "componentVariable") != NULL)
  12730. {
  12731. if(json_object_array_length(json_object_object_get(GetReport, "componentVariable")) <= ARRAY_SIZE(ShmOCPP20Data->GetReport.componentVariable))
  12732. {
  12733. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetReport, "componentVariable"));idx++)
  12734. {
  12735. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component") != NULL)
  12736. {
  12737. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "name") != NULL)
  12738. {
  12739. 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")));
  12740. }
  12741. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "instance") != NULL)
  12742. {
  12743. 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")));
  12744. }
  12745. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "evse") != NULL)
  12746. {
  12747. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "getVariableData"), idx), "component"), "evse"), "id") != NULL)
  12748. {
  12749. 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"));
  12750. }
  12751. 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)
  12752. {
  12753. 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"));
  12754. }
  12755. }
  12756. }
  12757. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable") != NULL)
  12758. {
  12759. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "name") != NULL)
  12760. {
  12761. 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")));
  12762. }
  12763. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "instance") != NULL)
  12764. {
  12765. 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")));
  12766. }
  12767. }
  12768. }
  12769. }
  12770. }
  12771. }
  12772. json_object_put(GetReport);
  12773. /*
  12774. * TODO:
  12775. * 1. Response result
  12776. */
  12777. strcpy((char*)ShmOCPP20Data->GetReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  12778. sendGetReportConfirmation(uuid);
  12779. return result;
  12780. }
  12781. int handleGetTransactionStatusRequest(char *uuid, char *payload)
  12782. {
  12783. mtrace();
  12784. int result = FAIL;
  12785. int8_t gun_index = -1;
  12786. json_object *GetTransactionStatus;
  12787. DEBUG_INFO("handleGetTransactionStatusRequest...\n");
  12788. GetTransactionStatus = json_tokener_parse(payload);
  12789. if(!is_error(GetTransactionStatus))
  12790. {
  12791. /*
  12792. * TODO:
  12793. * 1. Check transaction locate which connector
  12794. */
  12795. memset(&ShmOCPP20Data->GetTransactionStatus[gun_index], 0, sizeof(struct GetTransactionStatus_20));
  12796. memcpy(&ShmOCPP20Data->GetTransactionStatus[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetTransactionStatus[gun_index].guid));
  12797. if(json_object_object_get(GetTransactionStatus, "transactionId") != NULL)
  12798. {
  12799. sprintf((char*)ShmOCPP20Data->GetTransactionStatus[gun_index].transactionId, "%s", json_object_get_string(json_object_object_get(GetTransactionStatus, "transactionId")));
  12800. }
  12801. ShmOCPP20Data->GetTransactionStatus[gun_index].Response_messagesInQueue = FALSE;
  12802. ShmOCPP20Data->GetTransactionStatus[gun_index].Response_ongoingIndicator = FALSE;
  12803. }
  12804. json_object_put(GetTransactionStatus);
  12805. sendGetTransactionStatusConfirmation(uuid, gun_index);
  12806. return result;
  12807. }
  12808. int handleGetVariablesRequest(char *uuid, char *payload)
  12809. {
  12810. mtrace();
  12811. int result = FAIL;
  12812. json_object *GetVariables;
  12813. DEBUG_INFO("handleGetVariablesRequest...\n");
  12814. GetVariables = json_tokener_parse(payload);
  12815. if(!is_error(GetVariables))
  12816. {
  12817. memset(&ShmOCPP20Data->GetVariables, 0, sizeof(struct SetVariables_20));
  12818. memcpy(&ShmOCPP20Data->GetVariables.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetVariables.guid));
  12819. // Required data
  12820. if(json_object_array_length(json_object_object_get(GetVariables, "getVariableData")) <= ARRAY_SIZE(ShmOCPP20Data->GetVariables.getVariableData))
  12821. {
  12822. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetVariables, "getVariableData"));idx++)
  12823. {
  12824. if(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx) != NULL)
  12825. {
  12826. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "attributeType") != NULL)
  12827. {
  12828. 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")));
  12829. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, (char*)ShmOCPP20Data->GetVariables.getVariableData[idx].attributeType);
  12830. }
  12831. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component") != NULL)
  12832. {
  12833. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "name") != NULL)
  12834. {
  12835. 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")));
  12836. }
  12837. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "instance") != NULL)
  12838. {
  12839. 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")));
  12840. }
  12841. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "evse") != NULL)
  12842. {
  12843. 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)
  12844. {
  12845. 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"));
  12846. }
  12847. 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)
  12848. {
  12849. 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"));
  12850. }
  12851. }
  12852. memcpy(&ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component, &ShmOCPP20Data->GetVariables.getVariableData[idx].component, sizeof(struct ComponentType));
  12853. }
  12854. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable") != NULL)
  12855. {
  12856. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "name") != NULL)
  12857. {
  12858. 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")));
  12859. }
  12860. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "instance") != NULL)
  12861. {
  12862. 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")));
  12863. }
  12864. memcpy(&ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable , &ShmOCPP20Data->GetVariables.getVariableData[idx].variable, sizeof(struct VariableType));
  12865. }
  12866. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  12867. {
  12868. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name) == 0) &&
  12869. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.instance, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.instance) == 0) &&
  12870. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name) == 0) &&
  12871. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.instance, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.instance) == 0))
  12872. {
  12873. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_Accepted]);
  12874. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, "ChargingStation") == 0) &&
  12875. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, "SystemUptimeSec") == 0))
  12876. {
  12877. struct sysinfo s_info;
  12878. int error = sysinfo(&s_info);
  12879. if(error != 0)
  12880. {
  12881. DEBUG_WARN("System uptime get error: %d\n", error);
  12882. }
  12883. else
  12884. {
  12885. sprintf((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, "%ld", s_info.uptime);
  12886. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value, "%ld", s_info.uptime);
  12887. }
  12888. }
  12889. else if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, "ChargingStation") == 0) &&
  12890. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, "FreeVend") == 0))
  12891. {
  12892. sprintf((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, "%s", (ShmSysConfigAndInfo->SysConfig.AuthorisationMode?"TRUE":"FALSE"));
  12893. }
  12894. else
  12895. {
  12896. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value);
  12897. }
  12898. break;
  12899. }
  12900. else
  12901. {
  12902. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_UnknownComponent]);
  12903. memset(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, 0x00, ARRAY_SIZE(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue));
  12904. }
  12905. }
  12906. }
  12907. }
  12908. }
  12909. sendGetVariablesConfirmation(uuid, json_object_array_length(json_object_object_get(GetVariables, "getVariableData")));
  12910. }
  12911. json_object_put(GetVariables);
  12912. return result;
  12913. }
  12914. int handleInstallCertificateRequest(char *uuid, char *payload)
  12915. {
  12916. mtrace();
  12917. int result = FAIL;
  12918. json_object *InstallCertificate;
  12919. DEBUG_INFO("handleInstallCertificateRequest...\n");
  12920. InstallCertificate = json_tokener_parse(payload);
  12921. if(!is_error(InstallCertificate))
  12922. {
  12923. memset(&ShmOCPP20Data->InstallCertificate, 0, sizeof(struct InstallCertificate_20));
  12924. memcpy(&ShmOCPP20Data->InstallCertificate.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->InstallCertificate.guid));
  12925. // Required data
  12926. if(json_object_object_get(InstallCertificate, "certificateType") != NULL)
  12927. {
  12928. sprintf((char*)ShmOCPP20Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  12929. }
  12930. if(json_object_object_get(InstallCertificate, "certificate") != NULL)
  12931. {
  12932. sprintf((char*)ShmOCPP20Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  12933. }
  12934. }
  12935. json_object_put(InstallCertificate);
  12936. /*
  12937. * TODO:
  12938. * 1. Install certification preocess and response
  12939. */
  12940. if(strstr((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_V2GRootCertificate]))
  12941. {
  12942. }
  12943. else if(strstr((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_MORootCertificate]))
  12944. {
  12945. }
  12946. else if(strstr((char*)ShmOCPP20Data->InstallCertificate.certificateType, InstallCertificateUseEnumTypeStr[InstallCertificateUseEnumType_CSMSRootCertificate]))
  12947. {
  12948. }
  12949. else
  12950. {
  12951. }
  12952. strcpy((char*)ShmOCPP20Data->InstallCertificate.Response_status, InstallCertificateStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  12953. sendInstallCertificateConfirmation(uuid);
  12954. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12955. return result;
  12956. }
  12957. int handlePublishFirmwareRequest(char *uuid, char *payload)
  12958. {
  12959. mtrace();
  12960. int result = FAIL;
  12961. json_object *PublishFirmware;
  12962. DEBUG_INFO("handlePublishFirmwareRequest...\n");
  12963. PublishFirmware = json_tokener_parse(payload);
  12964. if(!is_error(PublishFirmware))
  12965. {
  12966. memset(&ShmOCPP20Data->PublishFirmware, 0, sizeof(struct PublishFirmware_20));
  12967. memcpy(&ShmOCPP20Data->PublishFirmware.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->PublishFirmware.guid));
  12968. // Required data
  12969. if(json_object_object_get(PublishFirmware, "requestId") != NULL)
  12970. {
  12971. ShmOCPP20Data->PublishFirmware.requestId = json_object_get_int(json_object_object_get(PublishFirmware, "requestId"));
  12972. }
  12973. if(json_object_object_get(PublishFirmware, "checksum") != NULL)
  12974. {
  12975. sprintf((char*)ShmOCPP20Data->PublishFirmware.requestId, "%s", json_object_get_string(json_object_object_get(PublishFirmware, "checksum")));
  12976. }
  12977. // Optional data
  12978. if(json_object_object_get(PublishFirmware, "location") != NULL)
  12979. {
  12980. sprintf((char*)ShmOCPP20Data->PublishFirmware.location, "%s", json_object_get_string(json_object_object_get(PublishFirmware, "location")));
  12981. }
  12982. if(json_object_object_get(PublishFirmware, "retries") != NULL)
  12983. {
  12984. ShmOCPP20Data->PublishFirmware.retries = json_object_get_int(json_object_object_get(PublishFirmware, "retries"));
  12985. }
  12986. if(json_object_object_get(PublishFirmware, "retryInterval") != NULL)
  12987. {
  12988. ShmOCPP20Data->PublishFirmware.retryInterval = json_object_get_int(json_object_object_get(PublishFirmware, "retryInterval"));
  12989. }
  12990. }
  12991. json_object_put(PublishFirmware);
  12992. /*
  12993. * TODO:
  12994. * 1. Publish firmware preocess and response
  12995. */
  12996. strcpy((char*)ShmOCPP20Data->PublishFirmware.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  12997. sendPublishFirmwareConfirmation(uuid);
  12998. return result;
  12999. }
  13000. int handleRequestStartTransactionRequest(char *uuid, char *payload)
  13001. {
  13002. mtrace();
  13003. int result = FAIL;
  13004. int8_t connectorIdx = -1;
  13005. uint8_t tempIndex;
  13006. uint8_t isOverConnectorMax = FALSE;
  13007. uint8_t isPeriodOverMax = FALSE;
  13008. uint8_t isTxProfile = TRUE;
  13009. uint8_t isAllowStart = TRUE;
  13010. uint8_t filename[128]={0};
  13011. char cmdBuf[128];
  13012. FILE *filePtr;
  13013. json_object *RemoteStartTransaction;
  13014. DEBUG_INFO("handleRequestStartTransactionRequest...\n");
  13015. RemoteStartTransaction = json_tokener_parse(payload);
  13016. if(!is_error(RemoteStartTransaction))
  13017. {
  13018. if(json_object_object_get(RemoteStartTransaction, "evseId") != NULL)
  13019. {
  13020. if((0 < json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"))) && (json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"))<=gunTotalNumber))
  13021. {
  13022. connectorIdx = json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"));
  13023. }
  13024. else
  13025. {
  13026. isOverConnectorMax = TRUE;
  13027. DEBUG_WARN("Connector id shall not equal 0 and less than max connector id.\n");
  13028. }
  13029. }
  13030. else
  13031. {
  13032. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13033. {
  13034. if(!cpinitateMsg.bits[idx].isOnCharging && (strstr((char*)ShmOCPP20Data->StatusNotification[idx].connectorStatus, ConnectorStatusEnumTypeStr[ConnectorStatusEnumType_Occupied]) != NULL))
  13035. {
  13036. connectorIdx = (idx+1);
  13037. DEBUG_INFO("Remote start without connectorId but detect connector-%02d connected ready to start.\n", connectorIdx);
  13038. break;
  13039. }
  13040. }
  13041. }
  13042. if(isOverConnectorMax == FALSE)
  13043. {
  13044. if(connectorIdx > 0)
  13045. {
  13046. DEBUG_INFO("Connector id: %d\n", connectorIdx);
  13047. memset(&ShmOCPP20Data->RequestStartTransaction[connectorIdx-1], 0, sizeof(struct RequestStartTransaction_20));
  13048. memcpy(&ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].guid));
  13049. // Required data
  13050. if(json_object_object_get(RemoteStartTransaction, "remoteStartId") != NULL)
  13051. {
  13052. ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].remoteStartId = json_object_get_int(json_object_object_get(RemoteStartTransaction, "remoteStartId"));
  13053. }
  13054. if(json_object_object_get(RemoteStartTransaction, "idToken") != NULL)
  13055. {
  13056. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken") != NULL)
  13057. {
  13058. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken")));
  13059. }
  13060. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type") != NULL)
  13061. {
  13062. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type")));
  13063. }
  13064. }
  13065. // Optional data
  13066. if(json_object_object_get(RemoteStartTransaction, "groupIdToken") != NULL)
  13067. {
  13068. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken") != NULL)
  13069. {
  13070. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken")));
  13071. }
  13072. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type") != NULL)
  13073. {
  13074. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type")));
  13075. }
  13076. }
  13077. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  13078. {
  13079. // Check periods is over max configuration
  13080. 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))
  13081. {
  13082. isPeriodOverMax = TRUE;
  13083. }
  13084. // Check profile purpose is TxProfile
  13085. if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  13086. {
  13087. ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].chargingProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "id"));
  13088. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", connectorIdx);
  13089. }
  13090. else
  13091. {
  13092. isTxProfile = FALSE;
  13093. }
  13094. }
  13095. //check Transaction active
  13096. if(gunType[connectorIdx-1] == GUN_TYPE_CHAdeMO)
  13097. {
  13098. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13099. {
  13100. tempIndex = ((connectorIdx-1) == 2) ? 1: 0;
  13101. }
  13102. else
  13103. {
  13104. tempIndex = (connectorIdx-1);
  13105. }
  13106. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13107. {
  13108. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  13109. {
  13110. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) == 0))
  13111. {
  13112. //Reserved
  13113. DEBUG_INFO("CHAdeMO connector already reserved and idTag match.\n");
  13114. }
  13115. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) != 0))
  13116. {
  13117. //Reserved
  13118. DEBUG_INFO("CHAdeMO connector already reserved and idTag does not match.\n");
  13119. isAllowStart = FALSE;
  13120. }
  13121. else
  13122. {
  13123. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  13124. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  13125. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  13126. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  13127. {
  13128. DEBUG_WARN("CHAdeMO connector not allow start cause busy.\n.");
  13129. isAllowStart = FALSE;
  13130. }
  13131. }//END FOR ELSE
  13132. }
  13133. }// END FOR CHAdeMO_QUANTITY
  13134. }
  13135. else if(gunType[connectorIdx-1] == GUN_TYPE_CCS)
  13136. {
  13137. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13138. {
  13139. tempIndex = ((connectorIdx-1) == 2) ? 1: 0;
  13140. }
  13141. else
  13142. {
  13143. tempIndex = (connectorIdx-1);
  13144. }
  13145. for (int index = 0; index < CCS_QUANTITY; index++)
  13146. {
  13147. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13148. {
  13149. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) == 0))
  13150. {
  13151. //Reserved
  13152. DEBUG_INFO("CCS connector already reserved and idTag match.\n");
  13153. }
  13154. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) != 0))
  13155. {
  13156. //Reserved
  13157. DEBUG_INFO("CCS connector already reserved and idTag does not match.\n");
  13158. isAllowStart = FALSE;
  13159. }
  13160. else
  13161. {
  13162. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  13163. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  13164. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  13165. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  13166. {
  13167. DEBUG_WARN("CCS connector not allow start cause busy.\n.");
  13168. isAllowStart = FALSE;
  13169. }
  13170. }// END FOR ELSE
  13171. }
  13172. }// END FOR CCS_QUANTITY
  13173. }
  13174. else if(gunType[connectorIdx-1] == GUN_TYPE_GBT)
  13175. {
  13176. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13177. {
  13178. tempIndex = ((connectorIdx-1) == 2) ? 1: 0;
  13179. }
  13180. else
  13181. {
  13182. tempIndex = (connectorIdx-1);
  13183. }
  13184. for (int index = 0; index < GB_QUANTITY; index++)
  13185. {
  13186. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  13187. {
  13188. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) == 0))
  13189. {
  13190. //Reserved
  13191. DEBUG_INFO("GBT connector already reserved and idTag match.\n");
  13192. }
  13193. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) != 0))
  13194. {
  13195. //Reserved
  13196. DEBUG_INFO("GBT connector already reserved and idTag does not match.\n");
  13197. isAllowStart = FALSE;
  13198. }
  13199. else
  13200. {
  13201. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  13202. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  13203. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  13204. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  13205. {
  13206. DEBUG_WARN("GBT connector not allow start cause busy.\n");
  13207. isAllowStart = FALSE;
  13208. }
  13209. }// END FOR ELSE
  13210. }
  13211. } // END FOR GB_QUANTITY
  13212. }
  13213. else if(gunType[connectorIdx-1] == GUN_TYPE_DO)
  13214. {
  13215. tempIndex = (connectorIdx-1);
  13216. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13217. {
  13218. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  13219. {
  13220. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) == 0))
  13221. {
  13222. //Reserved
  13223. DEBUG_INFO("Dispenser connector already reserved and idTag match.\n");
  13224. }
  13225. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) != 0))
  13226. {
  13227. //Reserved
  13228. DEBUG_INFO("Dispenser connector already reserved and idTag does not match.\n");
  13229. isAllowStart = FALSE;
  13230. }
  13231. else
  13232. {
  13233. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  13234. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  13235. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  13236. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  13237. {
  13238. DEBUG_WARN("Dispenser connector not allow start cause busy.\n");
  13239. isAllowStart = FALSE;
  13240. }
  13241. }// END FOR ELSE
  13242. }
  13243. } // END FOR GB_QUANTITY
  13244. }
  13245. else
  13246. {
  13247. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13248. {
  13249. tempIndex = 2;
  13250. }
  13251. else
  13252. {
  13253. tempIndex = (connectorIdx-1);
  13254. }
  13255. for (int index = 0; index < AC_QUANTITY; index++)
  13256. {
  13257. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  13258. {
  13259. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) == 0))
  13260. {
  13261. //Reserved
  13262. DEBUG_INFO("AC connector already reserved and idTag match.\n");
  13263. }
  13264. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP20Data->ReserveNow[index].idToken.idToken, (char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].idToken.idToken) != 0))
  13265. {
  13266. //Reserved
  13267. DEBUG_INFO("AC connector already reserved and idTag does not match.\n");
  13268. isAllowStart = FALSE;
  13269. }
  13270. else
  13271. {
  13272. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  13273. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  13274. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  13275. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  13276. {
  13277. DEBUG_WARN("AC connector not allow start cause busy.\n");
  13278. isAllowStart = FALSE;
  13279. }
  13280. }//END FOR ELSE
  13281. }
  13282. }// END FOR AC_QUANTITY
  13283. }
  13284. }
  13285. else
  13286. {
  13287. DEBUG_INFO("Connector id does not specific.\n");
  13288. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  13289. {
  13290. memset(&ShmOCPP20Data->RequestStartTransaction[gun_index], 0, sizeof(struct RequestStartTransaction_20));
  13291. memcpy(&ShmOCPP20Data->RequestStartTransaction[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->RequestStartTransaction[gun_index].guid));
  13292. // Required data
  13293. if(json_object_object_get(RemoteStartTransaction, "remoteStartId") != NULL)
  13294. {
  13295. ShmOCPP20Data->RequestStartTransaction[gun_index].remoteStartId = json_object_get_int(json_object_object_get(RemoteStartTransaction, "remoteStartId"));
  13296. }
  13297. if(json_object_object_get(RemoteStartTransaction, "idToken") != NULL)
  13298. {
  13299. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken") != NULL)
  13300. {
  13301. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken")));
  13302. }
  13303. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type") != NULL)
  13304. {
  13305. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type")));
  13306. }
  13307. }
  13308. // Optional data
  13309. if(json_object_object_get(RemoteStartTransaction, "groupIdToken") != NULL)
  13310. {
  13311. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken") != NULL)
  13312. {
  13313. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken")));
  13314. }
  13315. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type") != NULL)
  13316. {
  13317. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type")));
  13318. }
  13319. }
  13320. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  13321. {
  13322. // Check periods is over max configuration
  13323. 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))
  13324. {
  13325. isPeriodOverMax = TRUE;
  13326. }
  13327. // Check profile purpose is TxProfile
  13328. if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  13329. {
  13330. ShmOCPP20Data->RequestStartTransaction[gun_index].chargingProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "id"));
  13331. sprintf((char*)filename, "/Storage/OCPP/TxProfile_Tmp_OCPP20.json");
  13332. }
  13333. else
  13334. {
  13335. isTxProfile = FALSE;
  13336. }
  13337. }
  13338. }
  13339. }
  13340. }
  13341. // Profile replace or add info
  13342. if((isOverConnectorMax == FALSE) && !isPeriodOverMax && isTxProfile && isAllowStart)
  13343. {
  13344. if(connectorIdx != -1)
  13345. {
  13346. if(strlen((char*)filename) > 0)
  13347. {
  13348. // Save profile to file
  13349. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d_OCPP20.json", connectorIdx);
  13350. system(cmdBuf);
  13351. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json.json", connectorIdx);
  13352. filePtr = fopen((char*)filename, "w");
  13353. fprintf(filePtr, "{\"evseId\":%d,\"chargingProfile\":%s}\n", connectorIdx, json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  13354. fclose(filePtr);
  13355. }
  13356. ShmOCPP20Data->CsMsg.bits[connectorIdx-1].RequestStartTransactionReq = ON;
  13357. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  13358. random_uuid((char*)ShmOCPP20Data->RequestStartTransaction[connectorIdx-1].Response_transactionId);
  13359. result = PASS;
  13360. }
  13361. else
  13362. {
  13363. uint8_t isHasIdleConnector = FALSE;
  13364. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  13365. {
  13366. if(!cpinitateMsg.bits[gun_index].isOnCharging)
  13367. {
  13368. isHasIdleConnector = TRUE;
  13369. break;
  13370. }
  13371. }
  13372. if(isHasIdleConnector == TRUE)
  13373. {
  13374. DEBUG_INFO("Start wait connector link to EV in %s seconds.\n", ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value);
  13375. if(strlen((char*)filename) > 0)
  13376. {
  13377. // Save profile to file
  13378. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_Tmp_OCPP20.json");
  13379. system(cmdBuf);
  13380. sprintf((char*)filename, "/Storage/OCPP/TxProfile_Tmp_OCPP20.json.json");
  13381. filePtr = fopen((char*)filename, "w");
  13382. fprintf(filePtr, "{\"evseId\":0,\"chargingProfile\":%s}\n", json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  13383. fclose(filePtr);
  13384. }
  13385. refreshStartTimer(&clientTime.RemoteStartWait);
  13386. ShmOCPP20Data->MsMsg.bits.isRemoteStartWaitReq = ON;
  13387. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  13388. {
  13389. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  13390. random_uuid((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId);
  13391. }
  13392. result = PASS;
  13393. }
  13394. else
  13395. {
  13396. DEBUG_INFO("There is not any connector is idle.\n");
  13397. for(uint8_t gun_index=0;gun_index<gunTotalNumber;gun_index++)
  13398. strcpy((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status, RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  13399. }
  13400. }
  13401. }
  13402. else
  13403. {
  13404. if(isOverConnectorMax != FALSE)
  13405. DEBUG_WARN("evseId id equal 0 or over maximun id.\n");
  13406. if(isPeriodOverMax)
  13407. DEBUG_WARN("Profile periods quantity is over spec.\n");
  13408. if(!isTxProfile)
  13409. DEBUG_WARN("Profile purpose is not TxProfile.\n");
  13410. if(!isAllowStart)
  13411. DEBUG_WARN("Target connector does not allow start.\n");
  13412. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[((connectorIdx-1)<0?0:(connectorIdx-1))].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected] );
  13413. }
  13414. }
  13415. json_object_put(RemoteStartTransaction);
  13416. sendRemoteStartTransactionConfirmation(uuid, ((connectorIdx-1)<0?0:(connectorIdx-1)));
  13417. return result;
  13418. }
  13419. int handleRequestStopTransactionRequest(char *uuid, char *payload)
  13420. {
  13421. mtrace();
  13422. int result = FAIL;
  13423. int match = FALSE;
  13424. int GunNO = 0;
  13425. int tempIndex = 0;
  13426. char transactionIdStr[37];
  13427. int transactionIdIsNULL= TRUE;
  13428. json_object *RemoteStopTransaction;
  13429. DEBUG_INFO("handleRequestStopTransactionRequest...\n");
  13430. if(server_pending == TRUE)
  13431. {
  13432. return 0;
  13433. }
  13434. RemoteStopTransaction = json_tokener_parse(payload);
  13435. if(!is_error(RemoteStopTransaction))
  13436. {
  13437. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  13438. {
  13439. sprintf(transactionIdStr, "%s", json_object_get_string(json_object_object_get(RemoteStopTransaction, "transactionId")));
  13440. transactionIdIsNULL = FALSE;
  13441. }
  13442. }
  13443. json_object_put(RemoteStopTransaction);
  13444. if(transactionIdIsNULL == FALSE)
  13445. {
  13446. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  13447. {
  13448. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, transactionIdStr) != NULL)
  13449. {
  13450. //check Transaction active
  13451. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  13452. {
  13453. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13454. {
  13455. tempIndex = ((gun_index==2) ? 1: 0);
  13456. }
  13457. else
  13458. {
  13459. tempIndex = gun_index;
  13460. }
  13461. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13462. {
  13463. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13464. {
  13465. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  13466. {
  13467. match = TRUE;
  13468. GunNO = gun_index;
  13469. }
  13470. }
  13471. }// END FOR CHAdeMO_QUANTITY
  13472. }
  13473. else if(gunType[gun_index] == GUN_TYPE_CCS)
  13474. {
  13475. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13476. {
  13477. tempIndex = ((gun_index==2) ? 1: 0);
  13478. }
  13479. else
  13480. {
  13481. tempIndex = gun_index;
  13482. }
  13483. for (int index = 0; index < CCS_QUANTITY; index++)
  13484. {
  13485. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13486. {
  13487. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  13488. {
  13489. match = TRUE;
  13490. GunNO = gun_index;
  13491. }
  13492. }
  13493. }// END FOR CCS_QUANTITY
  13494. }
  13495. else if(gunType[gun_index] == GUN_TYPE_GBT)
  13496. {
  13497. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13498. {
  13499. tempIndex = ((gun_index==2) ? 1: 0);
  13500. }
  13501. else
  13502. {
  13503. tempIndex = gun_index;
  13504. }
  13505. for (int index = 0; index < GB_QUANTITY; index++)
  13506. {
  13507. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13508. {
  13509. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  13510. {
  13511. match = TRUE;
  13512. GunNO = gun_index;
  13513. }
  13514. }
  13515. }// END FOR GB_QUANTITY
  13516. }
  13517. else if(gunType[gun_index] == GUN_TYPE_DO)
  13518. {
  13519. tempIndex = gun_index;
  13520. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13521. {
  13522. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13523. {
  13524. 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
  13525. {
  13526. match = TRUE;
  13527. GunNO = gun_index;
  13528. }
  13529. }
  13530. }// END FOR GB_QUANTITY
  13531. }
  13532. else
  13533. {
  13534. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13535. {
  13536. tempIndex = 2;
  13537. }
  13538. else
  13539. {
  13540. tempIndex = gun_index;
  13541. }
  13542. for (int index = 0; index < AC_QUANTITY; index++)
  13543. {
  13544. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13545. {
  13546. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  13547. {
  13548. match = TRUE;
  13549. GunNO = gun_index;
  13550. }
  13551. }
  13552. }// END FOR CHAdeMO_QUANTITY
  13553. } // END FOR AC ELSE
  13554. }// CHECK IF ResponseTransactionId == transactionIdInt
  13555. }//END FOR
  13556. if( match == TRUE)
  13557. {
  13558. ShmOCPP20Data->CsMsg.bits[GunNO].RequestStopTransactionReq = ON; // inform csu of StopTransaction
  13559. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  13560. }
  13561. else
  13562. {
  13563. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  13564. }
  13565. }
  13566. else
  13567. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  13568. sendRemoteStopTransactionConfirmation(uuid, GunNO);
  13569. return result;
  13570. }
  13571. int handleReserveNowRequest(char *uuid, char *payload)
  13572. {
  13573. mtrace();
  13574. int result = FAIL;
  13575. int connectorIdInt=0, reservationIdInt=0;
  13576. int tempIndex = 0;
  13577. json_object *ReserveNow;
  13578. DEBUG_INFO("handleReserveNowRequest ...\n");
  13579. ReserveNow = json_tokener_parse(payload);
  13580. if(!is_error(ReserveNow))
  13581. {
  13582. if(json_object_object_get(ReserveNow, "evseId") != NULL)
  13583. {
  13584. connectorIdInt = json_object_get_int(json_object_object_get(ReserveNow, "evseId"));
  13585. connectorIdInt = (connectorIdInt==0)?1:connectorIdInt;
  13586. memset(&ShmOCPP20Data->ReserveNow[connectorIdInt-1], 0x00, sizeof(struct ReserveNow_20));
  13587. ShmOCPP20Data->ReserveNow[connectorIdInt-1].evseId = json_object_get_int(json_object_object_get(ReserveNow, "evseId"));
  13588. }
  13589. // Required data
  13590. if(json_object_object_get(ReserveNow, "reservationId") != NULL)
  13591. ShmOCPP20Data->ReserveNow[connectorIdInt-1].id = json_object_get_int(json_object_object_get(ReserveNow, "reservationId"));
  13592. if(json_object_object_get(ReserveNow, "expiryDateTime") != NULL)
  13593. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].expiryDateTime, "%s", json_object_get_string(json_object_object_get(ReserveNow, "expiryDateTime")));
  13594. if(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "idToken") != NULL)
  13595. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "idToken")));
  13596. if(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "type") != NULL)
  13597. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "type")));
  13598. // Optional data
  13599. if(json_object_object_get(ReserveNow, "connectorType") != NULL)
  13600. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].connectorType, "%s", json_object_get_string(json_object_object_get(ReserveNow, "connectorType")));
  13601. if(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "idToken") != NULL)
  13602. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "idToken")));
  13603. if(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "type") != NULL)
  13604. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "type")));
  13605. result = PASS;
  13606. }
  13607. json_object_put(ReserveNow);
  13608. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  13609. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  13610. {
  13611. //check Transaction active
  13612. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  13613. {
  13614. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13615. {
  13616. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13617. }
  13618. else
  13619. {
  13620. tempIndex = connectorIdInt -1;
  13621. }
  13622. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13623. {
  13624. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13625. {
  13626. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  13627. {
  13628. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  13629. {
  13630. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  13631. {
  13632. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  13633. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  13634. }
  13635. 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'))
  13636. {
  13637. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  13638. }
  13639. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  13640. {
  13641. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  13642. }
  13643. else
  13644. {
  13645. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  13646. }
  13647. }
  13648. 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
  13649. {
  13650. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  13651. }
  13652. }
  13653. else
  13654. {
  13655. //replace reservation
  13656. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  13657. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  13658. }
  13659. }
  13660. } // END FOR CHAdeMO_QUANTITY
  13661. }
  13662. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  13663. {
  13664. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13665. {
  13666. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13667. }
  13668. else
  13669. {
  13670. tempIndex = connectorIdInt -1;
  13671. }
  13672. for (int index = 0; index < CCS_QUANTITY; index++)
  13673. {
  13674. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13675. {
  13676. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  13677. {
  13678. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  13679. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  13680. {
  13681. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  13682. {
  13683. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  13684. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  13685. }
  13686. 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'))
  13687. {
  13688. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  13689. }
  13690. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  13691. {
  13692. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  13693. }
  13694. else
  13695. {
  13696. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  13697. }
  13698. }
  13699. 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
  13700. {
  13701. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  13702. }
  13703. }
  13704. else
  13705. {
  13706. //replace reservation
  13707. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  13708. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  13709. }
  13710. }
  13711. } // END FOR CCS_QUANTITY
  13712. }
  13713. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  13714. {
  13715. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13716. {
  13717. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13718. }
  13719. else
  13720. {
  13721. tempIndex = connectorIdInt -1;
  13722. }
  13723. for (int index = 0; index < GB_QUANTITY; index++)
  13724. {
  13725. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13726. {
  13727. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  13728. {
  13729. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  13730. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  13731. {
  13732. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  13733. {
  13734. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  13735. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  13736. }
  13737. 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'))
  13738. {
  13739. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  13740. }
  13741. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  13742. {
  13743. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  13744. }
  13745. else
  13746. {
  13747. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  13748. }
  13749. }
  13750. 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
  13751. {
  13752. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  13753. }
  13754. }
  13755. else
  13756. {
  13757. //replace reservation
  13758. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  13759. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  13760. }
  13761. }
  13762. }// END FOR GB_QUANTITY
  13763. }
  13764. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  13765. {
  13766. tempIndex = connectorIdInt -1;
  13767. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13768. {
  13769. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13770. {
  13771. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  13772. {
  13773. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  13774. 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
  13775. {
  13776. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  13777. {
  13778. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  13779. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  13780. }
  13781. 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'))
  13782. {
  13783. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  13784. }
  13785. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  13786. {
  13787. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  13788. }
  13789. else
  13790. {
  13791. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  13792. }
  13793. }
  13794. 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
  13795. {
  13796. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  13797. }
  13798. }
  13799. else
  13800. {
  13801. //replace reservation
  13802. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  13803. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  13804. }
  13805. }
  13806. }// END FOR DO_QUANTITY
  13807. }
  13808. else
  13809. {
  13810. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  13811. {
  13812. tempIndex = 2;
  13813. }
  13814. else
  13815. {
  13816. tempIndex = (connectorIdInt -1);
  13817. }
  13818. for (int index = 0; index < AC_QUANTITY; index++)
  13819. {
  13820. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13821. {
  13822. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  13823. {
  13824. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  13825. {
  13826. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  13827. {
  13828. 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))
  13829. {
  13830. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  13831. }
  13832. else
  13833. {
  13834. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  13835. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  13836. }
  13837. }
  13838. 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'))
  13839. {
  13840. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  13841. }
  13842. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  13843. {
  13844. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  13845. }
  13846. else
  13847. {
  13848. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  13849. }
  13850. }
  13851. 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
  13852. {
  13853. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  13854. }
  13855. }
  13856. else
  13857. {
  13858. //replace reservation
  13859. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  13860. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  13861. }
  13862. }
  13863. } // END FOR AC_QUANTITY
  13864. }
  13865. }
  13866. else if(connectorIdInt == 0)
  13867. {
  13868. //check Transaction active
  13869. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13870. {
  13871. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  13872. {
  13873. 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'))
  13874. {
  13875. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  13876. goto end;
  13877. }
  13878. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  13879. {
  13880. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  13881. goto end;
  13882. }
  13883. 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
  13884. {
  13885. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  13886. goto end;
  13887. }
  13888. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  13889. {
  13890. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  13891. goto end;
  13892. }
  13893. }
  13894. }// END FOR CHAdeMO_QUANTITY
  13895. for (int index = 0; index < CCS_QUANTITY; index++)
  13896. {
  13897. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  13898. {
  13899. 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'))
  13900. {
  13901. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  13902. goto end;
  13903. }
  13904. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  13905. {
  13906. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  13907. goto end;
  13908. }
  13909. 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
  13910. {
  13911. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  13912. goto end;
  13913. }
  13914. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  13915. {
  13916. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  13917. goto end;
  13918. }
  13919. }
  13920. } // END FOR CCS_QUANTITY
  13921. for (int index = 0; index < GB_QUANTITY; index++)
  13922. {
  13923. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  13924. {
  13925. 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'))
  13926. {
  13927. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  13928. goto end;
  13929. }
  13930. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  13931. {
  13932. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  13933. goto end;
  13934. }
  13935. 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
  13936. {
  13937. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  13938. goto end;
  13939. }
  13940. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  13941. {
  13942. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  13943. goto end;
  13944. }
  13945. }
  13946. } // END FOR GB_QUANTITY
  13947. for (int index = 0; index < AC_QUANTITY; index++)
  13948. {
  13949. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  13950. {
  13951. 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'))
  13952. {
  13953. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  13954. goto end;
  13955. }
  13956. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  13957. {
  13958. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  13959. goto end;
  13960. }
  13961. 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
  13962. {
  13963. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  13964. goto end;
  13965. }
  13966. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  13967. {
  13968. 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))
  13969. {
  13970. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  13971. goto end;
  13972. }
  13973. }
  13974. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  13975. {
  13976. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  13977. goto end;
  13978. }
  13979. }
  13980. }// END FOR AC_QUANTITY
  13981. //The connectorId is 0
  13982. ShmOCPP20Data->CsMsg.bits[0].ReserveNowReq = ON;
  13983. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  13984. strcpy((char *)ShmOCPP20Data->ReserveNow[0].guid, uuid);
  13985. result = TRUE;
  13986. return result;
  13987. }
  13988. else
  13989. {
  13990. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  13991. }
  13992. if(strcmp((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status,ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]) == 0)
  13993. {
  13994. strcpy((char *)ShmOCPP20Data->ReserveNow[connectorIdInt-1].guid, uuid);
  13995. result = TRUE;
  13996. return result;
  13997. }
  13998. end:
  13999. sendReserveNowConfirmation(uuid, (connectorIdInt==0?connectorIdInt:connectorIdInt-1));
  14000. return result;
  14001. }
  14002. int handleResetRequest(char *uuid, char *payload)
  14003. {
  14004. mtrace();
  14005. int result = FAIL;
  14006. json_object *Reset = json_object_new_object();
  14007. DEBUG_INFO("handleResetRequest...\n");
  14008. Reset = json_tokener_parse(payload);
  14009. if(!is_error(Reset))
  14010. {
  14011. // Required data
  14012. if(json_object_object_get(Reset, "type") != NULL)
  14013. {
  14014. sprintf((char*)ShmOCPP20Data->Reset.type, "%s", json_object_get_string(json_object_object_get(Reset, "type")));
  14015. }
  14016. if(json_object_object_get(Reset, "evseId") != NULL)
  14017. {
  14018. ShmOCPP20Data->Reset.evseId = json_object_get_int(json_object_object_get(Reset, "evseId"));
  14019. }
  14020. }
  14021. json_object_put(Reset);
  14022. if((strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_Immediate])==0) || (strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_OnIdle])==0))
  14023. {
  14024. strcpy((char *)ShmOCPP20Data->Reset.guid, uuid);
  14025. strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]);
  14026. ShmOCPP20Data->MsMsg.bits.ResetReq = ON;
  14027. result = PASS;
  14028. }
  14029. else
  14030. {
  14031. strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Rejected]);
  14032. }
  14033. if(strlen((char*)ShmOCPP20Data->Reset.Response_status) > 0)
  14034. sendResetConfirmation(uuid);
  14035. return result;
  14036. }
  14037. int handleSendLocalListRequest(char *uuid, char *payload)
  14038. {
  14039. mtrace();
  14040. int result = FAIL;
  14041. char updateTypestr[15]={0};
  14042. int checkState_Faulted = FALSE;
  14043. json_object *SendLocalList;
  14044. DEBUG_INFO("handleSendLocalListRequest...\n");
  14045. if(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "FALSE") == 0)
  14046. {
  14047. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  14048. goto end;
  14049. }
  14050. SendLocalList = json_tokener_parse(payload);
  14051. if(!is_error(SendLocalList))
  14052. {
  14053. memset(&ShmOCPP20Data->SendLocalList, 0x00, sizeof(struct SendLocalList_20));
  14054. // Required data
  14055. if(json_object_object_get(SendLocalList, "versionNumber") != NULL)
  14056. {
  14057. ShmOCPP20Data->SendLocalList.versionNumber = json_object_get_int(json_object_object_get(SendLocalList, "versionNumber"));
  14058. }
  14059. if(json_object_object_get(SendLocalList, "updateType") != NULL)
  14060. sprintf((char*)ShmOCPP20Data->SendLocalList.updateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  14061. // Optional data
  14062. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  14063. {
  14064. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  14065. {
  14066. // Required data
  14067. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idToken") != NULL)
  14068. {
  14069. 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")));
  14070. sprintf((char*)ShmOCPP20Data->SendLocalList.localAuthorizationList[idx].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idToken"), "type")));
  14071. }
  14072. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  14073. {
  14074. sprintf((char*)ShmOCPP20Data->SendLocalList.localAuthorizationList[idx].idTokenInfo.status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "status")));
  14075. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "cacheExpiryDateTime") != NULL)
  14076. 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")));
  14077. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "chargingPriority") != NULL)
  14078. 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"));
  14079. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "groupIdToken") != NULL)
  14080. {
  14081. 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")));
  14082. 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")));
  14083. }
  14084. }
  14085. }
  14086. }
  14087. }
  14088. json_object_put(SendLocalList);
  14089. //check Charge Point state
  14090. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14091. {
  14092. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  14093. {
  14094. checkState_Faulted = TRUE; //OCPP Status: Faulted
  14095. }
  14096. }
  14097. for (int index = 0; index < CCS_QUANTITY; index++)
  14098. {
  14099. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  14100. {
  14101. checkState_Faulted = TRUE; //OCPP Status
  14102. }
  14103. }
  14104. for (int index = 0; index < GB_QUANTITY; index++)
  14105. {
  14106. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  14107. {
  14108. checkState_Faulted = TRUE; //OCPP Status: Faulted
  14109. }
  14110. }
  14111. for (int index = 0; index < AC_QUANTITY; index++)
  14112. {
  14113. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  14114. {
  14115. checkState_Faulted = TRUE; //OCPP Status: Faulted
  14116. }
  14117. }
  14118. if(checkState_Faulted == TRUE)
  14119. {
  14120. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  14121. goto end;
  14122. }
  14123. // Check update type
  14124. if(strcmp(updateTypestr, UpdateEnumTypeStr[UpdateEnumType_Full]) == 0)
  14125. {
  14126. //Local list full update
  14127. DEBUG_INFO("Local list full update.\n");
  14128. DB_getListVerion();
  14129. if(ShmOCPP20Data->SendLocalList.versionNumber < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  14130. {
  14131. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  14132. goto end;
  14133. }
  14134. DB_cleanLocalList();
  14135. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->SendLocalList.localAuthorizationList);idx++)
  14136. DB_addLocalList(ShmOCPP20Data->SendLocalList.versionNumber, &ShmOCPP20Data->SendLocalList.localAuthorizationList[idx]);
  14137. }
  14138. else if(strcmp(updateTypestr, UpdateEnumTypeStr[UpdateEnumType_Differential]) == 0)
  14139. {
  14140. //Local list different update
  14141. DEBUG_INFO("Local list different update.\n");
  14142. DB_getListVerion();
  14143. if(ShmOCPP20Data->SendLocalList.versionNumber < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  14144. {
  14145. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_VersionMismatch]);
  14146. goto end;
  14147. }
  14148. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->SendLocalList.localAuthorizationList);idx++)
  14149. DB_addLocalList(ShmOCPP20Data->SendLocalList.versionNumber, &ShmOCPP20Data->SendLocalList.localAuthorizationList[idx]);
  14150. }
  14151. else
  14152. {
  14153. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  14154. goto end;
  14155. }
  14156. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Accepted]);
  14157. end:
  14158. sendSendLocalListConfirmation(uuid);
  14159. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14160. return result;
  14161. }
  14162. int handleSetChargingProfileRequest(char *uuid, char *payload)
  14163. {
  14164. mtrace();
  14165. int result = FAIL;
  14166. struct SetChargingProfile_20 SetProfileReq = {0};
  14167. uint8_t isLostConnectorId = FALSE;
  14168. uint8_t isPeriodOverMax = FALSE;
  14169. uint8_t isProfileOverMax = FALSE;
  14170. uint8_t isConnectorMismatch = FALSE;
  14171. uint8_t isTransactiodIdMismatch = FALSE;
  14172. uint8_t existProfileQuantity = 0;
  14173. uint8_t filename[128]={0};
  14174. uint8_t dataLine[4096]={0};
  14175. FILE *filePtr;
  14176. json_object *SetChargingProfile;
  14177. DEBUG_INFO("handleSetChargingProfileRequest...\n");
  14178. SetChargingProfile = json_tokener_parse(payload);
  14179. if(!is_error(SetChargingProfile))
  14180. {
  14181. // Required data
  14182. if(json_object_object_get(SetChargingProfile, "evseId") != NULL)
  14183. SetProfileReq.evseId = json_object_get_int(json_object_object_get(SetChargingProfile, "evseId"));
  14184. else
  14185. isLostConnectorId = TRUE;
  14186. if(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "id") != NULL)
  14187. SetProfileReq.chargingProfile.id = json_object_get_int((json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "id")));
  14188. if(json_object_object_get(SetChargingProfile, "chargingProfile") != NULL)
  14189. {
  14190. sprintf((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")));
  14191. // Check periods is over max configuration
  14192. if(json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod")) > atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].value))
  14193. {
  14194. isPeriodOverMax = TRUE;
  14195. }
  14196. // Check periods is over max configuration
  14197. if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL)
  14198. {
  14199. if(SetProfileReq.evseId == 0)
  14200. {
  14201. sprintf((char*)filename, ChargePointMaxProfile_JSON);
  14202. filePtr = fopen((char*)filename, "r");
  14203. if (!filePtr)
  14204. {
  14205. DEBUG_INFO("%s not exist, create it.\n", ChargePointMaxProfile_JSON);
  14206. filePtr = fopen((char*)filename, "w+");
  14207. }
  14208. else
  14209. {
  14210. //Check Charging Profile Count
  14211. while(fscanf(filePtr, "%s", dataLine) != EOF)
  14212. {
  14213. //DEBUG_INFO("word=%s\n",word);
  14214. if(strstr((char*)dataLine, "id")!= NULL)
  14215. {
  14216. existProfileQuantity += 1;
  14217. }
  14218. }
  14219. }
  14220. fclose(filePtr);
  14221. }
  14222. else
  14223. isConnectorMismatch = TRUE;
  14224. }
  14225. else if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) != NULL)
  14226. {
  14227. if((0 < SetProfileReq.evseId) && (SetProfileReq.evseId > gunTotalNumber))
  14228. isConnectorMismatch = TRUE;
  14229. if(!isConnectorMismatch)
  14230. {
  14231. if(SetProfileReq.evseId == 0)
  14232. {
  14233. int tmpExistProfileQuantity;
  14234. for(int idxCon=1;idxCon<=gunTotalNumber;idxCon++)
  14235. {
  14236. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", idxCon);
  14237. filePtr = fopen((char*)filename, "r");
  14238. if (!filePtr)
  14239. {
  14240. DEBUG_INFO("%s not exist, create it.\n", filename);
  14241. filePtr = fopen((char*)filename, "w+");
  14242. }
  14243. else
  14244. {
  14245. //Check Charging Profile Count
  14246. while(fscanf(filePtr, "%s", dataLine) != EOF)
  14247. {
  14248. //DEBUG_INFO("word=%s\n",word);
  14249. if(strstr((char*)dataLine, "id")!= NULL)
  14250. {
  14251. tmpExistProfileQuantity += 1;
  14252. }
  14253. }
  14254. }
  14255. fclose(filePtr);
  14256. existProfileQuantity = (existProfileQuantity < tmpExistProfileQuantity) ? tmpExistProfileQuantity : existProfileQuantity;
  14257. }
  14258. }
  14259. else
  14260. {
  14261. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", SetProfileReq.evseId);
  14262. filePtr = fopen((char*)filename, "r");
  14263. if (!filePtr)
  14264. {
  14265. DEBUG_INFO("%s not exist, create it.\n", filename);
  14266. filePtr = fopen((char*)filename, "w+");
  14267. }
  14268. else
  14269. {
  14270. //Check Charging Profile Count
  14271. while(fscanf(filePtr, "%s", dataLine) != EOF)
  14272. {
  14273. //DEBUG_INFO("word=%s\n",word);
  14274. if(strstr((char*)dataLine, "id")!= NULL)
  14275. {
  14276. existProfileQuantity += 1;
  14277. }
  14278. }
  14279. }
  14280. fclose(filePtr);
  14281. }
  14282. }
  14283. }
  14284. else if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  14285. {
  14286. if((SetProfileReq.evseId > 0) && (SetProfileReq.evseId <= gunTotalNumber))
  14287. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", SetProfileReq.evseId);
  14288. else
  14289. isConnectorMismatch = TRUE;
  14290. if(!isConnectorMismatch)
  14291. {
  14292. filePtr = fopen((char*)filename, "r");
  14293. if (!filePtr)
  14294. {
  14295. DEBUG_INFO("%s not exist, create it.\n", filename);
  14296. filePtr = fopen((char*)filename, "w+");
  14297. }
  14298. else
  14299. {
  14300. //Check Charging Profile Count
  14301. while(fscanf(filePtr, "%s", dataLine) != EOF)
  14302. {
  14303. //DEBUG_INFO("word=%s\n",word);
  14304. if(strstr((char*)dataLine, "id")!= NULL)
  14305. {
  14306. existProfileQuantity += 1;
  14307. }
  14308. }
  14309. }
  14310. fclose(filePtr);
  14311. if(SetProfileReq.chargingProfile.transactionId != ShmOCPP20Data->TransactionEvent[SetProfileReq.evseId-1].transactionInfo.transactionId)
  14312. isTransactiodIdMismatch = TRUE;
  14313. }
  14314. }
  14315. else if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationExternalConstraints]) != NULL)
  14316. {
  14317. /*
  14318. * TODO:
  14319. *
  14320. */
  14321. }
  14322. else
  14323. {}
  14324. if(existProfileQuantity >= atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value))
  14325. isProfileOverMax = TRUE;
  14326. }
  14327. // Profile replace or add info
  14328. if(!isLostConnectorId && !isPeriodOverMax && !isProfileOverMax && !isConnectorMismatch && !isTransactiodIdMismatch)
  14329. {
  14330. FILE *infile;
  14331. FILE *outfile;
  14332. char tmpProfileName[] = "/Storage/OCPP/SetChargingProfiletemp_OCPP20.json";
  14333. char rmFileCmd[128];
  14334. int tempchargingProfileIdInt;
  14335. int chkChar;
  14336. for(int idxCon=1; idxCon <= (SetProfileReq.evseId==0?gunTotalNumber:1); idxCon++)
  14337. {
  14338. if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) == 0)
  14339. {
  14340. sprintf((char*)filename, "%s", ChargePointMaxProfile_JSON);
  14341. }
  14342. else if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0)
  14343. {
  14344. if(SetProfileReq.evseId==0)
  14345. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", idxCon);
  14346. else
  14347. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", SetProfileReq.evseId);
  14348. }
  14349. else if(strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) == 0)
  14350. {
  14351. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", SetProfileReq.evseId);
  14352. }
  14353. else
  14354. {
  14355. /*
  14356. * TODO:
  14357. *
  14358. */
  14359. }
  14360. infile = fopen ((char*)filename, "r");
  14361. outfile = fopen ((char*)tmpProfileName, "w");
  14362. chkChar = fgetc(infile);
  14363. rewind(infile);
  14364. if(chkChar == EOF)
  14365. {
  14366. // Profile is empty
  14367. if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
  14368. json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
  14369. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  14370. fclose(infile);
  14371. fclose(outfile);
  14372. sprintf(rmFileCmd,"rm -f %s",filename);
  14373. system(rmFileCmd);
  14374. rename((char*)tmpProfileName, (char*)filename);
  14375. }
  14376. else
  14377. {
  14378. // Profile is not empty
  14379. int ChargingProfileAdded = FALSE;
  14380. while (fgets((char*)dataLine, ARRAY_SIZE(dataLine), infile) != NULL)
  14381. {
  14382. dataLine[strlen((char*)dataLine) - 1] = '\0'; // eat the newline fgets() stores
  14383. json_object *tmpChargingProfile;
  14384. tmpChargingProfile = json_tokener_parse((char*)dataLine);
  14385. if(!is_error(tmpChargingProfile))
  14386. {
  14387. if(json_object_object_get(tmpChargingProfile, "chargingProfile") != NULL)
  14388. {
  14389. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "id") != NULL)
  14390. {
  14391. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "chargingProfile"), "id"));
  14392. DEBUG_INFO("tempchargingProfileIdInt: %d\n", tempchargingProfileIdInt);
  14393. DEBUG_INFO("SetProfileReq.chargingProfile.id: %d\n", SetProfileReq.chargingProfile.id);
  14394. }
  14395. }
  14396. }
  14397. json_object_put(tmpChargingProfile);
  14398. if((tempchargingProfileIdInt == SetProfileReq.chargingProfile.id))
  14399. {
  14400. if(ChargingProfileAdded == FALSE)
  14401. {
  14402. if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
  14403. json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
  14404. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  14405. ChargingProfileAdded = TRUE;
  14406. }
  14407. }
  14408. else
  14409. {
  14410. fprintf(outfile,"%s\n",dataLine);
  14411. if(ChargingProfileAdded == FALSE)
  14412. {
  14413. if((strcmp((char*)SetProfileReq.chargingProfile.chargingProfilePurpose, ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) == 0) && (SetProfileReq.evseId==0))
  14414. json_object_object_add(SetChargingProfile, "evseId", json_object_new_int(idxCon));
  14415. fprintf(outfile,"%s\n",json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  14416. ChargingProfileAdded = TRUE;
  14417. }
  14418. }
  14419. } // end of while loop
  14420. fclose(infile);
  14421. fclose(outfile);
  14422. sprintf(rmFileCmd,"rm -f %s",filename);
  14423. system(rmFileCmd);
  14424. rename((char*)tmpProfileName, (char*)filename);
  14425. }
  14426. }
  14427. sleep(1);
  14428. sprintf((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted] );
  14429. result = PASS;
  14430. }
  14431. else
  14432. {
  14433. if(isLostConnectorId)
  14434. DEBUG_WARN("Connector id is wrong.\n");
  14435. if(isConnectorMismatch)
  14436. DEBUG_WARN("Connector id is mismatch.\n");
  14437. if(isPeriodOverMax)
  14438. DEBUG_WARN("Profile periods quantity is over spec.\n");
  14439. if(isProfileOverMax)
  14440. DEBUG_WARN("Profile quantity is over spec.\n");
  14441. if(isTransactiodIdMismatch)
  14442. DEBUG_WARN("Transaction id is mismatch.\n");
  14443. sprintf((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Rejected] );
  14444. }
  14445. }
  14446. json_object_put(SetChargingProfile);
  14447. if(strcmp((char*)ShmOCPP20Data->SetChargingProfile[(SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1)].Response_status, ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted]) == 0)
  14448. {
  14449. if(SetProfileReq.evseId == 0)
  14450. {
  14451. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  14452. {
  14453. checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx], 0, TRUE);
  14454. }
  14455. }
  14456. else
  14457. checkCompositeSchedule(SetProfileReq.evseId, 86400, &ShmOCPP20Data->SmartChargingProfile[SetProfileReq.evseId-1], 0, TRUE);
  14458. }
  14459. sendSetChargingProfileConfirmation(uuid, (SetProfileReq.evseId==0?SetProfileReq.evseId:SetProfileReq.evseId-1));
  14460. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  14461. return result;
  14462. }
  14463. int handleSetDisplayMessageRequest(char *uuid, char *payload)
  14464. {
  14465. mtrace();
  14466. int result = FAIL;
  14467. json_object *SetDisplayMessage;
  14468. DEBUG_INFO("handleSetDisplayMessageRequest...\n");
  14469. SetDisplayMessage = json_tokener_parse(payload);
  14470. if(!is_error(SetDisplayMessage))
  14471. {
  14472. memset(&ShmOCPP20Data->SetDisplayMessage, 0, sizeof(struct SetDisplayMessage_20));
  14473. memcpy(&ShmOCPP20Data->SetDisplayMessage.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetDisplayMessage.guid));
  14474. // Required data
  14475. if(json_object_object_get(SetDisplayMessage, "message") != NULL)
  14476. {
  14477. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "id") != NULL)
  14478. ShmOCPP20Data->SetDisplayMessage.message.id = json_object_get_int(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "id"));
  14479. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "priority") != NULL)
  14480. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.priority, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "priority")));
  14481. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "state") != NULL)
  14482. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.state, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "state")));
  14483. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "startDateTime") != NULL)
  14484. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.startDateTime, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "startDateTime")));
  14485. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "endDateTime") != NULL)
  14486. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.endDateTime, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "endDateTime")));
  14487. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "transactionId") != NULL)
  14488. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.transactionId, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "transactionId")));
  14489. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message") != NULL)
  14490. {
  14491. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "format") != NULL)
  14492. 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")));
  14493. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "language") != NULL)
  14494. 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")));
  14495. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "content") != NULL)
  14496. 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")));
  14497. }
  14498. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display") != NULL)
  14499. {
  14500. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "name") != NULL)
  14501. 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")));
  14502. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "instance") != NULL)
  14503. 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")));
  14504. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse") != NULL)
  14505. {
  14506. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "id") != NULL)
  14507. 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"));
  14508. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "connectorId") != NULL)
  14509. 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"));
  14510. }
  14511. }
  14512. }
  14513. }
  14514. json_object_put(SetDisplayMessage);
  14515. strcpy((char*)ShmOCPP20Data->SetDisplayMessage.Response_status, DisplayMessageStatusEnumTypeStr[DisplayMessageStatusEnumType_Accepted]);
  14516. sendSetDisplayMessagesConfirmation(uuid);
  14517. // Announce CSU there is display request come from server
  14518. ShmOCPP20Data->MsMsg.bits.SetDisplayMessageReq = ON;
  14519. return result;
  14520. }
  14521. int handleSetMonitoringBaseRequest(char *uuid, char *payload)
  14522. {
  14523. mtrace();
  14524. int result = FAIL;
  14525. json_object *SetMonitoringBase;
  14526. DEBUG_INFO("handleSetMonitoringBaseRequest...\n");
  14527. SetMonitoringBase = json_tokener_parse(payload);
  14528. if(!is_error(SetMonitoringBase))
  14529. {
  14530. memset(&ShmOCPP20Data->SetMonitoringBase, 0, sizeof(struct SetMonitoringBase_20));
  14531. memcpy(&ShmOCPP20Data->SetMonitoringBase.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetMonitoringBase.guid));
  14532. // Required data
  14533. if(json_object_object_get(SetMonitoringBase, "monitoringBase") != NULL)
  14534. sprintf((char*)ShmOCPP20Data->SetMonitoringBase.monitoringBase, "%s",json_object_get_string(json_object_object_get(SetMonitoringBase, "monitoringBase")));
  14535. }
  14536. json_object_put(SetMonitoringBase);
  14537. /*
  14538. * TODO:
  14539. * 1. Configure monitor base and response
  14540. */
  14541. strcpy((char*)ShmOCPP20Data->SetMonitoringBase.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  14542. sendSetMonitoringBaseConfirmation(uuid);
  14543. return result;
  14544. }
  14545. int handleSetMonitoringLevelRequest(char *uuid, char *payload)
  14546. {
  14547. mtrace();
  14548. int result = FAIL;
  14549. json_object *SetMonitoringLevel;
  14550. DEBUG_INFO("handleSetMonitoringLevelRequest...\n");
  14551. SetMonitoringLevel = json_tokener_parse(payload);
  14552. if(!is_error(SetMonitoringLevel))
  14553. {
  14554. memset(&ShmOCPP20Data->SetMonitoringLevel, 0, sizeof(struct SetMonitoringLevel_20));
  14555. memcpy(&ShmOCPP20Data->SetMonitoringLevel.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetMonitoringLevel.guid));
  14556. // Required data
  14557. if(json_object_object_get(SetMonitoringLevel, "severity") != NULL)
  14558. ShmOCPP20Data->SetMonitoringLevel.severity = json_object_get_int(json_object_object_get(SetMonitoringLevel, "severity"));
  14559. }
  14560. json_object_put(SetMonitoringLevel);
  14561. /*
  14562. * TODO:
  14563. * Configure monitor status and response
  14564. */
  14565. strcpy((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  14566. sendSetMonitoringLevelConfirmation(uuid);
  14567. return result;
  14568. }
  14569. int handleSetNetworkProfileRequest(char *uuid, char *payload)
  14570. {
  14571. mtrace();
  14572. int result = FAIL;
  14573. json_object *SetNetworkProfile;
  14574. DEBUG_INFO("handleSetNetworkProfileRequest...\n");
  14575. SetNetworkProfile = json_tokener_parse(payload);
  14576. if(!is_error(SetNetworkProfile))
  14577. {
  14578. memset(&ShmOCPP20Data->SetNetworkProfile, 0, sizeof(struct SetNetworkProfile_20));
  14579. memcpy(&ShmOCPP20Data->SetNetworkProfile.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.guid));
  14580. // Required data
  14581. if(json_object_object_get(SetNetworkProfile, "configurationSlot") != NULL)
  14582. ShmOCPP20Data->SetNetworkProfile.configurationSlot = json_object_get_int(json_object_object_get(SetNetworkProfile, "configurationSlot"));
  14583. if(json_object_object_get(SetNetworkProfile, "connectionData") != NULL)
  14584. {
  14585. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppVersion") != NULL)
  14586. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppVersion")));
  14587. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport") != NULL)
  14588. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport")));
  14589. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl") != NULL)
  14590. {
  14591. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl")));
  14592. memcpy((char*)ShmOCPP20Data->OcppServerURL, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl));
  14593. }
  14594. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout") != NULL)
  14595. ShmOCPP20Data->SetNetworkProfile.connectionData.messageTimeout = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout"));
  14596. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppInterface") != NULL)
  14597. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppInterface, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppInterface")));
  14598. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn") != NULL)
  14599. {
  14600. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "server") != NULL)
  14601. 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")));
  14602. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "user") != NULL)
  14603. 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")));
  14604. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "group") != NULL)
  14605. 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")));
  14606. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "password") != NULL)
  14607. 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")));
  14608. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "key") != NULL)
  14609. 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")));
  14610. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "type") != NULL)
  14611. 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")));
  14612. }
  14613. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn") != NULL)
  14614. {
  14615. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apn") != NULL)
  14616. {
  14617. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn));
  14618. 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")));
  14619. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn);
  14620. }
  14621. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnUserName") != NULL)
  14622. {
  14623. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName));
  14624. 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")));
  14625. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName);
  14626. }
  14627. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnPassword") != NULL)
  14628. {
  14629. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword));
  14630. 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")));
  14631. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword);
  14632. }
  14633. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "simPin") != NULL)
  14634. 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"));
  14635. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "preferredNetwork") != NULL)
  14636. 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")));
  14637. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "useOnlyPreferredNetwork") != NULL)
  14638. 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"));
  14639. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnAuthentication") != NULL)
  14640. 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")));
  14641. }
  14642. DB_addNetworkProfile(ShmOCPP20Data->SetNetworkProfile.configurationSlot, (char*)json_object_get_string(json_object_object_get(SetNetworkProfile, "connectionData")));
  14643. }
  14644. }
  14645. json_object_put(SetNetworkProfile);
  14646. /*
  14647. * TODO:
  14648. * 1. Process network configuration and response
  14649. */
  14650. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP12]) == 0)
  14651. {
  14652. }
  14653. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP15]) == 0)
  14654. {
  14655. }
  14656. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP16]) == 0)
  14657. {
  14658. }
  14659. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP20]) == 0)
  14660. {
  14661. }
  14662. else
  14663. {
  14664. }
  14665. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, OCPPTransportEnumTypeStr[OCPPTransportEnumType_JSON]) == 0)
  14666. {
  14667. }
  14668. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, OCPPTransportEnumTypeStr[OCPPTransportEnumType_SOAP]) == 0)
  14669. {
  14670. }
  14671. else
  14672. {
  14673. }
  14674. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired0]) == 0)
  14675. {
  14676. }
  14677. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired1]) == 0)
  14678. {
  14679. }
  14680. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired2]) == 0)
  14681. {
  14682. }
  14683. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired3]) == 0)
  14684. {
  14685. }
  14686. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless0]) == 0)
  14687. {
  14688. }
  14689. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless1]) == 0)
  14690. {
  14691. }
  14692. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless2]) == 0)
  14693. {
  14694. }
  14695. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless3]) == 0)
  14696. {
  14697. }
  14698. else
  14699. {
  14700. }
  14701. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_IKEv2]) == 0)
  14702. {
  14703. }
  14704. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_IPSec]) == 0)
  14705. {
  14706. }
  14707. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_L2TP]) == 0)
  14708. {
  14709. }
  14710. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_PPTP]) == 0)
  14711. {
  14712. }
  14713. else
  14714. {
  14715. }
  14716. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_CHAP]) == 0)
  14717. {
  14718. }
  14719. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_NONE]) == 0)
  14720. {
  14721. }
  14722. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_PAP]) == 0)
  14723. {
  14724. }
  14725. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_AUTO]) == 0)
  14726. {
  14727. }
  14728. else
  14729. {
  14730. }
  14731. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Accepted]);
  14732. sendSetNetworkProfileConfirmation(uuid);
  14733. return result;
  14734. }
  14735. int handleSetVariableMonitoringRequest(char *uuid, char *payload)
  14736. {
  14737. mtrace();
  14738. int result = FAIL;
  14739. json_object *SetVariableMonitoring;
  14740. uint8_t variableQuantity = 0;
  14741. DEBUG_INFO("handleSetVariableMonitoringRequest...\n");
  14742. SetVariableMonitoring = json_tokener_parse(payload);
  14743. if(!is_error(SetVariableMonitoring))
  14744. {
  14745. memset(&ShmOCPP20Data->SetVariableMonitoring, 0, sizeof(struct SetVariableMonitoring_20));
  14746. memcpy(&ShmOCPP20Data->SetVariableMonitoring.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetVariableMonitoring.guid));
  14747. // Required data
  14748. for(int idx=0;idx<json_object_array_length(json_object_object_get(SetVariableMonitoring, "setMonitoringData"));idx++)
  14749. {
  14750. variableQuantity++;
  14751. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "id") != NULL)
  14752. {
  14753. 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"));
  14754. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].id = ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].id;
  14755. }
  14756. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "value") != NULL)
  14757. {
  14758. 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"));
  14759. }
  14760. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "type") != NULL)
  14761. {
  14762. 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")));
  14763. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type, (char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type);
  14764. }
  14765. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "severity") != NULL)
  14766. {
  14767. 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"));
  14768. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].severity = ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].severity;
  14769. }
  14770. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "transaction") != NULL)
  14771. {
  14772. 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"));
  14773. }
  14774. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "component") != NULL)
  14775. {
  14776. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "component"), "name") != NULL)
  14777. {
  14778. sprintf((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.name, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "component"), "name")));
  14779. }
  14780. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "component"), "instance") != NULL)
  14781. {
  14782. sprintf((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.instance, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "component"), "instance")));
  14783. }
  14784. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "component"), "evse") != NULL)
  14785. {
  14786. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "component"), "evse"), "id") != NULL)
  14787. {
  14788. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.id = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "component"), "instance"), "id"));
  14789. }
  14790. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "component"), "evse"), "connectorId") != NULL)
  14791. {
  14792. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.connectorId = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "component"), "instance"), "connectorId"));
  14793. }
  14794. }
  14795. memcpy(&ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component, &ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].component, sizeof(struct ComponentType));
  14796. }
  14797. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "variable") != NULL)
  14798. {
  14799. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "variable"), "name") != NULL)
  14800. {
  14801. sprintf((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.name, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "variable"), "name")));
  14802. }
  14803. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "variable"), "instance") != NULL)
  14804. {
  14805. sprintf((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.instance, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "variable"), "instance")));
  14806. }
  14807. memcpy(&ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable , &ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].variable, sizeof(struct VariableType));
  14808. }
  14809. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status, SetMonitoringStatusEnumTypeStr[SetMonitoringStatusEnumType_Accepted]);
  14810. }
  14811. }
  14812. json_object_put(SetVariableMonitoring);
  14813. sendSetVariableMonitoringConfirmation(uuid, variableQuantity);
  14814. return result;
  14815. }
  14816. int handleSetVariablesRequest(char *uuid, char *payload)
  14817. {
  14818. mtrace();
  14819. int result = FAIL;
  14820. json_object *SetVariables;
  14821. DEBUG_INFO("handleSetVariablesRequest...\n");
  14822. SetVariables = json_tokener_parse(payload);
  14823. if(!is_error(SetVariables))
  14824. {
  14825. memset(&ShmOCPP20Data->SetVariables, 0, sizeof(struct SetVariables_20));
  14826. memcpy(&ShmOCPP20Data->SetVariables.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetVariables.guid));
  14827. // Required data
  14828. for(int idx=0;idx<json_object_array_length(json_object_object_get(SetVariables, "setVariableData"));idx++)
  14829. {
  14830. if(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx) != NULL)
  14831. {
  14832. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component") != NULL)
  14833. {
  14834. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "name") != NULL)
  14835. {
  14836. 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")));
  14837. }
  14838. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "instance") != NULL)
  14839. {
  14840. 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")));
  14841. }
  14842. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "evse") != NULL)
  14843. {
  14844. 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)
  14845. {
  14846. 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"));
  14847. }
  14848. 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)
  14849. {
  14850. 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"));
  14851. }
  14852. }
  14853. memcpy(&ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component, &ShmOCPP20Data->SetVariables.setVariableData[idx].component, sizeof(struct ComponentType));
  14854. }
  14855. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable") != NULL)
  14856. {
  14857. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "name") != NULL)
  14858. {
  14859. 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")));
  14860. }
  14861. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "instance") != NULL)
  14862. {
  14863. 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")));
  14864. }
  14865. memcpy(&ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable , &ShmOCPP20Data->SetVariables.setVariableData[idx].variable, sizeof(struct VariableType));
  14866. }
  14867. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeType") != NULL)
  14868. {
  14869. 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")));
  14870. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeType);
  14871. }
  14872. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeValue") != NULL)
  14873. {
  14874. 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")));
  14875. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownComponent]);
  14876. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  14877. {
  14878. if((strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name) != NULL) &&
  14879. (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) &&
  14880. (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name) != NULL) &&
  14881. (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))
  14882. {
  14883. if(((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL)) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "NetworkConfigurationPriority") != NULL))
  14884. {
  14885. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_RebootRequired]);
  14886. }
  14887. else
  14888. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  14889. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "WebSocketPingInterval") != NULL))
  14890. {
  14891. if((0 < atoi((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value)) && (atoi((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value) < 10) )
  14892. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  14893. }
  14894. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "HeartbeatInterval") != NULL))
  14895. {
  14896. if(((atoi((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value)) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  14897. {
  14898. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  14899. }
  14900. else
  14901. HeartBeatWaitTime = atoi((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value);
  14902. }
  14903. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "StatusNotificationPeriodically") != NULL))
  14904. {
  14905. char tmp[ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value)];
  14906. for(int idx=0;idx<ARRAY_SIZE(tmp);idx++)
  14907. tmp[idx] = tolower(ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value[idx]);
  14908. if((strstr((char*)tmp, "true") != NULL) || (strstr((char*)tmp, "false") != NULL))
  14909. {
  14910. strcpy((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value,(strstr((char*)tmp, "true") != NULL)? "TRUE" : "FALSE");
  14911. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  14912. }
  14913. }
  14914. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "StatusNotificationInterval") != NULL))
  14915. {
  14916. if((atoi((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  14917. {
  14918. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  14919. }
  14920. else
  14921. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  14922. }
  14923. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "SecurityCtrlr") != NULL) &&
  14924. ((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "SecurityProfile") != NULL) || (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "BasicAuthPassword") != NULL)))
  14925. {
  14926. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  14927. SetOcppConnStatus(FALSE);
  14928. }
  14929. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "AlignedDataCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "Interval") != NULL))
  14930. {
  14931. if((0 < atoi((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value)) && (atoi((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  14932. {
  14933. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  14934. }
  14935. }
  14936. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "SampledDataCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "TxUpdatedInterval") != NULL))
  14937. {
  14938. if((0 < atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue)) && (atoi((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) < (int)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableCharacteristics.minLimit) )
  14939. {
  14940. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  14941. }
  14942. }
  14943. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "ChargingStation") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "FreeVend") != NULL))
  14944. {
  14945. char tmp[ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value)];
  14946. for(int idx=0;idx<ARRAY_SIZE(tmp);idx++)
  14947. tmp[idx] = tolower(ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value[idx]);
  14948. ShmSysConfigAndInfo->SysConfig.AuthorisationMode =((strstr((char*)tmp, "true") != NULL)? 1 : 0);
  14949. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  14950. }
  14951. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "ChargingStation") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "FreeVendIdtag") != NULL))
  14952. {
  14953. if(strlen((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue) > 20)
  14954. {
  14955. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_OutOfRange]);
  14956. }
  14957. }
  14958. if((strstr((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]) != NULL) ||
  14959. (strstr((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_RebootRequired]) != NULL))
  14960. {
  14961. strcpy((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  14962. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[idx_var]);
  14963. }
  14964. }
  14965. }
  14966. }
  14967. }
  14968. }
  14969. sendSetVariableConfirmation(uuid, json_object_array_length(json_object_object_get(SetVariables, "setVariableData")));
  14970. }
  14971. json_object_put(SetVariables);
  14972. return result;
  14973. }
  14974. int handleTriggerMessageRequest(char *uuid, char *payload)
  14975. {
  14976. mtrace();
  14977. int result = FAIL;
  14978. int connectorIdIsNULL = FALSE;
  14979. int connectorIdInt =0;
  14980. json_object *TriggerMessage;
  14981. DEBUG_INFO("handleTriggerMessageRequest\n");
  14982. TriggerMessage = json_tokener_parse(payload);
  14983. if(!is_error(TriggerMessage))
  14984. {
  14985. memset(&ShmOCPP20Data->TriggerMessage, 0, sizeof(struct TriggerMessage_20));
  14986. memcpy(&ShmOCPP20Data->TriggerMessage.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->TriggerMessage.guid));
  14987. // Required data
  14988. if(json_object_object_get(TriggerMessage, "requestedMessage") != NULL)
  14989. sprintf((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(TriggerMessage, "requestedMessage")));
  14990. // Optional data
  14991. if(json_object_object_get(TriggerMessage, "evse") != NULL)
  14992. {
  14993. // Required data
  14994. if(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "id") != NULL)
  14995. ShmOCPP20Data->TriggerMessage.evse.id = json_object_get_int(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "id"));
  14996. // Optional data
  14997. if(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "connectorId") != NULL)
  14998. {
  14999. ShmOCPP20Data->TriggerMessage.evse.connectorId = json_object_get_int(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "connectorId"));
  15000. connectorIdInt = ShmOCPP20Data->TriggerMessage.evse.connectorId;
  15001. }
  15002. else
  15003. connectorIdIsNULL = TRUE;
  15004. }
  15005. else
  15006. connectorIdIsNULL = TRUE;
  15007. }
  15008. json_object_put(TriggerMessage);
  15009. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  15010. {
  15011. if((strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_BootNotification]) != 0) &&
  15012. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_LogStatusNotification]) != 0) &&
  15013. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_FirmwareStatusNotification]) != 0 ) &&
  15014. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_Heartbeat]) != 0) &&
  15015. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_MeterValues]) != 0) &&
  15016. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) != 0 ) &&
  15017. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignV2GCertificate]) != 0 ) &&
  15018. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_StatusNotification]) != 0 ) &&
  15019. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_TransactionEvent]) != 0 ) &&
  15020. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignCombinedCertificate]) != 0 ) &&
  15021. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_PublishFirmwareStatusNotification]) != 0 ))
  15022. {
  15023. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_NotImplemented] );
  15024. sendTriggerMessageConfirmation(uuid);
  15025. return TRUE;
  15026. }
  15027. else
  15028. {
  15029. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Accepted] );
  15030. sendTriggerMessageConfirmation(uuid);
  15031. }
  15032. }
  15033. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  15034. {
  15035. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Rejected] );
  15036. sendTriggerMessageConfirmation(uuid);
  15037. return TRUE;
  15038. }
  15039. //==========================
  15040. // Trigger message
  15041. //==========================
  15042. if( strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_FirmwareStatusNotification]) == 0)
  15043. {
  15044. if((strlen((char*)ShmOCPP20Data->FirmwareStatusNotification.status) == 0) ||
  15045. ((FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Downloading) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Downloaded) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Idle) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Installing)))
  15046. {
  15047. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle;
  15048. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  15049. }
  15050. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  15051. }
  15052. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_LogStatusNotification]) == 0 )
  15053. {
  15054. if(strlen((char*)ShmOCPP20Data->LogStatusNotification.status) == 0)
  15055. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Idle]);
  15056. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  15057. }
  15058. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_BootNotification]) == 0 )
  15059. {
  15060. if(DB_updateBootType(BootReasonEnumType_Triggered))
  15061. server_sign = FALSE;
  15062. }
  15063. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_Heartbeat]) == 0 )
  15064. {
  15065. refreshStartTimer(&clientTime.Heartbeat);
  15066. clientTime.Heartbeat.tv_sec -= ShmOCPP20Data->BootNotification.Response_interval;
  15067. }
  15068. else if (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_MeterValues]) == 0 )
  15069. {
  15070. if(connectorIdIsNULL == FALSE)
  15071. {
  15072. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  15073. {
  15074. cpinitateMsg.bits[connectorIdInt-1].TriggerMeterValueReq = ON;
  15075. }
  15076. }
  15077. else
  15078. {
  15079. for(int idx=0;idx< gunTotalNumber;idx++)
  15080. {
  15081. cpinitateMsg.bits[idx].TriggerMeterValueReq = ON;
  15082. }
  15083. }
  15084. }
  15085. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_StatusNotification]) == 0 )
  15086. {
  15087. if(connectorIdIsNULL == FALSE)
  15088. {
  15089. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  15090. {
  15091. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = ON;
  15092. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  15093. }
  15094. }
  15095. else
  15096. {
  15097. for(int idx=0;idx< gunTotalNumber;idx++)
  15098. {
  15099. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = ON;
  15100. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  15101. }
  15102. }
  15103. }
  15104. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) == 0 )
  15105. {
  15106. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  15107. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  15108. {
  15109. 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\" &");
  15110. }
  15111. }
  15112. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignV2GCertificate]) == 0 )
  15113. {
  15114. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  15115. if(access("/Storage/OCPP/certV2G.csr",F_OK) == -1)
  15116. {
  15117. 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\" &");
  15118. }
  15119. }
  15120. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_TransactionEvent]) == 0 )
  15121. {
  15122. if(connectorIdIsNULL == FALSE)
  15123. {
  15124. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  15125. {
  15126. ShmOCPP20Data->CpMsg.bits[connectorIdInt -1].TransactionEventReq = ON;
  15127. }
  15128. }
  15129. else
  15130. {
  15131. for(int idx=0;idx< gunTotalNumber;idx++)
  15132. ShmOCPP20Data->CpMsg.bits[idx].TransactionEventReq = ON;
  15133. }
  15134. }
  15135. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignCombinedCertificate]) == 0 )
  15136. {
  15137. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  15138. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  15139. {
  15140. 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\" &");
  15141. }
  15142. if(access("/Storage/OCPP/certV2G.csr",F_OK) == -1)
  15143. {
  15144. 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\" &");
  15145. }
  15146. }
  15147. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_PublishFirmwareStatusNotification]) == 0 )
  15148. {
  15149. ShmOCPP20Data->MsMsg.bits.PublishFirmwareReq = ON;
  15150. }
  15151. return result;
  15152. }
  15153. int handleUnlockConnectorRequest(char *uuid, char *payload)
  15154. {
  15155. mtrace();
  15156. int result = FAIL;
  15157. int connectorIdInt =0;
  15158. int tempIndex = 0;
  15159. json_object *UnlockConnector;
  15160. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  15161. UnlockConnector = json_tokener_parse(payload);
  15162. if(!is_error(UnlockConnector))
  15163. {
  15164. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  15165. {
  15166. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  15167. }
  15168. if(json_object_object_get(UnlockConnector, "evseId") != NULL)
  15169. {
  15170. ShmOCPP20Data->UnlockConnector[(connectorIdInt>0?connectorIdInt-1:0)].evseId = json_object_get_int(json_object_object_get(UnlockConnector, "evseId"));
  15171. }
  15172. }
  15173. json_object_put(UnlockConnector);
  15174. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  15175. if(gunTotalNumber == 0)
  15176. {
  15177. sprintf((char*)ShmOCPP20Data->UnlockConnector[connectorIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  15178. goto end;
  15179. }
  15180. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  15181. {
  15182. sprintf((char*)ShmOCPP20Data->UnlockConnector[connectorIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  15183. goto end;
  15184. }
  15185. else
  15186. {
  15187. memset(&ShmOCPP20Data->UnlockConnector[connectorIdInt-1], 0, sizeof(struct UnlockConnector_20));
  15188. memcpy(&ShmOCPP20Data->UnlockConnector[connectorIdInt-1].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->UnlockConnector[connectorIdInt-1].guid));
  15189. //check Transaction active
  15190. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  15191. {
  15192. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15193. {
  15194. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  15195. }
  15196. else
  15197. {
  15198. tempIndex = connectorIdInt -1;
  15199. }
  15200. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15201. {
  15202. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ))
  15203. {
  15204. //stop Transaction
  15205. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  15206. }
  15207. }
  15208. }
  15209. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  15210. {
  15211. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15212. {
  15213. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  15214. }
  15215. else
  15216. {
  15217. tempIndex = connectorIdInt -1;
  15218. }
  15219. for (int index = 0; index < CCS_QUANTITY; index++)
  15220. {
  15221. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ))
  15222. {
  15223. //stop Transaction
  15224. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  15225. }
  15226. }
  15227. }
  15228. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  15229. {
  15230. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15231. {
  15232. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  15233. }
  15234. else
  15235. {
  15236. tempIndex = connectorIdInt -1;
  15237. }
  15238. for (int index = 0; index < GB_QUANTITY; index++)
  15239. {
  15240. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ))
  15241. {
  15242. //stop Transaction
  15243. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  15244. }
  15245. }
  15246. }
  15247. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  15248. {
  15249. tempIndex = connectorIdInt -1;
  15250. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15251. {
  15252. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ))
  15253. {
  15254. //stop Transaction
  15255. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  15256. }
  15257. }
  15258. }
  15259. else
  15260. {
  15261. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15262. {
  15263. tempIndex = 2;
  15264. }
  15265. else
  15266. {
  15267. tempIndex = connectorIdInt-1;
  15268. }
  15269. for (int index = 0; index < AC_QUANTITY; index++)
  15270. {
  15271. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ))
  15272. {
  15273. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  15274. }
  15275. }
  15276. }
  15277. ShmOCPP20Data->UnlockConnector[connectorIdInt-1].connectorId = connectorIdInt;
  15278. strcpy((char *)ShmOCPP20Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  15279. result = TRUE;
  15280. return result;
  15281. }
  15282. end:
  15283. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorConf = ON;
  15284. return result;
  15285. }
  15286. int handleUnpublishFirmwareRequest(char *uuid, char *payload)
  15287. {
  15288. mtrace();
  15289. int result = FAIL;
  15290. json_object *UnpublishFirmware;
  15291. DEBUG_INFO("handleUnpublishFirmwareRequest...\n");
  15292. UnpublishFirmware = json_tokener_parse(payload);
  15293. if(!is_error(UnpublishFirmware))
  15294. {
  15295. memset(&ShmOCPP20Data->UnpublishFirmware, 0, sizeof(struct UnpublishFirmware_20));
  15296. memcpy(&ShmOCPP20Data->UnpublishFirmware.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->UnpublishFirmware.guid));
  15297. // Required data
  15298. if(json_object_object_get(UnpublishFirmware, "checksum") != NULL)
  15299. sprintf((char*)ShmOCPP20Data->UnpublishFirmware.checksum, json_object_get_string(json_object_object_get(UnpublishFirmware, "checksum")));
  15300. }
  15301. json_object_put(UnpublishFirmware);
  15302. ShmOCPP20Data->MsMsg.bits.UnpublishFirmwareReq = ON;
  15303. /*
  15304. * TODO:
  15305. * 1. Check unpublished status
  15306. */
  15307. sprintf((char*)ShmOCPP20Data->UnpublishFirmware.Response_status, UnpublishFirmwareStatusEnumTypeStr[Unpublished_NoFirmware]);
  15308. sendUnpublishFirmwareConfirmation(uuid);
  15309. return result;
  15310. }
  15311. static char UpdateFirmwarepayloadData[512]={0};
  15312. void *UpdateFirmwareProcess(void *data)
  15313. {
  15314. pthread_detach(pthread_self());
  15315. mtrace();
  15316. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  15317. int port=0;
  15318. int isSuccess = 0;
  15319. char ftpbuf[1024];
  15320. char temp[1024];
  15321. char * pch;
  15322. DEBUG_INFO("handleUpdateFirmwareRequest...\n");
  15323. json_object *UpdateFirmware;
  15324. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  15325. if(!is_error(UpdateFirmware))
  15326. {
  15327. // Required data
  15328. if(json_object_object_get(UpdateFirmware, "requestId"))
  15329. {
  15330. ShmOCPP20Data->UpdateFirmware.requestId = json_object_get_int(json_object_object_get(UpdateFirmware, "requestId"));
  15331. }
  15332. if(json_object_object_get(UpdateFirmware, "firmware"))
  15333. {
  15334. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "location") != NULL)
  15335. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "location")));
  15336. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "retrieveDate") != NULL)
  15337. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "retrieveDate")));
  15338. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "installDateTime") != NULL)
  15339. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "installDateTime")));
  15340. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signingCertificate") != NULL)
  15341. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signingCertificate")));
  15342. if(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signature") != NULL)
  15343. sprintf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location, "%s", json_object_get_string(json_object_object_get(json_object_object_get(UpdateFirmware, "firmware"), "signature")));
  15344. }
  15345. // Optional data
  15346. if(json_object_object_get(UpdateFirmware, "retries"))
  15347. {
  15348. ShmOCPP20Data->UpdateFirmware.retries = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  15349. }
  15350. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  15351. {
  15352. ShmOCPP20Data->UpdateFirmware.retryInterval = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  15353. }
  15354. }
  15355. json_object_put(UpdateFirmware);
  15356. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  15357. memset(path, 0, ARRAY_SIZE(path));
  15358. // Wait retrieveData
  15359. if(strlen((char*)ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime) > 10)
  15360. {
  15361. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  15362. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadScheduled]);
  15363. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  15364. do
  15365. {
  15366. sleep(1);
  15367. }while(!isOvertNow(ShmOCPP20Data->UpdateFirmware.firmware.retrieveDateTime));
  15368. }
  15369. system("rm -f /mnt/*");
  15370. if(strncmp((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"http", 4) == 0)
  15371. {
  15372. sscanf((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  15373. sprintf(ftppath,"/%s", path);
  15374. DEBUG_INFO("locationstr: %s\n", ShmOCPP20Data->UpdateFirmware.firmware.location);
  15375. DEBUG_INFO("protocol: %s\n",protocol);
  15376. DEBUG_INFO("host: %s\n",host);
  15377. DEBUG_INFO("path: %s\n",path);
  15378. DEBUG_INFO("ftppath: %s\n",ftppath);
  15379. int ftppathlen=strlen(ftppath);
  15380. int i=1;
  15381. char filenametemp[50];
  15382. while(i < ftppathlen)
  15383. {
  15384. int len=ftppathlen-i;
  15385. if(ftppath[len]== 47) // '/' ascll code: 47
  15386. {
  15387. DEBUG_INFO("compare '/' all right\n");
  15388. break;
  15389. }
  15390. i=i+1;
  15391. }
  15392. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  15393. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  15394. filenametemp[i+1] = 0;
  15395. do
  15396. {
  15397. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  15398. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading]);
  15399. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  15400. sleep(3);
  15401. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  15402. if(!isSuccess)
  15403. {
  15404. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  15405. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  15406. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  15407. if(ShmOCPP20Data->UpdateFirmware.retries>0)sleep(ShmOCPP20Data->UpdateFirmware.retryInterval);else sleep(1);
  15408. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  15409. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  15410. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  15411. }
  15412. else
  15413. {
  15414. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  15415. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]);
  15416. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  15417. }
  15418. ShmOCPP20Data->UpdateFirmware.retries--;
  15419. }while((isSuccess == 0)&&(ShmOCPP20Data->UpdateFirmware.retries >= 0));
  15420. }
  15421. else if(strncmp((char*)ShmOCPP20Data->UpdateFirmware.firmware.location,"ftp", 3) == 0)
  15422. {
  15423. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  15424. memset(temp, 0, ARRAY_SIZE(temp));
  15425. strcpy(ftpbuf, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  15426. int ftppathlen=strlen(ftpbuf);
  15427. int i=1;
  15428. char filenametemp[50];
  15429. while(i < ftppathlen)
  15430. {
  15431. int len=ftppathlen-i;
  15432. if(ftpbuf[len]== 47) // '/' ascll code: 47
  15433. {
  15434. DEBUG_INFO(" compare '/' all right\n");
  15435. break;
  15436. }
  15437. i=i+1;
  15438. }
  15439. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  15440. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  15441. filenametemp[i+1] = 0;
  15442. strncpy(temp, ftpbuf, ftppathlen-i+1);
  15443. pch=strchr(temp,'@');
  15444. if(pch==NULL)
  15445. {
  15446. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  15447. protocol, host, &port, path);
  15448. strcpy(user,"anonymous");
  15449. strcpy(password,"");
  15450. }
  15451. else
  15452. {
  15453. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  15454. protocol, user, password, host, &port, path);
  15455. }
  15456. sscanf(host,"%[^/]%s",host1, path1);
  15457. sprintf(ftppath,"%s", path1);
  15458. if(port == 0)
  15459. {
  15460. port = 21;
  15461. }
  15462. do
  15463. {
  15464. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  15465. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading]);
  15466. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  15467. sleep(3);
  15468. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, (char*)ShmOCPP20Data->UpdateFirmware.firmware.location);
  15469. if(!isSuccess)
  15470. {
  15471. //BulldogUtil.sleepMs(interval*1000);
  15472. DEBUG_INFO("Update firmware request and download file fail.\n");
  15473. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  15474. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  15475. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  15476. if(ShmOCPP20Data->UpdateFirmware.retries>0)sleep(ShmOCPP20Data->UpdateFirmware.retryInterval);else sleep(1);
  15477. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  15478. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  15479. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  15480. }
  15481. else
  15482. {
  15483. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  15484. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]);
  15485. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  15486. }
  15487. ShmOCPP20Data->UpdateFirmware.retries--;
  15488. }while((!isSuccess)&&(ShmOCPP20Data->UpdateFirmware.retries >= 0));
  15489. }
  15490. else
  15491. {
  15492. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  15493. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  15494. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  15495. sleep(1);
  15496. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  15497. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  15498. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  15499. }
  15500. if(strstr((char*)ShmOCPP20Data->FirmwareStatusNotification.status, FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]) != NULL)ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq = ON;
  15501. interLock.isUpdateFirmwareGoing = OFF;
  15502. pthread_exit(NULL);
  15503. }
  15504. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  15505. {
  15506. mtrace();
  15507. int result = FAIL;
  15508. pthread_t t;
  15509. sendUpdateFirmwareConfirmation(uuid);
  15510. memset(UpdateFirmwarepayloadData, 0, ARRAY_SIZE(UpdateFirmwarepayloadData));
  15511. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  15512. memset(&ShmOCPP20Data->UpdateFirmware, 0, sizeof(struct UpdateFirmware_20));
  15513. if(!interLock.isUpdateFirmwareGoing)
  15514. {
  15515. interLock.isUpdateFirmwareGoing = ON;
  15516. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  15517. sleep(1);
  15518. }
  15519. else
  15520. DEBUG_WARN("Other UpdateFirmware request on going.\n");
  15521. ShmOCPP20Data->MsMsg.bits.UpdateFirmwareConf = ON;
  15522. return result;
  15523. }
  15524. int handleUnknownRequest(char *uuid, char *payload)
  15525. {
  15526. mtrace();
  15527. int result = FAIL;
  15528. DEBUG_INFO("handleUnknownRequest...\n");
  15529. sendUnknownConfirmation(uuid);
  15530. result = PASS;
  15531. return result;
  15532. }
  15533. //==========================================
  15534. // Handle server response routine
  15535. //==========================================
  15536. void handleAuthorizeResponse(char *payload, int gun_index)
  15537. {
  15538. mtrace();
  15539. DEBUG_INFO("handleAuthorizeResponse...\n");
  15540. json_object *Authorize;
  15541. Authorize = json_tokener_parse(payload);
  15542. if(!is_error(Authorize))
  15543. {
  15544. if(json_object_object_get(Authorize, "idTokenInfo") != NULL)
  15545. {
  15546. // Required data
  15547. sprintf((char *)(char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "status")));
  15548. // Optional data
  15549. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "cacheExpiryDateTime") != NULL)
  15550. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "cacheExpiryDateTime")));
  15551. else
  15552. memset(ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime));
  15553. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "chargingPriority") != NULL)
  15554. ShmOCPP20Data->Authorize.Response_idTokenInfo.chargingPriority = json_object_get_int(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "chargingPriority"));
  15555. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "language1") != NULL)
  15556. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.language1, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language1")));
  15557. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "evseId") != NULL)
  15558. {
  15559. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(Authorize, "idTagInfo"), "evseId"));idx++)
  15560. {
  15561. 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));
  15562. }
  15563. }
  15564. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "language2") != NULL)
  15565. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.language2, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language2")));
  15566. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "groupIdToken") != NULL)
  15567. {
  15568. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "idToken") != NULL)
  15569. 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")));
  15570. else
  15571. memset(ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken));
  15572. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "type") != NULL)
  15573. 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")));
  15574. }
  15575. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "personalMessage") != NULL)
  15576. {
  15577. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "format") != NULL)
  15578. 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")));
  15579. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "language") != NULL)
  15580. 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")));
  15581. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "content") != NULL)
  15582. 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")));
  15583. }
  15584. }
  15585. if(json_object_object_get(Authorize, "certificateStatus") != NULL)
  15586. {
  15587. strcpy((char *)ShmOCPP20Data->Authorize.Response_certificateStatus, json_object_get_string(json_object_object_get(Authorize, "certificateStatus")));
  15588. }
  15589. }
  15590. json_object_put(Authorize);
  15591. //Update idTag information to authorization cache if supported
  15592. if((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].value, "TRUE") == 0) &&
  15593. (strlen((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken) > 0) &&
  15594. (strlen((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime) >0) &&
  15595. strstr((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != NULL)
  15596. {
  15597. DB_addLocalCache(&ShmOCPP20Data->Authorize.idToken, &ShmOCPP20Data->Authorize.Response_idTokenInfo);
  15598. }
  15599. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  15600. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  15601. authorizeRetryTimes = 0;
  15602. }
  15603. void handleBootNotificationResponse(char *payload, int gun_index)
  15604. {
  15605. mtrace();
  15606. char statusStr[12]={0};
  15607. char currentTimeStr[30]={0};
  15608. int intervalInt = 0;
  15609. DEBUG_INFO("handleBootNotificationResponse...\n");
  15610. json_object *BootNotification;
  15611. BootNotification = json_tokener_parse(payload);
  15612. if(!is_error(BootNotification))
  15613. {
  15614. // Required data
  15615. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  15616. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  15617. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  15618. }
  15619. json_object_put(BootNotification);
  15620. DEBUG_INFO("statusStr: %s\n", statusStr);
  15621. ShmOCPP20Data->BootNotification.Response_interval = intervalInt;
  15622. BootNotificationInterval = intervalInt;
  15623. //write back to ShmOCPP20Data->BootNotification
  15624. strcpy((char *)ShmOCPP20Data->BootNotification.Response_currentTime, currentTimeStr);
  15625. strcpy((char *)ShmOCPP20Data->BootNotification.Response_status, statusStr);
  15626. if((strcmp(statusStr, RegistrationStatusEnumTypeStr[RegistrationStatusEnumType_Accepted]) == 0 ))
  15627. {
  15628. if(intervalInt < (int)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.minLimit)
  15629. {
  15630. //Do nothing because the value is out of range.
  15631. }
  15632. else
  15633. {
  15634. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value,"%d", HeartBeatWaitTime);
  15635. HeartBeatWaitTime = intervalInt;
  15636. DEBUG_INFO("BootNotificationResponse setting interval to %d...\n",intervalInt);
  15637. }
  15638. server_sign = TRUE;
  15639. server_pending =FALSE;
  15640. DB_updateBootType(BootReasonEnumType_PowerUp);
  15641. }
  15642. else if(strcmp(statusStr, RegistrationStatusEnumTypeStr[RegistrationStatusEnumType_Pending]) == 0)
  15643. {
  15644. server_pending = TRUE;
  15645. }
  15646. syncDateTimeRTC(ShmOCPP20Data->BootNotification.Response_currentTime);
  15647. srand(time(NULL));
  15648. refreshStartTimer(&clientTime.Heartbeat);
  15649. clientTime.Heartbeat.tv_sec -= (ShmOCPP20Data->BootNotification.Response_interval-((rand()%8)+3));
  15650. SetOcppConnStatus(TRUE);
  15651. ShmOCPP20Data->SpMsg.bits.BootNotificationConf = ON;
  15652. }
  15653. void handleClearedChargingLimitResponse(char *payload, int gun_index)
  15654. {
  15655. mtrace();
  15656. json_object *ClearedChargingLimit;
  15657. DEBUG_INFO("handleClearedChargingLimitResponse...\n");
  15658. ClearedChargingLimit = json_tokener_parse(payload);
  15659. if(!is_error(ClearedChargingLimit))
  15660. {
  15661. // Required data
  15662. if(json_object_object_get(ClearedChargingLimit,"status") != NULL)
  15663. sprintf((char*)ShmOCPP20Data->ClearChargingProfile[gun_index].Response_status, json_object_get_string(json_object_object_get(ClearedChargingLimit,"status")));
  15664. }
  15665. json_object_put(ClearedChargingLimit);
  15666. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq = OFF;
  15667. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitConf = ON;
  15668. }
  15669. void handleDataTransferResponse(char *payload, int gun_index)
  15670. {
  15671. mtrace();
  15672. json_object *DataTrans;
  15673. DEBUG_INFO("handleDataTransferResponse...\n");
  15674. DataTrans = json_tokener_parse(payload);
  15675. if(!is_error(DataTrans))
  15676. {
  15677. // Required data
  15678. if(json_object_object_get(DataTrans,"status") != NULL)
  15679. sprintf((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_status, json_object_get_string(json_object_object_get(DataTrans,"status")));
  15680. // Optional data
  15681. if(json_object_object_get(DataTrans,"data") != NULL)
  15682. sprintf((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_data, json_object_get_string(json_object_object_get(DataTrans,"data")));
  15683. }
  15684. json_object_put(DataTrans);
  15685. ShmOCPP20Data->CpMsg.bits[gun_index].DataTransferReq = OFF;
  15686. ShmOCPP20Data->CpMsg.bits[gun_index].DataTransferConf = ON;
  15687. }
  15688. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15689. {
  15690. mtrace();
  15691. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  15692. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = OFF;
  15693. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationConf = ON;
  15694. }
  15695. void handleGet15118EVCertificateResponse(char *payload, int gun_index)
  15696. {
  15697. mtrace();
  15698. json_object *Get15118EVCertificate;
  15699. DEBUG_INFO("handleGet15118EVCertificateResponse...\n");
  15700. Get15118EVCertificate = json_tokener_parse(payload);
  15701. if(!is_error(Get15118EVCertificate))
  15702. {
  15703. // Required data
  15704. if(json_object_object_get(Get15118EVCertificate,"status") != NULL)
  15705. sprintf((char*)ShmOCPP20Data->Get15118EVCertificate.Response_status, json_object_get_string(json_object_object_get(Get15118EVCertificate,"status")));
  15706. // Optional data
  15707. if(json_object_object_get(Get15118EVCertificate,"exiResponse") != NULL)
  15708. sprintf((char*)ShmOCPP20Data->Get15118EVCertificate.Response_exiResponse, json_object_get_string(json_object_object_get(Get15118EVCertificate,"exiResponse")));
  15709. }
  15710. json_object_put(Get15118EVCertificate);
  15711. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq = OFF;
  15712. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateConf = ON;
  15713. }
  15714. void handleGetCertificateStatusResponse(char *payload, int gun_index)
  15715. {
  15716. mtrace();
  15717. json_object *GetCertificateStatus;
  15718. DEBUG_INFO("handleGetCertificateStatusResponse...\n");
  15719. GetCertificateStatus = json_tokener_parse(payload);
  15720. if(!is_error(GetCertificateStatus))
  15721. {
  15722. // Required data
  15723. if(json_object_object_get(GetCertificateStatus,"status") != NULL)
  15724. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_status, json_object_get_string(json_object_object_get(GetCertificateStatus,"status")));
  15725. // Optional data
  15726. if(json_object_object_get(GetCertificateStatus,"ocspResult") != NULL)
  15727. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_ocspResult, json_object_get_string(json_object_object_get(GetCertificateStatus,"ocspResult")));
  15728. if(json_object_object_get(GetCertificateStatus,"statusInfo") != NULL)
  15729. {
  15730. if(json_object_object_get(json_object_object_get(GetCertificateStatus,"statusInfo"), "reasonCode") != NULL)
  15731. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_statusInfo.reasonCode, json_object_get_string(json_object_object_get(json_object_object_get(GetCertificateStatus,"ocspResult"), "reasonCode")));
  15732. if(json_object_object_get(json_object_object_get(GetCertificateStatus,"statusInfo"), "additionalInfo") != NULL)
  15733. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_statusInfo.additionalInfo, json_object_get_string(json_object_object_get(json_object_object_get(GetCertificateStatus,"ocspResult"), "additionalInfo")));
  15734. }
  15735. }
  15736. json_object_put(GetCertificateStatus);
  15737. if(strstr((char*)ShmOCPP20Data->GetCertificateStatus.Response_status, GetCertificateStatusEnumTypeStr[GetCertificateStatusEnumType_Accepted]) != NULL)
  15738. {
  15739. /*
  15740. * TODO:
  15741. * 1. If get certificate response accepted process something here
  15742. */
  15743. }
  15744. ShmOCPP20Data->SpMsg.bits.GetCertificateStatusReq = OFF;
  15745. ShmOCPP20Data->SpMsg.bits.GetCertificateStatusConf = ON;
  15746. }
  15747. void handleHeartbeatResponse(char *payload, int gun_index)
  15748. {
  15749. mtrace();
  15750. DEBUG_INFO("handleHeartbeatResponse...\n");
  15751. json_object *Heartbeat;
  15752. Heartbeat = json_tokener_parse(payload);
  15753. if(!is_error(Heartbeat))
  15754. {
  15755. // Required data
  15756. if(json_object_object_get(Heartbeat,"currentTime") != NULL)
  15757. sprintf((char *)ShmOCPP20Data->Heartbeat.Response_currentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  15758. }
  15759. json_object_put(Heartbeat);
  15760. if(FirstHeartBeat == OFF)
  15761. {
  15762. FirstHeartBeat = ON;
  15763. DEBUG_INFO("FirstHeartBeat \n");
  15764. }
  15765. HeartBeatWithNOResponse = 0;
  15766. refreshStartTimer(&clientTime.Heartbeat);
  15767. syncDateTimeRTC(ShmOCPP20Data->Heartbeat.Response_currentTime);
  15768. }
  15769. void handleLogStatusNotificationResponse(char *payload, int gun_index)
  15770. {
  15771. mtrace();
  15772. DEBUG_INFO("handleLogStatusNotificationResponse...\n");
  15773. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  15774. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationConf = ON;
  15775. }
  15776. void handleMeterValuesResponse(char *payload, int gun_index)
  15777. {
  15778. mtrace();
  15779. DEBUG_INFO("handleMeterValuesResponse...\n");
  15780. isQueueSendable = ON;
  15781. }
  15782. void handleNotifyChargingLimitResponse(char *payload, int gun_index)
  15783. {
  15784. mtrace();
  15785. DEBUG_INFO("handleNotifyChargingLimitResponse...\n");
  15786. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitReq = OFF;
  15787. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitConf = ON;
  15788. }
  15789. void handleNotifyCustomerInformationResponse(char *payload, int gun_index)
  15790. {
  15791. mtrace();
  15792. DEBUG_INFO("handleNotifyCustomerInformationResponse...\n");
  15793. }
  15794. void handleNotifyDisplayMessagesResponse(char *payload, int gun_index)
  15795. {
  15796. mtrace();
  15797. DEBUG_INFO("handleNotifyDisplayMessagesResponse...\n");
  15798. ShmOCPP20Data->SpMsg.bits.NotifyDisplayMessagesReq = OFF;
  15799. ShmOCPP20Data->SpMsg.bits.NotifyDisplayMessagesConf = ON;
  15800. }
  15801. void handleNotifyEVChargingNeedsResponse(char *payload, int gun_index)
  15802. {
  15803. mtrace();
  15804. json_object *NotifyEVChargingNeeds;
  15805. DEBUG_INFO("handleNotifyEVChargingNeedsResponse...\n");
  15806. NotifyEVChargingNeeds = json_tokener_parse(payload);
  15807. if(!is_error(NotifyEVChargingNeeds))
  15808. {
  15809. // Required data
  15810. if(json_object_object_get(NotifyEVChargingNeeds,"status") != NULL)
  15811. sprintf((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].Response_status, json_object_get_string(json_object_object_get(NotifyEVChargingNeeds,"status")));
  15812. }
  15813. json_object_put(NotifyEVChargingNeeds);
  15814. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitReq = OFF;
  15815. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitConf = ON;
  15816. }
  15817. void handleNotifyEVChargingScheduleResponse(char *payload, int gun_index)
  15818. {
  15819. mtrace();
  15820. json_object *NotifyEVChargingSchedule;
  15821. DEBUG_INFO("handleNotifyEVChargingScheduleResponse...\n");
  15822. NotifyEVChargingSchedule = json_tokener_parse(payload);
  15823. if(!is_error(NotifyEVChargingSchedule))
  15824. {
  15825. // Required data
  15826. if(json_object_object_get(NotifyEVChargingSchedule,"status") != NULL)
  15827. sprintf((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].Response_status, json_object_get_string(json_object_object_get(NotifyEVChargingSchedule,"status")));
  15828. }
  15829. json_object_put(NotifyEVChargingSchedule);
  15830. ShmOCPP20Data->SpMsg.bits.NotifyEVChargingScheduleReq = OFF;
  15831. ShmOCPP20Data->SpMsg.bits.NotifyEVChargingScheduleConf = ON;
  15832. }
  15833. void handleNotifyEventResponse(char *payload, int gun_index)
  15834. {
  15835. mtrace();
  15836. DEBUG_INFO("handleNotifyEventResponse...\n");
  15837. ShmOCPP20Data->SpMsg.bits.NotifyEventReq = OFF;
  15838. ShmOCPP20Data->SpMsg.bits.NotifyEventConf = ON;
  15839. }
  15840. void handleNotifyMonitoringReportResponse(char *payload, int gun_index)
  15841. {
  15842. mtrace();
  15843. DEBUG_INFO("handleNotifyMonitoringReportResponse...\n");
  15844. ShmOCPP20Data->SpMsg.bits.NotifyMonitoringReportReq = OFF;
  15845. ShmOCPP20Data->SpMsg.bits.NotifyMonitoringReportConf = ON;
  15846. }
  15847. void handleNotifyReportResponse(char *payload, int gun_index)
  15848. {
  15849. mtrace();
  15850. DEBUG_INFO("handleNotifyReportResponse...\n");
  15851. ShmOCPP20Data->SpMsg.bits.NotifyReportReq = OFF;
  15852. ShmOCPP20Data->SpMsg.bits.NotifyReportConf = ON;
  15853. }
  15854. void handlePublishFirmwareStatusNotificationResponse(char *payload, int gun_index)
  15855. {
  15856. mtrace();
  15857. DEBUG_INFO("handlePublishFirmwareStatusNotificationResponse...\n");
  15858. ShmOCPP20Data->CsMsg.bits[gun_index].PublishFirmwareStatusNotificationReq = OFF;
  15859. ShmOCPP20Data->CsMsg.bits[gun_index].PublishFirmwareStatusNotificationConf = ON;
  15860. }
  15861. void handleReportChargingProfilesResponse(char *payload, int gun_index)
  15862. {
  15863. mtrace();
  15864. DEBUG_INFO("handleReportChargingProfilesResponse...gun_index: %d\n", gun_index);
  15865. ShmOCPP20Data->SpMsg.bits.ReportChargingProfilesReq = OFF;
  15866. ShmOCPP20Data->SpMsg.bits.ReportChargingProfilesConf = ON;
  15867. }
  15868. void handleReservationStatusUpdateResponse(char *payload, int gun_index)
  15869. {
  15870. mtrace();
  15871. DEBUG_INFO("handleReservationStatusUpdateResponse...gun_index: %d\n", gun_index);
  15872. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = OFF;
  15873. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateConf = ON;
  15874. }
  15875. void handleSecurityEventNotificationResponse(char *payload, int gun_index)
  15876. {
  15877. mtrace();
  15878. DEBUG_INFO("handleSecurityEventNotificationResponse...\n");
  15879. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = OFF;
  15880. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationConf = ON;
  15881. }
  15882. void handleSignCertificateResponse(char *payload, int gun_index)
  15883. {
  15884. mtrace();
  15885. json_object *SignCertificate;
  15886. DEBUG_INFO("handleSignCertificateResponse...\n");
  15887. SignCertificate = json_tokener_parse(payload);
  15888. if(!is_error(SignCertificate))
  15889. {
  15890. // Required data
  15891. if(json_object_object_get(SignCertificate,"status") != NULL)
  15892. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_status, json_object_get_string(json_object_object_get(SignCertificate,"status")));
  15893. // Optional data
  15894. if(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "reasonCode") != NULL)
  15895. {
  15896. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_statusInfo.reasonCode, json_object_get_string(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "reasonCode")));
  15897. if(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "additionalInfo") != NULL)
  15898. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_statusInfo.additionalInfo, json_object_get_string(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "additionalInfo")));
  15899. }
  15900. }
  15901. json_object_put(SignCertificate);
  15902. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = OFF;
  15903. ShmOCPP20Data->SpMsg.bits.SignCertificateConf = ON;
  15904. }
  15905. void handleStatusNotificationResponse(char *payload, int gun_index)
  15906. {
  15907. mtrace();
  15908. DEBUG_INFO("handleStatusNotificationResponse...gun_index: %d\n", gun_index);
  15909. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  15910. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  15911. cpinitateMsg.bits[gun_index].StatusNotificationConf = ON;
  15912. }
  15913. void handleTransactionEventResponse(char *payload, int gun_index)
  15914. {
  15915. mtrace();
  15916. json_object *TransactionEven;
  15917. DEBUG_INFO("handleTransactionEventResponse...\n");
  15918. TransactionEven = json_tokener_parse(payload);
  15919. if(!is_error(TransactionEven))
  15920. {
  15921. // Required data
  15922. // Optional data
  15923. if(json_object_object_get(TransactionEven,"totalCost") != NULL)
  15924. ShmOCPP20Data->TransactionEvent[gun_index].Response_totalCost = json_object_get_double(json_object_object_get(TransactionEven,"totalCost"));
  15925. if(json_object_object_get(TransactionEven,"chargingPriority") != NULL)
  15926. ShmOCPP20Data->TransactionEvent[gun_index].Response_chargingPriority = json_object_get_int(json_object_object_get(TransactionEven,"chargingPriority"));
  15927. if(json_object_object_get(TransactionEven,"idTokenInfo") != NULL)
  15928. {
  15929. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "status") != NULL)
  15930. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "status")));
  15931. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "cacheExpiryDateTime") != NULL)
  15932. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.cacheExpiryDateTime, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "cacheExpiryDateTime")));
  15933. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "chargingPriority") != NULL)
  15934. ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.chargingPriority = json_object_get_int(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "chargingPriority"));
  15935. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "language1") != NULL)
  15936. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.language1, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "language1")));
  15937. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken") != NULL)
  15938. {
  15939. if(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "idToken") != NULL)
  15940. 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")));
  15941. if(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "type") != NULL)
  15942. 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")));
  15943. }
  15944. }
  15945. if(json_object_object_get(TransactionEven,"updatedPersonalMessage") != NULL)
  15946. {
  15947. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "format") != NULL)
  15948. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.format, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "format")));
  15949. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "language") != NULL)
  15950. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.language, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "language")));
  15951. if(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "content") != NULL)
  15952. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_updatedPersonalMessage.content, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"updatedPersonalMessage"), "content")));
  15953. }
  15954. }
  15955. json_object_put(TransactionEven);
  15956. isQueueSendable = ON;
  15957. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf = ON;
  15958. }
  15959. //==========================================
  15960. // Handle Error routine
  15961. //==========================================
  15962. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  15963. {
  15964. mtrace();
  15965. #ifdef SystemLogMessage
  15966. DEBUG_INFO("errorCode: %s\n", errorCode);
  15967. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  15968. DEBUG_INFO("errorDetails: %s\n", payload);
  15969. #endif
  15970. }
  15971. //===============================================
  15972. // Common routine
  15973. //===============================================
  15974. int initialConfigurationTable(void)
  15975. {
  15976. DEBUG_INFO("initialConfigurationTable...\n");
  15977. memset(&ShmOCPP20Data->ControllerComponentVariable[0], 0, ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable));
  15978. DB_variableIsCreate();
  15979. DB_variableLoadFromDb();
  15980. if(atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_VariableVersion].variableAttribute[0].value) != variableVersion)
  15981. {
  15982. DEBUG_WARN("EVSE variable version in local db older than firmware.\n");
  15983. DB_variableClear();
  15984. DB_variableIsCreate();
  15985. DB_variableLoadFromDb();
  15986. }
  15987. DB_getNetworkProfileFromDb();
  15988. return 0;
  15989. }
  15990. int TransactionMessageAttemptsGet(void)
  15991. {
  15992. return TransactionMessageAttemptsValue;
  15993. }
  15994. int FirstHeartBeatResponse(void)
  15995. {
  15996. return FirstHeartBeat;
  15997. }
  15998. int TransactionMessageRetryIntervalGet(void)
  15999. {
  16000. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP20Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  16001. }
  16002. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  16003. {
  16004. int result = TRUE;
  16005. char rmFileCmd[100]={0};
  16006. char FilePath[100]={0};
  16007. char ftpbuf[200];
  16008. int systemresult;
  16009. sprintf(FilePath,"/mnt/%s",filename);
  16010. system("ping 8.8.8.8 &");
  16011. if((access(FilePath,F_OK))!=-1)
  16012. {
  16013. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16014. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16015. system(rmFileCmd);
  16016. }
  16017. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16018. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-check-certificate",filename, url);
  16019. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16020. systemresult = system(ftpbuf);
  16021. if(systemresult != 0)
  16022. {
  16023. DEBUG_INFO("http DownLoad error!\n");
  16024. result = FALSE;
  16025. }
  16026. system("pkill ping");
  16027. return result;
  16028. }
  16029. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  16030. {
  16031. int result = TRUE;
  16032. char rmFileCmd[100]={0};
  16033. char FilePath[100]={0};
  16034. char ftpbuf[200];
  16035. int systemresult;
  16036. sprintf(FilePath,"/mnt/%s",filename);
  16037. system("ping 8.8.8.8 &");
  16038. if((access(FilePath,F_OK))!=-1)
  16039. {
  16040. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16041. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16042. system(rmFileCmd);
  16043. }
  16044. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16045. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  16046. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16047. systemresult = system(ftpbuf);
  16048. if(systemresult != 0)
  16049. {
  16050. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120 --no-passive-ftp",filename, url);
  16051. DEBUG_INFO("Download command: %s\n",ftpbuf);
  16052. systemresult = system(ftpbuf);
  16053. if(systemresult != 0)
  16054. {
  16055. DEBUG_WARN("wget error!\n");
  16056. result = FALSE;
  16057. }
  16058. }
  16059. system("pkill ping");
  16060. return result;
  16061. }
  16062. int httpUploadFile(char *location, char *path, char *filename,char *url)
  16063. {
  16064. char rmFileCmd[100]={0};
  16065. char FilePath[100]={0};
  16066. char buf[512];
  16067. int systemresult = 0;
  16068. //DEBUG_INFO("filename=%s\n",filename);
  16069. //DEBUG_INFO("url=%s\n",url);
  16070. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  16071. if((access(FilePath,F_OK))!=-1)
  16072. {
  16073. DEBUG_INFO("filename=%s exist.\n",FilePath);
  16074. sprintf(rmFileCmd,"rm -f %s",FilePath);
  16075. system(rmFileCmd);
  16076. }
  16077. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  16078. if(fp == NULL)
  16079. {
  16080. DEBUG_INFO("log is NULL\n");
  16081. return FALSE;
  16082. }
  16083. else
  16084. {
  16085. fprintf(fp, "%s\n", url);
  16086. fprintf(fp, "%s\n", filename);
  16087. fclose(fp);
  16088. }
  16089. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  16090. if(phpFP == NULL)
  16091. {
  16092. DEBUG_INFO("PHP upload fail.\n");
  16093. return FALSE;
  16094. }
  16095. else
  16096. {
  16097. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  16098. {
  16099. if(strstr(buf, "result") != NULL)
  16100. {
  16101. sscanf(buf, "result: %d", &systemresult);
  16102. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  16103. }
  16104. }
  16105. pclose(phpFP);
  16106. }
  16107. if(systemresult != 1)
  16108. {
  16109. DEBUG_INFO("HTTP upload error!\n");
  16110. return FALSE;
  16111. }
  16112. return TRUE;
  16113. }
  16114. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  16115. {
  16116. int result = FALSE;
  16117. char ftpbuf[200];
  16118. int systemresult;
  16119. /*
  16120. // Domaind name transfer to IP address
  16121. struct hostent* server;
  16122. char *IPbuffer;
  16123. server = gethostbyname(location);
  16124. IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
  16125. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  16126. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
  16127. DEBUG_INFO("ftp command: %s\n",ftpbuf);
  16128. systemresult = system(ftpbuf);
  16129. if(systemresult != 0)
  16130. {
  16131. DEBUG_INFO("ftpput error!\n");
  16132. }
  16133. else
  16134. {
  16135. result = TRUE;
  16136. DEBUG_INFO("ftpput OK!\n");
  16137. }
  16138. return result;
  16139. }
  16140. //=========================================
  16141. // Routine
  16142. //=========================================
  16143. int GetOcppServerURL()
  16144. {
  16145. int result = FALSE;
  16146. struct yuarel url;
  16147. char urlStr[512];
  16148. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  16149. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  16150. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  16151. if((ShmOCPP20Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP20Data->OcppServerURL,"") != 0))
  16152. {
  16153. memcpy(urlStr, ShmOCPP20Data->OcppServerURL, ARRAY_SIZE(ShmOCPP20Data->OcppServerURL));
  16154. if(yuarel_parse(&url, urlStr) != -1)
  16155. {
  16156. sprintf(OcppProtocol, "%s", url.scheme);
  16157. sprintf(OcppHost, "%s", url.host);
  16158. if(url.path == NULL)
  16159. OcppTempPath[0] = '\0';
  16160. else
  16161. sprintf(OcppTempPath, "%s", url.path);
  16162. if(url.port == 0)
  16163. {
  16164. if(strcmp(OcppProtocol, "wss") == 0)
  16165. OcppPort = 443;
  16166. else
  16167. OcppPort = 80;
  16168. }
  16169. else
  16170. OcppPort = url.port;
  16171. result = TRUE;
  16172. }
  16173. }
  16174. else
  16175. {
  16176. strcpy(OcppHost,"");
  16177. }
  16178. return result;
  16179. }
  16180. int GetOcppPath()
  16181. {
  16182. int result = FALSE;
  16183. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  16184. {
  16185. if(OcppTempPath == NULL)
  16186. {
  16187. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16188. }
  16189. else
  16190. {
  16191. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16192. }
  16193. result = TRUE;
  16194. }
  16195. else if((ShmOCPP20Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP20Data->ChargeBoxId,"") != 0))
  16196. {
  16197. if(OcppTempPath == NULL)
  16198. {
  16199. sprintf(OcppPath,"/%s",ShmOCPP20Data->ChargeBoxId);
  16200. }
  16201. else
  16202. {
  16203. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP20Data->ChargeBoxId);
  16204. }
  16205. result = TRUE;
  16206. }
  16207. else
  16208. {
  16209. strcpy(OcppPath,"");
  16210. }
  16211. return result;
  16212. }
  16213. int GetOcppPort()
  16214. {
  16215. return OcppPort;
  16216. }
  16217. int GetOcppConnStatus(void)
  16218. {
  16219. return ShmOCPP20Data->OcppConnStatus;
  16220. }
  16221. void SetOcppConnStatus(uint8_t status)
  16222. {
  16223. ShmOCPP20Data->OcppConnStatus = status;
  16224. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  16225. }
  16226. int GetHeartBeatWithNOResponse(void)
  16227. {
  16228. return HeartBeatWithNOResponse;
  16229. }
  16230. void SetHeartBeatWithNOResponse(void)
  16231. {
  16232. HeartBeatWithNOResponse = 0;
  16233. }
  16234. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  16235. void storeTempStopTransaction(int gun_index)
  16236. {
  16237. char TempStopTransaction[256];
  16238. char message[1024*20]={0};
  16239. char guid[37]={0};
  16240. json_object *TransactionEvent = json_object_new_object();
  16241. json_object *transactionInfo = json_object_new_object();
  16242. json_object *idToken = json_object_new_object();
  16243. json_object *evse = json_object_new_object();
  16244. json_object *meterValues = json_object_new_array();
  16245. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  16246. DEBUG_INFO("storeTempStopTransaction...\n");
  16247. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  16248. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  16249. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  16250. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  16251. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  16252. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  16253. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  16254. // Message
  16255. json_object_object_add(TransactionEvent, "eventType", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  16256. json_object_object_add(TransactionEvent, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].timestamp));
  16257. json_object_object_add(TransactionEvent, "triggerReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason));
  16258. json_object_object_add(TransactionEvent, "seqNo", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].seqNo+1));
  16259. json_object_object_add(TransactionEvent, "offline", json_object_new_boolean(ShmOCPP20Data->TransactionEvent[gun_index].offline));
  16260. if(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed > 0)
  16261. json_object_object_add(TransactionEvent, "numberOfPhasesUsed", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed));
  16262. if(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent > 0)
  16263. json_object_object_add(TransactionEvent, "cableMaxCurrent", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent));
  16264. if(ShmOCPP20Data->TransactionEvent[gun_index].reservationId > 0)
  16265. json_object_object_add(TransactionEvent, "reservationId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].reservationId));
  16266. json_object_object_add(transactionInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId));
  16267. json_object_object_add(transactionInfo, "chargingState", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState));
  16268. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging > 0)
  16269. json_object_object_add(transactionInfo, "timeSpentCharging", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging));
  16270. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason) > 0)
  16271. json_object_object_add(transactionInfo, "stoppedReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason));
  16272. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId > 0)
  16273. json_object_object_add(transactionInfo, "remoteStartId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId));
  16274. json_object_object_add(TransactionEvent, "transactionInfo", transactionInfo);
  16275. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken) > 0)
  16276. {
  16277. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
  16278. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type));
  16279. json_object_object_add(TransactionEvent, "idToken", idToken);
  16280. }
  16281. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.id));
  16282. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId));
  16283. json_object_object_add(TransactionEvent, "evse", evse);
  16284. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0].timestamp) > 0)
  16285. {
  16286. for(int idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue);idxMeter++)
  16287. {
  16288. json_object *meterValue = json_object_new_object();
  16289. json_object *sampledValues = json_object_new_array();
  16290. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].timestamp));
  16291. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  16292. {
  16293. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0) &&
  16294. ((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0) || (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_SoC]) == 0) || (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Offered]) == 0) || (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Offered]) == 0)))
  16295. {
  16296. if(strstr((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, (char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) != NULL)
  16297. {
  16298. json_object *sampledValue = json_object_new_object();
  16299. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  16300. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  16301. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  16302. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  16303. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  16304. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  16305. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  16306. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  16307. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  16308. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  16309. {
  16310. json_object *unitOfMeasure = json_object_new_object();
  16311. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  16312. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  16313. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  16314. }
  16315. json_object_array_add(sampledValues, sampledValue);
  16316. }
  16317. }
  16318. }
  16319. json_object_object_add(meterValue, "sampledValue", sampledValues);
  16320. json_object_array_add(meterValues, meterValue);
  16321. }
  16322. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  16323. }
  16324. random_uuid(guid);
  16325. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL
  16326. , guid
  16327. , "TransactionEvent"
  16328. , json_object_to_json_string_ext(TransactionEvent, JSON_C_TO_STRING_PLAIN));
  16329. json_object_put(TransactionEvent);
  16330. // open file for writing
  16331. FILE *outfile;
  16332. outfile = fopen (TempStopTransaction, "w+");
  16333. //DEBUG_INFO("data = %s\n", queuedata);
  16334. fputs(message, outfile);
  16335. fputs("\n", outfile);
  16336. fclose (outfile);
  16337. }
  16338. void checkTempStopTransaction(int gun_index)
  16339. {
  16340. FILE *fptr1;
  16341. char ch;
  16342. char str[QUEUE_MESSAGE_LENGTH]={0};
  16343. char guid[37]={0};
  16344. char tempdata[65]={0};
  16345. char TempStopTransaction[256];
  16346. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction20_%d", (gun_index+1));
  16347. fptr1 = fopen(TempStopTransaction, "r");
  16348. if (!fptr1)
  16349. {
  16350. //DEBUG_INFO("TempStopTransaction20_%d not found or unable to open the input file!\n", (gun_index+1));
  16351. return ;
  16352. }
  16353. ch=fgetc(fptr1);
  16354. rewind(fptr1);
  16355. if(ch!=EOF)
  16356. {
  16357. // copy all contents to the temporary file except the specific line
  16358. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  16359. {
  16360. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  16361. if(str[0]=='\0')
  16362. {
  16363. break;
  16364. }
  16365. strncpy(guid, str+4, 36); //copy guid
  16366. sprintf(tempdata, "TransactionEvent,%d", (gun_index));
  16367. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  16368. {
  16369. //DEBUG_INFO("StopTransaction mapitem pass\n");
  16370. }
  16371. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  16372. memset(str,0,ARRAY_SIZE(str));
  16373. }
  16374. }
  16375. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  16376. fclose(fptr1);
  16377. remove(TempStopTransaction); // remove the original file
  16378. }
  16379. int GetWebSocketPingInterval(void)
  16380. {
  16381. return atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].value);
  16382. }
  16383. int GetServerSign(void)
  16384. {
  16385. return server_sign;
  16386. }
  16387. uint8_t GetOcppSecurityProfile()
  16388. {
  16389. return atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].value);
  16390. }
  16391. void GetOcppChargerBoxId(uint8_t *data)
  16392. {
  16393. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  16394. }
  16395. void GetOcppSecurityPassword(uint8_t *data)
  16396. {
  16397. sprintf((char*)data, "%s", ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].value);
  16398. }
  16399. void SetServerSign(int value)
  16400. {
  16401. server_sign = value;
  16402. }
  16403. int GetBootNotificationInterval(void)
  16404. {
  16405. return BootNotificationInterval;
  16406. }
  16407. int GetInternetConn(void)
  16408. {
  16409. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  16410. }
  16411. int GetBackendConnectionTimeout(void)
  16412. {
  16413. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  16414. }
  16415. int isConnectorInitMode(int gun_index)
  16416. {
  16417. int tempIndex = 0;
  16418. int result = TRUE;
  16419. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  16420. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  16421. {
  16422. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16423. {
  16424. tempIndex = ((gun_index==2) ? 1: 0);
  16425. }
  16426. else
  16427. {
  16428. tempIndex = gun_index;
  16429. }
  16430. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16431. {
  16432. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  16433. {
  16434. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16435. } //end of the same index
  16436. }//end of for CHAdeMO_QUANTITY
  16437. }
  16438. else if(gunType[gun_index] == GUN_TYPE_CCS)
  16439. {
  16440. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16441. {
  16442. tempIndex = ((gun_index==2) ? 1: 0);
  16443. }
  16444. else
  16445. {
  16446. tempIndex = gun_index;
  16447. }
  16448. for (int index = 0; index < CCS_QUANTITY; index++)
  16449. {
  16450. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  16451. {
  16452. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16453. } //end of the same index
  16454. } // end of for CCS_QUANTITY
  16455. }
  16456. else if(gunType[gun_index] == GUN_TYPE_GBT)
  16457. {
  16458. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  16459. {
  16460. tempIndex = ((gun_index==2) ? 1: 0);
  16461. }
  16462. else
  16463. {
  16464. tempIndex = gun_index;
  16465. }
  16466. for (int index = 0; index < GB_QUANTITY; index++)
  16467. {
  16468. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  16469. {
  16470. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16471. } //end of the same index
  16472. } // end of for GB_QUANTITY
  16473. }
  16474. else if(gunType[gun_index] == GUN_TYPE_DO)
  16475. {
  16476. tempIndex = gun_index;
  16477. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16478. {
  16479. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  16480. {
  16481. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16482. } //end of the same index
  16483. }
  16484. }
  16485. else
  16486. {
  16487. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  16488. {
  16489. tempIndex = 2;
  16490. }
  16491. else
  16492. {
  16493. tempIndex = gun_index;
  16494. }
  16495. for (int index = 0; index < AC_QUANTITY; index++)
  16496. {
  16497. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  16498. {
  16499. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  16500. }//end of the same index
  16501. }//end of for AC_QUANTITY
  16502. }
  16503. return result;
  16504. }
  16505. void refreshProcDogTimer()
  16506. {
  16507. ShmOCPP20Data->procDogTime = time((time_t*)NULL);
  16508. }
  16509. void InitialSystemValue(void)
  16510. {
  16511. localversion=0;
  16512. BootNotificationInterval = 10;
  16513. authorizeRetryTimes = 0;
  16514. GunStatusInterval = 10;
  16515. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].value);
  16516. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].value);
  16517. //Hear Beat
  16518. HeartBeatWithNOResponse = 0;
  16519. HeartBeatCountPerHour = 0;
  16520. HeartBeatWaitTime = atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value);;
  16521. FirstHeartBeat = 0;
  16522. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle; // Idle
  16523. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle; // Idle
  16524. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  16525. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  16526. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  16527. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  16528. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  16529. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  16530. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  16531. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  16532. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  16533. //Status && ConnectorPlugIn Setting
  16534. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  16535. {
  16536. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  16537. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  16538. }
  16539. for (int index = 0; index < CCS_QUANTITY; index++)
  16540. {
  16541. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  16542. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  16543. }
  16544. for (int index = 0; index < GB_QUANTITY; index++)
  16545. {
  16546. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  16547. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  16548. }
  16549. for (int index = 0; index < AC_QUANTITY; index++)
  16550. {
  16551. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  16552. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  16553. }
  16554. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  16555. {
  16556. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  16557. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  16558. }
  16559. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  16560. {
  16561. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  16562. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  16563. cpinitateMsg.bits[gun_index].StatusNotificationConf = OFF;
  16564. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  16565. refreshStartTimer(&clientTime.StatusNotification[gun_index]);
  16566. memset(&ShmOCPP20Data->StatusNotification[gun_index], 0x00, sizeof(struct StatusNotification_20));
  16567. }
  16568. refreshStartTimer(&clientTime.Heartbeat);
  16569. sleep(1);
  16570. }
  16571. void LWS_Send(char *str)
  16572. {
  16573. //=====================================================
  16574. // Check InternetConn 0: disconnected, 1: connected
  16575. //====================================================
  16576. if(GetOcppConnStatus() == 0)
  16577. {
  16578. DEBUG_INFO("offline now !!!\n");
  16579. return;
  16580. }
  16581. // Only disable isWebsocketSendable operation initiated by charger
  16582. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16583. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16584. || (strstr((char*)str, "\"ClearedChargingLimit\"") != NULL)
  16585. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16586. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16587. || (strstr((char*)str, "\"Get15118EVCertificate\"") != NULL)
  16588. || (strstr((char*)str, "\"GetCertificateStatus\"") != NULL)
  16589. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16590. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16591. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16592. || (strstr((char*)str, "\"NotifyChargingLimit\"") != NULL)
  16593. || (strstr((char*)str, "\"NotifyCustomerInformation\"") != NULL)
  16594. || (strstr((char*)str, "\"NotifyDisplayMessages\"") != NULL)
  16595. || (strstr((char*)str, "\"NotifyEVChargingNeeds\"") != NULL)
  16596. || (strstr((char*)str, "\"NotifyEVChargingSchedule\"") != NULL)
  16597. || (strstr((char*)str, "\"NotifyEvent\"") != NULL)
  16598. || (strstr((char*)str, "\"NotifyMonitoringReport\"") != NULL)
  16599. || (strstr((char*)str, "\"NotifyReport\"") != NULL)
  16600. || (strstr((char*)str, "\"PublishFirmwareStatusNotification\"") != NULL)
  16601. || (strstr((char*)str, "\"ReportChargingProfiles\"") != NULL)
  16602. || (strstr((char*)str, "\"ReservationStatusUpdate\"") != NULL)
  16603. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16604. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16605. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16606. || (strstr((char*)str, "\"TransactionEvent\"") != NULL))
  16607. {
  16608. isWebsocketSendable = OFF;
  16609. }
  16610. pthread_mutex_lock(&lock_send);
  16611. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16612. sprintf((char *)SendBuffer, "%s", str);
  16613. SendBufLen = strlen(str);
  16614. pthread_mutex_unlock(&lock_send);
  16615. lws_callback_on_writable(wsi_client);
  16616. //lws_service(context, 0);
  16617. //sleep(1);
  16618. }
  16619. void LWS_SendNow(char *str)
  16620. {
  16621. //=====================================================
  16622. // Check InternetConn 0: disconnected, 1: connected
  16623. //====================================================
  16624. if(GetOcppConnStatus() == 0)
  16625. {
  16626. DEBUG_INFO("offline now !!!\n");
  16627. return;
  16628. }
  16629. // Only disable isWebsocketSendable operation initiated by charger
  16630. if((strstr((char*)str, "\"Authorize\"") != NULL)
  16631. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  16632. || (strstr((char*)str, "\"ClearedChargingLimit\"") != NULL)
  16633. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  16634. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  16635. || (strstr((char*)str, "\"Get15118EVCertificate\"") != NULL)
  16636. || (strstr((char*)str, "\"GetCertificateStatus\"") != NULL)
  16637. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  16638. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  16639. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  16640. || (strstr((char*)str, "\"NotifyChargingLimit\"") != NULL)
  16641. || (strstr((char*)str, "\"NotifyCustomerInformation\"") != NULL)
  16642. || (strstr((char*)str, "\"NotifyDisplayMessages\"") != NULL)
  16643. || (strstr((char*)str, "\"NotifyEVChargingNeeds\"") != NULL)
  16644. || (strstr((char*)str, "\"NotifyEVChargingSchedule\"") != NULL)
  16645. || (strstr((char*)str, "\"NotifyEvent\"") != NULL)
  16646. || (strstr((char*)str, "\"NotifyMonitoringReport\"") != NULL)
  16647. || (strstr((char*)str, "\"NotifyReport\"") != NULL)
  16648. || (strstr((char*)str, "\"PublishFirmwareStatusNotification\"") != NULL)
  16649. || (strstr((char*)str, "\"ReportChargingProfiles\"") != NULL)
  16650. || (strstr((char*)str, "\"ReservationStatusUpdate\"") != NULL)
  16651. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  16652. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  16653. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  16654. || (strstr((char*)str, "\"TransactionEvent\"") != NULL))
  16655. {
  16656. isWebsocketSendable = OFF;
  16657. }
  16658. pthread_mutex_lock(&lock_send);
  16659. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  16660. sprintf((char *)SendBuffer, "%s", str);
  16661. SendBufLen = strlen(str);
  16662. pthread_mutex_unlock(&lock_send);
  16663. lws_callback_on_writable(wsi_client);
  16664. lws_service(context, 0);
  16665. //sleep(1);
  16666. }