MessageHandler.c 939 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233
  1. #include "Module_OcppBackend20.h"
  2. #include "define.h"
  3. static char *APNAuthenticationEnumTypeStr[] = {
  4. MACROSTR(CHAP),
  5. MACROSTR(NONE),
  6. MACROSTR(PAP),
  7. MACROSTR(AUTO)
  8. };
  9. static char *AttributeEnumTypeStr[] = {
  10. MACROSTR(Actual),
  11. MACROSTR(Target),
  12. MACROSTR(MinSet),
  13. MACROSTR(MaxSet)
  14. };
  15. static char *AuthorizationStatusEnumTypeStr[] = {
  16. MACROSTR(Accepted),
  17. MACROSTR(Blocked),
  18. MACROSTR(ConcurrentTx),
  19. MACROSTR(Expired),
  20. MACROSTR(Invalid),
  21. MACROSTR(NoCredit),
  22. MACROSTR(NotAllowedTypeEVSE),
  23. MACROSTR(NotAtThisLocation),
  24. MACROSTR(NotAtThisTime),
  25. MACROSTR(Unknown)
  26. };
  27. #if 0
  28. static char *AuthorizeCertificateStatusEnumTypeStr[] = {
  29. MACROSTR(Accepted),
  30. MACROSTR(SignatureError),
  31. MACROSTR(CertificateExpired),
  32. MACROSTR(CertificateRevoked),
  33. MACROSTR(NoCertificateAvailable),
  34. MACROSTR(CertChainError),
  35. MACROSTR(ContractCancelled)
  36. };
  37. #endif
  38. static char *BootReasonEnumTypeStr[] = {
  39. MACROSTR(ApplicationReset),
  40. MACROSTR(FirmwareUpdate),
  41. MACROSTR(LocalReset),
  42. MACROSTR(PowerUp),
  43. MACROSTR(RemoteReset),
  44. MACROSTR(ScheduledReset),
  45. MACROSTR(Triggered),
  46. MACROSTR(Unknown),
  47. MACROSTR(Watchdog)
  48. };
  49. static char *CancelReservationStatusEnumTypeStr[] = {
  50. MACROSTR(Accepted),
  51. MACROSTR(Rejected)
  52. };
  53. static char *CertificateActionEnumTypeStr[] = {
  54. MACROSTR(Install),
  55. MACROSTR(Update)
  56. };
  57. static char *CertificateSignedStatusEnumTypeStr[] = {
  58. MACROSTR(Accepted),
  59. MACROSTR(Rejected)
  60. };
  61. static char *CertificateSigningUseEnumTypeStr[] = {
  62. MACROSTR(ChargingStationCertificate),
  63. MACROSTR(V2GCertificate)
  64. };
  65. static char *ChangeAvailabilityStatusEnumTypeStr[] = {
  66. MACROSTR(Accepted),
  67. MACROSTR(Rejected),
  68. MACROSTR(Scheduled)
  69. };
  70. #if 0
  71. static char *ChargingLimitSourceEnumTypeStr[] = {
  72. MACROSTR(EMS),
  73. MACROSTR(Other),
  74. MACROSTR(SO),
  75. MACROSTR(CSO)
  76. };
  77. #endif
  78. static char *ChargingProfileKindEnumTypeStr[] = {
  79. MACROSTR(Absolute),
  80. MACROSTR(Recurring),
  81. MACROSTR(Relative)
  82. };
  83. static char *ChargingProfilePurposeEnumTypeStr[] = {
  84. MACROSTR(ChargingStationExternalConstraints),
  85. MACROSTR(ChargingStationMaxProfile),
  86. MACROSTR(TxDefaultProfile),
  87. MACROSTR(TxProfile)
  88. };
  89. static char *ChargingProfileStatusEnumTypeStr[] = {
  90. MACROSTR(Accepted),
  91. MACROSTR(Rejected)
  92. };
  93. static char *ChargingRateUnitEnumTypeStr[] = {
  94. MACROSTR(W),
  95. MACROSTR(A)
  96. };
  97. static char *ChargingStateEnumTypeStr[] = {
  98. MACROSTR(Charging),
  99. MACROSTR(EVConnected),
  100. MACROSTR(SuspendedEV),
  101. MACROSTR(SuspendedEVSE),
  102. MACROSTR(Idle)
  103. };
  104. static char *ClearCacheStatusEnumTypeStr[] = {
  105. MACROSTR(Accepted),
  106. MACROSTR(Rejected)
  107. };
  108. static char *ClearChargingProfileStatusEnumTypeStr[] = {
  109. MACROSTR(Accepted),
  110. MACROSTR(Unknown)
  111. };
  112. static char *ClearMessageStatusEnumTypeStr[] = {
  113. MACROSTR(Accepted),
  114. MACROSTR(Unknown)
  115. };
  116. static char *ClearMonitoringStatusEnumTypeStr[] = {
  117. MACROSTR(Accepted),
  118. MACROSTR(Rejected),
  119. MACROSTR(NotFound)
  120. };
  121. static char *ComponentCriterionEnumTypeStr[] = {
  122. MACROSTR(Active),
  123. MACROSTR(Available),
  124. MACROSTR(Enabled),
  125. MACROSTR(Problem)
  126. };
  127. #if 0
  128. static char *ConnectorEnumTypeStr[] = {
  129. MACROSTR(cCCS1),
  130. MACROSTR(cCCS2),
  131. MACROSTR(cG105),
  132. MACROSTR(cTesla),
  133. MACROSTR(cType1),
  134. MACROSTR(cType2),
  135. MACROSTR(s309-1P-16A),
  136. MACROSTR(s309-1P-32A),
  137. MACROSTR(s309-3P-16A),
  138. MACROSTR(s309-3P-32A),
  139. MACROSTR(sBS1361),
  140. MACROSTR(sCEE-7-7),
  141. MACROSTR(sType2),
  142. MACROSTR(sType3),
  143. MACROSTR(Other1PhMax16A),
  144. MACROSTR(Other1PhOver16A),
  145. MACROSTR(Other3Ph),
  146. MACROSTR(Pan),
  147. MACROSTR(wInductive),
  148. MACROSTR(wResonant),
  149. MACROSTR(Undetermined),
  150. MACROSTR(Unknown)
  151. };
  152. #endif
  153. static char *ConnectorStatusEnumTypeStr[] = {
  154. MACROSTR(Available),
  155. MACROSTR(Occupied),
  156. MACROSTR(Reserved),
  157. MACROSTR(Unavailable),
  158. MACROSTR(Faulted)
  159. };
  160. #if 0
  161. static char *CostKindEnumTypeStr[] = {
  162. MACROSTR(CarbonDioxideEmission),
  163. MACROSTR(RelativePricePercentage),
  164. MACROSTR(RenewableGenerationPercentage)
  165. };
  166. #endif
  167. static char *CustomerInformationStatusEnumTypeStr[] = {
  168. MACROSTR(Accepted),
  169. MACROSTR(Rejected),
  170. MACROSTR(Invalid)
  171. };
  172. static char *DataEnumTypeStr[] = {
  173. MACROSTR(string),
  174. MACROSTR(decimal),
  175. MACROSTR(integer),
  176. MACROSTR(dateTime),
  177. MACROSTR(boolean),
  178. MACROSTR(OptionList),
  179. MACROSTR(SequenceList),
  180. MACROSTR(MemberList)
  181. };
  182. static char *DataTransferStatusEnumTypeStr[] = {
  183. MACROSTR(Accepted),
  184. MACROSTR(Rejected),
  185. MACROSTR(UnknownMessageId),
  186. MACROSTR(UnknownVendorId)
  187. };
  188. static char *DeleteCertificateStatusEnumTypeStr[] = {
  189. MACROSTR(Accepted),
  190. MACROSTR(Failed),
  191. MACROSTR(NotFound)
  192. };
  193. static char *DisplayMessageStatusEnumTypeStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(NotSupportedMessageFormat),
  196. MACROSTR(Rejected),
  197. MACROSTR(NotSupportedPriority),
  198. MACROSTR(NotSupportedState),
  199. MACROSTR(UnknownTransaction)
  200. };
  201. #if 0
  202. static char *EnergyTransferModeEnumTypeStr[] = {
  203. MACROSTR(DC),
  204. MACROSTR(AC_single_phase),
  205. MACROSTR(AC_two_phase),
  206. MACROSTR(AC_three_phase)
  207. };
  208. #endif
  209. static char *EventNotificationEnumTypeStr[] = {
  210. MACROSTR(HardWiredNotification),
  211. MACROSTR(HardWiredMonitor),
  212. MACROSTR(PreconfiguredMonitor),
  213. MACROSTR(CustomMonitor)
  214. };
  215. static char *EventTriggerEnumTypeStr[] = {
  216. MACROSTR(Alerting),
  217. MACROSTR(Delta),
  218. MACROSTR(Periodic)
  219. };
  220. static char *FirmwareStatusEnumTypeStr[] = {
  221. MACROSTR(Downloaded),
  222. MACROSTR(DownloadFailed),
  223. MACROSTR(Downloading),
  224. MACROSTR(DownloadScheduled),
  225. MACROSTR(DownloadPaused),
  226. MACROSTR(Idle),
  227. MACROSTR(InstallationFailed),
  228. MACROSTR(Installing),
  229. MACROSTR(Installed),
  230. MACROSTR(InstallRebooting),
  231. MACROSTR(InstallScheduled),
  232. MACROSTR(InstallVerificationFailed),
  233. MACROSTR(InvalidSignature),
  234. MACROSTR(SignatureVerified)
  235. };
  236. static char *GenericDeviceModelStatusEnumTypeStr[] = {
  237. MACROSTR(Accepted),
  238. MACROSTR(Rejected),
  239. MACROSTR(NotSupported),
  240. MACROSTR(EmptyResultSet)
  241. };
  242. static char *GenericStatusEnumTypeStr[] = {
  243. MACROSTR(Accepted),
  244. MACROSTR(Rejected)
  245. };
  246. static char *GetCertificateIdUseEnumTypeStr[] = {
  247. MACROSTR(V2GRootCertificate),
  248. MACROSTR(MORootCertificate),
  249. MACROSTR(CSMSRootCertificate),
  250. MACROSTR(V2GCertificateChain),
  251. MACROSTR(ManufacturerRootCertificate)
  252. };
  253. static char *GetCertificateStatusEnumTypeStr[] = {
  254. MACROSTR(Accepted),
  255. MACROSTR(Failed)
  256. };
  257. static char *GetChargingProfileStatusEnumTypeStr[] = {
  258. MACROSTR(Accepted),
  259. MACROSTR(NoProfiles)
  260. };
  261. static char *GetDisplayMessagesStatusEnumTypeStr[] = {
  262. MACROSTR(Accepted),
  263. MACROSTR(Unknown)
  264. };
  265. static char *GetInstalledCertificateStatusEnumTypeStr[] = {
  266. MACROSTR(Accepted),
  267. MACROSTR(NotFound)
  268. };
  269. static char *GetVariableStatusEnumTypeStr[] = {
  270. MACROSTR(Accepted),
  271. MACROSTR(Rejected),
  272. MACROSTR(UnknownComponent),
  273. MACROSTR(UnknownVariable),
  274. MACROSTR(NotSupportedAttributeType)
  275. };
  276. static char *HashAlgorithmEnumTypeStr[] = {
  277. MACROSTR(SHA256),
  278. MACROSTR(SHA384),
  279. MACROSTR(SHA512)
  280. };
  281. static char *IdTokenEnumTypeStr[] = {
  282. MACROSTR(Central),
  283. MACROSTR(eMAID),
  284. MACROSTR(ISO14443),
  285. MACROSTR(KeyCode),
  286. MACROSTR(Local),
  287. MACROSTR(NoAuthorization),
  288. MACROSTR(ISO15693)
  289. };
  290. static char *InstallCertificateUseEnumTypeStr[] = {
  291. MACROSTR(V2GRootCertificate),
  292. MACROSTR(MORootCertificate),
  293. MACROSTR(CSMSRootCertificate),
  294. MACROSTR(ManufacturerRootCertificate)
  295. };
  296. static char *InstallCertificateStatusEnumTypeStr[]={
  297. MACROSTR(Accepted),
  298. MACROSTR(Failed),
  299. MACROSTR(Rejected)
  300. };
  301. static char *Iso15118EVCertificateStatusEnumTypeStr[] = {
  302. MACROSTR(Accepted),
  303. MACROSTR(Failed)
  304. };
  305. static char *LocationEnumTypeStr[] = {
  306. MACROSTR(Body),
  307. MACROSTR(Cable),
  308. MACROSTR(EV),
  309. MACROSTR(Inlet),
  310. MACROSTR(Outlet)
  311. };
  312. static char *LogEnumTypeStr[] = {
  313. MACROSTR(DiagnosticsLog),
  314. MACROSTR(SecurityLog)
  315. };
  316. static char *LogStatusEnumTypeStr[] = {
  317. MACROSTR(Accepted),
  318. MACROSTR(Rejected),
  319. MACROSTR(AcceptedCanceled)
  320. };
  321. static char *MeasurandEnumTypeStr[] = {
  322. MACROSTR(Current.Export),
  323. MACROSTR(Current.Import),
  324. MACROSTR(Current.Offered),
  325. MACROSTR(Energy.Active.Export.Register),
  326. MACROSTR(Energy.Active.Import.Register),
  327. MACROSTR(Energy.Reactive.Export.Register),
  328. MACROSTR(Energy.Reactive.Import.Register),
  329. MACROSTR(Energy.Active.Export.Interval),
  330. MACROSTR(Energy.Active.Import.Interval),
  331. MACROSTR(Energy.Active.Net),
  332. MACROSTR(Energy.Reactive.Export.Interval),
  333. MACROSTR(Energy.Reactive.Import.Interval),
  334. MACROSTR(Energy.Reactive.Net),
  335. MACROSTR(Energy.Apparent.Net),
  336. MACROSTR(Energy.Apparent.Import),
  337. MACROSTR(Energy.Apparent.Export),
  338. MACROSTR(Frequency),
  339. MACROSTR(Power.Active.Export),
  340. MACROSTR(Power.Active.Import),
  341. MACROSTR(Power.Factor),
  342. MACROSTR(Power.Offered),
  343. MACROSTR(Power.Reactive.Export),
  344. MACROSTR(Power.Reactive.Import),
  345. MACROSTR(SoC),
  346. MACROSTR(Voltage)
  347. };
  348. static char *MessageFormatEnumTypeStr[] = {
  349. MACROSTR(ASCII),
  350. MACROSTR(HTML),
  351. MACROSTR(URI),
  352. MACROSTR(UTF8)
  353. };
  354. static char *MessagePriorityEnumTypeStr[] = {
  355. MACROSTR(AlwaysFront),
  356. MACROSTR(InFront),
  357. MACROSTR(NormalCycle)
  358. };
  359. static char *MessageStateEnumTypeStr[] = {
  360. MACROSTR(Charging),
  361. MACROSTR(Faulted),
  362. MACROSTR(Idle),
  363. MACROSTR(Unavailable)
  364. };
  365. static char *MessageTriggerEnumTypeStr[] = {
  366. MACROSTR(BootNotification),
  367. MACROSTR(LogStatusNotification),
  368. MACROSTR(FirmwareStatusNotification),
  369. MACROSTR(Heartbeat),
  370. MACROSTR(MeterValues),
  371. MACROSTR(SignChargingStationCertificate),
  372. MACROSTR(SignV2GCertificate),
  373. MACROSTR(StatusNotification),
  374. MACROSTR(TransactionEvent),
  375. MACROSTR(SignCombinedCertificate),
  376. MACROSTR(PublishFirmwareStatusNotification)
  377. };
  378. static char *MonitorEnumTypeStr[] = {
  379. MACROSTR(UpperThreshold),
  380. MACROSTR(LowerThreshold),
  381. MACROSTR(Delta),
  382. MACROSTR(Periodic),
  383. MACROSTR(PeriodicClockAligned)
  384. };
  385. static char *MonitoringBaseEnumTypeStr[] = {
  386. MACROSTR(All),
  387. MACROSTR(FactoryDefault),
  388. MACROSTR(HardWiredOnly)
  389. };
  390. static char *MonitoringCriterionEnumTypeStr[] = {
  391. MACROSTR(ThresholdMonitoring),
  392. MACROSTR(DeltaMonitoring),
  393. MACROSTR(PeriodicMonitoring)
  394. };
  395. static char *MutabilityEnumTypeStr[] = {
  396. MACROSTR(ReadOnly),
  397. MACROSTR(WriteOnly),
  398. MACROSTR(ReadWrite)
  399. };
  400. static char *NotifyEVChargingNeedsStatusEnumTypeStr[] = {
  401. MACROSTR(Accepted),
  402. MACROSTR(Rejected),
  403. MACROSTR(Processing)
  404. };
  405. static char *OCPPInterfaceEnumTypeStr[] = {
  406. MACROSTR(Wired0),
  407. MACROSTR(Wired1),
  408. MACROSTR(Wired2),
  409. MACROSTR(Wired3),
  410. MACROSTR(Wireless0),
  411. MACROSTR(Wireless1),
  412. MACROSTR(Wireless2),
  413. MACROSTR(Wireless3)
  414. };
  415. static char *OCPPTransportEnumTypeStr[] = {
  416. MACROSTR(JSON),
  417. MACROSTR(SOAP)
  418. };
  419. static char *OCPPVersionEnumTypeStr[] = {
  420. MACROSTR(OCPP12),
  421. MACROSTR(OCPP15),
  422. MACROSTR(OCPP16),
  423. MACROSTR(OCPP20)
  424. };
  425. static char *OperationalStatusEnumTypeStr[] = {
  426. MACROSTR(Inoperative),
  427. MACROSTR(Operative)
  428. };
  429. static char *PhaseEnumTypeStr[] = {
  430. MACROSTR(L1),
  431. MACROSTR(L2),
  432. MACROSTR(L3),
  433. MACROSTR(N),
  434. MACROSTR(L1-N),
  435. MACROSTR(L2-N),
  436. MACROSTR(L3-N),
  437. MACROSTR(L1-L2),
  438. MACROSTR(L2-L3),
  439. MACROSTR(L3-L1)
  440. };
  441. static char *PublishFirmwareStatusEnumTypeStr[] = {
  442. MACROSTR(Downloaded),
  443. MACROSTR(DownloadFailed),
  444. MACROSTR(Downloading),
  445. MACROSTR(DownloadScheduled),
  446. MACROSTR(DownloadPaused),
  447. MACROSTR(PublishFailed),
  448. MACROSTR(Published),
  449. MACROSTR(InvalidChecksum),
  450. MACROSTR(ChecksumVerified)
  451. };
  452. static char *ReadingContextEnumTypeStr[] = {
  453. MACROSTR(Interruption.Begin),
  454. MACROSTR(Interruption.End),
  455. MACROSTR(Other),
  456. MACROSTR(Sample.Clock),
  457. MACROSTR(Sample.Periodic),
  458. MACROSTR(Transaction.Begin),
  459. MACROSTR(Transaction.End),
  460. MACROSTR(Trigger)
  461. };
  462. #if 0
  463. static char *ReasonEnumTypeStr[] = {
  464. MACROSTR(DeAuthorized),
  465. MACROSTR(EmergencyStop),
  466. MACROSTR(EnergyLimitReached),
  467. MACROSTR(EVDisconnected),
  468. MACROSTR(GroundFault),
  469. MACROSTR(ImmediateReset),
  470. MACROSTR(Local),
  471. MACROSTR(LocalOutOfCredit),
  472. MACROSTR(MasterPass),
  473. MACROSTR(Other),
  474. MACROSTR(OvercurrentFault),
  475. MACROSTR(PowerLoss),
  476. MACROSTR(PowerQuality),
  477. MACROSTR(Reboot),
  478. MACROSTR(Remote),
  479. MACROSTR(SOCLimitReached),
  480. MACROSTR(StoppedByEV),
  481. MACROSTR(TimeLimitReached),
  482. MACROSTR(TimeLimitReached)
  483. };
  484. #endif
  485. static char *RecurrencyKindEnumTypeStr[] = {
  486. MACROSTR(Daily),
  487. MACROSTR(Weekly)
  488. };
  489. static char *RegistrationStatusEnumTypeStr[] = {
  490. MACROSTR(Accepted),
  491. MACROSTR(Pending),
  492. MACROSTR(Rejected)
  493. };
  494. static char *ReportBaseEnumTypeStr[] = {
  495. MACROSTR(ConfigurationInventory),
  496. MACROSTR(FullInventory),
  497. MACROSTR(SummaryInventory)
  498. };
  499. static char *RequestStartStopStatusEnumTypeStr[] = {
  500. MACROSTR(Accepted),
  501. MACROSTR(Rejected)
  502. };
  503. static char *ReservationUpdateStatusEnumTypeStr[] = {
  504. MACROSTR(Expired),
  505. MACROSTR(Removed)
  506. };
  507. static char *ReserveNowStatusEnumTypeStr[] = {
  508. MACROSTR(Accepted),
  509. MACROSTR(Faulted),
  510. MACROSTR(Occupied),
  511. MACROSTR(Rejected),
  512. MACROSTR(Unavailable)
  513. };
  514. static char *ResetEnumTypeStr[] = {
  515. MACROSTR(Immediate),
  516. MACROSTR(OnIdle)
  517. };
  518. static char *ResetStatusEnumTypeStr[] = {
  519. MACROSTR(Accepted),
  520. MACROSTR(Rejected),
  521. MACROSTR(Scheduled)
  522. };
  523. static char *SetMonitoringStatusEnumTypeStr[] = {
  524. MACROSTR(Accepted),
  525. MACROSTR(UnknownComponent),
  526. MACROSTR(UnknownVariable),
  527. MACROSTR(UnsupportedMonitorType),
  528. MACROSTR(Rejected),
  529. MACROSTR(OutOfRange),
  530. MACROSTR(Duplicate)
  531. };
  532. static char *SetNetworkProfileStatusEnumTypeStr[] = {
  533. MACROSTR(Accepted),
  534. MACROSTR(Rejected),
  535. MACROSTR(Failed)
  536. };
  537. static char *SetVariableStatusEnumTypeStr[] = {
  538. MACROSTR(Accepted),
  539. MACROSTR(Rejected),
  540. MACROSTR(InvalidValue),
  541. MACROSTR(UnknownComponent),
  542. MACROSTR(UnknownVariable),
  543. MACROSTR(NotSupportedAttributeType),
  544. MACROSTR(OutOfRange),
  545. MACROSTR(RebootRequired)
  546. };
  547. static char *TransactionEventEnumTypeStr[] = {
  548. MACROSTR(Ended),
  549. MACROSTR(Started),
  550. MACROSTR(Updated)
  551. };
  552. static char *TriggerMessageStatusEnumTypeStr[] = {
  553. MACROSTR(Accepted),
  554. MACROSTR(Rejected),
  555. MACROSTR(NotImplemented)
  556. };
  557. static char *TriggerReasonEnumTypeStr[] = {
  558. MACROSTR(Authorized),
  559. MACROSTR(CablePluggedIn),
  560. MACROSTR(ChargingRateChanged),
  561. MACROSTR(ChargingStateChanged),
  562. MACROSTR(Deauthorized),
  563. MACROSTR(EnergyLimitReached),
  564. MACROSTR(EVCommunicationLost),
  565. MACROSTR(EVConnectTimeout),
  566. MACROSTR(MeterValueClock),
  567. MACROSTR(MeterValuePeriodic),
  568. MACROSTR(TimeLimitReached),
  569. MACROSTR(Trigger),
  570. MACROSTR(UnlockCommand),
  571. MACROSTR(StopAuthorized),
  572. MACROSTR(EVDeparted),
  573. MACROSTR(EVDetected),
  574. MACROSTR(RemoteStop),
  575. MACROSTR(RemoteStart),
  576. MACROSTR(AbnormalCondition),
  577. MACROSTR(SignedDataReceived),
  578. MACROSTR(ResetCommand)
  579. };
  580. static char *UnlockStatusEnumTypeStr[] = {
  581. MACROSTR(Unlocked),
  582. MACROSTR(UnlockFailed),
  583. MACROSTR(OngoingAuthorizedTransaction),
  584. MACROSTR(UnknownConnector)
  585. };
  586. static char *UnpublishFirmwareStatusEnumTypeStr[] = {
  587. MACROSTR(DownloadOngoing),
  588. MACROSTR(NoFirmware),
  589. MACROSTR(Unpublished)
  590. };
  591. static char *UpdateEnumTypeStr[] = {
  592. MACROSTR(Differential),
  593. MACROSTR(Full)
  594. };
  595. static char *UpdateFirmwareStatusEnumTypeStr[] = {
  596. MACROSTR(Accepted),
  597. MACROSTR(Rejected),
  598. MACROSTR(AcceptedCanceled),
  599. MACROSTR(InvalidCertificate),
  600. MACROSTR(RevokedCertificate)
  601. };
  602. static char *UpdateStatusEnumTypeStr[] = {
  603. MACROSTR(Accepted),
  604. MACROSTR(Failed),
  605. MACROSTR(VersionMismatch)
  606. };
  607. static char *UploadLogStatusEnumTypeStr[] = {
  608. MACROSTR(BadMessage),
  609. MACROSTR(Idle),
  610. MACROSTR(NotSupportedOperation),
  611. MACROSTR(PermissionDenied),
  612. MACROSTR(Uploaded),
  613. MACROSTR(UploadFailure),
  614. MACROSTR(Uploading)
  615. };
  616. static char *VPNEnumTypeStr[] = {
  617. MACROSTR(IKEv2),
  618. MACROSTR(IPSec),
  619. MACROSTR(L2TP),
  620. MACROSTR(PPTP)
  621. };
  622. #if 0
  623. static char *ChargePointErrorCodeEnumTypeStr[] = {
  624. MACROSTR(ConnectorLockFailure),
  625. MACROSTR(EVCommunicationError),
  626. MACROSTR(GroundFailure),
  627. MACROSTR(HighTemperature),
  628. MACROSTR(InternalError),
  629. MACROSTR(LocalListConflict),
  630. MACROSTR(NoError),
  631. MACROSTR(OtherError),
  632. MACROSTR(OverCurrentFailure),
  633. MACROSTR(OverVoltage),
  634. MACROSTR(PowerMeterFailure),
  635. MACROSTR(PowerSwitchFailure),
  636. MACROSTR(ReaderFailure),
  637. MACROSTR(ResetFailure),
  638. MACROSTR(UnderVoltage),
  639. MACROSTR(WeakSignal)
  640. };
  641. #endif
  642. static char *GetCompositeScheduleStatusEnumTypeStr[] = {
  643. MACROSTR(Accepted),
  644. MACROSTR(Rejected)
  645. };
  646. static char *RemoteStartStopStatusEnumTypeStr[] = {
  647. MACROSTR(Accepted),
  648. MACROSTR(Rejected)
  649. };
  650. #if 0
  651. static char * StopTransactionReasonEnumTypeStr[] = {
  652. MACROSTR(EmergencyStop),
  653. MACROSTR(EVDisconnected),
  654. MACROSTR(HardReset),
  655. MACROSTR(Local),
  656. MACROSTR(Other),
  657. MACROSTR(PowerLoss),
  658. MACROSTR(Reboot),
  659. MACROSTR(Remote),
  660. MACROSTR(SoftReset),
  661. MACROSTR(UnlockCommand),
  662. MACROSTR(DeAuthorized)
  663. };
  664. #endif
  665. //ChargePointMaxProfile
  666. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile_OCPP20.json"
  667. //TxDefaultProfile
  668. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0_OCPP20.json"
  669. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  670. struct StatusCodeData *ShmStatusCodeData;
  671. struct PsuData *ShmPsuData ;
  672. struct OCPP20Data *ShmOCPP20Data;
  673. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  674. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  675. //===============================
  676. // Gun Total Numbers
  677. //===============================
  678. static int gunTotalNumber = 0;
  679. static uint8_t gunType[4] = {0};
  680. //===============================
  681. // Local List Version
  682. //===============================
  683. static int localversion=0;
  684. //===============================
  685. // OCPP sign variable
  686. //===============================
  687. static int server_sign = FALSE;
  688. int server_pending = FALSE;
  689. static int BootNotificationInterval = 10;
  690. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  691. //===============================
  692. // OCPP auth variable
  693. //===============================
  694. static int authorizeRetryTimes = 0; //number of Retry times
  695. //===============================
  696. // OCPP other variables
  697. //===============================
  698. static int HeartBeatWaitTime = 10;
  699. static int FirstHeartBeat = 0;
  700. static int FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle; // Idle
  701. static int LogStatusNotificationStatus = UploadLogStatusEnumType_Idle; // Idle
  702. static char CurrentChargingProfileScheduleStr[30] = {0};
  703. //========================================
  704. // OCPP status/previous related variables
  705. //========================================
  706. static int GunStatusInterval = 10;
  707. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  708. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  709. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  710. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  711. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  712. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  713. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  714. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  715. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  716. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  717. static int TransactionMessageAttemptsValue = 0;
  718. static int TransactionMessageRetryIntervalValue = 0;
  719. static struct AuthorizationData idTagQuery;
  720. //=============================================
  721. // OCPP HeartBeat Response Not Receive Counts
  722. //============================================
  723. static int HeartBeatWithNOResponse = 0;
  724. static int HeartBeatCountPerHour = 0;
  725. sqlite3 *db;
  726. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  727. int TransactionMessageAttemptsGet(void);
  728. int TransactionMessageRetryIntervalGet(void);
  729. int GetOcppConnStatus(void);
  730. void SetOcppConnStatus(uint8_t status);
  731. int setKeyValue(char *key, char *value);
  732. void OCPP_get_TableAuthlocalAllData(void);
  733. void processUnkownKey(void);
  734. struct StructOCPPMeterValue
  735. {
  736. unsigned char TimeStamp[28];
  737. struct StructSampledValue SampledValue[10];
  738. };
  739. struct ClientTime
  740. {
  741. unsigned int Heartbeat;
  742. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  743. unsigned int StartTransaction;
  744. unsigned int StopTransaction;
  745. unsigned int MeterValues[CONNECTOR_QUANTITY];
  746. }clientTime;
  747. typedef union
  748. {
  749. //Operations Initiated by Central System
  750. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  751. struct
  752. {
  753. //CsMsgValue[0]
  754. unsigned char StatusNotificationReq:1; //bit 0,
  755. unsigned char StatusNotificationConf:1; //bit 1,
  756. unsigned char TriggerMeterValueReq:1; //bit 2,
  757. unsigned char TransactionEventReq:1; //bit 3,
  758. unsigned char SampleMeterReq:1; //bit 4,
  759. unsigned char ClockAlignMeterReq:1; //bit 5,
  760. unsigned char TriggerStatusNotificationReq:1; //bit 6,
  761. unsigned char isOnCharging:1; //bit7
  762. }bits[CONNECTOR_QUANTITY];
  763. }CpinitiateMsg;
  764. CpinitiateMsg cpinitateMsg;
  765. //=========================================
  766. // Save configuration
  767. //=========================================
  768. int runShellCmd(const char*cmd)
  769. {
  770. int result = FAIL;
  771. char buf[256];
  772. FILE *fp;
  773. fp = popen(cmd, "r");
  774. if(fp != NULL)
  775. {
  776. while(fgets(buf, sizeof(buf), fp) != NULL)
  777. {
  778. DEBUG_INFO("%s\n", buf);
  779. }
  780. result = PASS;
  781. }
  782. pclose(fp);
  783. return result;
  784. }
  785. int StoreUsrConfigData(struct SysConfigData *UsrData)
  786. {
  787. int result = PASS;
  788. int fd,wrd;
  789. unsigned int i,Chk;
  790. unsigned char *ptr, *BufTmp;
  791. int MtdBlockSize = 0x300000;
  792. Chk=0;
  793. ptr=(unsigned char *)UsrData;
  794. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  795. {
  796. memset(BufTmp,0,MtdBlockSize);
  797. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  798. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  799. Chk+=*(BufTmp+i);
  800. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  801. // Output configuration to file.
  802. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  803. if (fd < 0)
  804. {
  805. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  806. free(BufTmp);
  807. return 0;
  808. }
  809. wrd=write(fd, BufTmp, MtdBlockSize);
  810. close(fd);
  811. if(wrd<MtdBlockSize)
  812. {
  813. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  814. free(BufTmp);
  815. return 0;
  816. }
  817. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  818. DEBUG_INFO("Erase /dev/mtd10.\n");
  819. runShellCmd("flash_erase /dev/mtd10 0 0");
  820. DEBUG_INFO("Write /dev/mtd10.\n");
  821. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  822. DEBUG_INFO("Erase /dev/mtd11.\n");
  823. runShellCmd("flash_erase /dev/mtd11 0 0");
  824. DEBUG_INFO("Write /dev/mtd11.\n");
  825. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  826. system("rm -f /mnt/EvseConfig.bin");
  827. DEBUG_INFO("EvseConfig write to flash OK\n");
  828. }
  829. else
  830. {
  831. DEBUG_ERROR("alloc BlockSize NG\r\n");
  832. result = FAIL;
  833. }
  834. if(BufTmp!=NULL)
  835. free(BufTmp);
  836. return result;
  837. }
  838. //=========================================
  839. // Date time related function
  840. //=========================================
  841. void getNowDatetime(uint8_t *data)
  842. {
  843. time_t t = time(NULL);
  844. struct tm tm = *localtime(&t);
  845. 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);
  846. }
  847. //=========================================
  848. // Sqlite3 related function
  849. //=========================================
  850. int DB_Initial()
  851. {
  852. int result = PASS;
  853. char* errMsg = NULL;
  854. char *sqlOcppAuthCache = "create table if not exists ocpp20_auth_cache (idx integer primary key,"
  855. "idToken text UNIQUE,"
  856. "type text,"
  857. "status text,"
  858. "cacheExpiryDateTime text,"
  859. "chargingPriority integer,"
  860. "language1 text,"
  861. "evseId text,"
  862. "language2 text,"
  863. "groupIdToken_idToken text,"
  864. "groupIdToken_type text,"
  865. "personalMessage text);";
  866. char *sqlOcppAuthLocal = "create table if not exists ocpp20_auth_local (idx integer primary key,"
  867. "idToken text UNIQUE,"
  868. "type text,"
  869. "status text,"
  870. "cacheExpiryDateTime text,"
  871. "chargingPriority integer,"
  872. "language1 text,"
  873. "evseId text,"
  874. "language2 text,"
  875. "groupIdToken_idToken text,"
  876. "groupIdToken_type text,"
  877. "personalMessage text,"
  878. "version text);";
  879. char *sqlOcppVariable = "create table if not exists ocpp20_variable (idx integer primary key,"
  880. "componentName text NOT NULL ,"
  881. "componentInstance text, "
  882. "variableName text NOT NULL, "
  883. "variableInstance text, "
  884. "variableCharacteristicsDataType integer, "
  885. "variableCharacteristicsUnit text, "
  886. "variableCharacteristicsMaxLimit real,"
  887. "variableAttributesType text, "
  888. "variableAttributesTypeMutability text, "
  889. "variableAttributesTypeValue text, "
  890. "unique(componentName, componentInstance,variableName, variableInstance) on conflict replace);";
  891. char *sqlBootType = "create table if not exists ocpp20_boot_type (idx integer primary key,"
  892. "type text);";
  893. char *sqlNetworkProfile = "create table if not exists ocpp20_networkprofile (idx integer primary key,"
  894. "slot integer UNIQUE, connectionData text);";
  895. char *sqlTransaction = "create table if not exists ocpp20_transaction_record (idx integer primary key,"
  896. "occurDatetime text,"
  897. "message_type text,"
  898. "message_content text)";
  899. //sqlite3_config(SQLITE_CONFIG_URI, 1);
  900. if(sqlite3_open(OCPP_LOCAL_DB_FILE, &db))
  901. {
  902. result = FAIL;
  903. DEBUG_ERROR( "Can't open database: %s\n", sqlite3_errmsg(db));
  904. sqlite3_close(db);
  905. }
  906. else
  907. {
  908. DEBUG_INFO( "OCPP local database open successfully.\n");
  909. if (sqlite3_exec(db, sqlOcppAuthCache, 0, 0, &errMsg) != SQLITE_OK)
  910. {
  911. result = FAIL;
  912. DEBUG_ERROR( "Create OCPP 2.0 auth cache table error message: %s\n", errMsg);
  913. }
  914. else
  915. {
  916. DEBUG_INFO( "Create OCPP 2.0 auth cache table table successfully\n");
  917. }
  918. if (sqlite3_exec(db, sqlOcppAuthLocal, 0, 0, &errMsg) != SQLITE_OK)
  919. {
  920. result = FAIL;
  921. DEBUG_ERROR( "Create OCPP 2.0 auth list table error message: %s\n", errMsg);
  922. }
  923. else
  924. {
  925. DEBUG_INFO( "Create OCPP 2.0 auth list table successfully\n");
  926. }
  927. if (sqlite3_exec(db, sqlOcppVariable, 0, 0, &errMsg) != SQLITE_OK)
  928. {
  929. result = FAIL;
  930. DEBUG_ERROR( "Create OCPP 2.0 variable table error message: %s\n", errMsg);
  931. }
  932. else
  933. {
  934. DEBUG_INFO( "Create OCPP 2.0 variable table successfully\n");
  935. }
  936. if (sqlite3_exec(db, sqlBootType, 0, 0, &errMsg) != SQLITE_OK)
  937. {
  938. result = FAIL;
  939. DEBUG_ERROR( "Create OCPP 2.0 boot_type table error message: %s\n", errMsg);
  940. }
  941. else
  942. {
  943. DEBUG_INFO( "Create OCPP 2.0 boot_type table successfully\n");
  944. }
  945. if (sqlite3_exec(db, sqlNetworkProfile, 0, 0, &errMsg) != SQLITE_OK)
  946. {
  947. result = FAIL;
  948. DEBUG_ERROR( "Create OCPP 2.0 ocpp20_networkprofile table error message: %s\n", errMsg);
  949. }
  950. else
  951. {
  952. DEBUG_INFO( "Create OCPP 2.0 ocpp20_networkprofile table successfully\n");
  953. }
  954. if (sqlite3_exec(db, sqlTransaction, 0, 0, &errMsg) != SQLITE_OK)
  955. {
  956. result = FAIL;
  957. DEBUG_ERROR( "Create OCPP 2.0 ocpp20_transaction_record table error message: %s\n", errMsg);
  958. }
  959. else
  960. {
  961. DEBUG_INFO( "Create OCPP 2.0 ocpp20_transaction_record table successfully\n");
  962. }
  963. //sqlite3_close(db);
  964. }
  965. return result;
  966. }
  967. int DB_cbGetVersion(void *para, int columnCount, char **columnValue, char **columnName)
  968. {
  969. localversion = columnValue[12] ? atoi(columnValue[12]) : 0;
  970. return 0;
  971. }
  972. void DB_getListVerion()
  973. {
  974. char sql[256];
  975. char* errMsg = NULL;
  976. strcpy(sql, "select * from ocpp20_auth_local order by version desc, idx desc limit 1");
  977. /* Execute SQL statement */
  978. if( sqlite3_exec(db, sql, DB_cbGetVersion, 0, &errMsg) != SQLITE_OK )
  979. {
  980. DEBUG_INFO("SQL error: %s", errMsg);
  981. }
  982. }
  983. int DB_cbGetIdTag(void *para, int columnCount, char **columnValue, char **columnName)
  984. {
  985. sprintf((char*)idTagQuery.idToken.idToken,"%s", columnValue[1] ? columnValue[1] : "NULL");
  986. sprintf((char*)idTagQuery.idToken.type,"%s", columnValue[2] ? columnValue[2] : "NULL");
  987. sprintf((char*)idTagQuery.idTokenInfo.status,"%s", columnValue[3] ? columnValue[3] : "NULL");
  988. sprintf((char*)idTagQuery.idTokenInfo.cacheExpiryDateTime,"%s", columnValue[4] ? columnValue[4] : "NULL");
  989. idTagQuery.idTokenInfo.chargingPriority = columnValue[5] ? atoi(columnValue[5]) : -1;
  990. sprintf((char*)idTagQuery.idTokenInfo.language1,"%s", columnValue[6] ? columnValue[6] : "NULL");
  991. sprintf((char*)idTagQuery.idTokenInfo.language2,"%s", columnValue[8] ? columnValue[8] : "NULL");
  992. sprintf((char*)idTagQuery.idTokenInfo.groupIdToken.idToken,"%s", columnValue[9] ? columnValue[9] : "NULL");
  993. sprintf((char*)idTagQuery.idTokenInfo.groupIdToken.type,"%s", columnValue[10] ? columnValue[10] : "NULL");
  994. return 0;
  995. }
  996. void DB_getIdTag(char idTag[], uint8_t isQueryFromCache)
  997. {
  998. char sql[256];
  999. char* errMsg = NULL;
  1000. memset(&idTagQuery, 0, sizeof(idTagQuery));
  1001. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  1002. if(isQueryFromCache)
  1003. sprintf(sql,"select * from ocpp20_auth_cache where idToken='%s'", idTag);
  1004. else
  1005. sprintf(sql,"select * from ocpp20_auth_local where idToken='%s'", idTag);
  1006. /* Execute SQL statement */
  1007. if(sqlite3_exec(db, sql, DB_cbGetIdTag, 0, &errMsg) != SQLITE_OK )
  1008. {
  1009. DEBUG_INFO("SQL error: %s", errMsg);
  1010. }
  1011. }
  1012. int DB_cbTableAuthlocalAllData(void *para, int columnCount, char **columnValue, char **columnName)
  1013. {
  1014. for (int i = 0; i < columnCount; i++)
  1015. {
  1016. DEBUG_INFO("%s = %s, ", columnName[i], columnValue[i]);
  1017. }
  1018. return 0;
  1019. }
  1020. void DB_get_TableAuthlocalAllData(void)
  1021. {
  1022. char sql[256];
  1023. char* errMsg = NULL;
  1024. sprintf(sql,"select * from ocpp20_auth_local;");
  1025. /* Execute SQL statement */
  1026. if(sqlite3_exec(db, sql, DB_cbTableAuthlocalAllData, 0,&errMsg) != SQLITE_OK)
  1027. {
  1028. DEBUG_INFO("SQL error: %s", errMsg);
  1029. }
  1030. }
  1031. int DB_cbAddLocalListCache(void *para, int columnCount, char **columnValue, char **columnName)
  1032. {
  1033. for(int i = 0; i<columnCount; i++)
  1034. {
  1035. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1036. }
  1037. return 0;
  1038. }
  1039. int DB_addLocalList(int listVersion, struct AuthorizationData *data)
  1040. {
  1041. int result = PASS;
  1042. char sql[512];
  1043. char* errMsg = NULL;
  1044. 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;",
  1045. data->idToken.idToken,
  1046. data->idToken.type,
  1047. data->idTokenInfo.status,
  1048. data->idTokenInfo.cacheExpiryDateTime,
  1049. data->idTokenInfo.chargingPriority,
  1050. data->idTokenInfo.language1,
  1051. data->idTokenInfo.language2,
  1052. data->idTokenInfo.groupIdToken.idToken,
  1053. data->idTokenInfo.groupIdToken.type,
  1054. listVersion);
  1055. //* Execute SQL statement */
  1056. if(sqlite3_exec(db, sql, DB_cbAddLocalListCache, 0, &errMsg) != SQLITE_OK)
  1057. {
  1058. DEBUG_INFO("SQL error: %s\n", errMsg);
  1059. result = FAIL;
  1060. }
  1061. else
  1062. {
  1063. memset(sql, 0, ARRAY_SIZE(sql));
  1064. sprintf(sql, "UPDATE ocpp20_auth_local SET version=%d",listVersion);
  1065. if( sqlite3_exec(db, sql, NULL, NULL, &errMsg) != SQLITE_OK )
  1066. {
  1067. DEBUG_INFO("SQL error: %s\n", errMsg);
  1068. result = FAIL;
  1069. }
  1070. }
  1071. return result;
  1072. }
  1073. int DB_addLocalCache(struct IdTokenType *idToken, struct IdTokenInfoType *idTokenInfo)
  1074. {
  1075. int result = PASS;
  1076. char sql[512];
  1077. char* errMsg = NULL;
  1078. 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;",
  1079. idToken->idToken,
  1080. idToken->type,
  1081. idTokenInfo->status,
  1082. idTokenInfo->cacheExpiryDateTime,
  1083. idTokenInfo->chargingPriority,
  1084. idTokenInfo->language1,
  1085. idTokenInfo->language2,
  1086. idTokenInfo->groupIdToken.idToken,
  1087. idTokenInfo->groupIdToken.type);
  1088. //* Execute SQL statement */
  1089. if(sqlite3_exec(db, sql, DB_cbAddLocalListCache, 0, &errMsg) != SQLITE_OK)
  1090. {
  1091. DEBUG_INFO("SQL error: %s\n", errMsg);
  1092. result = FAIL;
  1093. }
  1094. return result;
  1095. }
  1096. int deleteIdTagcallback(void *para, int columnCount, char **columnValue, char **columnName)
  1097. {
  1098. // localversion = argv[5] ? atoi(columnValue[5]) : 0;
  1099. // printf("localversion=%d\n", localversion);
  1100. return 0;
  1101. }
  1102. void DB_deleteIdTag(char idTag[])
  1103. {
  1104. char sql[512];
  1105. char* errMsg = NULL;
  1106. sprintf(sql,"DELETE from ocpp20_auth_local where idToken='%s'; SELECT * from ocpp20_auth_local;", idTag);
  1107. //* Execute SQL statement */
  1108. if( sqlite3_exec(db, sql, deleteIdTagcallback, 0, &errMsg) != SQLITE_OK )
  1109. {
  1110. DEBUG_INFO("SQL error: %s", errMsg);
  1111. }
  1112. }
  1113. int DB_cleanLocalList()
  1114. {
  1115. int result = PASS;
  1116. char * sqlcleanLocalList = "delete from ocpp20_auth_cache";
  1117. char *errMsg = 0;
  1118. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1119. {
  1120. DEBUG_INFO("%s\n", errMsg);
  1121. result = FAIL;
  1122. }
  1123. return result;
  1124. }
  1125. int DB_cleanLocalCache()
  1126. {
  1127. int result = PASS;
  1128. char * sqlcleanLocalList = "delete from ocpp20_auth_local";
  1129. char *errMsg = 0;
  1130. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1131. {
  1132. DEBUG_INFO("%s\n", errMsg);
  1133. result = FAIL;
  1134. }
  1135. return result;
  1136. }
  1137. int BootTypecallback(void *para, int columnCount, char **columnValue, char **columnName)
  1138. {
  1139. sprintf((char*)ShmOCPP20Data->BootNotification.reason,"%s", columnValue[1] ? columnValue[1] : BootReasonEnumTypeStr[BootReasonEnumType_PowerUp]);
  1140. return 0;
  1141. }
  1142. void DB_getBooType()
  1143. {
  1144. char sql[256];
  1145. char* errMsg = NULL;
  1146. sprintf(sql,"select * from ocpp20_boot_type;");
  1147. /* Execute SQL statement */
  1148. if(sqlite3_exec(db, sql, BootTypecallback, 0, &errMsg) != SQLITE_OK )
  1149. {
  1150. DEBUG_INFO("SQL error: %s\n", errMsg);
  1151. }
  1152. }
  1153. int DB_cbUpdateBootType(void *para, int columnCount, char **columnValue, char **columnName)
  1154. {
  1155. for(int i = 0; i<columnCount; i++)
  1156. {
  1157. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1158. }
  1159. return 0;
  1160. }
  1161. int DB_updateBootType(BootReasonEnumType reason)
  1162. {
  1163. int result = PASS;
  1164. char sql[512];
  1165. char* errMsg = NULL;
  1166. sprintf(sql,"insert or replace into ocpp20_boot_type (idx, type) VALUES(1, '%s');", BootReasonEnumTypeStr[reason>BootReasonEnumType_Watchdog?BootReasonEnumType_PowerUp:reason]);
  1167. //* Execute SQL statement */
  1168. if(sqlite3_exec(db, sql, DB_cbUpdateBootType, 0, &errMsg) != SQLITE_OK)
  1169. {
  1170. DEBUG_INFO("SQL error: %s\n", errMsg);
  1171. result = FAIL;
  1172. }
  1173. return result;
  1174. }
  1175. int DB_cbVariableSaveToDb(void *para, int columnCount, char **columnValue, char **columnName)
  1176. {
  1177. for(int i = 0; i<columnCount; i++)
  1178. {
  1179. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1180. }
  1181. return 0;
  1182. }
  1183. int DB_variableSaveToDb(struct ReportDataType *variable)
  1184. {
  1185. int result = FAIL;
  1186. char sql[4096];
  1187. char* errMsg = NULL;
  1188. sprintf(sql,"insert or replace into ocpp20_variable (componentName, componentInstance, variableName, variableInstance, variableCharacteristicsDataType, variableCharacteristicsUnit, variableCharacteristicsMaxLimit, variableAttributesType, variableAttributesTypeMutability, variableAttributesTypeValue) VALUES('%s', '%s', '%s', '%s', '%s', '%s', %f, '%s', '%s', '%s'); SELECT * from ocpp20_variable;",
  1189. variable->component.name,
  1190. variable->component.instance,
  1191. variable->variable.name,
  1192. variable->variable.instance,
  1193. variable->variableCharacteristics.dataType,
  1194. variable->variableCharacteristics.unit,
  1195. variable->variableCharacteristics.maxLimit,
  1196. variable->variableAttribute[0].type,
  1197. variable->variableAttribute[0].mutability,
  1198. variable->variableAttribute[0].value);
  1199. //* Execute SQL statement */
  1200. if(sqlite3_exec(db, sql, DB_cbVariableSaveToDb, 0, &errMsg) != SQLITE_OK)
  1201. {
  1202. DEBUG_INFO("SQL error: %s\n", errMsg);
  1203. result = FAIL;
  1204. }
  1205. return result;
  1206. }
  1207. int DB_cbVariableIsCreate(void *para, int columnCount, char **columnValue, char **columnName)
  1208. {
  1209. memset(&ShmOCPP20Data->ControllerComponentVariable[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable));
  1210. if(atoi(columnValue[0]) == 0)
  1211. {
  1212. DB_updateBootType(BootReasonEnumType_PowerUp);
  1213. // Create variable table content
  1214. /* AlignedDataCtrlr Required item */
  1215. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].component.name, "AlignedDataCtrlr");
  1216. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variable.name, "Enabled");
  1217. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1218. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1219. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1220. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1221. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled]);
  1222. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].component.name, "AlignedDataCtrlr");
  1223. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variable.name, "Available");
  1224. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1225. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1226. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1227. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].value, "TRUE");
  1228. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available]);
  1229. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].component.name, "AlignedDataCtrlr");
  1230. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variable.name, "Measurands");
  1231. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1232. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableCharacteristics.maxLimit = 10;
  1233. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1234. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1235. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1236. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC");
  1237. else
  1238. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage");
  1239. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands]);
  1240. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].component.name, "AlignedDataCtrlr");
  1241. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variable.name, "Interval");
  1242. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.unit, "Seconds");
  1243. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1244. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.minLimit = 10;
  1245. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1246. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1247. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value, "0");
  1248. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval]);
  1249. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].component.name, "AlignedDataCtrlr");
  1250. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variable.name, "SendDuringIdle");
  1251. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1252. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1253. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1254. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].value, "TRUE");
  1255. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle]);
  1256. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].component.name, "AlignedDataCtrlr");
  1257. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variable.name, "SignReadings");
  1258. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1259. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1260. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1261. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].value, "FALSE");
  1262. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings]);
  1263. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].component.name, "AlignedDataCtrlr");
  1264. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  1265. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1266. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableCharacteristics.maxLimit = 10;
  1267. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1268. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1269. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1270. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC");
  1271. else
  1272. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage");
  1273. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands]);
  1274. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].component.name, "AlignedDataCtrlr");
  1275. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  1276. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableCharacteristics.unit, "Seconds");
  1277. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1278. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1279. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1280. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].value, "0");
  1281. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval]);
  1282. /* AuthCtrlrVariable Required item */
  1283. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].component.name, "AuthCtrlr");
  1284. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variable.name, "Enabled");
  1285. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1286. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1287. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1288. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1289. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled]);
  1290. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].component.name, "AlignedDataCtrlr");
  1291. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variable.name, "AdditionalInfoItemsPerMessage");
  1292. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1293. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1294. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1295. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].value, "0");
  1296. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage]);
  1297. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].component.name, "AuthCtrlr");
  1298. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variable.name, "OfflineTxForUnknownIdEnabled");
  1299. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1300. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1301. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1302. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].value, "FALSE");
  1303. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled]);
  1304. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].component.name, "AuthCtrlr");
  1305. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variable.name, "AuthorizeRemoteStart");
  1306. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1307. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1308. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1309. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].value, "FALSE");
  1310. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart]);
  1311. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].component.name, "AuthCtrlr");
  1312. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variable.name, "LocalAuthorizeOffline");
  1313. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1314. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1315. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1316. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "TRUE");
  1317. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline]);
  1318. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].component.name, "AuthCtrlr");
  1319. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variable.name, "LocalPreAuthorize");
  1320. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1321. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1322. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1323. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].value, "TRUE");
  1324. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize]);
  1325. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].component.name, "AuthCtrlr");
  1326. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variable.name, "MasterPassGroupId");
  1327. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1328. ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableCharacteristics.maxLimit = 36;
  1329. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1330. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1331. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].value, " ");
  1332. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId]);
  1333. /* AuthCacheCtrlr Variable Required item*/
  1334. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].component.name, "AuthCacheCtrlr");
  1335. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variable.name, "Enabled");
  1336. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1337. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1338. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1339. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1340. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled]);
  1341. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].component.name, "AuthCacheCtrlr");
  1342. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variable.name, "Available");
  1343. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1344. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1345. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1346. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].value, "TRUE");
  1347. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available]);
  1348. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].component.name, "AuthCacheCtrlr");
  1349. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variable.name, "LifeTime");
  1350. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableCharacteristics.unit, "Seconds");
  1351. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1352. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1353. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1354. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].value, "TRUE");
  1355. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime]);
  1356. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].component.name, "AuthCacheCtrlr");
  1357. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variable.name, "Storage");
  1358. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1359. ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableCharacteristics.maxLimit = (1024*10);
  1360. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1361. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1362. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].value, "TRUE");
  1363. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage]);
  1364. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].component.name, "AuthCacheCtrlr");
  1365. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variable.name, "Policy");
  1366. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1367. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1368. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1369. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].value, "LRU,LFU");
  1370. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy]);
  1371. /* ClockCtrlr Variable Required item */
  1372. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].component.name, "ClockCtrlr");
  1373. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variable.name, "DateTime");
  1374. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_dateTime]);
  1375. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1376. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1377. getNowDatetime(ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].value);
  1378. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime]);
  1379. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].component.name, "ClockCtrlr");
  1380. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variable.name, "NtpSource");
  1381. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1382. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1383. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1384. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].value, "DHCP, manual");
  1385. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource]);
  1386. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].component.name, "ClockCtrlr");
  1387. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.name, "NtpServerUri");
  1388. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.instance, "1");
  1389. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1390. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1391. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1392. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].value, " ");
  1393. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri]);
  1394. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].component.name, "ClockCtrlr");
  1395. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variable.name, "TimeOffset");
  1396. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1397. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1398. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1399. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].value, "+00:00");
  1400. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset]);
  1401. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].component.name, "ClockCtrlr");
  1402. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variable.name, "NextTimeOffsetTransitionDateTime");
  1403. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_dateTime]);
  1404. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1405. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1406. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].value, " ");
  1407. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime]);
  1408. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].component.name, "ClockCtrlr");
  1409. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.name, "TimeOffset");
  1410. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.instance, "NextTransition");
  1411. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1412. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1413. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1414. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].value, "+00:00");
  1415. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset]);
  1416. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].component.name, "ClockCtrlr");
  1417. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variable.name, "TimeSource");
  1418. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_SequenceList]);
  1419. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1420. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1421. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].value, "Heartbeat,RealTimeClock");
  1422. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource]);
  1423. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].component.name, "ClockCtrlr");
  1424. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variable.name, "TimeZone");
  1425. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1426. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1427. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1428. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].value, "UTC");
  1429. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone]);
  1430. /* ChargingStation Required item */
  1431. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].component.name, "ChargingStation");
  1432. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variable.name, "Available");
  1433. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1434. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1435. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1436. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].value, "FALSE");
  1437. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available]);
  1438. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].component.name, "ChargingStation");
  1439. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variable.name, "AvailabilityState");
  1440. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1441. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1442. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1443. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].value, "Available,Occupied,Reserved,Unavailable,Faulted");
  1444. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState]);
  1445. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].component.name, "ChargingStation");
  1446. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variable.name, "SupplyPhases");
  1447. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1448. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1449. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1450. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].value, "3");
  1451. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases]);
  1452. /* Connector Required item */
  1453. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].component.name, "Connector");
  1454. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variable.name, "Available");
  1455. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1456. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1457. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1458. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].value, "FALSE");
  1459. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_Available]);
  1460. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].component.name, "Connector");
  1461. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variable.name, "ConnectorType");
  1462. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1463. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1464. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1465. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].value, " ");
  1466. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType]);
  1467. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].component.name, "Connector");
  1468. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variable.name, "SupplyPhases");
  1469. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1470. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1471. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1472. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].value, "3");
  1473. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases]);
  1474. /* CustomizationCtrlr Required item */
  1475. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].component.name, "CustomizationCtrlr");
  1476. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variable.name, "CustomImplementationEnabled");
  1477. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1478. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1479. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1480. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].value, "FALSE");
  1481. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled]);
  1482. /* DeviceDataCtrlr Required item */
  1483. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  1484. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.instance, "GetReport");
  1485. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1486. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1487. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1488. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1489. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].value, "10");
  1490. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage]);
  1491. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  1492. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.instance, "GetVariables");
  1493. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1494. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1495. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1496. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1497. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].value, "10");
  1498. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage]);
  1499. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].component.name, "DeviceDataCtrlr");
  1500. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.instance, "GetReport");
  1501. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.name, "BytesPerMessage");
  1502. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1503. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1504. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1505. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].value, "2048");
  1506. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage]);
  1507. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  1508. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.instance, "GetVariables");
  1509. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  1510. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1511. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1512. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1513. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].value, "2048");
  1514. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage]);
  1515. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].component.name, "DeviceDataCtrlr");
  1516. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variable.name, "ConfigurationValueSize");
  1517. ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableCharacteristics.maxLimit = 1000;
  1518. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1519. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1520. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1521. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].value, "10");
  1522. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize]);
  1523. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].component.name, "DeviceDataCtrlr");
  1524. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variable.name, "ReportingValueSize");
  1525. ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableCharacteristics.maxLimit = 2500;
  1526. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1527. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1528. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1529. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].value, "10");
  1530. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize]);
  1531. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  1532. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.instance, "SetVariables");
  1533. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1534. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1535. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1536. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1537. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].value, "10");
  1538. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage]);
  1539. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  1540. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.instance, "SetVariables");
  1541. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  1542. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1543. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1544. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1545. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].value, "2048");
  1546. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage]);
  1547. /* DisplayMessageCtrlr Required item */
  1548. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].component.name, "DisplayMessageCtrlr");
  1549. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variable.name, "Enabled");
  1550. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1551. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1552. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1553. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1554. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled]);
  1555. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].component.name, "DisplayMessageCtrlr");
  1556. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variable.name, "Available");
  1557. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1558. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1559. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1560. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].value, "FALSE");
  1561. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available]);
  1562. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].component.name, "DisplayMessageCtrlr");
  1563. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variable.name, "DisplayMessages");
  1564. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1565. ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableCharacteristics.maxLimit = 1;
  1566. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1567. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1568. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].value, "%s", "1");
  1569. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages]);
  1570. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].component.name, "DisplayMessageCtrlr");
  1571. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variable.name, "SupportedFormats");
  1572. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1573. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1574. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1575. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].value, " ");
  1576. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats]);
  1577. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].component.name, "DisplayMessageCtrlr");
  1578. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variable.name, "SupportedPriorities");
  1579. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1580. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1581. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1582. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].value, " ");
  1583. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities]);
  1584. /* EVSE Required item */
  1585. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].component.name, "EVSE");
  1586. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variable.name, "Available");
  1587. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1588. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1589. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1590. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].value, "FALSE");
  1591. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_Available]);
  1592. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].component.name, "EVSE");
  1593. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variable.name, "AvailabilityState");
  1594. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1595. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1596. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1597. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].value, "Available,Occupied,Reserved,Unavailable,Faulted");
  1598. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState]);
  1599. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].component.name, "EVSE");
  1600. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variable.name, "SupplyPhases");
  1601. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1602. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1603. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1604. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].value, "3");
  1605. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases]);
  1606. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].component.name, "EVSE");
  1607. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variable.name, "Power");
  1608. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_decimal]);
  1609. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1610. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1611. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].value, "7700");
  1612. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_Power]);
  1613. /* LocalAuthListCtrlr Required item */
  1614. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].component.name, "LocalAuthListCtrlr");
  1615. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variable.name, "Enabled");
  1616. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1617. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1618. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1619. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  1620. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled]);
  1621. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].component.name, "LocalAuthListCtrlr");
  1622. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variable.name, "Entries");
  1623. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1624. ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableCharacteristics.maxLimit = 5000;
  1625. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1626. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1627. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].value, "5000");
  1628. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries]);
  1629. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].component.name, "LocalAuthListCtrlr");
  1630. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variable.name, "Available");
  1631. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1632. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1633. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1634. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].value, "TRUE");
  1635. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available]);
  1636. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].component.name, "LocalAuthListCtrlr");
  1637. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1638. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.instance, "SendLocalList");
  1639. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1640. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1641. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1642. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].value, "50");
  1643. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage]);
  1644. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].component.name, "LocalAuthListCtrlr");
  1645. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.name, "BytesPerMessage");
  1646. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.instance, "SendLocalList");
  1647. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1648. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1649. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1650. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].value, "2048");
  1651. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage]);
  1652. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].component.name, "LocalAuthListCtrlr");
  1653. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variable.name, "Storage");
  1654. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1655. ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableCharacteristics.maxLimit = (1024*10);
  1656. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1657. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1658. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].value, "5000");
  1659. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage]);
  1660. /* MonitoringCtrlr Required item */
  1661. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].component.name, "MonitoringCtrlr");
  1662. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variable.instance, "Enabled");
  1663. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1664. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1665. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1666. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1667. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled]);
  1668. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].component.name, "MonitoringCtrlr");
  1669. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variable.instance, "Available");
  1670. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1671. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1672. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1673. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].value, "FALSE");
  1674. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available]);
  1675. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  1676. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.instance, "ClearVariableMonitoring");
  1677. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1678. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1679. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1680. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1681. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].value, "1");
  1682. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage]);
  1683. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  1684. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.instance, "SetVariableMonitoring");
  1685. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1686. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1687. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1688. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1689. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].value, "1");
  1690. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage]);
  1691. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  1692. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.instance, "ClearVariableMonitoring");
  1693. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  1694. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1695. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1696. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1697. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].value, "2048");
  1698. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage]);
  1699. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  1700. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.instance, "SetVariableMonitoring");
  1701. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  1702. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1703. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1704. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1705. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].value, "2048");
  1706. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage]);
  1707. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].component.name, "MonitoringCtrlr");
  1708. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variable.name, "OfflineQueuingSeverity");
  1709. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1710. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1711. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1712. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].value, "2048");
  1713. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity]);
  1714. /* OCPPCommCtrlr Required item */
  1715. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].component.name, "OCPPCommCtrlr");
  1716. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variable.name, "ActiveNetworkProfile");
  1717. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1718. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1719. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1720. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].value, "1");
  1721. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile]);
  1722. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].component.name, "OCPPCommCtrlr");
  1723. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.instance, "Default");
  1724. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.name, "MessageTimeout");
  1725. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableCharacteristics.unit, "Seconds");
  1726. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1727. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1728. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1729. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].value, "30");
  1730. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout]);
  1731. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].component.name, "OCPPCommCtrlr");
  1732. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variable.name, "FileTransferProtocols");
  1733. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1734. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1735. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1736. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].value, "FTP,FTPS,HTTP,HTTPS");
  1737. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols]);
  1738. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].component.name, "OCPPCommCtrlr");
  1739. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variable.name, "HeartbeatInterval");
  1740. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.unit, "Seconds");
  1741. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1742. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1743. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1744. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value, "30");
  1745. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval]);
  1746. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].component.name, "OCPPCommCtrlr");
  1747. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variable.name, "NetworkConfigurationPriority");
  1748. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_SequenceList]);
  1749. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1750. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1751. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value, "[0]");
  1752. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority]);
  1753. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].component.name, "OCPPCommCtrlr");
  1754. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variable.name, "NetworkProfileConnectionAttempts");
  1755. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1756. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1757. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1758. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].value, "3");
  1759. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts]);
  1760. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].component.name, "OCPPCommCtrlr");
  1761. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variable.name, "OfflineThreshold");
  1762. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableCharacteristics.unit, "Seconds");
  1763. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1764. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1765. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1766. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].value, "30");
  1767. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold]);
  1768. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].component.name, "OCPPCommCtrlr");
  1769. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variable.name, "QueueAllMessages");
  1770. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1771. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1772. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1773. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].value, "FALSE");
  1774. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages]);
  1775. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].component.name, "OCPPCommCtrlr");
  1776. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.instance, "TransactionEvent");
  1777. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.name, "MessageAttempts");
  1778. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableCharacteristics.unit, "Seconds");
  1779. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1780. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1781. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1782. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].value, "3");
  1783. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts]);
  1784. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].component.name, "OCPPCommCtrlr");
  1785. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.instance, "TransactionEvent");
  1786. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.name, "MessageAttemptInterval");
  1787. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableCharacteristics.unit, "Seconds");
  1788. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1789. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1790. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1791. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].value, "3");
  1792. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval]);
  1793. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].component.name, "OCPPCommCtrlr");
  1794. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variable.name, "UnlockOnEVSideDisconnect");
  1795. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1796. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1797. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1798. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].value, "TRUE");
  1799. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect]);
  1800. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].component.name, "OCPPCommCtrlr");
  1801. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variable.name, "WebSocketPingInterval");
  1802. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.unit, "Seconds");
  1803. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1804. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1805. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1806. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].value, "30");
  1807. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval]);
  1808. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].component.name, "OCPPCommCtrlr");
  1809. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variable.name, "ResetRetries");
  1810. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1811. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1812. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1813. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].value, "3");
  1814. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries]);
  1815. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].component.name, "OCPPCommCtrlr");
  1816. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variable.name, "PublicKeyWithSignedMeterValue");
  1817. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1818. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1819. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1820. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].value, "Never,OncePerTransaction,EveryMeterValue");
  1821. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue]);
  1822. /* ReservationCtrlr Required item */
  1823. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].component.name, "ReservationCtrlr");
  1824. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variable.name, "Enabled");
  1825. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1826. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1827. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1828. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  1829. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled]);
  1830. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].component.name, "ReservationCtrlr");
  1831. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variable.name, "Available");
  1832. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1833. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1834. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1835. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].value, "TRUE");
  1836. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available]);
  1837. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].component.name, "ReservationCtrlr");
  1838. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variable.name, "NonEvseSpecific");
  1839. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1840. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1841. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1842. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].value, "FALSE");
  1843. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific]);
  1844. /* SampledDataCtrlr Required item */
  1845. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].component.name, "SampledDataCtrlr");
  1846. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variable.name, "Enabled");
  1847. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1848. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1849. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1850. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  1851. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled]);
  1852. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].component.name, "SampledDataCtrlr");
  1853. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variable.name, "Available");
  1854. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1855. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1856. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1857. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].value, "TRUE");
  1858. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available]);
  1859. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].component.name, "SampledDataCtrlr");
  1860. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variable.name, "SignReadings");
  1861. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1862. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1863. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1864. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].value, "FALSE");
  1865. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings]);
  1866. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].component.name, "SampledDataCtrlr");
  1867. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  1868. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1869. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableCharacteristics.maxLimit = 10;
  1870. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1871. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1872. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1873. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC");
  1874. else
  1875. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage");
  1876. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands]);
  1877. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].component.name, "SampledDataCtrlr");
  1878. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  1879. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableCharacteristics.unit, "Seconds");
  1880. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1881. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1882. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1883. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].value, "0");
  1884. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval]);
  1885. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].component.name, "SampledDataCtrlr");
  1886. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variable.name, "TxStartedMeasurands");
  1887. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1888. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableCharacteristics.maxLimit = 10;
  1889. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1890. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1891. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].value, " ");
  1892. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands]);
  1893. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].component.name, "SampledDataCtrlr");
  1894. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variable.name, "TxUpdatedMeasurands");
  1895. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1896. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableCharacteristics.maxLimit = 10;
  1897. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1898. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1899. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1900. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC");
  1901. else
  1902. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage");
  1903. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands]);
  1904. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].component.name, "SampledDataCtrlr");
  1905. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variable.name, "TxUpdatedInterval");
  1906. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.unit, "Seconds");
  1907. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1908. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.minLimit = 10;
  1909. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1910. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1911. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value, "30");
  1912. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval]);
  1913. /* SecurityCtrlr Required item */
  1914. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].component.name, "SecurityCtrlr");
  1915. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variable.name, "BasicAuthPassword");
  1916. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1917. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableCharacteristics.maxLimit = 40;
  1918. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1919. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_WriteOnly]);
  1920. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].value, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  1921. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword]);
  1922. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].component.name, "SecurityCtrlr");
  1923. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variable.name, "Identity");
  1924. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1925. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableCharacteristics.maxLimit = 48;
  1926. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1927. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1928. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].value, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  1929. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity]);
  1930. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].component.name, "SecurityCtrlr");
  1931. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variable.name, "OrganizationName");
  1932. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1933. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1934. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1935. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].value, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1936. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName]);
  1937. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].component.name, "SecurityCtrlr");
  1938. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variable.name, "CertificateEntries");
  1939. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1940. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableCharacteristics.maxLimit = 1;
  1941. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1942. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1943. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].value, "1");
  1944. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries]);
  1945. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].component.name, "SecurityCtrlr");
  1946. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variable.name, "SecurityProfile");
  1947. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1948. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1949. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1950. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].value, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  1951. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile]);
  1952. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].component.name, "SecurityCtrlr");
  1953. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variable.name, "AdditionalRootCertificateCheck");
  1954. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1955. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1956. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1957. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].value, "FALSE");
  1958. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck]);
  1959. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].component.name, "SecurityCtrlr");
  1960. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variable.name, "MaxCertificateChainSize");
  1961. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1962. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableCharacteristics.maxLimit = 10000;
  1963. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1964. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1965. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].value, "10000");
  1966. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize]);
  1967. /* SmartChargingCtrlr Required item */
  1968. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].component.name, "SmartChargingCtrlr");
  1969. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variable.name, "Enabled");
  1970. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1971. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1972. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1973. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  1974. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled]);
  1975. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].component.name, "SmartChargingCtrlr");
  1976. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variable.name, "Available");
  1977. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1978. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1979. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1980. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].value, "TRUE");
  1981. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available]);
  1982. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].component.name, "SmartChargingCtrlr");
  1983. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variable.name, "ACPhaseSwitchingSupported");
  1984. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1985. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1986. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1987. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].value, "FALSE");
  1988. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported]);
  1989. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].component.name, "SmartChargingCtrlr");
  1990. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variable.name, "ProfileStackLevel");
  1991. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1992. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1993. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1994. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value, "0");
  1995. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel]);
  1996. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].component.name, "SmartChargingCtrlr");
  1997. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variable.name, "RateUnit");
  1998. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1999. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2000. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2001. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].value, "A,W");
  2002. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit]);
  2003. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].component.name, "SmartChargingCtrlr");
  2004. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variable.name, "PeriodsPerSchedule");
  2005. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2006. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2007. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2008. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].value, "10");
  2009. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule]);
  2010. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].component.name, "SmartChargingCtrlr");
  2011. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variable.name, "ExternalControlSignalsEnabled");
  2012. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2013. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2014. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2015. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].value, "FALSE");
  2016. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled]);
  2017. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].component.name, "SmartChargingCtrlr");
  2018. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variable.name, "NotifyChargingLimitWithSchedules");
  2019. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2020. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2021. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2022. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].value, "FALSE");
  2023. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules]);
  2024. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].component.name, "SmartChargingCtrlr");
  2025. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variable.name, "Phases3to1");
  2026. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2027. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2028. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2029. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].value, "FALSE");
  2030. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1]);
  2031. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].component.name, "SmartChargingCtrlr");
  2032. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variable.name, "Entries");
  2033. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2034. ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableCharacteristics.maxLimit = 10;
  2035. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2036. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2037. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value, "10");
  2038. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries]);
  2039. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].component.name, "SmartChargingCtrlr");
  2040. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variable.name, "LimitChangeSignificance");
  2041. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_decimal]);
  2042. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2043. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2044. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].value, "1");
  2045. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance]);
  2046. /* TariffCostCtrlr Required item */
  2047. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].component.name, "TariffCostCtrlr");
  2048. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.instance, "Tariff");
  2049. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.name, "Enabled");
  2050. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2051. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2052. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2053. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].value, "FALSE");
  2054. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled]);
  2055. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].component.name, "TariffCostCtrlr");
  2056. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.instance, "Tariff");
  2057. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.name, "Available");
  2058. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2059. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2060. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2061. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].value, "FALSE");
  2062. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_Available]);
  2063. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].component.name, "TariffCostCtrlr");
  2064. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variable.name, "TariffFallbackMessage");
  2065. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2066. ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableCharacteristics.maxLimit = 255;
  2067. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2068. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2069. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].value, " ");
  2070. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage]);
  2071. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].component.name, "TariffCostCtrlr");
  2072. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.instance, "Cost");
  2073. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.name, "Enabled");
  2074. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2075. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2076. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2077. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].value, "FALSE");
  2078. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled]);
  2079. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].component.name, "TariffCostCtrlr");
  2080. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.instance, "Cost");
  2081. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.name, "Available");
  2082. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2083. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2084. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2085. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].value, "FALSE");
  2086. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Available]);
  2087. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].component.name, "TariffCostCtrlr");
  2088. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variable.name, "TotalCostFallbackMessage");
  2089. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2090. ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableCharacteristics.maxLimit = 255;
  2091. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2092. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2093. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].value, " ");
  2094. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage]);
  2095. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].component.name, "TariffCostCtrlr");
  2096. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variable.name, "Currency");
  2097. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2098. ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableCharacteristics.maxLimit = 3;
  2099. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2100. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2101. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].value, "NTD");
  2102. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Currency]);
  2103. /* TxCtrlr Required item */
  2104. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2105. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variable.name, "ChargingBeforeAcceptedEnabled");
  2106. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2107. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2108. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2109. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].value, "FALSE");
  2110. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled]);
  2111. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].component.name, "TxCtrlr");
  2112. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variable.name, "EVConnectionTimeOut");
  2113. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableCharacteristics.unit, "Seconds");
  2114. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2115. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2116. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2117. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value, "180");
  2118. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut]);
  2119. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].component.name, "TxCtrlr");
  2120. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variable.name, "StopTxOnEVSideDisconnect");
  2121. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2122. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2123. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2124. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].value, "TRUE");
  2125. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect]);
  2126. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2127. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variable.name, "TxBeforeAcceptedEnabled");
  2128. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2129. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2130. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2131. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].value, "FALSE");
  2132. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled]);
  2133. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].component.name, "TxCtrlr");
  2134. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variable.name, "TxStartPoint");
  2135. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2136. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2137. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2138. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].value, "PowerPathClosed");
  2139. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint]);
  2140. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].component.name, "TxCtrlr");
  2141. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variable.name, "TxStopPoint");
  2142. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2143. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2144. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2145. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].value, "PowerPathClosed");
  2146. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint]);
  2147. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].component.name, "TxCtrlr");
  2148. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variable.name, "MaxEnergyOnInvalidId");
  2149. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2150. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableCharacteristics.unit, "Wh");
  2151. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2152. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2153. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].value, "0");
  2154. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId]);
  2155. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].component.name, "TxCtrlr");
  2156. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variable.name, "StopTxOnInvalidId");
  2157. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2158. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2159. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2160. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].value, "FALSE");
  2161. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId]);
  2162. }
  2163. else
  2164. {
  2165. // Variable name init
  2166. /* AlignedDataCtrlr Required item */
  2167. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].component.name, "AlignedDataCtrlr");
  2168. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variable.name, "Enabled");
  2169. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].component.name, "AlignedDataCtrlr");
  2170. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variable.name, "Available");
  2171. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].component.name, "AlignedDataCtrlr");
  2172. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variable.name, "Measurands");
  2173. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].component.name, "AlignedDataCtrlr");
  2174. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variable.name, "Interval");
  2175. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].component.name, "AlignedDataCtrlr");
  2176. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variable.name, "SendDuringIdle");
  2177. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].component.name, "AlignedDataCtrlr");
  2178. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variable.name, "SignReadings");
  2179. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].component.name, "AlignedDataCtrlr");
  2180. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2181. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].component.name, "AlignedDataCtrlr");
  2182. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2183. /* AuthCtrlrVariable Required item */
  2184. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].component.name, "AuthCtrlr");
  2185. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variable.name, "Enabled");
  2186. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].component.name, "AlignedDataCtrlr");
  2187. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variable.name, "AdditionalInfoItemsPerMessage");
  2188. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].component.name, "AuthCtrlr");
  2189. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variable.name, "OfflineTxForUnknownIdEnabled");
  2190. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].component.name, "AuthCtrlr");
  2191. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variable.name, "AuthorizeRemoteStart");
  2192. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].component.name, "AuthCtrlr");
  2193. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variable.name, "LocalAuthorizeOffline");
  2194. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].component.name, "AuthCtrlr");
  2195. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variable.name, "LocalPreAuthorize");
  2196. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].component.name, "AuthCtrlr");
  2197. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variable.name, "MasterPassGroupId");
  2198. /* AuthCacheCtrlr Variable Required item */
  2199. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].component.name, "AuthCacheCtrlr");
  2200. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variable.name, "Enabled");
  2201. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].component.name, "AuthCacheCtrlr");
  2202. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variable.name, "Available");
  2203. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].component.name, "AuthCacheCtrlr");
  2204. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variable.name, "LifeTime");
  2205. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].component.name, "AuthCacheCtrlr");
  2206. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variable.name, "Storage");
  2207. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].component.name, "AuthCacheCtrlr");
  2208. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variable.name, "Policy");
  2209. /* ClockCtrlr Variable Required item */
  2210. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].component.name, "ClockCtrlr");
  2211. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variable.name, "DateTime");
  2212. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].component.name, "ClockCtrlr");
  2213. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variable.name, "NtpSource");
  2214. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].component.name, "ClockCtrlr");
  2215. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.name, "NtpServerUri");
  2216. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.instance, "1");
  2217. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].component.name, "ClockCtrlr");
  2218. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variable.name, "TimeOffset");
  2219. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].component.name, "ClockCtrlr");
  2220. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variable.name, "NextTimeOffsetTransitionDateTime");
  2221. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].component.name, "ClockCtrlr");
  2222. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.name, "TimeOffset");
  2223. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.instance, "NextTransition");
  2224. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].component.name, "ClockCtrlr");
  2225. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variable.name, "TimeSource");
  2226. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].component.name, "ClockCtrlr");
  2227. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variable.name, "TimeZone");
  2228. /* ChargingStation Required item */
  2229. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].component.name, "ChargingStation");
  2230. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variable.name, "Available");
  2231. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].component.name, "ChargingStation");
  2232. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variable.name, "AvailabilityState");
  2233. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].component.name, "ChargingStation");
  2234. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variable.name, "SupplyPhases");
  2235. /* Connector Required item */
  2236. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].component.name, "Connector");
  2237. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variable.name, "Available");
  2238. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].component.name, "Connector");
  2239. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variable.name, "ConnectorType");
  2240. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].component.name, "Connector");
  2241. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variable.name, "SupplyPhases");
  2242. /* CustomizationCtrlr Required item */
  2243. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].component.name, "CustomizationCtrlr");
  2244. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variable.name, "CustomImplementationEnabled");
  2245. /* DeviceDataCtrlr Required item */
  2246. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2247. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.instance, "GetReport");
  2248. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2249. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2250. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.instance, "GetVariables");
  2251. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2252. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2253. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.instance, "GetReport");
  2254. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.name, "BytesPerMessage");
  2255. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2256. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.instance, "GetVariables");
  2257. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2258. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].component.name, "DeviceDataCtrlr");
  2259. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variable.name, "ConfigurationValueSize");
  2260. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].component.name, "DeviceDataCtrlr");
  2261. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variable.name, "ReportingValueSize");
  2262. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2263. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.instance, "SetVariables");
  2264. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2265. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2266. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.instance, "SetVariables");
  2267. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2268. /* DisplayMessageCtrlr Required item */
  2269. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].component.name, "DisplayMessageCtrlr");
  2270. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variable.name, "Enabled");
  2271. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].component.name, "DisplayMessageCtrlr");
  2272. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variable.name, "Available");
  2273. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].component.name, "DisplayMessageCtrlr");
  2274. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variable.name, "DisplayMessages");
  2275. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].component.name, "DisplayMessageCtrlr");
  2276. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variable.name, "SupportedFormats");
  2277. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].component.name, "DisplayMessageCtrlr");
  2278. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variable.name, "SupportedPriorities");
  2279. /* EVSE Required item */
  2280. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].component.name, "EVSE");
  2281. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variable.name, "Available");
  2282. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].component.name, "EVSE");
  2283. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variable.name, "AvailabilityState");
  2284. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].component.name, "EVSE");
  2285. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variable.name, "SupplyPhases");
  2286. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].component.name, "EVSE");
  2287. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variable.name, "Power");
  2288. /* LocalAuthListCtrlr Required item */
  2289. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].component.name, "LocalAuthListCtrlr");
  2290. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variable.name, "Enabled");
  2291. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].component.name, "LocalAuthListCtrlr");
  2292. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variable.name, "Entries");
  2293. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].component.name, "LocalAuthListCtrlr");
  2294. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variable.name, "Available");
  2295. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].component.name, "LocalAuthListCtrlr");
  2296. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2297. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.instance, "SendLocalList");
  2298. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].component.name, "LocalAuthListCtrlr");
  2299. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.name, "BytesPerMessage");
  2300. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.instance, "SendLocalList");
  2301. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].component.name, "LocalAuthListCtrlr");
  2302. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variable.name, "Storage");
  2303. /* MonitoringCtrlr Required item */
  2304. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].component.name, "MonitoringCtrlr");
  2305. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variable.instance, "Enabled");
  2306. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].component.name, "MonitoringCtrlr");
  2307. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variable.instance, "Available");
  2308. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2309. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.instance, "ClearVariableMonitoring");
  2310. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2311. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2312. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.instance, "SetVariableMonitoring");
  2313. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2314. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2315. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.instance, "ClearVariableMonitoring");
  2316. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2317. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2318. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.instance, "SetVariableMonitoring");
  2319. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2320. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].component.name, "MonitoringCtrlr");
  2321. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variable.name, "OfflineQueuingSeverity");
  2322. /* OCPPCommCtrlr Required item */
  2323. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].component.name, "OCPPCommCtrlr");
  2324. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variable.name, "ActiveNetworkProfile");
  2325. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].component.name, "OCPPCommCtrlr");
  2326. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.instance, "Default");
  2327. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.name, "MessageTimeout");
  2328. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].component.name, "OCPPCommCtrlr");
  2329. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variable.name, "FileTransferProtocols");
  2330. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].component.name, "OCPPCommCtrlr");
  2331. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variable.name, "HeartbeatInterval");
  2332. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].component.name, "OCPPCommCtrlr");
  2333. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variable.name, "NetworkConfigurationPriority");
  2334. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].component.name, "OCPPCommCtrlr");
  2335. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variable.name, "NetworkProfileConnectionAttempts");
  2336. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].component.name, "OCPPCommCtrlr");
  2337. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variable.name, "OfflineThreshold");
  2338. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].component.name, "OCPPCommCtrlr");
  2339. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variable.name, "QueueAllMessages");
  2340. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].component.name, "OCPPCommCtrlr");
  2341. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.instance, "TransactionEvent");
  2342. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.name, "MessageAttempts");
  2343. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].component.name, "OCPPCommCtrlr");
  2344. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.instance, "TransactionEvent");
  2345. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.name, "MessageAttemptInterval");
  2346. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].component.name, "OCPPCommCtrlr");
  2347. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variable.name, "UnlockOnEVSideDisconnect");
  2348. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].component.name, "OCPPCommCtrlr");
  2349. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variable.name, "WebSocketPingInterval");
  2350. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].component.name, "OCPPCommCtrlr");
  2351. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variable.name, "ResetRetries");
  2352. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].component.name, "OCPPCommCtrlr");
  2353. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variable.name, "PublicKeyWithSignedMeterValue");
  2354. /* ReservationCtrlr Required item */
  2355. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].component.name, "ReservationCtrlr");
  2356. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variable.name, "Enabled");
  2357. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].component.name, "ReservationCtrlr");
  2358. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variable.name, "Available");
  2359. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].component.name, "ReservationCtrlr");
  2360. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variable.name, "NonEvseSpecific");
  2361. /* SampledDataCtrlr Required item */
  2362. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].component.name, "SampledDataCtrlr");
  2363. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variable.name, "Enabled");
  2364. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].component.name, "SampledDataCtrlr");
  2365. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variable.name, "Available");
  2366. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].component.name, "SampledDataCtrlr");
  2367. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variable.name, "SignReadings");
  2368. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].component.name, "SampledDataCtrlr");
  2369. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2370. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].component.name, "SampledDataCtrlr");
  2371. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2372. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].component.name, "SampledDataCtrlr");
  2373. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variable.name, "TxStartedMeasurands");
  2374. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].component.name, "SampledDataCtrlr");
  2375. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variable.name, "TxUpdatedMeasurands");
  2376. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].component.name, "SampledDataCtrlr");
  2377. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variable.name, "TxUpdatedInterval");
  2378. /* SecurityCtrlr Required item */
  2379. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].component.name, "SecurityCtrlr");
  2380. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variable.name, "BasicAuthPassword");
  2381. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].component.name, "SecurityCtrlr");
  2382. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variable.name, "Identity");
  2383. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].component.name, "SecurityCtrlr");
  2384. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variable.name, "OrganizationName");
  2385. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].component.name, "SecurityCtrlr");
  2386. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variable.name, "CertificateEntries");
  2387. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].component.name, "SecurityCtrlr");
  2388. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variable.name, "SecurityProfile");
  2389. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].component.name, "SecurityCtrlr");
  2390. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variable.name, "AdditionalRootCertificateCheck");
  2391. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].component.name, "SecurityCtrlr");
  2392. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variable.name, "MaxCertificateChainSize");
  2393. /* SmartChargingCtrlr Required item */
  2394. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].component.name, "SmartChargingCtrlr");
  2395. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variable.name, "Enabled");
  2396. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].component.name, "SmartChargingCtrlr");
  2397. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variable.name, "Available");
  2398. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].component.name, "SmartChargingCtrlr");
  2399. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variable.name, "ACPhaseSwitchingSupported");
  2400. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].component.name, "SmartChargingCtrlr");
  2401. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variable.name, "ProfileStackLevel");
  2402. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].component.name, "SmartChargingCtrlr");
  2403. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variable.name, "RateUnit");
  2404. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].component.name, "SmartChargingCtrlr");
  2405. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variable.name, "PeriodsPerSchedule");
  2406. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].component.name, "SmartChargingCtrlr");
  2407. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variable.name, "ExternalControlSignalsEnabled");
  2408. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].component.name, "SmartChargingCtrlr");
  2409. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variable.name, "NotifyChargingLimitWithSchedules");
  2410. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].component.name, "SmartChargingCtrlr");
  2411. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variable.name, "Phases3to1");
  2412. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].component.name, "SmartChargingCtrlr");
  2413. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variable.name, "Entries");
  2414. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].component.name, "SmartChargingCtrlr");
  2415. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variable.name, "LimitChangeSignificance");
  2416. /* TariffCostCtrlr Required item */
  2417. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].component.name, "TariffCostCtrlr");
  2418. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.instance, "Tariff");
  2419. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.name, "Enabled");
  2420. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].component.name, "TariffCostCtrlr");
  2421. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.instance, "Tariff");
  2422. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.name, "Available");
  2423. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].component.name, "TariffCostCtrlr");
  2424. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variable.name, "TariffFallbackMessage");
  2425. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].component.name, "TariffCostCtrlr");
  2426. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.instance, "Cost");
  2427. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.name, "Enabled");
  2428. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].component.name, "TariffCostCtrlr");
  2429. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.instance, "Cost");
  2430. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.name, "Available");
  2431. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].component.name, "TariffCostCtrlr");
  2432. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variable.name, "TotalCostFallbackMessage");
  2433. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].component.name, "TariffCostCtrlr");
  2434. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variable.name, "Currency");
  2435. /* TxCtrlr Required item */
  2436. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2437. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variable.name, "ChargingBeforeAcceptedEnabled");
  2438. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].component.name, "TxCtrlr");
  2439. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variable.name, "EVConnectionTimeOut");
  2440. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].component.name, "TxCtrlr");
  2441. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variable.name, "StopTxOnEVSideDisconnect");
  2442. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2443. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variable.name, "TxBeforeAcceptedEnabled");
  2444. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].component.name, "TxCtrlr");
  2445. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variable.name, "TxStartPoint");
  2446. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].component.name, "TxCtrlr");
  2447. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variable.name, "TxStopPoint");
  2448. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].component.name, "TxCtrlr");
  2449. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variable.name, "MaxEnergyOnInvalidId");
  2450. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].component.name, "TxCtrlr");
  2451. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variable.name, "StopTxOnInvalidId");
  2452. }
  2453. return 0;
  2454. }
  2455. void DB_variableIsCreate()
  2456. {
  2457. char sql[512];
  2458. char* errMsg = NULL;
  2459. sprintf(sql,"select count(idx) as quantity from ocpp20_variable;");
  2460. /* Execute SQL statement */
  2461. if(sqlite3_exec(db, sql, DB_cbVariableIsCreate, 0, &errMsg) != SQLITE_OK )
  2462. {
  2463. DEBUG_INFO("SQL error: %s\n", errMsg);
  2464. }
  2465. }
  2466. int DB_cbVariableLoadFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  2467. {
  2468. for(int idx=0;idx<CtrlrVariable_CNT;idx++)
  2469. {
  2470. if((strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].component.name, columnValue[1]) == 0) &&
  2471. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].component.instance, columnValue[2]) == 0) &&
  2472. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variable.name, columnValue[3]) == 0) &&
  2473. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variable.instance, columnValue[4]) == 0))
  2474. {
  2475. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.dataType, "%s", columnValue[5]);
  2476. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.unit, "%s", columnValue[6]);
  2477. ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.maxLimit = strlen(columnValue[7])>0?atoi(columnValue[7]):255;
  2478. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].type, "%s", columnValue[8]);
  2479. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].mutability, "%s", columnValue[9]);
  2480. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].value, "%s", columnValue[10]);
  2481. }
  2482. }
  2483. return 0;
  2484. }
  2485. void DB_variableLoadFromDb()
  2486. {
  2487. char sql[512];
  2488. char* errMsg = NULL;
  2489. sprintf(sql,"select * from ocpp20_variable order by idx;");
  2490. /* Execute SQL statement */
  2491. if(sqlite3_exec(db, sql, DB_cbVariableLoadFromDb, 0, &errMsg) != SQLITE_OK )
  2492. {
  2493. DEBUG_INFO("SQL error: %s\n", errMsg);
  2494. }
  2495. }
  2496. int DB_cbGetNetworkProfileFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  2497. {
  2498. memset(&ShmOCPP20Data->NetworkConnectionProfile[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile));
  2499. if(columnCount > 0)
  2500. {
  2501. for(int idx=0;idx<columnCount;idx++)
  2502. {
  2503. json_object *SetNetworkProfile;
  2504. SetNetworkProfile = json_tokener_parse(columnValue[2]);
  2505. if(!is_error(SetNetworkProfile))
  2506. {
  2507. // Required data
  2508. if(json_object_object_get(SetNetworkProfile, "ocppVersion") != NULL)
  2509. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppVersion, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppVersion")));
  2510. if(json_object_object_get(SetNetworkProfile, "ocppTransport") != NULL)
  2511. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppTransport")));
  2512. if(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl") != NULL)
  2513. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl")));
  2514. if(json_object_object_get(SetNetworkProfile, "messageTimeout") != NULL)
  2515. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.messageTimeout = json_object_get_int(json_object_object_get(SetNetworkProfile, "messageTimeout"));
  2516. if(json_object_object_get(SetNetworkProfile, "ocppInterface") != NULL)
  2517. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppInterface, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppInterface")));
  2518. if(json_object_object_get(SetNetworkProfile, "vpn") != NULL)
  2519. {
  2520. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server") != NULL)
  2521. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.server, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server")));
  2522. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user") != NULL)
  2523. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.user, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user")));
  2524. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group") != NULL)
  2525. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.group, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group")));
  2526. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password") != NULL)
  2527. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.password, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password")));
  2528. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key") != NULL)
  2529. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.key, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key")));
  2530. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type") != NULL)
  2531. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type")));
  2532. }
  2533. if(json_object_object_get(SetNetworkProfile, "apn") != NULL)
  2534. {
  2535. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn") != NULL)
  2536. {
  2537. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn));
  2538. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn")));
  2539. }
  2540. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName") != NULL)
  2541. {
  2542. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName));
  2543. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName")));
  2544. }
  2545. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword") != NULL)
  2546. {
  2547. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword));
  2548. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword")));
  2549. }
  2550. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin") != NULL)
  2551. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.simPin = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin"));
  2552. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork") != NULL)
  2553. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.preferredNetwork, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork")));
  2554. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork") != NULL)
  2555. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.useOnlyPreferredNetwork = json_object_get_boolean(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork"));
  2556. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication") != NULL)
  2557. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnAuthentication, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication")));
  2558. }
  2559. }
  2560. json_object_put(SetNetworkProfile);
  2561. ShmOCPP20Data->NetworkConnectionProfile[idx].slot = atoi(columnValue[1]);
  2562. }
  2563. }
  2564. return 0;
  2565. }
  2566. void DB_getNetworkProfileFromDb()
  2567. {
  2568. char sql[512];
  2569. char* errMsg = NULL;
  2570. sprintf(sql,"select * from ocpp20_networkprofile order by slot;");
  2571. /* Execute SQL statement */
  2572. if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
  2573. {
  2574. DEBUG_INFO("SQL error: %s\n", errMsg);
  2575. }
  2576. }
  2577. int DB_addNetworkProfile(int slot, char *data)
  2578. {
  2579. int result = PASS;
  2580. char sql[512];
  2581. char* errMsg = NULL;
  2582. sprintf(sql,"insert or replace into ocpp20_networkprofile (slot, connectionData) VALUES('%d', '%s'); SELECT * from ocpp20_networkprofile order by slot;",
  2583. slot,
  2584. data);
  2585. //* Execute SQL statement */
  2586. if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK)
  2587. {
  2588. DEBUG_INFO("SQL error: %s\n", errMsg);
  2589. result = FAIL;
  2590. }
  2591. return result;
  2592. }
  2593. int DB_deleteNetworkProfile(int slot)
  2594. {
  2595. int result = PASS;
  2596. char sql[512];
  2597. char* errMsg = NULL;
  2598. sprintf(sql,"DELETE from ocpp20_networkprofile where slot=%d; SELECT * from ocpp20_networkprofile order by slot;", slot);
  2599. //* Execute SQL statement */
  2600. if( sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
  2601. {
  2602. DEBUG_INFO("SQL error: %s", errMsg);
  2603. result = FAIL;
  2604. }
  2605. return result;
  2606. }
  2607. int getCurrentYear()
  2608. {
  2609. int result = 0;
  2610. time_t CurrentTime;
  2611. struct tm *tm;
  2612. CurrentTime = time(NULL);
  2613. tm=localtime(&CurrentTime);
  2614. result = (tm->tm_year + 1900);
  2615. return result;
  2616. }
  2617. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  2618. {
  2619. int result = PASS;
  2620. char* errMsg = NULL;
  2621. char sqlStr[8192];
  2622. sprintf(sqlStr, "insert into ocpp20_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  2623. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  2624. {
  2625. result = FAIL;
  2626. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  2627. }
  2628. 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));
  2629. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  2630. {
  2631. result = FAIL;
  2632. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  2633. }
  2634. return result;
  2635. }
  2636. //==========================================
  2637. // Check time passed since today
  2638. //==========================================
  2639. long long DiffTimebWithNow(struct timeb ST)
  2640. {
  2641. //return milli-second
  2642. struct timeb ET;
  2643. long long StartTime,StopTime;
  2644. ftime(&ET);
  2645. StartTime=(long long)ST.time;
  2646. StopTime=(long long)ET.time;
  2647. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  2648. }
  2649. int getTimePassSinceToday(uint8_t gun_index)
  2650. {
  2651. int result = -1;
  2652. static time_t lastTime[4];
  2653. time_t t;
  2654. struct tm *tmStartToday;
  2655. struct timeb tbStartToday;
  2656. t=time(NULL);
  2657. if(difftime(t, lastTime[gun_index])>0)
  2658. {
  2659. tmStartToday=localtime(&t);
  2660. tmStartToday->tm_hour = 0;
  2661. tmStartToday->tm_min = 0;
  2662. tmStartToday->tm_sec = 0;
  2663. tbStartToday.time = mktime(tmStartToday);
  2664. tbStartToday.millitm = 0;
  2665. result = DiffTimebWithNow(tbStartToday)/1000;
  2666. lastTime[gun_index] = t;
  2667. }
  2668. return result;
  2669. }
  2670. int syncDateTimeRTC(uint8_t *data)
  2671. {
  2672. struct ParsingResult
  2673. {
  2674. int result;
  2675. int scanedElement;
  2676. int year;
  2677. int month;
  2678. int mday;
  2679. int hour;
  2680. int min;
  2681. int sec;
  2682. int tz_hour;
  2683. int tz_min;
  2684. float minSec;
  2685. }result;
  2686. struct tm tmOrg;
  2687. struct tm *tmTarget;
  2688. struct timeb tbTarget;
  2689. char buf[128];
  2690. memset(&result, 0x00, sizeof(struct ParsingResult));
  2691. result.result = PASS;
  2692. if(strstr((char*)data, ".") != NULL)
  2693. {
  2694. // Original data with mini second
  2695. if(strstr((char*)data, "Z") != NULL)
  2696. {
  2697. // Original data with Z
  2698. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  2699. &result.year,
  2700. &result.month,
  2701. &result.mday,
  2702. &result.hour,
  2703. &result.min,
  2704. &result.sec,
  2705. &result.minSec);
  2706. }
  2707. else
  2708. {
  2709. // Original data without Z
  2710. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  2711. &result.year,
  2712. &result.month,
  2713. &result.mday,
  2714. &result.hour,
  2715. &result.min,
  2716. &result.sec,
  2717. &result.minSec,
  2718. &result.tz_hour,
  2719. &result.tz_min);
  2720. }
  2721. }
  2722. else
  2723. {
  2724. // Original data without mini second
  2725. if(strstr((char*)data, "Z") != NULL)
  2726. {
  2727. // Original data with Z
  2728. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  2729. &result.year,
  2730. &result.month,
  2731. &result.mday,
  2732. &result.hour,
  2733. &result.min,
  2734. &result.sec);
  2735. }
  2736. else
  2737. {
  2738. // Original data without Z
  2739. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  2740. &result.year,
  2741. &result.month,
  2742. &result.mday,
  2743. &result.hour,
  2744. &result.min,
  2745. &result.sec,
  2746. &result.tz_hour,
  2747. &result.tz_min);
  2748. }
  2749. }
  2750. tmOrg.tm_year = result.year - 1900;
  2751. tmOrg.tm_mon = result.month - 1;
  2752. tmOrg.tm_mday = result.mday;
  2753. tmOrg.tm_hour = result.hour;
  2754. tmOrg.tm_min = result.min;
  2755. tmOrg.tm_sec = result.sec;
  2756. tmOrg.tm_gmtoff = 0;
  2757. tbTarget.time = mktime(&tmOrg);
  2758. tbTarget.timezone = 0;
  2759. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  2760. tmTarget = gmtime(&tbTarget.time);
  2761. 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);
  2762. //DEBUG_INFO(" org date time: %s\n", data);
  2763. //DEBUG_INFO("parse date time: %s\n", buf);
  2764. system(buf);
  2765. system("/sbin/hwclock -w --systohc");
  2766. if(result.scanedElement < 6)
  2767. result.result = FAIL;
  2768. return result.result;
  2769. }
  2770. //==========================================
  2771. // GetCompositeSchedule logic related function
  2772. //==========================================
  2773. int DiffTimebSec(struct timeb ST, struct timeb ET)
  2774. {
  2775. //return milli-second
  2776. unsigned int StartTime,StopTime;
  2777. StartTime=(unsigned int)ST.time;
  2778. StopTime=(unsigned int)ET.time;
  2779. return (StopTime-StartTime);
  2780. }
  2781. int DiffTimebWithNowSec(struct timeb ST)
  2782. {
  2783. //return milli-second
  2784. struct timeb ET;
  2785. unsigned int StartTime,StopTime;
  2786. ftime(&ET);
  2787. StartTime=(unsigned int)ST.time;
  2788. StopTime=(unsigned int)ET.time;
  2789. return (StopTime-StartTime);
  2790. }
  2791. int getStartStop(uint8_t *start, uint8_t *stop)
  2792. {
  2793. int result = -1;
  2794. struct tm tmStart;
  2795. struct timeb tbStart;
  2796. struct tm tmStop;
  2797. struct timeb tbStop;
  2798. 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) &&
  2799. (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))
  2800. {
  2801. //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);
  2802. //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);
  2803. tmStart.tm_year -= 1900;
  2804. tmStart.tm_mon -= 1;
  2805. tbStart.time = mktime(&tmStart);
  2806. tbStart.millitm = 0;
  2807. tmStop.tm_year -= 1900;
  2808. tmStop.tm_mon -= 1;
  2809. tbStop.time = mktime(&tmStop);
  2810. tbStop.millitm = 0;
  2811. result = DiffTimebSec(tbStart, tbStop);
  2812. //DEBUG_INFO("getStartStop(): %d\n", result);
  2813. }
  2814. else
  2815. {
  2816. DEBUG_WARN("Start or stop date parsing error.\r\n");
  2817. }
  2818. return result;
  2819. }
  2820. int isOvertNow(uint8_t *start)
  2821. {
  2822. int result = NO;
  2823. struct tm tmStart;
  2824. struct timeb tbStart;
  2825. 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))
  2826. {
  2827. //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);
  2828. tmStart.tm_year -= 1900;
  2829. tmStart.tm_mon -= 1;
  2830. tbStart.time = mktime(&tmStart);
  2831. tbStart.millitm = 0;
  2832. if(DiffTimebWithNowSec(tbStart) <= 0)
  2833. result = NO;
  2834. else
  2835. result = YES;
  2836. }
  2837. else
  2838. {
  2839. DEBUG_WARN("Start date parsing error.\n");
  2840. }
  2841. return result;
  2842. }
  2843. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  2844. {
  2845. int result = -1;
  2846. struct tm tmStart;
  2847. struct timeb tbStart;
  2848. struct tm tmStop;
  2849. struct timeb tbStop;
  2850. 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) &&
  2851. (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))
  2852. {
  2853. tmStart.tm_year -= 1900;
  2854. tmStart.tm_mon -= 1;
  2855. tbStart.time = mktime(&tmStart);
  2856. tbStart.millitm = 0;
  2857. tmStop.tm_year -= 1900;
  2858. tmStop.tm_mon -= 1;
  2859. tbStop.time = mktime(&tmStop);
  2860. tbStop.millitm = 0;
  2861. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  2862. }
  2863. return result;
  2864. }
  2865. void checkChargePointMaxProfile(uint32_t durationReq, struct ChargingProfileType *compositeProfile, uint8_t idxSchedule, uint8_t isUnitA)
  2866. {
  2867. FILE *fp;
  2868. char profileFileName[128];
  2869. char *line = NULL;
  2870. size_t len = 0;
  2871. time_t CurrentTime;
  2872. struct tm *tmComposite;
  2873. struct ChargingProfileType maxProfile;
  2874. uint8_t limitMax=0;
  2875. int compositePeriodIdx = 0;
  2876. CurrentTime = time(NULL);
  2877. tmComposite=localtime(&CurrentTime);
  2878. 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);
  2879. if(isUnitA)
  2880. sprintf((char*)compositeProfile->chargingSchedule[idxSchedule].chargingRateUnit, "A");
  2881. else
  2882. sprintf((char*)compositeProfile->chargingSchedule[idxSchedule].chargingRateUnit, "W");
  2883. compositeProfile->chargingSchedule[idxSchedule].duration = durationReq;
  2884. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  2885. {
  2886. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  2887. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  2888. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  2889. }
  2890. compositeProfile->id = 0;
  2891. compositeProfile->stackLevel = 99 ;
  2892. sprintf((char*)compositeProfile->chargingProfileKind ,"Absolute");
  2893. maxProfile.id = -1;
  2894. maxProfile.chargingSchedule[idxSchedule].duration = -1;
  2895. system("rm -f /tmp/*.json");
  2896. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2897. // Search max profile
  2898. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  2899. if((access(profileFileName, F_OK))!=-1)
  2900. {
  2901. fp = fopen(profileFileName, "r");
  2902. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  2903. {
  2904. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  2905. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  2906. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  2907. }
  2908. maxProfile.id = -1;
  2909. maxProfile.stackLevel = -1;
  2910. while(getline(&line, &len, fp) != -1)
  2911. {
  2912. json_object *obj = NULL;
  2913. obj = json_tokener_parse(line);
  2914. if(is_error(obj))
  2915. {
  2916. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  2917. }
  2918. else
  2919. {
  2920. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.id) &&
  2921. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.stackLevel)
  2922. )
  2923. {
  2924. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2925. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2926. )
  2927. {
  2928. struct tm tmFrom, tmTo;
  2929. struct timeb tbFrom, tbTo;
  2930. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  2931. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  2932. {
  2933. tmFrom.tm_year -= 1900;
  2934. tmFrom.tm_mon -= 1;
  2935. tbFrom.time = mktime(&tmFrom);
  2936. tmTo.tm_year -= 1900;
  2937. tmTo.tm_mon -= 1;
  2938. tbTo.time = mktime(&tmTo);
  2939. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2940. {
  2941. if(maxProfile.id == -1)
  2942. DEBUG_INFO("MaxProfile found.\n");
  2943. else
  2944. DEBUG_INFO("MaxProfile updated.\n");
  2945. // Required item
  2946. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2947. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2948. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2949. if(isUnitA)
  2950. {
  2951. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  2952. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2953. {
  2954. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2955. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2956. 3:
  2957. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2958. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  2959. }
  2960. }
  2961. else
  2962. {
  2963. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  2964. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  2965. {
  2966. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  2967. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  2968. 3:
  2969. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  2970. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  2971. }
  2972. }
  2973. // Optional item
  2974. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2975. {
  2976. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2977. }
  2978. else
  2979. {
  2980. sprintf((char*)maxProfile.validFrom, " ");
  2981. }
  2982. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2983. {
  2984. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2985. }
  2986. else
  2987. {
  2988. sprintf((char*)maxProfile.validTo, " ");
  2989. }
  2990. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2991. {
  2992. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2993. }
  2994. else
  2995. {
  2996. sprintf((char*)maxProfile.recurrencyKind, " ");
  2997. }
  2998. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2999. {
  3000. sprintf((char*)maxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  3001. }
  3002. else
  3003. {
  3004. sprintf((char*)maxProfile.transactionId, " ");
  3005. }
  3006. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3007. {
  3008. maxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3009. }
  3010. else
  3011. {
  3012. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  3013. }
  3014. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3015. {
  3016. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  3017. }
  3018. else
  3019. {
  3020. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", compositeProfile->chargingSchedule[idxSchedule].startSchedule);
  3021. }
  3022. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3023. {
  3024. maxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3025. }
  3026. else
  3027. {
  3028. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3029. }
  3030. }
  3031. }
  3032. }
  3033. else
  3034. {
  3035. if(maxProfile.id == -1)
  3036. DEBUG_INFO("MaxProfile found.\n");
  3037. else
  3038. DEBUG_INFO("MaxProfile updated.\n");
  3039. // Required item
  3040. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3041. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3042. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3043. if(isUnitA)
  3044. {
  3045. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3046. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3047. {
  3048. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3049. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3050. 3:
  3051. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3052. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3053. }
  3054. }
  3055. else
  3056. {
  3057. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3058. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3059. {
  3060. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3061. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3062. 3:
  3063. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3064. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  3065. }
  3066. }
  3067. // Optional item
  3068. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3069. {
  3070. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3071. }
  3072. else
  3073. {
  3074. sprintf((char*)maxProfile.validFrom, " ");
  3075. }
  3076. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3077. {
  3078. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3079. }
  3080. else
  3081. {
  3082. sprintf((char*)maxProfile.validTo, " ");
  3083. }
  3084. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  3085. {
  3086. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  3087. }
  3088. else
  3089. {
  3090. sprintf((char*)maxProfile.recurrencyKind, " ");
  3091. }
  3092. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3093. {
  3094. sprintf((char*)maxProfile.transactionId,"%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  3095. }
  3096. else
  3097. {
  3098. sprintf((char*)maxProfile.transactionId, " ");
  3099. }
  3100. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3101. {
  3102. maxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3103. }
  3104. else
  3105. {
  3106. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  3107. }
  3108. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3109. {
  3110. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  3111. }
  3112. else
  3113. {
  3114. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", compositeProfile->chargingSchedule[idxSchedule].startSchedule);
  3115. }
  3116. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3117. {
  3118. maxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3119. }
  3120. else
  3121. {
  3122. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3123. }
  3124. }
  3125. }
  3126. }
  3127. json_object_put(obj);
  3128. }
  3129. fclose(fp);
  3130. /*
  3131. if(maxProfile.ChargingProfileId !=-1)
  3132. {
  3133. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3134. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3135. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3136. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3137. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3138. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3139. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3140. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.chargingSchedule[idxSchedule].StartSchedule);
  3141. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  3142. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  3143. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  3144. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  3145. {
  3146. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3147. {
  3148. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3149. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  3150. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3151. }
  3152. }
  3153. }
  3154. else
  3155. DEBUG_INFO("MaxProfile not found.\n");
  3156. DEBUG_INFO("------------------------------------\n");*/
  3157. }
  3158. if(maxProfile.id != -1)
  3159. {
  3160. if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  3161. {
  3162. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3163. {
  3164. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  3165. 0:
  3166. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  3167. }
  3168. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3169. {
  3170. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3171. {
  3172. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  3173. 0:
  3174. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  3175. if(idxPeriod > 0)
  3176. {
  3177. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3178. {
  3179. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3180. }
  3181. }
  3182. }
  3183. }
  3184. }
  3185. else if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  3186. {
  3187. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3188. {
  3189. maxProfile.chargingSchedule[idxSchedule].duration = maxProfile.chargingSchedule[idxSchedule].duration;
  3190. }
  3191. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3192. {
  3193. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3194. {
  3195. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod;
  3196. if(idxPeriod > 0)
  3197. {
  3198. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3199. {
  3200. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3201. }
  3202. }
  3203. }
  3204. }
  3205. }
  3206. else
  3207. {
  3208. if(strstr((char*)maxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  3209. {
  3210. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3211. {
  3212. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  3213. 0:
  3214. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  3215. }
  3216. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3217. {
  3218. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3219. {
  3220. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  3221. 0:
  3222. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  3223. if(idxPeriod > 0)
  3224. {
  3225. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3226. {
  3227. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3228. }
  3229. }
  3230. }
  3231. }
  3232. }
  3233. else
  3234. {
  3235. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3236. {
  3237. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  3238. 0:
  3239. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  3240. }
  3241. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3242. {
  3243. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3244. {
  3245. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  3246. 0:
  3247. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  3248. if(idxPeriod > 0)
  3249. {
  3250. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3251. {
  3252. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3253. }
  3254. }
  3255. }
  3256. }
  3257. }
  3258. }
  3259. /*
  3260. DEBUG_INFO("MaxProfile after align.\n");
  3261. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3262. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3263. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3264. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3265. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3266. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3267. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3268. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3269. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  3270. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  3271. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  3272. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  3273. {
  3274. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3275. {
  3276. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3277. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  3278. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3279. }
  3280. }
  3281. DEBUG_INFO("------------------------------------\n");*/
  3282. }
  3283. // Find each profile period quantity
  3284. for(int idx=0;idx<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  3285. {
  3286. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  3287. limitMax = idx+1;
  3288. }
  3289. if(maxProfile.id != -1)
  3290. {
  3291. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  3292. {
  3293. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  3294. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  3295. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  3296. {
  3297. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  3298. {
  3299. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct ChargingSchedulePeriodType));
  3300. compositePeriodIdx++;
  3301. }
  3302. else
  3303. {
  3304. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod],sizeof(struct ChargingSchedulePeriodType));
  3305. }
  3306. }
  3307. }
  3308. }
  3309. DEBUG_INFO("ChargePointMaxProfile ready.\n");
  3310. DEBUG_INFO("Schedule start: %s\n", compositeProfile->chargingSchedule[idxSchedule].startSchedule);
  3311. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->chargingSchedule[idxSchedule].duration);
  3312. DEBUG_INFO("Rate unit: %s\n", compositeProfile->chargingSchedule[idxSchedule].chargingRateUnit);
  3313. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3314. {
  3315. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod >= 0)
  3316. {
  3317. compositeProfile->id = 1;
  3318. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  3319. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit);
  3320. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases);
  3321. }
  3322. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit == -1)
  3323. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit =0;
  3324. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod == -1)
  3325. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod =0;
  3326. }
  3327. if(line)
  3328. free(line);
  3329. }
  3330. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct ChargingProfileType *compositeProfile, uint8_t idxSchedule, uint8_t isUnitA)
  3331. {
  3332. FILE *fp;
  3333. char profileFileName[128];
  3334. char *line = NULL;
  3335. size_t len = 0;
  3336. time_t CurrentTime;
  3337. struct tm *tmComposite;
  3338. struct ChargingProfileType maxProfile;
  3339. struct ChargingProfileType defaultTxProfile;
  3340. struct ChargingProfileType txProfile;
  3341. struct ChargingSchedulePeriodType tmpPeriod;
  3342. uint8_t limitMax=0;
  3343. uint8_t limitDef=0;
  3344. uint8_t limitTx=0;
  3345. int compositePeriodIdx = 0;
  3346. CurrentTime = time(NULL);
  3347. tmComposite=localtime(&CurrentTime);
  3348. 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);
  3349. if(isUnitA)
  3350. sprintf((char*)compositeProfile->chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3351. else
  3352. sprintf((char*)compositeProfile->chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3353. compositeProfile->chargingSchedule[idxSchedule].duration = durationReq;
  3354. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3355. {
  3356. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3357. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3358. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3359. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 0;
  3360. }
  3361. compositeProfile->id = 0;
  3362. compositeProfile->stackLevel = 99 ;
  3363. sprintf((char*)compositeProfile->chargingProfileKind ,ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]);
  3364. maxProfile.id = -1;
  3365. defaultTxProfile.id = -1;
  3366. txProfile.id = -1;
  3367. maxProfile.chargingSchedule[idxSchedule].duration = -1;
  3368. defaultTxProfile.chargingSchedule[idxSchedule].duration = -1;
  3369. txProfile.chargingSchedule[idxSchedule].duration = -1;
  3370. system("rm -f /tmp/*.json");
  3371. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  3372. /*
  3373. * Search valid charging profile
  3374. */
  3375. //DEBUG_INFO("====================================\n");
  3376. // Search tx profile
  3377. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  3378. if((access(profileFileName, F_OK))!=-1)
  3379. {
  3380. fp = fopen(profileFileName, "r");
  3381. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3382. {
  3383. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3384. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3385. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3386. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  3387. }
  3388. txProfile.id = -1;
  3389. txProfile.stackLevel = -1;
  3390. while(getline(&line, &len, fp) != -1)
  3391. {
  3392. json_object *obj = NULL;
  3393. obj = json_tokener_parse(line);
  3394. if(is_error(obj))
  3395. {
  3396. DEBUG_ERROR("Parse txProfile from file error.\n");
  3397. }
  3398. else
  3399. {
  3400. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.id) &&
  3401. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.stackLevel)
  3402. )
  3403. {
  3404. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  3405. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3406. )
  3407. {
  3408. struct tm tmFrom, tmTo;
  3409. struct timeb tbFrom, tbTo;
  3410. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  3411. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  3412. {
  3413. tmFrom.tm_year -= 1900;
  3414. tmFrom.tm_mon -= 1;
  3415. tbFrom.time = mktime(&tmFrom);
  3416. tmTo.tm_year -= 1900;
  3417. tmTo.tm_mon -= 1;
  3418. tbTo.time = mktime(&tmTo);
  3419. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3420. {
  3421. if(txProfile.id == -1)
  3422. DEBUG_INFO("TxProfile found.\n");
  3423. else
  3424. DEBUG_INFO("TxProfile updated.\n");
  3425. // Required item
  3426. txProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3427. txProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3428. sprintf((char*)txProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3429. if(isUnitA)
  3430. {
  3431. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3432. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3433. {
  3434. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3435. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3436. 3:
  3437. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3438. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3439. }
  3440. }
  3441. else
  3442. {
  3443. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3444. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3445. {
  3446. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3447. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3448. 3:
  3449. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3450. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  3451. }
  3452. }
  3453. // Optional item
  3454. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3455. {
  3456. sprintf((char*)txProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3457. }
  3458. else
  3459. {
  3460. sprintf((char*)txProfile.validFrom, " ");
  3461. }
  3462. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3463. {
  3464. sprintf((char*)txProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3465. }
  3466. else
  3467. {
  3468. sprintf((char*)txProfile.validTo, " ");
  3469. }
  3470. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  3471. {
  3472. sprintf((char*)txProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  3473. }
  3474. else
  3475. {
  3476. sprintf((char*)txProfile.recurrencyKind, " ");
  3477. }
  3478. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3479. {
  3480. sprintf((char*)txProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  3481. }
  3482. else
  3483. {
  3484. sprintf((char*)txProfile.transactionId, " ");
  3485. }
  3486. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3487. {
  3488. txProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3489. }
  3490. else
  3491. {
  3492. txProfile.chargingSchedule[idxSchedule].duration = 86400;
  3493. }
  3494. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3495. {
  3496. sprintf((char*)txProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  3497. }
  3498. else
  3499. {
  3500. 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));
  3501. }
  3502. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3503. {
  3504. txProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3505. }
  3506. else
  3507. {
  3508. txProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3509. }
  3510. }
  3511. }
  3512. }
  3513. else
  3514. {
  3515. if(txProfile.id == -1)
  3516. DEBUG_INFO("TxProfile found.\n");
  3517. else
  3518. DEBUG_INFO("TxProfile updated.\n");
  3519. // Required item
  3520. txProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3521. txProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3522. sprintf((char*)txProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3523. if(isUnitA)
  3524. {
  3525. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3526. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3527. {
  3528. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3529. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3530. 3:
  3531. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3532. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3533. }
  3534. }
  3535. else
  3536. {
  3537. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3538. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3539. {
  3540. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3541. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3542. 3:
  3543. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3544. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  3545. }
  3546. }
  3547. // Optional item
  3548. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3549. {
  3550. sprintf((char*)txProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3551. }
  3552. else
  3553. {
  3554. sprintf((char*)txProfile.validFrom, " ");
  3555. }
  3556. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3557. {
  3558. sprintf((char*)txProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3559. }
  3560. else
  3561. {
  3562. sprintf((char*)txProfile.validTo, " ");
  3563. }
  3564. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  3565. {
  3566. sprintf((char*)txProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  3567. }
  3568. else
  3569. {
  3570. sprintf((char*)txProfile.recurrencyKind, " ");
  3571. }
  3572. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3573. {
  3574. sprintf((char*)txProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  3575. }
  3576. else
  3577. {
  3578. sprintf((char*)txProfile.transactionId, " ");
  3579. }
  3580. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3581. {
  3582. txProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3583. }
  3584. else
  3585. {
  3586. txProfile.chargingSchedule[idxSchedule].duration = 86400;
  3587. }
  3588. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3589. {
  3590. sprintf((char*)txProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  3591. }
  3592. else
  3593. {
  3594. 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));
  3595. }
  3596. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3597. {
  3598. txProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3599. }
  3600. else
  3601. {
  3602. txProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3603. }
  3604. }
  3605. }
  3606. }
  3607. json_object_put(obj);
  3608. }
  3609. fclose(fp);
  3610. /*
  3611. if(txProfile.ChargingProfileId != -1)
  3612. {
  3613. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3614. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3615. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3616. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3617. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3618. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3619. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  3620. DEBUG_INFO("Profile start schedule: %s\n", txProfile.chargingSchedule[idxSchedule].StartSchedule);
  3621. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.chargingSchedule[idxSchedule].Duration);
  3622. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  3623. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.chargingSchedule[idxSchedule].MinChargingRate);
  3624. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  3625. {
  3626. if(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3627. {
  3628. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3629. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  3630. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3631. }
  3632. }
  3633. }
  3634. else
  3635. DEBUG_INFO("TxProfile not found.\n");*/
  3636. }
  3637. // Search default tx profile
  3638. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  3639. if((access(profileFileName, F_OK))==-1)
  3640. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  3641. if((access(profileFileName, F_OK))!=-1)
  3642. {
  3643. fp = fopen(profileFileName, "r");
  3644. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3645. {
  3646. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3647. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3648. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3649. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  3650. }
  3651. defaultTxProfile.id = -1;
  3652. defaultTxProfile.stackLevel = -1;
  3653. while(getline(&line, &len, fp) != -1)
  3654. {
  3655. json_object *obj = NULL;
  3656. obj = json_tokener_parse(line);
  3657. if(is_error(obj))
  3658. {
  3659. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  3660. }
  3661. else
  3662. {
  3663. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.id) &&
  3664. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.stackLevel)
  3665. )
  3666. {
  3667. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  3668. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3669. )
  3670. {
  3671. struct tm tmFrom, tmTo;
  3672. struct timeb tbFrom, tbTo;
  3673. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  3674. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  3675. {
  3676. tmFrom.tm_year -= 1900;
  3677. tmFrom.tm_mon -= 1;
  3678. tbFrom.time = mktime(&tmFrom);
  3679. tmTo.tm_year -= 1900;
  3680. tmTo.tm_mon -= 1;
  3681. tbTo.time = mktime(&tmTo);
  3682. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3683. {
  3684. if(defaultTxProfile.id == -1)
  3685. DEBUG_INFO("TxDefaultProfile found.\n");
  3686. else
  3687. DEBUG_INFO("TxDefaultProfile updated.\n");
  3688. // Required item
  3689. defaultTxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3690. defaultTxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3691. sprintf((char*)defaultTxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3692. if(isUnitA)
  3693. {
  3694. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3695. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3696. {
  3697. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3698. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3699. 3:
  3700. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3701. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3702. }
  3703. }
  3704. else
  3705. {
  3706. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3707. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3708. {
  3709. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3710. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3711. 3:
  3712. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3713. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  3714. }
  3715. }
  3716. // Optional item
  3717. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3718. {
  3719. sprintf((char*)defaultTxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3720. }
  3721. else
  3722. {
  3723. sprintf((char*)defaultTxProfile.validFrom, " ");
  3724. }
  3725. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3726. {
  3727. sprintf((char*)defaultTxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3728. }
  3729. else
  3730. {
  3731. sprintf((char*)defaultTxProfile.validTo, " ");
  3732. }
  3733. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  3734. {
  3735. sprintf((char*)defaultTxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  3736. }
  3737. else
  3738. {
  3739. sprintf((char*)defaultTxProfile.recurrencyKind, " ");
  3740. }
  3741. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3742. {
  3743. sprintf((char*)defaultTxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  3744. }
  3745. else
  3746. {
  3747. sprintf((char*)defaultTxProfile.transactionId, " ");
  3748. }
  3749. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3750. {
  3751. defaultTxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3752. }
  3753. else
  3754. {
  3755. defaultTxProfile.chargingSchedule[idxSchedule].duration = 86400;
  3756. }
  3757. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3758. {
  3759. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  3760. }
  3761. else
  3762. {
  3763. 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));
  3764. }
  3765. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3766. {
  3767. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3768. }
  3769. else
  3770. {
  3771. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3772. }
  3773. }
  3774. }
  3775. }
  3776. else
  3777. {
  3778. if(defaultTxProfile.id == -1)
  3779. DEBUG_INFO("TxDefaultProfile found.\n");
  3780. else
  3781. DEBUG_INFO("TxDefaultProfile updated.\n");
  3782. // Required item
  3783. defaultTxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3784. defaultTxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3785. sprintf((char*)defaultTxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3786. if(isUnitA)
  3787. {
  3788. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3789. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3790. {
  3791. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3792. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3793. 3:
  3794. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3795. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3796. }
  3797. }
  3798. else
  3799. {
  3800. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3801. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3802. {
  3803. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3804. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3805. 3:
  3806. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3807. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  3808. }
  3809. }
  3810. // Optional item
  3811. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3812. {
  3813. sprintf((char*)defaultTxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3814. }
  3815. else
  3816. {
  3817. sprintf((char*)defaultTxProfile.validFrom, " ");
  3818. }
  3819. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3820. {
  3821. sprintf((char*)defaultTxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3822. }
  3823. else
  3824. {
  3825. sprintf((char*)defaultTxProfile.validTo, " ");
  3826. }
  3827. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  3828. {
  3829. sprintf((char*)defaultTxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  3830. }
  3831. else
  3832. {
  3833. sprintf((char*)defaultTxProfile.recurrencyKind, " ");
  3834. }
  3835. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3836. {
  3837. sprintf((char*)defaultTxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  3838. }
  3839. else
  3840. {
  3841. sprintf((char*)defaultTxProfile.transactionId, " ");
  3842. }
  3843. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3844. {
  3845. defaultTxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3846. }
  3847. else
  3848. {
  3849. defaultTxProfile.chargingSchedule[idxSchedule].duration = 86400;
  3850. }
  3851. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3852. {
  3853. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  3854. }
  3855. else
  3856. {
  3857. 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));
  3858. }
  3859. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3860. {
  3861. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3862. }
  3863. else
  3864. {
  3865. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3866. }
  3867. }
  3868. }
  3869. }
  3870. json_object_put(obj);
  3871. }
  3872. fclose(fp);
  3873. /*
  3874. if(defaultTxProfile.ChargingProfileId != -1)
  3875. {
  3876. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3877. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3878. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3879. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3880. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3881. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3882. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3883. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].StartSchedule);
  3884. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.chargingSchedule[idxSchedule].Duration);
  3885. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  3886. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  3887. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  3888. {
  3889. if(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3890. {
  3891. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3892. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  3893. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3894. }
  3895. }
  3896. }
  3897. else
  3898. DEBUG_INFO("TxDefaultProfile not found.\n");
  3899. DEBUG_INFO("------------------------------------\n");*/
  3900. }
  3901. // Search max profile
  3902. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  3903. if((access(profileFileName, F_OK))!=-1)
  3904. {
  3905. fp = fopen(profileFileName, "r");
  3906. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3907. {
  3908. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3909. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3910. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3911. }
  3912. maxProfile.id = -1;
  3913. maxProfile.stackLevel = -1;
  3914. while(getline(&line, &len, fp) != -1)
  3915. {
  3916. json_object *obj = NULL;
  3917. obj = json_tokener_parse(line);
  3918. if(is_error(obj))
  3919. {
  3920. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  3921. }
  3922. else
  3923. {
  3924. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.id) &&
  3925. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.stackLevel)
  3926. )
  3927. {
  3928. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  3929. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3930. )
  3931. {
  3932. struct tm tmFrom, tmTo;
  3933. struct timeb tbFrom, tbTo;
  3934. if((sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmFrom.tm_year, &tmFrom.tm_mon, &tmFrom.tm_mday, &tmFrom.tm_hour, &tmFrom.tm_min, &tmFrom.tm_sec) == 6) &&
  3935. (sscanf((char*)json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")), "%4d-%2d-%2dT%2d:%2d:%2d", &tmTo.tm_year, &tmTo.tm_mon, &tmTo.tm_mday, &tmTo.tm_hour, &tmTo.tm_min, &tmTo.tm_sec) == 6))
  3936. {
  3937. tmFrom.tm_year -= 1900;
  3938. tmFrom.tm_mon -= 1;
  3939. tbFrom.time = mktime(&tmFrom);
  3940. tmTo.tm_year -= 1900;
  3941. tmTo.tm_mon -= 1;
  3942. tbTo.time = mktime(&tmTo);
  3943. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3944. {
  3945. if(maxProfile.id == -1)
  3946. DEBUG_INFO("MaxProfile found.\n");
  3947. else
  3948. DEBUG_INFO("MaxProfile updated.\n");
  3949. // Required item
  3950. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3951. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3952. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3953. if(isUnitA)
  3954. {
  3955. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3956. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3957. {
  3958. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3959. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3960. 3:
  3961. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3962. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  3963. }
  3964. }
  3965. else
  3966. {
  3967. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3968. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  3969. {
  3970. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  3971. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  3972. 3:
  3973. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  3974. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  3975. }
  3976. }
  3977. // Optional item
  3978. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3979. {
  3980. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3981. }
  3982. else
  3983. {
  3984. sprintf((char*)maxProfile.validFrom, " ");
  3985. }
  3986. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3987. {
  3988. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3989. }
  3990. else
  3991. {
  3992. sprintf((char*)maxProfile.validTo, " ");
  3993. }
  3994. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  3995. {
  3996. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  3997. }
  3998. else
  3999. {
  4000. sprintf((char*)maxProfile.recurrencyKind, " ");
  4001. }
  4002. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  4003. {
  4004. sprintf((char*)maxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  4005. }
  4006. else
  4007. {
  4008. sprintf((char*)maxProfile.transactionId, " ");
  4009. }
  4010. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  4011. {
  4012. maxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  4013. }
  4014. else
  4015. {
  4016. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4017. }
  4018. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  4019. {
  4020. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  4021. }
  4022. else
  4023. {
  4024. 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));
  4025. }
  4026. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  4027. {
  4028. maxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  4029. }
  4030. else
  4031. {
  4032. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4033. }
  4034. }
  4035. }
  4036. }
  4037. else
  4038. {
  4039. if(maxProfile.id == -1)
  4040. DEBUG_INFO("MaxProfile found.\n");
  4041. else
  4042. DEBUG_INFO("MaxProfile updated.\n");
  4043. // Required item
  4044. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  4045. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  4046. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  4047. if(isUnitA)
  4048. {
  4049. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  4050. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  4051. {
  4052. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4053. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  4054. 3:
  4055. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  4056. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))/(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")));
  4057. }
  4058. }
  4059. else
  4060. {
  4061. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  4062. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  4063. {
  4064. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  4065. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = (json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")==NULL?
  4066. 3:
  4067. json_object_get_int(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases")));
  4068. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = (strstr((char*)json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),ChargingRateUnitEnumTypeStr[ChargingRateUnitEnumType_W])!=NULL?json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit")):json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"))*(220*maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  4069. }
  4070. }
  4071. // Optional item
  4072. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  4073. {
  4074. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  4075. }
  4076. else
  4077. {
  4078. sprintf((char*)maxProfile.validFrom, " ");
  4079. }
  4080. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  4081. {
  4082. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  4083. }
  4084. else
  4085. {
  4086. sprintf((char*)maxProfile.validTo, " ");
  4087. }
  4088. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  4089. {
  4090. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  4091. }
  4092. else
  4093. {
  4094. sprintf((char*)maxProfile.recurrencyKind, " ");
  4095. }
  4096. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  4097. {
  4098. sprintf((char*)maxProfile.transactionId,"%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  4099. }
  4100. else
  4101. {
  4102. sprintf((char*)maxProfile.transactionId, " ");
  4103. }
  4104. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  4105. {
  4106. maxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  4107. }
  4108. else
  4109. {
  4110. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  4111. }
  4112. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  4113. {
  4114. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  4115. }
  4116. else
  4117. {
  4118. 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));
  4119. }
  4120. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  4121. {
  4122. maxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  4123. }
  4124. else
  4125. {
  4126. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  4127. }
  4128. }
  4129. }
  4130. }
  4131. json_object_put(obj);
  4132. }
  4133. fclose(fp);
  4134. /*
  4135. if(maxProfile.ChargingProfileId !=-1)
  4136. {
  4137. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  4138. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  4139. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  4140. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  4141. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  4142. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  4143. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  4144. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.chargingSchedule[idxSchedule].StartSchedule);
  4145. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  4146. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4147. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4148. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4149. {
  4150. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4151. {
  4152. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4153. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4154. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4155. }
  4156. }
  4157. }
  4158. else
  4159. DEBUG_INFO("MaxProfile not found.\n");
  4160. DEBUG_INFO("------------------------------------\n");*/
  4161. }
  4162. /*
  4163. * Align found profile start schedule & periods
  4164. */
  4165. //DEBUG_INFO("====================================\n");
  4166. /*
  4167. // For local test usage, force modify found profile start schedule info
  4168. 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);
  4169. 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);
  4170. 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);
  4171. */
  4172. if(txProfile.id != -1)
  4173. {
  4174. if(strstr((char*)txProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  4175. {
  4176. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  4177. {
  4178. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4179. 0:
  4180. (txProfile.chargingSchedule[idxSchedule].duration-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4181. }
  4182. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4183. {
  4184. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4185. {
  4186. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4187. 0:
  4188. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4189. if(idxPeriod > 0)
  4190. {
  4191. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4192. {
  4193. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4194. }
  4195. }
  4196. }
  4197. }
  4198. }
  4199. else if(strstr((char*)txProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  4200. {
  4201. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  4202. {
  4203. 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?
  4204. 0:
  4205. (txProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4206. }
  4207. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4208. {
  4209. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4210. {
  4211. 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?
  4212. 0:
  4213. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4214. if(idxPeriod > 0)
  4215. {
  4216. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4217. {
  4218. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4219. }
  4220. }
  4221. }
  4222. }
  4223. }
  4224. else
  4225. {
  4226. if(strstr((char*)txProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  4227. {
  4228. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  4229. {
  4230. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4231. 0:
  4232. (txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4233. }
  4234. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4235. {
  4236. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4237. {
  4238. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4239. 0:
  4240. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4241. if(idxPeriod > 0)
  4242. {
  4243. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4244. {
  4245. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4246. }
  4247. }
  4248. }
  4249. }
  4250. }
  4251. else
  4252. {
  4253. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  4254. {
  4255. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4256. 0:
  4257. (txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4258. }
  4259. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4260. {
  4261. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4262. {
  4263. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4264. 0:
  4265. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4266. if(idxPeriod > 0)
  4267. {
  4268. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4269. {
  4270. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4271. }
  4272. }
  4273. }
  4274. }
  4275. }
  4276. }
  4277. /*
  4278. DEBUG_INFO("txProfile after align.\n");
  4279. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  4280. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  4281. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  4282. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  4283. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  4284. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  4285. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  4286. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  4287. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.chargingSchedule[idxSchedule].Duration);
  4288. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4289. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4290. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4291. {
  4292. if(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4293. {
  4294. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4295. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4296. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4297. }
  4298. }*/
  4299. }
  4300. if(defaultTxProfile.id != -1)
  4301. {
  4302. if(strstr((char*)defaultTxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  4303. {
  4304. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  4305. {
  4306. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4307. 0:
  4308. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4309. }
  4310. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4311. {
  4312. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4313. {
  4314. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4315. 0:
  4316. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4317. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod < txProfile.chargingSchedule[idxSchedule].duration)
  4318. {
  4319. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod += (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  4320. }
  4321. if(idxPeriod > 0)
  4322. {
  4323. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4324. {
  4325. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4326. }
  4327. }
  4328. }
  4329. }
  4330. }
  4331. else if(strstr((char*)defaultTxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  4332. {
  4333. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  4334. {
  4335. 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?
  4336. 0:
  4337. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4338. }
  4339. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4340. {
  4341. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4342. {
  4343. 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?
  4344. 0:
  4345. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4346. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod < txProfile.chargingSchedule[idxSchedule].duration)
  4347. {
  4348. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod += (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  4349. }
  4350. if(idxPeriod > 0)
  4351. {
  4352. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4353. {
  4354. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4355. }
  4356. }
  4357. }
  4358. }
  4359. }
  4360. else
  4361. {
  4362. if(strstr((char*)defaultTxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  4363. {
  4364. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  4365. {
  4366. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4367. 0:
  4368. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4369. }
  4370. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4371. {
  4372. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4373. {
  4374. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4375. 0:
  4376. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4377. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod < txProfile.chargingSchedule[idxSchedule].duration)
  4378. {
  4379. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod += (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  4380. }
  4381. if(idxPeriod > 0)
  4382. {
  4383. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4384. {
  4385. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4386. }
  4387. }
  4388. }
  4389. }
  4390. }
  4391. else
  4392. {
  4393. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  4394. {
  4395. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4396. 0:
  4397. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4398. }
  4399. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4400. {
  4401. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4402. {
  4403. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4404. 0:
  4405. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4406. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod < txProfile.chargingSchedule[idxSchedule].duration)
  4407. {
  4408. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod += (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  4409. }
  4410. if(idxPeriod > 0)
  4411. {
  4412. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4413. {
  4414. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4415. }
  4416. }
  4417. }
  4418. }
  4419. }
  4420. }
  4421. /*
  4422. DEBUG_INFO("defaultTxProfile after align.\n");
  4423. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  4424. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  4425. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  4426. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  4427. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  4428. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  4429. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  4430. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  4431. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.chargingSchedule[idxSchedule].Duration);
  4432. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4433. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4434. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4435. {
  4436. if(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4437. {
  4438. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4439. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4440. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4441. }
  4442. }
  4443. DEBUG_INFO("------------------------------------\n");*/
  4444. }
  4445. if(maxProfile.id != -1)
  4446. {
  4447. if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  4448. {
  4449. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4450. {
  4451. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4452. 0:
  4453. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4454. }
  4455. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4456. {
  4457. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4458. {
  4459. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4460. 0:
  4461. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4462. if(idxPeriod > 0)
  4463. {
  4464. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4465. {
  4466. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4467. }
  4468. }
  4469. }
  4470. }
  4471. }
  4472. else if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  4473. {
  4474. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4475. {
  4476. 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?
  4477. 0:
  4478. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[9].startSchedule)));
  4479. }
  4480. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4481. {
  4482. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4483. {
  4484. 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?
  4485. 0:
  4486. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4487. if(idxPeriod > 0)
  4488. {
  4489. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4490. {
  4491. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4492. }
  4493. }
  4494. }
  4495. }
  4496. }
  4497. else
  4498. {
  4499. if(strstr((char*)maxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  4500. {
  4501. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4502. {
  4503. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4504. 0:
  4505. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4506. }
  4507. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4508. {
  4509. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4510. {
  4511. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4512. 0:
  4513. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4514. if(idxPeriod > 0)
  4515. {
  4516. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4517. {
  4518. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4519. }
  4520. }
  4521. }
  4522. }
  4523. }
  4524. else
  4525. {
  4526. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4527. {
  4528. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4529. 0:
  4530. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4531. }
  4532. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4533. {
  4534. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4535. {
  4536. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4537. 0:
  4538. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4539. if(idxPeriod > 0)
  4540. {
  4541. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4542. {
  4543. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4544. }
  4545. }
  4546. }
  4547. }
  4548. }
  4549. }
  4550. /*
  4551. DEBUG_INFO("MaxProfile after align.\n");
  4552. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  4553. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  4554. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  4555. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  4556. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  4557. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  4558. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  4559. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  4560. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  4561. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4562. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4563. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4564. {
  4565. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4566. {
  4567. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4568. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4569. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4570. }
  4571. }
  4572. DEBUG_INFO("------------------------------------\n");*/
  4573. }
  4574. /*
  4575. * Merge to conposite schedule
  4576. */
  4577. //DEBUG_INFO("====================================\n");
  4578. // Find each profile period quantity
  4579. for(int idx=0;idx<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  4580. {
  4581. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  4582. limitMax = idx+1;
  4583. }
  4584. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  4585. {
  4586. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  4587. limitDef = idx+1;
  4588. }
  4589. for(int idx=0;idx<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  4590. {
  4591. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  4592. limitTx = idx+1;
  4593. }
  4594. // TxProfile found, composite schedule based on it
  4595. if(txProfile.id != -1)
  4596. {
  4597. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  4598. {
  4599. if((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit != -1) &&
  4600. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod < durationReq) &&
  4601. (txProfile.chargingSchedule[idxSchedule].duration > 0))
  4602. {
  4603. if(maxProfile.id != -1)
  4604. {
  4605. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4606. {
  4607. if((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod))
  4608. {
  4609. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  4610. {
  4611. tmpPeriod.startPeriod = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod;
  4612. tmpPeriod.numberPhases = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].numberPhases;
  4613. 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);
  4614. }
  4615. else
  4616. {
  4617. tmpPeriod.startPeriod = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod;
  4618. tmpPeriod.numberPhases = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].numberPhases;
  4619. tmpPeriod.limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit;
  4620. }
  4621. }
  4622. if(idxMaxPeriod == (limitMax-1))
  4623. {
  4624. if(tmpPeriod.limit != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  4625. {
  4626. if(tmpPeriod.startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4627. {
  4628. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4629. compositePeriodIdx++;
  4630. }
  4631. else
  4632. {
  4633. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4634. }
  4635. }
  4636. }
  4637. }
  4638. }
  4639. else
  4640. {
  4641. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4642. {
  4643. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod],sizeof(struct ChargingSchedulePeriodType));
  4644. compositePeriodIdx++;
  4645. }
  4646. else
  4647. {
  4648. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod],sizeof(struct ChargingSchedulePeriodType));
  4649. }
  4650. }
  4651. }
  4652. if(idxTxPeriod == (limitTx-1))
  4653. {
  4654. if(defaultTxProfile.id != -1)
  4655. {
  4656. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  4657. {
  4658. if((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod + (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod))) &&
  4659. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod < durationReq) &&
  4660. (defaultTxProfile.chargingSchedule[idxSchedule].duration>0))
  4661. {
  4662. if(maxProfile.id != -1)
  4663. {
  4664. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4665. {
  4666. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod)
  4667. {
  4668. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  4669. {
  4670. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  4671. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  4672. 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);
  4673. }
  4674. else
  4675. {
  4676. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  4677. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  4678. tmpPeriod.limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit;
  4679. }
  4680. if(tmpPeriod.limit != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  4681. {
  4682. if(tmpPeriod.startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4683. {
  4684. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4685. compositePeriodIdx++;
  4686. }
  4687. else
  4688. {
  4689. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4690. }
  4691. }
  4692. // Delete duplicate period
  4693. if(compositePeriodIdx > 1)
  4694. {
  4695. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  4696. {
  4697. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  4698. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  4699. compositePeriodIdx -= 1;
  4700. }
  4701. }
  4702. }
  4703. else
  4704. break;
  4705. }
  4706. }
  4707. else
  4708. {
  4709. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4710. {
  4711. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  4712. compositePeriodIdx++;
  4713. }
  4714. else
  4715. {
  4716. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  4717. }
  4718. }
  4719. }
  4720. }
  4721. }
  4722. }
  4723. }
  4724. }
  4725. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  4726. else if(defaultTxProfile.id != -1)
  4727. {
  4728. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  4729. {
  4730. if((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit != -1) &&
  4731. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod < durationReq) &&
  4732. (defaultTxProfile.chargingSchedule[idxSchedule].duration > 0))
  4733. {
  4734. if(maxProfile.id != -1)
  4735. {
  4736. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4737. {
  4738. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod)
  4739. {
  4740. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  4741. {
  4742. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  4743. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  4744. 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);
  4745. }
  4746. else
  4747. {
  4748. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  4749. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  4750. tmpPeriod.limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit;
  4751. }
  4752. if(tmpPeriod.limit != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  4753. {
  4754. if(tmpPeriod.startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4755. {
  4756. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4757. compositePeriodIdx++;
  4758. }
  4759. else
  4760. {
  4761. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4762. }
  4763. }
  4764. // Delete duplicate period
  4765. if(compositePeriodIdx > 1)
  4766. {
  4767. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  4768. {
  4769. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  4770. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  4771. compositePeriodIdx -= 1;
  4772. }
  4773. }
  4774. }
  4775. else
  4776. break;
  4777. }
  4778. }
  4779. else
  4780. {
  4781. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4782. {
  4783. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  4784. compositePeriodIdx++;
  4785. }
  4786. else
  4787. {
  4788. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  4789. }
  4790. }
  4791. }
  4792. }
  4793. }
  4794. // Fill other period by MaxProfile
  4795. if(maxProfile.id != -1)
  4796. {
  4797. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4798. {
  4799. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  4800. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  4801. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  4802. {
  4803. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod >= compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].startPeriod) &&
  4804. (maxProfile.chargingSchedule[idxSchedule].duration > compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].startPeriod))
  4805. {
  4806. tmpPeriod.startPeriod = (compositePeriodIdx==0)?0:compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].startPeriod;
  4807. tmpPeriod.numberPhases = compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].numberPhases;
  4808. tmpPeriod.limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit;
  4809. }
  4810. if((compositePeriodIdx > 0) && (maxProfile.chargingSchedule[idxSchedule].duration > compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].startPeriod))
  4811. {
  4812. tmpPeriod.startPeriod = (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod>compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod)?maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod:compositeProfile->chargingSchedule[idxSchedule].duration;
  4813. tmpPeriod.numberPhases = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].numberPhases;
  4814. tmpPeriod.limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit;
  4815. }
  4816. if(tmpPeriod.limit != -1)
  4817. {
  4818. if(tmpPeriod.limit != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  4819. {
  4820. if(tmpPeriod.startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4821. {
  4822. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4823. compositePeriodIdx++;
  4824. }
  4825. else
  4826. {
  4827. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4828. }
  4829. }
  4830. // Delete duplicate period
  4831. if(compositePeriodIdx > 1)
  4832. {
  4833. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  4834. {
  4835. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  4836. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  4837. compositePeriodIdx -= 1;
  4838. }
  4839. }
  4840. }
  4841. }
  4842. }
  4843. }
  4844. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  4845. DEBUG_INFO("Schedule start: %s\n", compositeProfile->chargingSchedule[idxSchedule].startSchedule);
  4846. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->chargingSchedule[idxSchedule].duration);
  4847. DEBUG_INFO("Rate unit: %s\n", compositeProfile->chargingSchedule[idxSchedule].chargingRateUnit);
  4848. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4849. {
  4850. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod >= 0)
  4851. {
  4852. compositeProfile->id = 1;
  4853. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  4854. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit);
  4855. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases);
  4856. }
  4857. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit == -1)
  4858. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit =0;
  4859. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod == -1)
  4860. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod =0;
  4861. }
  4862. if(line)
  4863. free(line);
  4864. checkChargePointMaxProfile(durationReq, &ShmOCPP20Data->MaxChargingProfile, idxSchedule, isUnitA);
  4865. ShmOCPP20Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = ON;
  4866. }
  4867. //==========================================
  4868. // Init all share memory
  4869. //==========================================
  4870. int InitShareMemory()
  4871. {
  4872. int result = PASS;
  4873. int MeterSMId;
  4874. //creat ShmSysConfigAndInfo
  4875. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  4876. {
  4877. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  4878. result = FAIL;
  4879. }
  4880. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4881. {
  4882. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  4883. result = FAIL;
  4884. }
  4885. else
  4886. {}
  4887. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  4888. {
  4889. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  4890. result = FAIL;
  4891. }
  4892. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4893. {
  4894. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  4895. result = FAIL;
  4896. }
  4897. else
  4898. {}
  4899. //creat ShmPsuData
  4900. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  4901. {
  4902. DEBUG_ERROR("shmget ShmPsuData NG\n");
  4903. result = FAIL;
  4904. }
  4905. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4906. {
  4907. DEBUG_ERROR("shmat ShmPsuData NG\n");
  4908. result = FAIL;
  4909. }
  4910. else
  4911. {}
  4912. //creat ShmOCPP20Data
  4913. if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), 0777)) < 0)
  4914. {
  4915. DEBUG_ERROR("shmget ShmOCPP20Data NG\n");
  4916. result = FAIL;
  4917. }
  4918. else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4919. {
  4920. DEBUG_ERROR("shmat ShmOCPP20Data NG\n");
  4921. result = FAIL;
  4922. }
  4923. else
  4924. {}
  4925. /****************************** For Initial Settings************************************************/
  4926. /*
  4927. DEBUG_INFO("Authorize_20 size: %d\n", sizeof(struct Authorize_20));
  4928. DEBUG_INFO("BootNotification_20 size: %d\n", sizeof(struct BootNotification_20));
  4929. DEBUG_INFO("CancelReservation_20 size: %d\n", sizeof(struct CancelReservation_20));
  4930. DEBUG_INFO("CertificateSigned_20 size: %d\n", sizeof(struct CertificateSigned_20));
  4931. DEBUG_INFO("ChangeAvailability_20 size: %d\n", sizeof(struct ChangeAvailability_20));
  4932. DEBUG_INFO("ClearCache_20 size: %d\n", sizeof(struct ClearCache_20));
  4933. DEBUG_INFO("ClearChargingProfile_20 size: %d\n", sizeof(struct ClearChargingProfile_20));
  4934. DEBUG_INFO("ClearDisplayMessage_20 size: %d\n", sizeof(struct ClearDisplayMessage_20));
  4935. DEBUG_INFO("ClearedChargingLimit_20 size: %d\n", sizeof(struct ClearedChargingLimit_20));
  4936. DEBUG_INFO("ClearVariableMonitoring_20 size: %d\n", sizeof(struct ClearVariableMonitoring_20));
  4937. DEBUG_INFO("CostUpdated_20 size: %d\n", sizeof(struct CostUpdated_20));
  4938. DEBUG_INFO("CustomerInformation_20 size: %d\n", sizeof(struct CustomerInformation_20));
  4939. DEBUG_INFO("DeleteCertificate_20 size: %d\n", sizeof(struct DeleteCertificate_20));
  4940. DEBUG_INFO("FirmwareStatusNotification_20 size: %d\n", sizeof(struct FirmwareStatusNotification_20));
  4941. DEBUG_INFO("Get15118EVCertificate_20 size: %d\n", sizeof(struct Get15118EVCertificate_20));
  4942. DEBUG_INFO("GetBaseReport_20 size: %d\n", sizeof(struct GetBaseReport_20));
  4943. DEBUG_INFO("GetCertificateStatus_20 size: %d\n", sizeof(struct GetCertificateStatus_20));
  4944. DEBUG_INFO("GetChargingProfiles_20 size: %d\n", sizeof(struct GetChargingProfiles_20));
  4945. DEBUG_INFO("GetCompositeSchedule_20 size: %d\n", sizeof(struct GetCompositeSchedule_20));
  4946. DEBUG_INFO("GetDisplayMessages_20 size: %d\n", sizeof(struct GetDisplayMessages_20));
  4947. DEBUG_INFO("GetInstalledCertificateIds_20 size: %d\n", sizeof(struct GetInstalledCertificateIds_20));
  4948. DEBUG_INFO("GetLog_20 size: %d\n", sizeof(struct GetLog_20));
  4949. DEBUG_INFO("GetMonitoringReport_20 size: %d\n", sizeof(struct GetMonitoringReport_20));
  4950. DEBUG_INFO("GetReport_20 size: %d\n", sizeof(struct GetReport_20));
  4951. DEBUG_INFO("GetTransactionStatus_20 size: %d\n", sizeof(struct GetTransactionStatus_20));
  4952. DEBUG_INFO("GetVariables_20 size: %d\n", sizeof(struct GetVariables_20));
  4953. DEBUG_INFO("InstallCertificate_20 size: %d\n", sizeof(struct InstallCertificate_20));
  4954. DEBUG_INFO("LogStatusNotification_20 size: %d\n", sizeof(struct LogStatusNotification_20));
  4955. DEBUG_INFO("MeterValues_20 size: %d\n", sizeof(struct MeterValues_20));
  4956. DEBUG_INFO("NotifyChargingLimit_20 size: %d\n", sizeof(struct NotifyChargingLimit_20));
  4957. DEBUG_INFO("NotifyCustomerInformation_20 size: %d\n", sizeof(struct NotifyCustomerInformation_20));
  4958. DEBUG_INFO("NotifyDisplayMessages_20 size: %d\n", sizeof(struct NotifyDisplayMessages_20));
  4959. DEBUG_INFO("NotifyEVChargingNeeds_20 size: %d\n", sizeof(struct NotifyEVChargingNeeds_20));
  4960. DEBUG_INFO("NotifyEVChargingSchedule_20 size: %d\n", sizeof(struct NotifyEVChargingSchedule_20));
  4961. DEBUG_INFO("NotifyEvent_20 size: %d\n", sizeof(struct NotifyEvent_20));
  4962. DEBUG_INFO("NotifyMonitoringReport_20 size: %d\n", sizeof(struct NotifyMonitoringReport_20));
  4963. DEBUG_INFO("NotifyReport_20 size: %d\n", sizeof(struct NotifyReport_20));
  4964. DEBUG_INFO("PublishFirmware_20 size: %d\n", sizeof(struct PublishFirmware_20));
  4965. DEBUG_INFO("PublishFirmwareStatusNotification_20 size: %d\n", sizeof(struct PublishFirmwareStatusNotification_20));
  4966. DEBUG_INFO("ReportChargingProfiles_20 size: %d\n", sizeof(struct ReportChargingProfiles_20));
  4967. DEBUG_INFO("RequestStartTransaction_20 size: %d\n", sizeof(struct RequestStartTransaction_20));
  4968. DEBUG_INFO("RequestStopTransaction_20 size: %d\n", sizeof(struct RequestStopTransaction_20));
  4969. DEBUG_INFO("ReservationStatusUpdate_20 size: %d\n", sizeof(struct ReservationStatusUpdate_20));
  4970. DEBUG_INFO("ReserveNow_20 size: %d\n", sizeof(struct ReserveNow_20));
  4971. DEBUG_INFO("Reset_20 size: %d\n", sizeof(struct Reset_20));
  4972. DEBUG_INFO("SecurityEventNotification_20 size: %d\n", sizeof(struct SecurityEventNotification_20));
  4973. DEBUG_INFO("SendLocalList_20 size: %d\n", sizeof(struct SendLocalList_20));
  4974. DEBUG_INFO("SetChargingProfile_20 size: %d\n", sizeof(struct SetChargingProfile_20));
  4975. DEBUG_INFO("SetDisplayMessage_20 size: %d\n", sizeof(struct SetDisplayMessage_20));
  4976. DEBUG_INFO("SetMonitoringBase_20 size: %d\n", sizeof(struct SetMonitoringBase_20));
  4977. DEBUG_INFO("SetMonitoringLevel_20 size: %d\n", sizeof(struct SetMonitoringLevel_20));
  4978. DEBUG_INFO("SetNetworkProfile_20 size: %d\n", sizeof(struct SetNetworkProfile_20));
  4979. DEBUG_INFO("SetVariableMonitoring_20 size: %d\n", sizeof(struct SetVariableMonitoring_20));
  4980. DEBUG_INFO("SetVariables_20 size: %d\n", sizeof(struct SetVariables_20));
  4981. DEBUG_INFO("SignCertificate_20 size: %d\n", sizeof(struct SignCertificate_20));
  4982. DEBUG_INFO("StatusNotification_20 size: %d\n", sizeof(struct StatusNotification_20));
  4983. DEBUG_INFO("TransactionEvent_20 size: %d\n", sizeof(struct TransactionEvent_20));
  4984. DEBUG_INFO("TriggerMessage_20 size: %d\n", sizeof(struct TriggerMessage_20));
  4985. DEBUG_INFO("UnlockConnector_20 size: %d\n", sizeof(struct UnlockConnector_20));
  4986. DEBUG_INFO("UnpublishFirmware_20 size: %d\n", sizeof(struct UnpublishFirmware_20));
  4987. DEBUG_INFO("UpdateFirmware_20 size: %d\n", sizeof(struct UpdateFirmware_20));
  4988. DEBUG_INFO("ChargingProfileType size: %d\n", sizeof(struct ChargingProfileType));
  4989. */
  4990. return result;
  4991. }
  4992. int ProcessShareMemory()
  4993. {
  4994. if(InitShareMemory() == FAIL)
  4995. {
  4996. DEBUG_ERROR("InitShareMemory NG\n");
  4997. if(ShmStatusCodeData!=NULL)
  4998. {
  4999. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  5000. }
  5001. sleep(5);
  5002. return FAIL;
  5003. }
  5004. return PASS;
  5005. }
  5006. //---------------------common routine---------------------------//
  5007. void checkNetworkProfile(void)
  5008. {
  5009. memcpy(ShmOCPP20Data->OcppServerURL, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmOCPP20Data->OcppServerURL));
  5010. json_object *priority;
  5011. priority = json_tokener_parse((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value);
  5012. if(!is_error(priority))
  5013. {
  5014. for(uint8_t idxPriority=0;idxPriority<json_object_array_length(priority);idxPriority++)
  5015. {
  5016. for(uint8_t idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile);idx++)
  5017. {
  5018. if((ShmOCPP20Data->NetworkConnectionProfile[idx].slot == json_object_get_int(json_object_array_get_idx(priority, idxPriority))) &&
  5019. (strlen((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl) > 0) &&
  5020. (ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount < 3))
  5021. {
  5022. memcpy(ShmOCPP20Data->OcppServerURL, ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl));
  5023. ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount++;
  5024. break;
  5025. }
  5026. }
  5027. }
  5028. }
  5029. json_object_put(priority);
  5030. DEBUG_INFO("Get network profile URL: %s\n", ShmOCPP20Data->OcppServerURL);
  5031. }
  5032. void CheckSystemValue(void)
  5033. {
  5034. char filenmae[100]={0};
  5035. char str[100]={0};
  5036. int tempIndex = 0;
  5037. //===============================
  5038. // EVSE operation check
  5039. //===============================
  5040. //===============================
  5041. // Heartbeat check
  5042. //===============================
  5043. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  5044. {
  5045. clientTime.Heartbeat = time((time_t*)NULL);
  5046. if(server_sign == TRUE)
  5047. {
  5048. HeartBeatWaitTime = ShmOCPP20Data->BootNotification.Response_interval;
  5049. }
  5050. else
  5051. {
  5052. HeartBeatWaitTime = atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value);
  5053. }
  5054. }
  5055. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  5056. {
  5057. //parameter for test
  5058. sendHeartbeatRequest(0);
  5059. //==============================================
  5060. // Reset Waiting Time
  5061. //==============================================
  5062. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  5063. }
  5064. //===============================
  5065. // CSU Trigger Authorize Request
  5066. //===============================
  5067. if(isWebsocketSendable &&
  5068. (server_sign == TRUE) &&
  5069. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON) &&
  5070. (authorizeRetryTimes < 3))
  5071. {
  5072. sendAuthorizeRequest(0);
  5073. authorizeRetryTimes = authorizeRetryTimes + 1;
  5074. if(authorizeRetryTimes < 3)
  5075. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  5076. }
  5077. else if((server_sign == TRUE) &&
  5078. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON) &&
  5079. (authorizeRetryTimes >= 3))
  5080. {
  5081. authorizeRetryTimes = 0;
  5082. SetOcppConnStatus(FALSE);
  5083. server_sign = FALSE;
  5084. }
  5085. else if((server_sign == FALSE) &&
  5086. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "TRUE") == 0) &&
  5087. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].value, "TRUE") == 0) &&
  5088. (ShmOCPP20Data->OcppConnStatus == OFF) &&
  5089. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON))
  5090. {
  5091. sendAuthorizeRequest(0);
  5092. }
  5093. if(isWebsocketSendable &&
  5094. (server_sign == TRUE) &&
  5095. (ShmOCPP20Data->GetMonitoringReport.requestId > 0))
  5096. {
  5097. for(uint8_t idxCriterion=0;idxCriterion<ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.monitoringCriteria);idxCriterion++)
  5098. {
  5099. if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_ThresholdMonitoring]) == 0)
  5100. {
  5101. /*
  5102. * TODO:
  5103. * 1. Report component that are ThresholdMonitoring
  5104. */
  5105. }
  5106. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_DeltaMonitoring]) == 0)
  5107. {
  5108. /*
  5109. * TODO:
  5110. * 1. Report component that are DeltaMonitoring
  5111. */
  5112. }
  5113. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_PeriodicMonitoring]) == 0)
  5114. {
  5115. /*
  5116. * TODO:
  5117. * 1. Report component that are PeriodicMonitoring
  5118. */
  5119. }
  5120. else
  5121. {
  5122. /*
  5123. * TODO:
  5124. * 1. Process unknown criteria condition
  5125. */
  5126. }
  5127. }
  5128. ShmOCPP20Data->GetMonitoringReport.requestId = 0;
  5129. }
  5130. if(isWebsocketSendable &&
  5131. (server_sign == TRUE) &&
  5132. (ShmOCPP20Data->GetReport.requestId > 0))
  5133. {
  5134. for(uint8_t idxCriterion=0;idxCriterion<ARRAY_SIZE(ShmOCPP20Data->GetReport.componentCriteria);idxCriterion++)
  5135. {
  5136. if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Active]) == 0)
  5137. {
  5138. /*
  5139. * TODO:
  5140. * 1. Report component that are active
  5141. */
  5142. }
  5143. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Available]) == 0)
  5144. {
  5145. /*
  5146. * TODO:
  5147. * 1. Report component that are available
  5148. */
  5149. }
  5150. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Enabled]) == 0)
  5151. {
  5152. /*
  5153. * TODO:
  5154. * 1. Report component that are enable
  5155. */
  5156. }
  5157. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Problem]) == 0)
  5158. {
  5159. /*
  5160. * TODO:
  5161. * 1. Report component that are problem
  5162. */
  5163. }
  5164. else
  5165. {
  5166. /*
  5167. * TODO:
  5168. * 1. Process unknown criteria condition
  5169. */
  5170. }
  5171. }
  5172. ShmOCPP20Data->GetReport.requestId = 0;
  5173. }
  5174. if(isWebsocketSendable &&
  5175. (server_sign == TRUE) &&
  5176. (ShmOCPP20Data->GetBaseReport.requestId > 0))
  5177. {
  5178. uint8_t reportIdx = 0;
  5179. ShmOCPP20Data->NotifyReport.requestId = ShmOCPP20Data->GetBaseReport.requestId;
  5180. if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_ConfigurationInventory]) == 0)
  5181. {
  5182. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  5183. {
  5184. if(reportIdx < ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData))
  5185. {
  5186. 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))
  5187. {
  5188. memcpy(&ShmOCPP20Data->NotifyReport.reportData[reportIdx], &ShmOCPP20Data->ControllerComponentVariable[idx_var], sizeof(struct ReportDataType));
  5189. reportIdx++;
  5190. }
  5191. }
  5192. else
  5193. {
  5194. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  5195. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  5196. ShmOCPP20Data->NotifyReport.seqNo += 1;
  5197. else
  5198. ShmOCPP20Data->NotifyReport.seqNo = 0;
  5199. sendNotifyReportRequest();
  5200. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  5201. reportIdx = 0;
  5202. }
  5203. }
  5204. }
  5205. else if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_FullInventory]) == 0)
  5206. {
  5207. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  5208. {
  5209. if(reportIdx < ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData))
  5210. {
  5211. memcpy(&ShmOCPP20Data->NotifyReport.reportData[reportIdx], &ShmOCPP20Data->ControllerComponentVariable[idx_var], sizeof(struct ReportDataType));
  5212. reportIdx++;
  5213. }
  5214. else
  5215. {
  5216. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  5217. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  5218. ShmOCPP20Data->NotifyReport.seqNo += 1;
  5219. else
  5220. ShmOCPP20Data->NotifyReport.seqNo = 0;
  5221. sendNotifyReportRequest();
  5222. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  5223. reportIdx = 0;
  5224. }
  5225. }
  5226. }
  5227. else
  5228. {
  5229. /*
  5230. * TODO:
  5231. * 1. Fill out summary inventory to response message, currently not support
  5232. */
  5233. }
  5234. if(reportIdx > 0)
  5235. {
  5236. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  5237. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  5238. ShmOCPP20Data->NotifyReport.seqNo += 1;
  5239. else
  5240. ShmOCPP20Data->NotifyReport.seqNo = 0;
  5241. sendNotifyReportRequest();
  5242. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  5243. reportIdx = 0;
  5244. }
  5245. ShmOCPP20Data->GetBaseReport.requestId = 0;
  5246. }
  5247. if(isWebsocketSendable &&
  5248. (server_sign == TRUE) &&
  5249. ShmOCPP20Data->SpMsg.bits.NotifyEventReq)
  5250. {
  5251. getNowDatetime(ShmOCPP20Data->NotifyEvent.generatedAt);
  5252. ShmOCPP20Data->NotifyEvent.tbc = FALSE;
  5253. if(ShmOCPP20Data->NotifyEvent.seqNo < INT_MAX)
  5254. ShmOCPP20Data->NotifyEvent.seqNo += 1;
  5255. else
  5256. ShmOCPP20Data->NotifyEvent.seqNo = 0;
  5257. sendNotifyEventRequest();
  5258. memset(&ShmOCPP20Data->NotifyEvent.eventData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)* sizeof(struct EventDataType ));
  5259. ShmOCPP20Data->SpMsg.bits.NotifyEventReq = OFF;
  5260. }
  5261. if(isWebsocketSendable &&
  5262. (server_sign == TRUE) &&
  5263. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq)
  5264. {
  5265. if(strcmp((char*)ShmOCPP20Data->Get15118EVCertificate.action, CertificateActionEnumTypeStr[CertificateActionEnumType_Install]) == 0)
  5266. {
  5267. /*
  5268. * TODO:
  5269. * 1.
  5270. */
  5271. }
  5272. else if(strcmp((char*)ShmOCPP20Data->Get15118EVCertificate.action, CertificateActionEnumTypeStr[CertificateActionEnumType_Update]) == 0)
  5273. {
  5274. /*
  5275. * TODO:
  5276. * 1.
  5277. */
  5278. }
  5279. else
  5280. {
  5281. /*
  5282. * TODO:
  5283. * 1.
  5284. */
  5285. }
  5286. sendGet15118EVCertificateRequest();
  5287. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq = OFF;
  5288. }
  5289. //===============================
  5290. // Each connector operation check
  5291. //===============================
  5292. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  5293. {
  5294. //==========================================
  5295. // csu trigger DataTransferReq
  5296. //==========================================
  5297. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].DataTransferReq == ON))
  5298. {
  5299. sendDataTransferRequest(gun_index);
  5300. ShmOCPP20Data->CsMsg.bits[gun_index].DataTransferReq = OFF;
  5301. }
  5302. //==============================================
  5303. // Charger start transaction
  5304. //==============================================
  5305. /*
  5306. if((ShmOCPP20Data->CpMsg.bits[gun_index].StartTransactionReq == ON))
  5307. {
  5308. ShmOCPP20Data->CpMsg.bits[gun_index].StartTransactionReq = OFF;
  5309. sendStartTransactionRequest(gun_index);
  5310. clientTime.StartTransaction = time((time_t*)NULL);
  5311. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  5312. }*/
  5313. //==============================================
  5314. // Charger stop transaction
  5315. //==============================================
  5316. /*
  5317. if(((ShmOCPP20Data->CpMsg.bits[gun_index].StopTransactionReq == ON)))
  5318. {
  5319. ShmOCPP20Data->CpMsg.bits[gun_index].StopTransactionReq =OFF;
  5320. sendStopTransactionRequest(gun_index);
  5321. clientTime.StopTransaction = time((time_t*)NULL);
  5322. }*/
  5323. //==============================================
  5324. // Charger status notification & Transaction event report
  5325. //==============================================
  5326. //--- Check Mode Change ---//
  5327. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  5328. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5329. {
  5330. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5331. {
  5332. tempIndex = ((gun_index==2) ? 1: 0);
  5333. }
  5334. else
  5335. {
  5336. tempIndex = gun_index;
  5337. }
  5338. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5339. {
  5340. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5341. {
  5342. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  5343. {
  5344. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  5345. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  5346. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  5347. if((SystemInitial == 0) &&
  5348. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING) &&
  5349. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_COMPLETE))
  5350. {
  5351. cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
  5352. }
  5353. }
  5354. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  5355. {
  5356. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5357. if((access(filenmae,F_OK))!=-1)
  5358. {
  5359. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5360. sprintf(str,"rm -f %s",filenmae);
  5361. system(str);
  5362. }
  5363. }
  5364. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5365. #if 1 // for TempStopTransaction
  5366. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5367. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  5368. {
  5369. checkTempStopTransaction(gun_index);
  5370. }
  5371. #endif
  5372. }
  5373. }
  5374. }
  5375. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5376. {
  5377. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5378. {
  5379. tempIndex = ((gun_index==2) ? 1: 0);
  5380. }
  5381. else
  5382. {
  5383. tempIndex = gun_index;
  5384. }
  5385. for (int index = 0; index < CCS_QUANTITY; index++)
  5386. {
  5387. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5388. {
  5389. 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]*/ )
  5390. {
  5391. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  5392. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  5393. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  5394. if((SystemInitial == 0) &&
  5395. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_PREPARING) &&
  5396. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_COMPLETE))
  5397. {
  5398. cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
  5399. }
  5400. }
  5401. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  5402. {
  5403. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5404. if((access(filenmae,F_OK))!=-1)
  5405. {
  5406. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5407. sprintf(str,"rm -f %s",filenmae);
  5408. system(str);
  5409. }
  5410. }
  5411. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5412. #if 1 // for TempStopTransaction
  5413. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5414. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  5415. {
  5416. checkTempStopTransaction(gun_index);
  5417. }
  5418. #endif
  5419. }
  5420. }
  5421. }
  5422. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5423. {
  5424. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5425. {
  5426. tempIndex = ((gun_index==2) ? 1: 0);
  5427. }
  5428. else
  5429. {
  5430. tempIndex = gun_index;
  5431. }
  5432. for (int index = 0; index < GB_QUANTITY; index++)
  5433. {
  5434. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5435. {
  5436. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  5437. {
  5438. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  5439. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  5440. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  5441. if((SystemInitial == 0) &&
  5442. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_PREPARING) &&
  5443. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_COMPLETE))
  5444. {
  5445. cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
  5446. }
  5447. }
  5448. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  5449. {
  5450. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5451. if((access(filenmae,F_OK))!=-1)
  5452. {
  5453. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5454. sprintf(str,"rm -f %s",filenmae);
  5455. system(str);
  5456. }
  5457. }
  5458. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5459. #if 1 // for TempStopTransaction
  5460. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5461. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  5462. {
  5463. checkTempStopTransaction(gun_index);
  5464. }
  5465. #endif
  5466. }
  5467. }
  5468. }
  5469. else if(gunType[gun_index] == GUN_TYPE_DO)
  5470. {
  5471. tempIndex = gun_index;
  5472. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5473. {
  5474. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5475. {
  5476. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  5477. {
  5478. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  5479. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  5480. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  5481. if((SystemInitial == 0) &&
  5482. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_PREPARING) &&
  5483. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_COMPLETE))
  5484. {
  5485. cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
  5486. }
  5487. }
  5488. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // complete
  5489. {
  5490. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5491. if((access(filenmae,F_OK))!=-1)
  5492. {
  5493. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5494. sprintf(str,"rm -f %s",filenmae);
  5495. system(str);
  5496. }
  5497. }
  5498. 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);
  5499. #if 1 // for TempStopTransaction
  5500. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  5501. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  5502. {
  5503. checkTempStopTransaction(gun_index);
  5504. }
  5505. #endif
  5506. }
  5507. }
  5508. }
  5509. else
  5510. {
  5511. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5512. {
  5513. tempIndex = 2;
  5514. }
  5515. else
  5516. {
  5517. tempIndex = gun_index;
  5518. }
  5519. for (int index = 0; index < AC_QUANTITY; index++)
  5520. {
  5521. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5522. {
  5523. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  5524. {
  5525. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  5526. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  5527. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  5528. if((SystemInitial == 0) &&
  5529. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_PREPARING) &&
  5530. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_COMPLETE))
  5531. {
  5532. cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
  5533. }
  5534. }
  5535. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  5536. {
  5537. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5538. if((access(filenmae,F_OK))!=-1)
  5539. {
  5540. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5541. sprintf(str,"rm -f %s",filenmae);
  5542. system(str);
  5543. }
  5544. }
  5545. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5546. #if 1 // for TempStopTransaction
  5547. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5548. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  5549. {
  5550. checkTempStopTransaction(gun_index);
  5551. }
  5552. #endif
  5553. }
  5554. }// END
  5555. }
  5556. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  5557. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == ON) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == ON)) )
  5558. {
  5559. if(SystemInitial > 0)
  5560. SystemInitial -= 1;
  5561. sendStatusNotificationRequest(gun_index);
  5562. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  5563. }
  5564. //===============================
  5565. // CSU Trigger Smart Charging Profilw
  5566. //===============================
  5567. if(ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq == ON)
  5568. {
  5569. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP20Data->SmartChargingProfile[gun_index], 0, TRUE);
  5570. ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq = OFF;
  5571. }
  5572. if(isWebsocketSendable && (server_sign == TRUE) && (cpinitateMsg.bits[gun_index].TransactionEventReq == ON))
  5573. {
  5574. sendTransactionEventRequest(gun_index);
  5575. cpinitateMsg.bits[gun_index].TransactionEventReq = OFF;
  5576. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0], 0x00, sizeof(struct MeterValueType));
  5577. }
  5578. //==============================================
  5579. // Meter report
  5580. //==============================================
  5581. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValueReq)
  5582. {
  5583. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Trigger);
  5584. cpinitateMsg.bits[gun_index].TriggerMeterValueReq = OFF;
  5585. }
  5586. // ClockAlign MeterValue
  5587. 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))
  5588. {
  5589. //check Transaction active
  5590. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5591. {
  5592. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5593. {
  5594. tempIndex = ((gun_index==2) ? 1: 0);
  5595. }
  5596. else
  5597. {
  5598. tempIndex = gun_index;
  5599. }
  5600. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5601. {
  5602. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5603. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5604. {
  5605. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  5606. }
  5607. }// End for CHAdeMO
  5608. }
  5609. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5610. {
  5611. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5612. {
  5613. tempIndex = ((gun_index==2) ? 1: 0);
  5614. }
  5615. else
  5616. {
  5617. tempIndex = gun_index;
  5618. }
  5619. for (int index = 0; index < CCS_QUANTITY; index++)
  5620. {
  5621. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5622. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5623. {
  5624. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  5625. }
  5626. } // End for CCS
  5627. }
  5628. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5629. {
  5630. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5631. {
  5632. tempIndex = ((gun_index==2) ? 1: 0);
  5633. }
  5634. else
  5635. {
  5636. tempIndex = gun_index;
  5637. }
  5638. for (int index = 0; index < GB_QUANTITY; index++)
  5639. {
  5640. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5641. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5642. {
  5643. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  5644. }
  5645. }// End for GB
  5646. }
  5647. else if(gunType[gun_index] == GUN_TYPE_DO)
  5648. {
  5649. tempIndex = gun_index;
  5650. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5651. {
  5652. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5653. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5654. {
  5655. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  5656. }
  5657. }
  5658. }
  5659. else
  5660. {
  5661. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5662. {
  5663. tempIndex = 2;
  5664. }
  5665. else
  5666. {
  5667. tempIndex = gun_index;
  5668. }
  5669. for (int index = 0; index < AC_QUANTITY; index++)
  5670. {
  5671. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5672. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5673. {
  5674. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  5675. }
  5676. }//End for AC
  5677. }
  5678. if(cpinitateMsg.bits[gun_index].ClockAlignMeterReq == ON)
  5679. {
  5680. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Clock);
  5681. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = OFF;
  5682. }
  5683. }
  5684. // Sample period MeterValue
  5685. if((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > ((atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value)>10)?(atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value)- 1):10))
  5686. {
  5687. //check Transaction active
  5688. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5689. {
  5690. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5691. {
  5692. tempIndex = ((gun_index==2) ? 1: 0);
  5693. }
  5694. else
  5695. {
  5696. tempIndex = gun_index;
  5697. }
  5698. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5699. {
  5700. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5701. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5702. {
  5703. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5704. {
  5705. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  5706. }
  5707. }
  5708. }// End for CHAdeMO
  5709. }
  5710. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5711. {
  5712. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5713. {
  5714. tempIndex = ((gun_index==2) ? 1: 0);
  5715. }
  5716. else
  5717. {
  5718. tempIndex = gun_index;
  5719. }
  5720. for (int index = 0; index < CCS_QUANTITY; index++)
  5721. {
  5722. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5723. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5724. {
  5725. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5726. {
  5727. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  5728. }
  5729. }
  5730. } // End for CCS
  5731. }
  5732. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5733. {
  5734. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5735. {
  5736. tempIndex = ((gun_index==2) ? 1: 0);
  5737. }
  5738. else
  5739. {
  5740. tempIndex = gun_index;
  5741. }
  5742. for (int index = 0; index < GB_QUANTITY; index++)
  5743. {
  5744. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5745. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5746. {
  5747. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5748. {
  5749. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  5750. }
  5751. }
  5752. }// End for GB
  5753. }
  5754. else if(gunType[gun_index] == GUN_TYPE_DO)
  5755. {
  5756. tempIndex = gun_index;
  5757. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5758. {
  5759. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5760. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5761. {
  5762. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  5763. {
  5764. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  5765. }
  5766. }
  5767. }
  5768. }
  5769. else
  5770. {
  5771. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5772. {
  5773. tempIndex = 2;
  5774. }
  5775. else
  5776. {
  5777. tempIndex = gun_index;
  5778. }
  5779. for (int index = 0; index < AC_QUANTITY; index++)
  5780. {
  5781. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5782. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5783. {
  5784. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5785. {
  5786. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  5787. }
  5788. }
  5789. }//End for AC
  5790. }
  5791. if(cpinitateMsg.bits[gun_index].SampleMeterReq == ON)
  5792. {
  5793. if(atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value) > 0)
  5794. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic);
  5795. storeTempStopTransaction(gun_index);
  5796. cpinitateMsg.bits[gun_index].SampleMeterReq = OFF;
  5797. }
  5798. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  5799. }
  5800. //==============================================
  5801. // Check Connector reserved
  5802. //==============================================
  5803. //===============================
  5804. // Check if Reserve is expired
  5805. //===============================
  5806. if((server_sign == TRUE) && (ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime[0] != 0) )
  5807. {
  5808. double diff_t;
  5809. struct tm tp;
  5810. // current time
  5811. time_t t = time(NULL);
  5812. strptime((char *)ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime, "%Y-%m-%dT%H:%M:%S", &tp);
  5813. tp.tm_isdst = -1;
  5814. time_t utc = mktime(&tp);
  5815. diff_t = difftime(utc, t);
  5816. if(diff_t <= 0)
  5817. {
  5818. DEBUG_INFO("reserve expired.\n");
  5819. memset(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime,0,ARRAY_SIZE(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime));
  5820. }
  5821. }//END OF Check if Reserve is expired
  5822. //==========================================
  5823. // csu trigger FirmwareStatusNotificationReq
  5824. //==========================================
  5825. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq == ON))
  5826. {
  5827. sendFirmwareStatusNotificationRequest((char *)ShmOCPP20Data->FirmwareStatusNotification.status);
  5828. }
  5829. //==========================================
  5830. // csu cleared charging limit request
  5831. //==========================================
  5832. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq == ON))
  5833. {
  5834. sendClearedChargingLimitRequest(gun_index);
  5835. }
  5836. //==========================================
  5837. // csu trigger CancelReservationConf
  5838. //==========================================
  5839. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationConf == ON))
  5840. {
  5841. sendCancelReservationConfirmation((char *)ShmOCPP20Data->CancelReservation[gun_index].guid, gun_index);
  5842. }
  5843. //==========================================
  5844. // csu notify EV charging need request
  5845. //==========================================
  5846. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsReq == ON))
  5847. {
  5848. sendNotifyEVChargingNeedsRequest(gun_index);
  5849. }
  5850. //==========================================
  5851. // csu trigger ChangeAvailabilityConf
  5852. //==========================================
  5853. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == ON))
  5854. {
  5855. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP20Data->ChangeAvailability[gun_index].ResponseStatus);
  5856. }
  5857. //==========================================
  5858. // csu trigger UnlockConnectorConf
  5859. //==========================================
  5860. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf == ON))
  5861. {
  5862. sendUnlockConnectorConfirmation((char *)ShmOCPP20Data->UnlockConnector[gun_index].guid, gun_index);
  5863. }
  5864. //==========================================
  5865. // csu trigger ReserveNowConf
  5866. //==========================================
  5867. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf == ON))
  5868. {
  5869. sendReserveNowConfirmation((char *)ShmOCPP20Data->ReserveNow[gun_index].guid, gun_index);
  5870. }
  5871. //==========================================
  5872. // csu trigger ReserveNowConf
  5873. //==========================================
  5874. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq == ON))
  5875. {
  5876. sendReservationStatusUpdateRequest(gun_index);
  5877. }
  5878. //==========================================
  5879. // csu trigger LogStatusNotificationReq
  5880. //==========================================
  5881. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq == ON))
  5882. {
  5883. sendLogStatusNotificationRequest((char *)ShmOCPP20Data->LogStatusNotification.status);
  5884. }
  5885. //==========================================
  5886. // csu trigger SignCertificateReq
  5887. //==========================================
  5888. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.SignCertificateReq == ON))
  5889. {
  5890. if((access("/Storage/OCPP/certCP.csr",F_OK) != -1) &&
  5891. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) == 0) )
  5892. {
  5893. sendSignCertificateRequest(CertificateSignedStatusEnumType_ChargingStationCertificate);
  5894. }
  5895. else if((access("/Storage/OCPP/certV2G.csr",F_OK) != -1) &&
  5896. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0))
  5897. {
  5898. sendSignCertificateRequest(CertificateSignedStatusEnumType_V2GCertificate);
  5899. }
  5900. }
  5901. }
  5902. }
  5903. //==========================================
  5904. // send request routine
  5905. //==========================================
  5906. int sendAuthorizeRequest(int gun_index)
  5907. {
  5908. mtrace();
  5909. int result = FAIL;
  5910. char message[4096]={0};
  5911. char guid[37];
  5912. char tempdata[128]={0};
  5913. json_object *Authorize = json_object_new_object();
  5914. json_object *idToken = json_object_new_object();
  5915. DEBUG_INFO("sendAuthorizeRequest...\n");
  5916. memset(&(ShmOCPP20Data->Authorize.Response_idTokenInfo),0,sizeof(struct IdTokenInfoType));
  5917. //Local Authorize
  5918. if ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].value, "TRUE")==0) && (ShmOCPP20Data->OcppConnStatus == 0))
  5919. {
  5920. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  5921. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "");
  5922. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, "");
  5923. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]);
  5924. result = PASS;
  5925. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  5926. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  5927. authorizeRetryTimes = 0;
  5928. return result;
  5929. }
  5930. 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)) ||
  5931. ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].value, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "TRUE") == 0)))
  5932. {
  5933. // Query idtag from cache
  5934. DB_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId, TRUE);
  5935. // Query idtag from list
  5936. if((strcmp((char*)idTagQuery.idToken.idToken,"") == 0) || (strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0) )
  5937. DB_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId, FALSE);
  5938. if((strcmp((char*)idTagQuery.idToken.idToken,"") == 0) || (strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0) )
  5939. {
  5940. if(strcmp((char*)idTagQuery.idToken.idToken,"") == 0)
  5941. {
  5942. DEBUG_INFO("Card %s does not find in list or cache\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5943. }
  5944. if(strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0)
  5945. {
  5946. DEBUG_INFO("Card %s does not accepted in list and cache\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5947. }
  5948. // Return authorize result if does not connect to server
  5949. if(!ShmOCPP20Data->OcppConnStatus)
  5950. {
  5951. DEBUG_INFO("Local Authorization Fail.\n");
  5952. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "");
  5953. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5954. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Invalid]);
  5955. DEBUG_INFO("ShmOCPP20Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
  5956. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  5957. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  5958. authorizeRetryTimes = 0;
  5959. return result;
  5960. }
  5961. }
  5962. else
  5963. {
  5964. DEBUG_INFO("Local Authorization get result.\n");
  5965. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, (char*)idTagQuery.idTokenInfo.cacheExpiryDateTime);
  5966. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5967. if(isOvertNow((uint8_t*)&idTagQuery.idTokenInfo.cacheExpiryDateTime[0]))
  5968. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Expired]);
  5969. else
  5970. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, (char*)idTagQuery.idTokenInfo.status);
  5971. DEBUG_INFO("ShmOCPP20Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
  5972. result = PASS;
  5973. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  5974. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  5975. authorizeRetryTimes = 0;
  5976. return result;
  5977. }
  5978. }
  5979. //get data from shared memory
  5980. strcpy((char *)ShmOCPP20Data->Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5981. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.idToken));
  5982. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.type));
  5983. json_object_object_add(Authorize, "idToken", idToken);
  5984. random_uuid(guid);
  5985. sprintf(message,"[%d,\"%s\",\"Authorize\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(Authorize, JSON_C_TO_STRING_PLAIN));
  5986. json_object_put(Authorize);
  5987. LWS_Send(message);
  5988. sprintf(tempdata, "Authorize,%d", gun_index);
  5989. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5990. {
  5991. result = PASS;
  5992. }
  5993. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  5994. return result;
  5995. }
  5996. int sendBootNotificationRequest()
  5997. {
  5998. mtrace();
  5999. int result = FAIL;
  6000. char message[4096]={0};
  6001. char guid[37]={0};
  6002. char tempdata[128]={0};
  6003. json_object *BootNotification = json_object_new_object();
  6004. json_object *chargingStation = json_object_new_object();
  6005. json_object *modem = json_object_new_object();
  6006. DEBUG_INFO("sendBootNotificationRequest...\n");
  6007. // Fill BootNotification fields
  6008. DB_getBooType();
  6009. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.model, "%s", ShmSysConfigAndInfo->SysConfig.ModelName);
  6010. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.vendorName, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  6011. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.serialNumber, "%s", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  6012. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.firmwareVersion, "%s", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  6013. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.modem.iccid, "%s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  6014. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.modem.imsi, "%s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  6015. if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
  6016. {
  6017. json_object_object_add(modem, "iccid", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.modem.iccid));
  6018. json_object_object_add(modem, "imsi", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.modem.imsi));
  6019. json_object_object_add(chargingStation, "modem", modem);
  6020. }
  6021. json_object_object_add(chargingStation, "model", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.model));
  6022. json_object_object_add(chargingStation, "vendorName", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.vendorName));
  6023. json_object_object_add(chargingStation, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.serialNumber));
  6024. json_object_object_add(chargingStation, "firmwareVersion", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.firmwareVersion));
  6025. json_object_object_add(BootNotification, "chargingStation", chargingStation);
  6026. json_object_object_add(BootNotification, "reason", json_object_new_string((char*)ShmOCPP20Data->BootNotification.reason));
  6027. random_uuid(guid);
  6028. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", json_object_to_json_string_ext(BootNotification, JSON_C_TO_STRING_PLAIN));
  6029. json_object_put(BootNotification);
  6030. LWS_Send(message);
  6031. sprintf(tempdata, "BootNotification,0");
  6032. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6033. {
  6034. result = PASS;
  6035. }
  6036. return result;
  6037. }
  6038. int sendClearedChargingLimitRequest(int gun_index)
  6039. {
  6040. mtrace();
  6041. int result = FAIL;
  6042. char message[4096]={0};
  6043. char guid[37]={0};
  6044. char tempdata[128]={0};
  6045. json_object *ClearedChargingLimit = json_object_new_object();
  6046. DEBUG_INFO("sendClearedChargingLimitRequest...\n");
  6047. json_object_object_add(ClearedChargingLimit, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->ClearedChargingLimit[gun_index].chargingLimitSource));
  6048. json_object_object_add(ClearedChargingLimit, "evseId", json_object_new_int(ShmOCPP20Data->ClearedChargingLimit[gun_index].evseId));
  6049. random_uuid(guid);
  6050. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ClearedChargingLimit", json_object_to_json_string_ext(ClearedChargingLimit, JSON_C_TO_STRING_PLAIN));
  6051. json_object_put(ClearedChargingLimit);
  6052. LWS_Send(message);
  6053. sprintf(tempdata, "ClearedChargingLimit,%d", gun_index);
  6054. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6055. {
  6056. result = PASS;
  6057. }
  6058. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq = OFF;
  6059. return result;
  6060. }
  6061. int sendDataTransferRequest(int gun_index)
  6062. {
  6063. mtrace();
  6064. char message[1000]={0};
  6065. char guid[37]={0};
  6066. char tempdata[65]={0};
  6067. int result = FAIL;
  6068. DEBUG_INFO("sendDataTransferRequest...\n");
  6069. random_uuid(guid);
  6070. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  6071. MESSAGE_TYPE_CALL,
  6072. guid,
  6073. ShmOCPP20Data->DataTransfer[gun_index].vendorId,
  6074. ShmOCPP20Data->DataTransfer[gun_index].messageId,
  6075. ShmOCPP20Data->DataTransfer[gun_index].data);
  6076. LWS_Send(message);
  6077. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  6078. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6079. {
  6080. result = PASS;
  6081. }
  6082. return result;
  6083. }
  6084. int sendFirmwareStatusNotificationRequest(char *status)
  6085. {
  6086. mtrace();
  6087. int result = FAIL;
  6088. char message[110]={0};
  6089. char guid[37]={0};
  6090. char tempdata[65]={0};
  6091. json_object *FirmwareStatusNotification = json_object_new_object();
  6092. DEBUG_INFO("sendFirmwareStatusNotificationRequest...\n");
  6093. sprintf((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", (const char *)status);
  6094. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  6095. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->FirmwareStatusNotification.status));
  6096. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->FirmwareStatusNotification.requestId));
  6097. random_uuid(guid);
  6098. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6099. json_object_put(FirmwareStatusNotification);
  6100. LWS_SendNow(message);
  6101. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  6102. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6103. {
  6104. result = PASS;
  6105. }
  6106. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = OFF;
  6107. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationConf = OFF;
  6108. //record status
  6109. if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded])==0)
  6110. {
  6111. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Downloaded;
  6112. }
  6113. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed])==0)
  6114. {
  6115. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadFailed;
  6116. }
  6117. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading])==0)
  6118. {
  6119. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Downloading;
  6120. }
  6121. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadScheduled])==0)
  6122. {
  6123. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadScheduled;
  6124. }
  6125. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadPaused])==0)
  6126. {
  6127. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadPaused;
  6128. }
  6129. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle])==0)
  6130. {
  6131. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle;
  6132. }
  6133. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallationFailed])==0)
  6134. {
  6135. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallationFailed;
  6136. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  6137. }
  6138. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Installing])==0)
  6139. {
  6140. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Installing;
  6141. }
  6142. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Installed])==0)
  6143. {
  6144. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Installed;
  6145. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  6146. }
  6147. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallRebooting])==0)
  6148. {
  6149. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallRebooting;
  6150. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  6151. }
  6152. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallScheduled])==0)
  6153. {
  6154. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallScheduled;
  6155. }
  6156. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallVerificationFailed])==0)
  6157. {
  6158. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallVerificationFailed;
  6159. }
  6160. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InvalidSignature])==0)
  6161. {
  6162. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InvalidSignature;
  6163. }
  6164. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_SignatureVerified])==0)
  6165. {
  6166. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_SignatureVerified;
  6167. }
  6168. return result;
  6169. }
  6170. int sendGet15118EVCertificateRequest()
  6171. {
  6172. mtrace();
  6173. int result = FAIL;
  6174. char message[4096]={0};
  6175. char guid[37]={0};
  6176. char tempdata[128]={0};
  6177. json_object *Get15118EVCertificate = json_object_new_object();
  6178. DEBUG_INFO("sendGet15118EVCertificateRequest...\n");
  6179. json_object_object_add(Get15118EVCertificate, "iso15118SchemaVersion", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.iso15118SchemaVersion));
  6180. json_object_object_add(Get15118EVCertificate, "action", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.action));
  6181. json_object_object_add(Get15118EVCertificate, "exiRequest", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.exiRequest));
  6182. random_uuid(guid);
  6183. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "Get15118EVCertificate", json_object_to_json_string_ext(Get15118EVCertificate, JSON_C_TO_STRING_PLAIN));
  6184. json_object_put(Get15118EVCertificate);
  6185. LWS_Send(message);
  6186. sprintf(tempdata, "Get15118EVCertificate,0");
  6187. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6188. {
  6189. result = PASS;
  6190. }
  6191. return result;
  6192. }
  6193. int sendGetCertificateStatusRequest()
  6194. {
  6195. mtrace();
  6196. int result = FAIL;
  6197. char message[4096]={0};
  6198. char guid[37]={0};
  6199. char tempdata[128]={0};
  6200. json_object *GetCertificateStatus = json_object_new_object();
  6201. json_object *ocspRequestData = json_object_new_object();
  6202. DEBUG_INFO("sendGetCertificateStatusRequest...\n");
  6203. json_object_object_add(ocspRequestData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.hashAlgorithm));
  6204. json_object_object_add(ocspRequestData, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.issuerNameHash));
  6205. json_object_object_add(ocspRequestData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.issuerKeyHash));
  6206. json_object_object_add(ocspRequestData, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.serialNumber));
  6207. json_object_object_add(ocspRequestData, "responderURL", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.responderURL));
  6208. json_object_object_add(GetCertificateStatus, "ocspRequestData", ocspRequestData);
  6209. random_uuid(guid);
  6210. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "GetCertificateStatus", json_object_to_json_string_ext(GetCertificateStatus, JSON_C_TO_STRING_PLAIN));
  6211. json_object_put(GetCertificateStatus);
  6212. LWS_Send(message);
  6213. sprintf(tempdata, "GetCertificateStatus,0");
  6214. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6215. {
  6216. result = PASS;
  6217. }
  6218. return result;
  6219. }
  6220. int sendHeartbeatRequest()
  6221. {
  6222. mtrace();
  6223. int result = FAIL;
  6224. char message[40096]={0};
  6225. char guid[37]={0};
  6226. char tempdata[128]={0};
  6227. DEBUG_INFO("sendHeartbeatRequest...\n");
  6228. random_uuid(guid);
  6229. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  6230. , MESSAGE_TYPE_CALL
  6231. , guid );
  6232. LWS_Send(message);
  6233. sprintf(tempdata, "Heartbeat,%d", 0);
  6234. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6235. {
  6236. result = PASS;
  6237. }
  6238. return result;
  6239. }
  6240. int sendLogStatusNotificationRequest(char *status)
  6241. {
  6242. mtrace();
  6243. int result = FAIL;
  6244. char message[4096]={0};
  6245. char guid[37]={0};
  6246. char tempdata[128]={0};
  6247. json_object *LogStatusNotification = json_object_new_object();
  6248. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  6249. ShmOCPP20Data->LogStatusNotification.requestId = ShmOCPP20Data->GetLog.requestId;
  6250. sprintf((char *)ShmOCPP20Data->LogStatusNotification.status,"%s",(const char *)status);
  6251. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->LogStatusNotification.status));
  6252. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->LogStatusNotification.requestId));
  6253. random_uuid(guid);
  6254. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  6255. json_object_put(LogStatusNotification);
  6256. LWS_SendNow(message);
  6257. sprintf(tempdata, "LogStatusNotification,%d", 0);
  6258. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6259. {
  6260. result = PASS;
  6261. }
  6262. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  6263. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationConf = OFF;
  6264. //record status
  6265. if(strcmp(status,"BadMessage")==0)
  6266. {
  6267. LogStatusNotificationStatus = UploadLogStatusEnumType_BadMessage;
  6268. }
  6269. else if(strcmp(status,"Idle")==0)
  6270. {
  6271. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle;
  6272. }
  6273. else if(strcmp(status,"NotSupportedOperation")==0)
  6274. {
  6275. LogStatusNotificationStatus = UploadLogStatusEnumType_NotSupportedOperation;
  6276. }
  6277. else if(strcmp(status,"PermissionDenied")==0)
  6278. {
  6279. LogStatusNotificationStatus = UploadLogStatusEnumType_PermissionDenied;
  6280. }
  6281. else if(strcmp(status,"Uploaded")==0)
  6282. {
  6283. LogStatusNotificationStatus = UploadLogStatusEnumType_Uploaded;
  6284. }
  6285. else if(strcmp(status,"UploadFailure")==0)
  6286. {
  6287. LogStatusNotificationStatus = UploadLogStatusEnumType_UploadFailure;
  6288. }
  6289. else if(strcmp(status,"Uploading")==0)
  6290. {
  6291. LogStatusNotificationStatus = UploadLogStatusEnumType_Uploading;
  6292. }
  6293. return result;
  6294. }
  6295. int sendMeterValuesRequest(int gun_index, ReadingContextEnumType dataType)
  6296. {
  6297. mtrace();
  6298. int result = FAIL;
  6299. char guid[37]={0};
  6300. char tempdata[65]={0};
  6301. int tempIndex = 0;
  6302. json_object *MeterValueReq = json_object_new_object();
  6303. json_object *meterValues = json_object_new_array();
  6304. json_object *sampledValues = json_object_new_array();
  6305. DEBUG_INFO("sendMeterValuesRequest...\n");
  6306. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  6307. //set value
  6308. ShmOCPP20Data->MeterValues[gun_index].evseId = gun_index + 1; // gun start from 1~
  6309. //UTC Date time
  6310. struct timeval tmnow;
  6311. struct tm *tm;
  6312. char buf[28];//, usec_buf[6];
  6313. gettimeofday(&tmnow, NULL);
  6314. time_t t;
  6315. t = time(NULL);
  6316. /*UTC time and date*/
  6317. tm = gmtime(&t);
  6318. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  6319. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].timestamp, buf);
  6320. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  6321. //idx_sample=0;
  6322. //********************************(1)Current.Import L1************************************************/
  6323. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6324. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6325. {
  6326. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6327. {
  6328. tempIndex = ((gun_index==2) ? 1: 0);
  6329. }
  6330. else
  6331. {
  6332. tempIndex = gun_index;
  6333. }
  6334. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6335. {
  6336. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6337. {
  6338. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent;
  6339. }
  6340. }
  6341. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6342. }
  6343. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6344. {
  6345. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6346. {
  6347. tempIndex = ((gun_index==2) ? 1: 0);
  6348. }
  6349. else
  6350. {
  6351. tempIndex = gun_index;
  6352. }
  6353. for (int index = 0; index < CCS_QUANTITY; index++)
  6354. {
  6355. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6356. {
  6357. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent;
  6358. }
  6359. }
  6360. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6361. }
  6362. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6363. {
  6364. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6365. {
  6366. tempIndex = ((gun_index==2) ? 1: 0);
  6367. }
  6368. else
  6369. {
  6370. tempIndex = gun_index;
  6371. }
  6372. for (int index = 0; index < GB_QUANTITY; index++)
  6373. {
  6374. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6375. {
  6376. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent;
  6377. }
  6378. }
  6379. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6380. }
  6381. else if(gunType[gun_index] == GUN_TYPE_DO)
  6382. {
  6383. tempIndex = gun_index;
  6384. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6385. {
  6386. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6387. {
  6388. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent;
  6389. }
  6390. }
  6391. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6392. }
  6393. else
  6394. {
  6395. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6396. {
  6397. tempIndex = 2;
  6398. }
  6399. else
  6400. {
  6401. tempIndex = gun_index;
  6402. }
  6403. for (int index = 0; index < AC_QUANTITY; index++)
  6404. {
  6405. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6406. {
  6407. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent;
  6408. }
  6409. }
  6410. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  6411. }
  6412. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].context, ReadingContextEnumTypeStr[dataType]);
  6413. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  6414. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  6415. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].unitOfMeasure.uint , "A");
  6416. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].unitOfMeasure.multiplier = 0;
  6417. //idx_sample=1;
  6418. //********************************(2)Energy.Active.Import.Register ************************************************/
  6419. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6420. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6421. {
  6422. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6423. {
  6424. tempIndex = ((gun_index==2) ? 1: 0);
  6425. }
  6426. else
  6427. {
  6428. tempIndex = gun_index;
  6429. }
  6430. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6431. {
  6432. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6433. {
  6434. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  6435. }
  6436. }
  6437. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6438. }
  6439. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6440. {
  6441. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6442. {
  6443. tempIndex = ((gun_index==2) ? 1: 0);
  6444. }
  6445. else
  6446. {
  6447. tempIndex = gun_index;
  6448. }
  6449. for (int index = 0; index < CCS_QUANTITY; index++)
  6450. {
  6451. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6452. {
  6453. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  6454. }
  6455. }
  6456. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6457. }
  6458. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6459. {
  6460. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6461. {
  6462. tempIndex = ((gun_index==2) ? 1: 0);
  6463. }
  6464. else
  6465. {
  6466. tempIndex = gun_index;
  6467. }
  6468. for (int index = 0; index < GB_QUANTITY; index++)
  6469. {
  6470. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6471. {
  6472. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6473. }
  6474. }
  6475. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6476. }
  6477. else if(gunType[gun_index] == GUN_TYPE_DO)
  6478. {
  6479. tempIndex = gun_index;
  6480. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6481. {
  6482. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6483. {
  6484. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6485. }
  6486. }
  6487. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6488. }
  6489. else
  6490. {
  6491. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6492. {
  6493. tempIndex = 2;
  6494. }
  6495. else
  6496. {
  6497. tempIndex = gun_index;
  6498. }
  6499. for (int index = 0; index < AC_QUANTITY; index++)
  6500. {
  6501. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6502. {
  6503. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6504. }
  6505. }
  6506. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  6507. }
  6508. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].context, ReadingContextEnumTypeStr[dataType]);
  6509. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]);
  6510. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  6511. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].unitOfMeasure.uint , "kWh");
  6512. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.multiplier = 0;
  6513. //idx_sample=2;
  6514. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6515. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6516. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6517. {
  6518. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6519. {
  6520. tempIndex = ((gun_index==2) ? 1: 0);
  6521. }
  6522. else
  6523. {
  6524. tempIndex = gun_index;
  6525. }
  6526. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6527. {
  6528. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6529. {
  6530. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  6531. }
  6532. } // END OF FOR CHAdeMO_QUANTITY
  6533. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6534. }
  6535. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6536. {
  6537. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6538. {
  6539. tempIndex = ((gun_index==2) ? 1: 0);
  6540. }
  6541. else
  6542. {
  6543. tempIndex = gun_index;
  6544. }
  6545. for (int index = 0; index < CCS_QUANTITY; index++)
  6546. {
  6547. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6548. {
  6549. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  6550. }
  6551. } // END OF CCS_QUANTITY
  6552. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6553. }
  6554. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6555. {
  6556. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6557. {
  6558. tempIndex = ((gun_index==2) ? 1: 0);
  6559. }
  6560. else
  6561. {
  6562. tempIndex = gun_index;
  6563. }
  6564. for (int index = 0; index < GB_QUANTITY; index++)
  6565. {
  6566. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6567. {
  6568. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  6569. }
  6570. } // END OF GB_QUANTITY
  6571. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6572. }
  6573. else if(gunType[gun_index] == GUN_TYPE_DO)
  6574. {
  6575. tempIndex = gun_index;
  6576. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6577. {
  6578. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6579. {
  6580. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy;
  6581. }
  6582. }
  6583. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6584. }
  6585. else
  6586. {
  6587. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6588. {
  6589. tempIndex = 2;
  6590. }
  6591. else
  6592. {
  6593. tempIndex = gun_index;
  6594. }
  6595. for (int index = 0; index < AC_QUANTITY; index++)
  6596. {
  6597. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6598. {
  6599. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  6600. }
  6601. }
  6602. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  6603. }
  6604. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].context, ReadingContextEnumTypeStr[dataType]);
  6605. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]);
  6606. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  6607. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.uint , "kWh");
  6608. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.multiplier = 0;
  6609. //idx_sample=3;
  6610. //********************************(4)Power.Active.Import************************************************/
  6611. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6612. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6613. {
  6614. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6615. {
  6616. tempIndex = ((gun_index==2) ? 1: 0);
  6617. }
  6618. else
  6619. {
  6620. tempIndex = gun_index;
  6621. }
  6622. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6623. {
  6624. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6625. {
  6626. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower;
  6627. }
  6628. } // END OF FOR
  6629. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6630. }
  6631. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6632. {
  6633. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6634. {
  6635. tempIndex = ((gun_index==2) ? 1: 0);
  6636. }
  6637. else
  6638. {
  6639. tempIndex = gun_index;
  6640. }
  6641. for (int index = 0; index < CCS_QUANTITY; index++)
  6642. {
  6643. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6644. {
  6645. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower;
  6646. }
  6647. }
  6648. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6649. }
  6650. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6651. {
  6652. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6653. {
  6654. tempIndex = ((gun_index==2) ? 1: 0);
  6655. }
  6656. else
  6657. {
  6658. tempIndex = gun_index;
  6659. }
  6660. for (int index = 0; index < GB_QUANTITY; index++)
  6661. {
  6662. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6663. {
  6664. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6665. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower;
  6666. }
  6667. }
  6668. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6669. }
  6670. else if(gunType[gun_index] == GUN_TYPE_DO)
  6671. {
  6672. tempIndex = gun_index;
  6673. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6674. {
  6675. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6676. {
  6677. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6678. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower;
  6679. }
  6680. }
  6681. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6682. }
  6683. else
  6684. {
  6685. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6686. {
  6687. tempIndex = 2;
  6688. }
  6689. else
  6690. {
  6691. tempIndex = gun_index;
  6692. }
  6693. for (int index = 0; index < AC_QUANTITY; index++)
  6694. {
  6695. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6696. {
  6697. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower;
  6698. }
  6699. }
  6700. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  6701. }
  6702. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].context, ReadingContextEnumTypeStr[dataType]);
  6703. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]);
  6704. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  6705. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].unitOfMeasure.uint , "kW");
  6706. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].unitOfMeasure.multiplier = 0;
  6707. //idx_sample=4;
  6708. //***********************************************(5)VOLTAGE L1******************************************************/
  6709. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6710. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6711. {
  6712. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6713. {
  6714. tempIndex = ((gun_index==2) ? 1: 0);
  6715. }
  6716. else
  6717. {
  6718. tempIndex = gun_index;
  6719. }
  6720. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6721. {
  6722. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6723. {
  6724. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage;
  6725. }
  6726. }
  6727. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6728. }
  6729. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6730. {
  6731. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6732. {
  6733. tempIndex = ((gun_index==2) ? 1: 0);
  6734. }
  6735. else
  6736. {
  6737. tempIndex = gun_index;
  6738. }
  6739. for (int index = 0; index < CCS_QUANTITY; index++)
  6740. {
  6741. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6742. {
  6743. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage;
  6744. }
  6745. }
  6746. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6747. }
  6748. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6749. {
  6750. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6751. {
  6752. tempIndex = ((gun_index==2) ? 1: 0);
  6753. }
  6754. else
  6755. {
  6756. tempIndex = gun_index;
  6757. }
  6758. for (int index = 0; index < GB_QUANTITY; index++)
  6759. {
  6760. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6761. {
  6762. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage;
  6763. }
  6764. }
  6765. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6766. }
  6767. else if(gunType[gun_index] == GUN_TYPE_DO)
  6768. {
  6769. tempIndex = gun_index;
  6770. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6771. {
  6772. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6773. {
  6774. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage;
  6775. }
  6776. }
  6777. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6778. }
  6779. else
  6780. {
  6781. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6782. {
  6783. tempIndex = 2;
  6784. }
  6785. else
  6786. {
  6787. tempIndex = gun_index;
  6788. }
  6789. for (int index = 0; index < AC_QUANTITY; index++)
  6790. {
  6791. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6792. {
  6793. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage;
  6794. }
  6795. }
  6796. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  6797. }
  6798. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].context, ReadingContextEnumTypeStr[dataType]);
  6799. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  6800. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  6801. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].unitOfMeasure.uint , "V");
  6802. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].unitOfMeasure.multiplier = 0;
  6803. //***********************************************(6)SOC******************************************************/
  6804. 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))
  6805. {
  6806. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6807. {
  6808. tempIndex = ((gun_index==2) ? 1: 0);
  6809. }
  6810. else
  6811. {
  6812. tempIndex = gun_index;
  6813. }
  6814. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6815. {
  6816. //tempIndex = ((gun_index==2) ? 1: 0);
  6817. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6818. {
  6819. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6820. {
  6821. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  6822. }
  6823. }
  6824. }
  6825. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6826. {
  6827. //tempIndex = ((gun_index==2) ? 1: 0);
  6828. for (int index = 0; index < CCS_QUANTITY; index++)
  6829. {
  6830. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6831. {
  6832. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  6833. }
  6834. }
  6835. }
  6836. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6837. {
  6838. //tempIndex = ((gun_index==2) ? 1: 0);
  6839. for (int index = 0; index < GB_QUANTITY; index++)
  6840. {
  6841. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6842. {
  6843. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  6844. }
  6845. }
  6846. }
  6847. else if(gunType[gun_index] == GUN_TYPE_DO)
  6848. {
  6849. //tempIndex = ((gun_index==2) ? 1: 0);
  6850. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6851. {
  6852. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6853. {
  6854. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  6855. }
  6856. }
  6857. }
  6858. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].context, ReadingContextEnumTypeStr[dataType]);
  6859. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].measurand, MeasurandEnumTypeStr[MeasurandEnumType_SoC]);
  6860. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6861. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].location, LocationEnumTypeStr[LocationEnumType_EV]);
  6862. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].unitOfMeasure.uint , "Percent");
  6863. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].unitOfMeasure.multiplier = 0;
  6864. }
  6865. //********************************(7)Current.Import L2************************************************/
  6866. // Only for AC 3 phase
  6867. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  6868. {
  6869. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6870. {
  6871. tempIndex = 2;
  6872. }
  6873. else
  6874. {
  6875. tempIndex = gun_index;
  6876. }
  6877. for (int index = 0; index < AC_QUANTITY; index++)
  6878. {
  6879. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6880. {
  6881. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2;
  6882. }
  6883. }
  6884. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].phase, PhaseEnumTypeStr[PhaseEnumType_L2_N]);
  6885. }
  6886. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].context, ReadingContextEnumTypeStr[dataType]);
  6887. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  6888. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  6889. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].unitOfMeasure.uint , "A");
  6890. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].unitOfMeasure.multiplier = 0;
  6891. //********************************(8)Current.Import L3************************************************/
  6892. // Only for AC 3 phase
  6893. if( (gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  6894. {
  6895. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6896. {
  6897. tempIndex = 2;
  6898. }
  6899. else
  6900. {
  6901. tempIndex = gun_index;
  6902. }
  6903. for (int index = 0; index < AC_QUANTITY; index++)
  6904. {
  6905. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6906. {
  6907. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3;
  6908. }
  6909. }
  6910. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6911. }
  6912. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].context, ReadingContextEnumTypeStr[dataType]);
  6913. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  6914. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  6915. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].unitOfMeasure.uint , "A");
  6916. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].unitOfMeasure.multiplier = 0;
  6917. //***********************************************(9)VOLTAGE L2******************************************************/
  6918. if( (gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  6919. {
  6920. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6921. {
  6922. tempIndex = 2;
  6923. }
  6924. else
  6925. {
  6926. tempIndex = gun_index;
  6927. }
  6928. for (int index = 0; index < AC_QUANTITY; index++)
  6929. {
  6930. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6931. {
  6932. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2;
  6933. }
  6934. }
  6935. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].phase, PhaseEnumTypeStr[PhaseEnumType_L2_N]);
  6936. }
  6937. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].context, ReadingContextEnumTypeStr[dataType]);
  6938. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  6939. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  6940. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].unitOfMeasure.uint , "V");
  6941. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].unitOfMeasure.multiplier = 0;
  6942. //***********************************************(10)VOLTAGE L3******************************************************/
  6943. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  6944. {
  6945. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6946. {
  6947. tempIndex = 2;
  6948. }
  6949. else
  6950. {
  6951. tempIndex = gun_index;
  6952. }
  6953. for (int index = 0; index < AC_QUANTITY; index++)
  6954. {
  6955. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6956. {
  6957. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3;
  6958. }
  6959. }
  6960. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6961. }
  6962. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].context, ReadingContextEnumTypeStr[dataType]);
  6963. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  6964. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  6965. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].unitOfMeasure.uint , "V");
  6966. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].unitOfMeasure.multiplier = 0;
  6967. // Message create ====================================================================================================
  6968. random_uuid(guid);
  6969. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->MeterValues[gun_index].meterValue);idxMeter++)
  6970. {
  6971. json_object *meterValue = json_object_new_object();
  6972. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  6973. {
  6974. if(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].value > 0)
  6975. {
  6976. json_object *sampledValue = json_object_new_object();
  6977. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  6978. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  6979. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  6980. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  6981. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  6982. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  6983. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  6984. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  6985. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  6986. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  6987. {
  6988. json_object *unitOfMeasure = json_object_new_object();
  6989. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  6990. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  6991. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  6992. }
  6993. json_object_array_add(sampledValues, sampledValue);
  6994. }
  6995. }
  6996. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].timestamp));
  6997. json_object_object_add(meterValue, "sampledValue", sampledValues);
  6998. json_object_array_add(meterValues, meterValue);
  6999. idxMeter++;
  7000. }
  7001. json_object_object_add(MeterValueReq, "meterValue", meterValues);
  7002. json_object_object_add(MeterValueReq, "evseId", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].evseId));
  7003. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  7004. ,gun_index + 1
  7005. ,MESSAGE_TYPE_CALL
  7006. ,guid
  7007. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  7008. json_object_put(MeterValueReq);
  7009. if((strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]) == 0) ||
  7010. (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]) == 0) ||
  7011. (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]) == 0))
  7012. {
  7013. // Transaction meter value send by TransactionEvent message
  7014. memcpy(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0], &ShmOCPP20Data->MeterValues[gun_index].meterValue[0], sizeof(struct MeterValueType));
  7015. cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
  7016. result = PASS;
  7017. }
  7018. else
  7019. {
  7020. // Put request guid to hash map
  7021. sprintf(tempdata, "MeterValues,%d", (gun_index));
  7022. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7023. {
  7024. result = PASS;
  7025. }
  7026. if((dataType != ReadingContextEnumType_Trigger) &&
  7027. (dataType != ReadingContextEnumType_Sample_Clock))
  7028. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  7029. else
  7030. {
  7031. if(FirstHeartBeat)
  7032. LWS_Send(queuedata +2);
  7033. }
  7034. }
  7035. return result;
  7036. }
  7037. int sendNotifyChargingLimitRequest(int gun_index)
  7038. {
  7039. mtrace();
  7040. int result = FAIL;
  7041. char message[4096]={0};
  7042. char guid[37]={0};
  7043. char tempdata[128]={0};
  7044. json_object *NotifyChargingLimit = json_object_new_object();
  7045. json_object *chargingLimit = json_object_new_object();
  7046. DEBUG_INFO("sendNotifyChargingLimitRequest...\n");
  7047. json_object_object_add(NotifyChargingLimit, "evseId", json_object_new_int(ShmOCPP20Data->NotifyChargingLimit[gun_index].evseId));
  7048. json_object_object_add(chargingLimit, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->NotifyChargingLimit[gun_index].chargingLimit.chargingLimitSource));
  7049. json_object_object_add(chargingLimit, "chargingLimitSource", json_object_new_boolean(ShmOCPP20Data->NotifyChargingLimit[gun_index].chargingLimit.isGridCritical));
  7050. json_object_object_add(NotifyChargingLimit, "chargingLimit", NotifyChargingLimit);
  7051. random_uuid(guid);
  7052. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyChargingLimit", json_object_to_json_string_ext(NotifyChargingLimit, JSON_C_TO_STRING_PLAIN));
  7053. json_object_put(NotifyChargingLimit);
  7054. LWS_Send(message);
  7055. sprintf(tempdata, "NotifyChargingLimit,%d", gun_index);
  7056. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7057. {
  7058. result = PASS;
  7059. }
  7060. return result;
  7061. }
  7062. int sendNotifyCustomerInformationRequest()
  7063. {
  7064. mtrace();
  7065. int result = FAIL;
  7066. char message[4096]={0};
  7067. char guid[37]={0};
  7068. char tempdata[128]={0};
  7069. json_object *NotifyCustomerInformation = json_object_new_object();
  7070. DEBUG_INFO("sendNotifyCustomerInformationRequest...\n");
  7071. json_object_object_add(NotifyCustomerInformation, "data", json_object_new_string((char*)ShmOCPP20Data->NotifyCustomerInformation.data));
  7072. json_object_object_add(NotifyCustomerInformation, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyCustomerInformation.tbc));
  7073. json_object_object_add(NotifyCustomerInformation, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyCustomerInformation.seqNo));
  7074. json_object_object_add(NotifyCustomerInformation, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyCustomerInformation.generatedAt));
  7075. json_object_object_add(NotifyCustomerInformation, "requestId", json_object_new_int(ShmOCPP20Data->NotifyCustomerInformation.requestId));
  7076. random_uuid(guid);
  7077. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyCustomerInformation", json_object_to_json_string_ext(NotifyCustomerInformation, JSON_C_TO_STRING_PLAIN));
  7078. json_object_put(NotifyCustomerInformation);
  7079. LWS_Send(message);
  7080. sprintf(tempdata, "NotifyCustomerInformation,0");
  7081. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7082. {
  7083. result = PASS;
  7084. }
  7085. return result;
  7086. }
  7087. int sendNotifyDisplayMessagesRequest()
  7088. {
  7089. mtrace();
  7090. int result = FAIL;
  7091. char message[4096]={0};
  7092. char guid[37]={0};
  7093. char tempdata[128]={0};
  7094. json_object *NotifyDisplayMessages = json_object_new_object();
  7095. json_object *messageInfos = json_object_new_array();
  7096. DEBUG_INFO("sendNotifyDisplayMessagesRequest...\n");
  7097. json_object_object_add(NotifyDisplayMessages, "requestId", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.requestId));
  7098. json_object_object_add(NotifyDisplayMessages, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyDisplayMessages.tbc));
  7099. for(int idxMsg=0;idxMsg<ARRAY_SIZE(ShmOCPP20Data->NotifyDisplayMessages.messageInfo);idxMsg++)
  7100. {
  7101. if(strlen((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.content) > 0)
  7102. {
  7103. json_object *messageInfo = json_object_new_object();
  7104. json_object *message = json_object_new_object();
  7105. json_object *display = json_object_new_object();
  7106. json_object *evse = json_object_new_object();
  7107. json_object_object_add(messageInfo, "id", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].id));
  7108. json_object_object_add(messageInfo, "priority", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].priority));
  7109. json_object_object_add(messageInfo, "state", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].state));
  7110. json_object_object_add(messageInfo, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].startDateTime));
  7111. json_object_object_add(messageInfo, "endDateTime", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].endDateTime));
  7112. json_object_object_add(messageInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].transactionId));
  7113. json_object_object_add(message, "format", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.format));
  7114. json_object_object_add(message, "language", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.language));
  7115. json_object_object_add(message, "content", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.content));
  7116. json_object_object_add(messageInfo, "message", message);
  7117. json_object_object_add(display, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.name));
  7118. json_object_object_add(display, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.instance));
  7119. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.evse.id));
  7120. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.evse.connectorId));
  7121. json_object_object_add(display, "evse",evse);
  7122. json_object_object_add(messageInfo, "evse", display);
  7123. json_object_array_add(messageInfos, messageInfo);
  7124. }
  7125. }
  7126. json_object_object_add(NotifyDisplayMessages, "messageInfo", messageInfos);
  7127. random_uuid(guid);
  7128. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyDisplayMessages", json_object_to_json_string_ext(NotifyDisplayMessages, JSON_C_TO_STRING_PLAIN));
  7129. json_object_put(NotifyDisplayMessages);
  7130. LWS_Send(message);
  7131. sprintf(tempdata, "NotifyDisplayMessages,0");
  7132. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7133. {
  7134. result = PASS;
  7135. }
  7136. return result;
  7137. }
  7138. int sendNotifyEVChargingNeedsRequest(int gun_index)
  7139. {
  7140. mtrace();
  7141. int result = FAIL;
  7142. char message[4096]={0};
  7143. char guid[37]={0};
  7144. char tempdata[128]={0};
  7145. json_object *NotifyEVChargingNeeds = json_object_new_object();
  7146. json_object *chargingNeeds = json_object_new_object();
  7147. json_object *acChargingParameters = json_object_new_object();
  7148. json_object *dcChargingParameters = json_object_new_object();
  7149. DEBUG_INFO("sendNotifyEVChargingNeedsRequest...\n");
  7150. json_object_object_add(NotifyEVChargingNeeds, "maxScheduleTuples", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].maxScheduleTuples));
  7151. json_object_object_add(NotifyEVChargingNeeds, "evseId", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].evseId));
  7152. json_object_object_add(chargingNeeds, "requestedEnergyTransfer", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.requestedEnergyTransfer));
  7153. json_object_object_add(chargingNeeds, "departureTime", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.departureTime));
  7154. json_object_object_add(acChargingParameters, "energyAmount", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.energyAmount));
  7155. json_object_object_add(acChargingParameters, "evMinCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMinCurrent));
  7156. json_object_object_add(acChargingParameters, "evMaxCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMaxCurrent));
  7157. json_object_object_add(acChargingParameters, "evMaxVoltage", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMaxVoltage));
  7158. json_object_object_add(chargingNeeds, "acChargingParameters", acChargingParameters);
  7159. json_object_object_add(dcChargingParameters, "evMaxCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxCurrent));
  7160. json_object_object_add(dcChargingParameters, "evMaxVoltage", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxVoltage));
  7161. json_object_object_add(dcChargingParameters, "energyAmount", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.energyAmount));
  7162. json_object_object_add(dcChargingParameters, "evMaxPower", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxPower));
  7163. json_object_object_add(dcChargingParameters, "stateOfCharge", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.stateOfCharge));
  7164. json_object_object_add(dcChargingParameters, "evEnergyCapacity", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evEnergyCapacity));
  7165. json_object_object_add(dcChargingParameters, "fullSoC", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.fullSoC));
  7166. json_object_object_add(dcChargingParameters, "bulkSoC", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.bulkSoC));
  7167. json_object_object_add(chargingNeeds, "dcChargingParameters", dcChargingParameters);
  7168. json_object_object_add(NotifyEVChargingNeeds, "chargingNeeds", chargingNeeds);
  7169. random_uuid(guid);
  7170. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEVChargingNeeds", json_object_to_json_string_ext(NotifyEVChargingNeeds, JSON_C_TO_STRING_PLAIN));
  7171. json_object_put(NotifyEVChargingNeeds);
  7172. LWS_Send(message);
  7173. sprintf(tempdata, "NotifyEVChargingNeeds,%d", gun_index);
  7174. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7175. {
  7176. result = PASS;
  7177. }
  7178. return result;
  7179. }
  7180. int sendNotifyEVChargingScheduleRequest(int gun_index)
  7181. {
  7182. mtrace();
  7183. int result = FAIL;
  7184. char message[4096]={0};
  7185. char guid[37]={0};
  7186. char tempdata[128]={0};
  7187. json_object *NotifyEVChargingSchedule = json_object_new_object();
  7188. json_object *chargingSchedule = json_object_new_object();
  7189. json_object *periods = json_object_new_array();
  7190. DEBUG_INFO("sendNotifyEVChargingScheduleRequest...\n");
  7191. json_object_object_add(NotifyEVChargingSchedule, "timeBase", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].timeBase));
  7192. json_object_object_add(NotifyEVChargingSchedule, "evseId", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].evseId));
  7193. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.startSchedule));
  7194. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.duration));
  7195. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingRateUnit));
  7196. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.minChargingRate));
  7197. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.id));
  7198. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  7199. {
  7200. if(((ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  7201. (ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  7202. {
  7203. json_object *Period = json_object_new_object();
  7204. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  7205. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  7206. if(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  7207. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  7208. if(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  7209. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  7210. json_object_array_add(periods, Period);
  7211. }
  7212. }
  7213. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", periods);
  7214. json_object_object_add(NotifyEVChargingSchedule, "chargingSchedule", chargingSchedule);
  7215. random_uuid(guid);
  7216. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEVChargingSchedule", json_object_to_json_string_ext(NotifyEVChargingSchedule, JSON_C_TO_STRING_PLAIN));
  7217. json_object_put(NotifyEVChargingSchedule);
  7218. LWS_Send(message);
  7219. sprintf(tempdata, "NotifyEVChargingSchedule,%d", gun_index);
  7220. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7221. {
  7222. result = PASS;
  7223. }
  7224. return result;
  7225. }
  7226. int sendNotifyEventRequest()
  7227. {
  7228. mtrace();
  7229. int result = FAIL;
  7230. char message[4096]={0};
  7231. char guid[37]={0};
  7232. char tempdata[128]={0};
  7233. json_object *NotifyEvent = json_object_new_object();
  7234. json_object *eventDatas = json_object_new_array();
  7235. DEBUG_INFO("sendNotifyEventRequest...\n");
  7236. json_object_object_add(NotifyEvent, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.generatedAt));
  7237. json_object_object_add(NotifyEvent, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyEvent.tbc));
  7238. json_object_object_add(NotifyEvent, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyEvent.seqNo));
  7239. for(int idxEvent=0;idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData);idxEvent++)
  7240. {
  7241. if(strlen((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp) > 0)
  7242. {
  7243. json_object *eventData = json_object_new_object();
  7244. json_object *component = json_object_new_object();
  7245. json_object *evse = json_object_new_object();
  7246. json_object *variable = json_object_new_object();
  7247. json_object_object_add(eventData, "eventId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId));
  7248. json_object_object_add(eventData, "timestamp", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp));
  7249. json_object_object_add(eventData, "trigger", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger));
  7250. json_object_object_add(eventData, "cause", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cause));
  7251. json_object_object_add(eventData, "actualValue", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue));
  7252. json_object_object_add(eventData, "techCode", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode));
  7253. json_object_object_add(eventData, "techInfo", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo));
  7254. json_object_object_add(eventData, "cleared", json_object_new_boolean(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared));
  7255. json_object_object_add(eventData, "transactionId", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].transactionId));
  7256. json_object_object_add(eventData, "variableMonitoringId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variableMonitoringId));
  7257. json_object_object_add(eventData, "eventNotificationType", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType));
  7258. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name));
  7259. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.instance));
  7260. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.id));
  7261. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId));
  7262. json_object_object_add(component, "evse",evse);
  7263. json_object_object_add(eventData, "component", component);
  7264. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name));
  7265. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.instance));
  7266. json_object_object_add(eventData, "variable", variable);
  7267. json_object_array_add(eventDatas, eventData);
  7268. }
  7269. }
  7270. json_object_object_add(NotifyEvent, "eventData", eventDatas);
  7271. random_uuid(guid);
  7272. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEvent", json_object_to_json_string_ext(NotifyEvent, JSON_C_TO_STRING_PLAIN));
  7273. json_object_put(NotifyEvent);
  7274. LWS_Send(message);
  7275. sprintf(tempdata, "NotifyEvent,0");
  7276. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7277. {
  7278. result = PASS;
  7279. }
  7280. return result;
  7281. }
  7282. int sendNotifyMonitoringReportRequest()
  7283. {
  7284. mtrace();
  7285. int result = FAIL;
  7286. char message[4096]={0};
  7287. char guid[37]={0};
  7288. char tempdata[128]={0};
  7289. json_object *NotifyMonitoringReport = json_object_new_object();
  7290. json_object *monitors = json_object_new_array();
  7291. DEBUG_INFO("sendNotifyMonitoringReportRequest...\n");
  7292. json_object_object_add(NotifyMonitoringReport, "requestId", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.requestId));
  7293. json_object_object_add(NotifyMonitoringReport, "tbc", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.tbc));
  7294. json_object_object_add(NotifyMonitoringReport, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.seqNo));
  7295. json_object_object_add(NotifyMonitoringReport, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.generatedAt));
  7296. for(int idxMonitor=0;idxMonitor<ARRAY_SIZE(ShmOCPP20Data->NotifyMonitoringReport.monitor);idxMonitor++)
  7297. {
  7298. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.name) > 0)
  7299. {
  7300. json_object *monitor = json_object_new_object();
  7301. json_object *component = json_object_new_object();
  7302. json_object *evse = json_object_new_object();
  7303. json_object *variable = json_object_new_object();
  7304. json_object *variableMonitorings = json_object_new_array();
  7305. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.name));
  7306. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.instance));
  7307. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.evse.id));
  7308. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.evse.connectorId));
  7309. json_object_object_add(component, "evse",evse);
  7310. json_object_object_add(monitor, "component", component);
  7311. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variable.name));
  7312. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variable.instance));
  7313. json_object_object_add(monitor, "variable", variable);
  7314. for(int idxVar=0;idxVar<ARRAY_SIZE(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring);idxVar++)
  7315. {
  7316. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].type) > 0)
  7317. {
  7318. json_object *variableMonitoring = json_object_new_object();
  7319. json_object_object_add(variableMonitoring, "id", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].id));
  7320. json_object_object_add(variableMonitoring, "value", json_object_new_double(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].value));
  7321. json_object_object_add(variableMonitoring, "type", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].type));
  7322. json_object_object_add(variableMonitoring, "severity", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].severity));
  7323. json_object_object_add(variableMonitoring, "transaction", json_object_new_boolean(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].transaction));
  7324. json_object_array_add(variableMonitorings, variableMonitoring);
  7325. }
  7326. }
  7327. json_object_object_add(monitor, "variableMonitoring", variableMonitorings);
  7328. json_object_array_add(monitors, monitor);
  7329. }
  7330. }
  7331. json_object_object_add(NotifyMonitoringReport, "monitor", monitors);
  7332. random_uuid(guid);
  7333. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyMonitoringReport", json_object_to_json_string_ext(NotifyMonitoringReport, JSON_C_TO_STRING_PLAIN));
  7334. json_object_put(NotifyMonitoringReport);
  7335. LWS_Send(message);
  7336. sprintf(tempdata, "NotifyMonitoringReport,0");
  7337. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7338. {
  7339. result = PASS;
  7340. }
  7341. return result;
  7342. }
  7343. int sendNotifyReportRequest()
  7344. {
  7345. mtrace();
  7346. int result = FAIL;
  7347. char message[4096]={0};
  7348. char guid[37]={0};
  7349. char tempdata[128]={0};
  7350. json_object *NotifyReport = json_object_new_object();
  7351. json_object *reportDatas = json_object_new_array();
  7352. DEBUG_INFO("sendNotifyReportRequest...\n");
  7353. json_object_object_add(NotifyReport, "requestId", json_object_new_int(ShmOCPP20Data->NotifyReport.requestId));
  7354. json_object_object_add(NotifyReport, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.generatedAt));
  7355. json_object_object_add(NotifyReport, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyReport.tbc));
  7356. json_object_object_add(NotifyReport, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyReport.seqNo));
  7357. for(int idxReport=0;idxReport<ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData);idxReport++)
  7358. {
  7359. if(strlen((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.name) > 0)
  7360. {
  7361. json_object *reportData = json_object_new_object();
  7362. json_object *component = json_object_new_object();
  7363. json_object *evse = json_object_new_object();
  7364. json_object *variable = json_object_new_object();
  7365. json_object *variableAttributes = json_object_new_array();
  7366. json_object *variableCharacteristics = json_object_new_object();
  7367. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.name));
  7368. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.instance));
  7369. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyReport.reportData[idxReport].component.evse.id));
  7370. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyReport.reportData[idxReport].component.evse.connectorId));
  7371. json_object_object_add(component, "evse",evse);
  7372. json_object_object_add(reportData, "component", component);
  7373. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variable.name));
  7374. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variable.instance));
  7375. json_object_object_add(reportData, "variable",variable);
  7376. json_object_object_add(variableCharacteristics, "unit", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.unit));
  7377. json_object_object_add(variableCharacteristics, "dataType", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.dataType));
  7378. json_object_object_add(variableCharacteristics, "minLimit", json_object_new_double(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.minLimit));
  7379. json_object_object_add(variableCharacteristics, "maxLimit", json_object_new_double(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.maxLimit));
  7380. json_object_object_add(reportData, "variableCharacteristics",variableCharacteristics);
  7381. for(int idxAttr=0;idxAttr<ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute);idxAttr++)
  7382. {
  7383. if(strlen((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].value) > 0)
  7384. {
  7385. json_object *variableAttribute = json_object_new_object();
  7386. json_object_object_add(variableAttribute, "type", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].type));
  7387. json_object_object_add(variableAttribute, "value", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].value));
  7388. json_object_object_add(variableAttribute, "mutability", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].mutability));
  7389. json_object_object_add(variableAttribute, "persistent", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].persistent));
  7390. json_object_object_add(variableAttribute, "constant", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].constant));
  7391. json_object_array_add(variableAttributes, variableAttribute);
  7392. }
  7393. }
  7394. json_object_object_add(reportData, "variableAttribute", variableAttributes);
  7395. json_object_array_add(reportDatas, reportData);
  7396. }
  7397. }
  7398. json_object_object_add(NotifyReport, "reportData", reportDatas);
  7399. random_uuid(guid);
  7400. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyReport", json_object_to_json_string_ext(NotifyReport, JSON_C_TO_STRING_PLAIN));
  7401. json_object_put(NotifyReport);
  7402. LWS_SendNow(message);
  7403. sprintf(tempdata, "NotifyReport,0");
  7404. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7405. {
  7406. result = PASS;
  7407. }
  7408. return result;
  7409. }
  7410. int sendPublishFirmwareStatusNotificationRequest()
  7411. {
  7412. mtrace();
  7413. int result = FAIL;
  7414. char message[4096]={0};
  7415. char guid[37]={0};
  7416. char tempdata[128]={0};
  7417. json_object *PublishFirmwareStatusNotification = json_object_new_object();
  7418. json_object *locations = json_object_new_array();
  7419. DEBUG_INFO("sendPublishFirmwareStatusNotificationRequest...\n");
  7420. json_object_object_add(PublishFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->PublishFirmwareStatusNotificatio.status));
  7421. json_object_object_add(PublishFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->PublishFirmwareStatusNotificatio.requestId));
  7422. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->PublishFirmwareStatusNotificatio.location);idx++)
  7423. {
  7424. json_object_array_add(locations, json_object_new_string((char*)ShmOCPP20Data->PublishFirmwareStatusNotificatio.location[idx]));
  7425. }
  7426. json_object_object_add(PublishFirmwareStatusNotification, "location", locations);
  7427. random_uuid(guid);
  7428. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "PublishFirmwareStatusNotification", json_object_to_json_string_ext(PublishFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  7429. json_object_put(PublishFirmwareStatusNotification);
  7430. LWS_Send(message);
  7431. sprintf(tempdata, "PublishFirmwareStatusNotification,0");
  7432. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7433. {
  7434. result = PASS;
  7435. }
  7436. return result;
  7437. }
  7438. int sendReportChargingProfilesRequest(int gun_index)
  7439. {
  7440. mtrace();
  7441. int result = FAIL;
  7442. char message[4096]={0};
  7443. char guid[37]={0};
  7444. char tempdata[128]={0};
  7445. json_object *ReportChargingProfiles = json_object_new_object();
  7446. json_object *chargingProfiles = json_object_new_array();
  7447. DEBUG_INFO("sendReportChargingProfilesRequest...\n");
  7448. json_object_object_add(ReportChargingProfiles, "requestId", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].requestId));
  7449. json_object_object_add(ReportChargingProfiles, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingLimitSource));
  7450. json_object_object_add(ReportChargingProfiles, "tbc", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].tbc));
  7451. json_object_object_add(ReportChargingProfiles, "evseId", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].evseId));
  7452. for(int idxProfile=0;idxProfile<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile);idxProfile++)
  7453. {
  7454. json_object *chargingProfile = json_object_new_object();
  7455. json_object *chargingSchedules = json_object_new_array();
  7456. json_object_object_add(chargingProfile, "id", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].id));
  7457. json_object_object_add(chargingProfile, "stackLevel", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].stackLevel));
  7458. json_object_object_add(chargingProfile, "chargingProfilePurpose", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingProfilePurpose));
  7459. json_object_object_add(chargingProfile, "chargingProfileKind", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingProfileKind));
  7460. json_object_object_add(chargingProfile, "recurrencyKind", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].recurrencyKind));
  7461. json_object_object_add(chargingProfile, "validFrom", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].validFrom));
  7462. json_object_object_add(chargingProfile, "validTo", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].validTo));
  7463. json_object_object_add(chargingProfile, "transactionId", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].transactionId));
  7464. for(int idxSchedule=0;idxSchedule<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule);idxSchedule++)
  7465. {
  7466. json_object *chargingSchedule = json_object_new_object();
  7467. json_object *chargingSchedulePeriods = json_object_new_array();
  7468. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].startSchedule));
  7469. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].duration));
  7470. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingRateUnit));
  7471. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].minChargingRate));
  7472. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].id));
  7473. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  7474. {
  7475. json_object *chargingSchedulePeriod = json_object_new_object();
  7476. json_object_object_add(chargingSchedulePeriod, "startPeriod", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod));
  7477. json_object_object_add(chargingSchedulePeriod, "limit", json_object_new_double(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit));
  7478. json_object_object_add(chargingSchedulePeriod, "numberPhases", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  7479. json_object_object_add(chargingSchedulePeriod, "phaseToUse", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse));
  7480. json_object_array_add(chargingSchedulePeriods, chargingSchedulePeriod);
  7481. }
  7482. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriods);
  7483. json_object_array_add(chargingSchedules, chargingSchedule);
  7484. }
  7485. json_object_object_add(chargingProfile, "chargingSchedule", chargingSchedules);
  7486. json_object_array_add(chargingProfiles, chargingProfile);
  7487. }
  7488. json_object_object_add(ReportChargingProfiles, "chargingProfile", chargingProfiles);
  7489. random_uuid(guid);
  7490. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ReportChargingProfiles", json_object_to_json_string_ext(ReportChargingProfiles, JSON_C_TO_STRING_PLAIN));
  7491. json_object_put(ReportChargingProfiles);
  7492. LWS_Send(message);
  7493. sprintf(tempdata, "ReportChargingProfiles,%d", gun_index);
  7494. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7495. {
  7496. result = PASS;
  7497. }
  7498. return result;
  7499. }
  7500. int sendReservationStatusUpdateRequest(int gun_index)
  7501. {
  7502. mtrace();
  7503. int result = FAIL;
  7504. char message[4096]={0};
  7505. char guid[37]={0};
  7506. char tempdata[128]={0};
  7507. json_object *ReservationStatusUpdate = json_object_new_object();
  7508. DEBUG_INFO("sendReservationStatusUpdateRequest...\n");
  7509. json_object_object_add(ReservationStatusUpdate, "reservationId", json_object_new_int(ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationId));
  7510. json_object_object_add(ReservationStatusUpdate, "reservationUpdateStatus", json_object_new_string((char*)ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationUpdateStatus));
  7511. random_uuid(guid);
  7512. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ReservationStatusUpdate", json_object_to_json_string_ext(ReservationStatusUpdate, JSON_C_TO_STRING_PLAIN));
  7513. json_object_put(ReservationStatusUpdate);
  7514. LWS_Send(message);
  7515. sprintf(tempdata, "ReservationStatusUpdate,%d", gun_index);
  7516. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7517. {
  7518. result = PASS;
  7519. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = OFF;
  7520. }
  7521. return result;
  7522. }
  7523. int sendSecurityEventNotificationRequest()
  7524. {
  7525. mtrace();
  7526. int result = FAIL;
  7527. char message[4096]={0};
  7528. char guid[37]={0};
  7529. char tempdata[128]={0};
  7530. json_object *SecurityEventNotification = json_object_new_object();
  7531. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7532. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.type));
  7533. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.timestamp));
  7534. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.techInfo));
  7535. random_uuid(guid);
  7536. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7537. json_object_put(SecurityEventNotification);
  7538. LWS_Send(message);
  7539. sprintf(tempdata, "SecurityEventNotification,0");
  7540. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7541. {
  7542. result = PASS;
  7543. }
  7544. return result;
  7545. }
  7546. int sendSignCertificateRequest(CertificateSigningUseEnumType certType)
  7547. {
  7548. mtrace();
  7549. int result = FAIL;
  7550. char message[4096]={0};
  7551. char guid[37]={0};
  7552. char tempdata[128]={0};
  7553. json_object *SignCertificate = json_object_new_object();
  7554. DEBUG_INFO("sendSignCertificateRequest...\n");
  7555. // Read csr file content
  7556. memset(ShmOCPP20Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP20Data->SignCertificate.csr));
  7557. FILE *fp=fopen(((certType == CertificateSignedStatusEnumType_V2GCertificate)?"/Storage/OCPP/certV2G.csr":"/Storage/OCPP/certCP.csr"),"r");
  7558. char *line = NULL;
  7559. size_t len = 0;
  7560. while(getline(&line, &len, fp) != -1)
  7561. {
  7562. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7563. {
  7564. memcpy(&ShmOCPP20Data->SignCertificate.csr[strlen((char*)ShmOCPP20Data->SignCertificate.csr)], line, (strlen(line)-1));
  7565. }
  7566. }
  7567. fclose(fp);
  7568. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP20Data->SignCertificate.csr));
  7569. sprintf((char*)ShmOCPP20Data->SignCertificate.certificateType, CertificateSigningUseEnumTypeStr[certType]);
  7570. json_object_object_add(SignCertificate, "certificateType", json_object_new_string((char*)ShmOCPP20Data->SignCertificate.certificateType));
  7571. random_uuid(guid);
  7572. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7573. json_object_put(SignCertificate);
  7574. LWS_Send(message);
  7575. sprintf(tempdata, "SignCertificate,0");
  7576. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7577. {
  7578. result = PASS;
  7579. }
  7580. return result;
  7581. }
  7582. int sendStatusNotificationRequest(int gun_index)
  7583. {
  7584. mtrace();
  7585. int result = FAIL;
  7586. char message[600]={0};
  7587. char guid[37];
  7588. int currentStatus = 0;
  7589. struct timeval tmnow;
  7590. struct tm *tm;
  7591. char buf[28];//, usec_buf[6];
  7592. char tempdata[65]={0};
  7593. int tempIndex = 0;
  7594. uint8_t isStateChanged = TRUE;
  7595. DEBUG_INFO("sendStatusNotificationRequest...\n");
  7596. gettimeofday(&tmnow, NULL);
  7597. time_t t;
  7598. t = time(NULL);
  7599. /*UTC time and date*/
  7600. tm = gmtime(&t);
  7601. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  7602. #if 0 // remove temporally
  7603. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  7604. strcat(buf,".");
  7605. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  7606. strcat(buf,usec_buf);
  7607. #endif
  7608. printf("%s",buf);
  7609. ShmOCPP20Data->StatusNotification[gun_index].evseId = (gun_index + 1);
  7610. ShmOCPP20Data->StatusNotification[gun_index].connectorId = (gun_index + 1);
  7611. strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].timestamp, buf);
  7612. //strcpy(ShmOCPP20Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  7613. /*
  7614. enum _SYSTEM_STATUS
  7615. {
  7616. S_BOOTING = 0,
  7617. S_IDLE, = 1
  7618. S_AUTHORIZING, =2
  7619. S_REASSIGN_CHECK, =3
  7620. S_REASSIGN, =4
  7621. S_PRECHARGE, =5
  7622. S_PREPARING_FOR_EV, =6
  7623. S_PREPARING_FOR_EVSE, =7
  7624. S_CHARGING, =8
  7625. S_TERMINATING, =9
  7626. S_COMPLETE, =10
  7627. S_ALARM, =11
  7628. S_FAULT =12
  7629. }
  7630. */
  7631. //check Transaction active
  7632. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  7633. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7634. {
  7635. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7636. {
  7637. tempIndex = ((gun_index==2) ? 1: 0);
  7638. }
  7639. else
  7640. {
  7641. tempIndex = gun_index;
  7642. }
  7643. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7644. {
  7645. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  7646. {
  7647. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  7648. {
  7649. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  7650. {
  7651. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  7652. }
  7653. else
  7654. {
  7655. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  7656. }
  7657. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  7658. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  7659. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  7660. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  7661. }
  7662. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  7663. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  7664. ) //S_PRECHARGE
  7665. {
  7666. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  7667. }
  7668. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  7669. {
  7670. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  7671. }
  7672. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  7673. {
  7674. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  7675. }
  7676. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  7677. {
  7678. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  7679. }
  7680. 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
  7681. {
  7682. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  7683. }
  7684. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  7685. {
  7686. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  7687. }
  7688. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  7689. {
  7690. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  7691. }
  7692. } //end of the same index
  7693. }//end of for CHAdeMO_QUANTITY
  7694. }
  7695. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7696. {
  7697. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7698. {
  7699. tempIndex = ((gun_index==2) ? 1: 0);
  7700. }
  7701. else
  7702. {
  7703. tempIndex = gun_index;
  7704. }
  7705. for (int index = 0; index < CCS_QUANTITY; index++)
  7706. {
  7707. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7708. {
  7709. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7710. {
  7711. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  7712. {
  7713. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  7714. }
  7715. else
  7716. {
  7717. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  7718. }
  7719. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  7720. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  7721. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  7722. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  7723. }
  7724. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  7725. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  7726. ) //S_PRECHARGE
  7727. {
  7728. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  7729. }
  7730. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  7731. {
  7732. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  7733. }
  7734. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  7735. {
  7736. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  7737. }
  7738. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  7739. {
  7740. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  7741. }
  7742. 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
  7743. {
  7744. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status : Unavailable
  7745. }
  7746. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  7747. {
  7748. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  7749. }
  7750. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  7751. {
  7752. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  7753. }
  7754. } //end of the same index
  7755. } // end of for CCS_QUANTITY
  7756. }
  7757. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7758. {
  7759. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7760. {
  7761. tempIndex = ((gun_index==2) ? 1: 0);
  7762. }
  7763. else
  7764. {
  7765. tempIndex = gun_index;
  7766. }
  7767. for (int index = 0; index < GB_QUANTITY; index++)
  7768. {
  7769. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7770. {
  7771. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7772. {
  7773. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  7774. {
  7775. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  7776. }
  7777. else
  7778. {
  7779. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  7780. }
  7781. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  7782. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  7783. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  7784. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  7785. }
  7786. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  7787. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  7788. ) //S_PRECHARGE
  7789. {
  7790. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  7791. }
  7792. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  7793. {
  7794. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  7795. }
  7796. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  7797. {
  7798. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  7799. }
  7800. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  7801. {
  7802. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  7803. }
  7804. 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
  7805. {
  7806. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  7807. }
  7808. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  7809. {
  7810. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  7811. }
  7812. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  7813. {
  7814. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  7815. }
  7816. } //end of the same index
  7817. } // end of for GB_QUANTITY
  7818. }
  7819. else if(gunType[gun_index] == GUN_TYPE_DO)
  7820. {
  7821. tempIndex = gun_index;
  7822. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7823. {
  7824. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7825. {
  7826. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7827. {
  7828. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  7829. {
  7830. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  7831. }
  7832. else
  7833. {
  7834. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  7835. }
  7836. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  7837. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  7838. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  7839. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  7840. }
  7841. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  7842. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  7843. ) //S_PRECHARGE
  7844. {
  7845. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  7846. }
  7847. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  7848. {
  7849. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  7850. }
  7851. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  7852. {
  7853. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  7854. }
  7855. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  7856. {
  7857. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  7858. }
  7859. 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
  7860. {
  7861. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  7862. }
  7863. 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
  7864. {
  7865. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  7866. }
  7867. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  7868. {
  7869. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  7870. }
  7871. } //end of the same index
  7872. }
  7873. }
  7874. else
  7875. {
  7876. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7877. {
  7878. tempIndex = 2;
  7879. }
  7880. else
  7881. {
  7882. tempIndex = gun_index;
  7883. }
  7884. for (int index = 0; index < AC_QUANTITY; index++)
  7885. {
  7886. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7887. {
  7888. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  7889. {
  7890. 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))
  7891. {
  7892. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  7893. }
  7894. else
  7895. {
  7896. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  7897. }
  7898. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  7899. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  7900. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  7901. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  7902. }
  7903. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  7904. {
  7905. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  7906. }
  7907. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  7908. {
  7909. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  7910. }
  7911. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  7912. {
  7913. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  7914. }
  7915. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  7916. {
  7917. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  7918. }
  7919. 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
  7920. {
  7921. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  7922. }
  7923. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  7924. {
  7925. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  7926. }
  7927. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  7928. {
  7929. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  7930. }
  7931. }//end of the same index
  7932. }//end of for AC_QUANTITY
  7933. }
  7934. //it's option
  7935. if((strstr((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]) != NULL) &&
  7936. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  7937. {
  7938. isStateChanged = FALSE;
  7939. }
  7940. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  7941. strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]);
  7942. random_uuid(guid);
  7943. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"evseId\":%d,\"connectorStatus\":\"%s\",\"timestamp\":\"%s\"}]"
  7944. , MESSAGE_TYPE_CALL
  7945. , guid
  7946. , ShmOCPP20Data->StatusNotification[gun_index].connectorId
  7947. , ShmOCPP20Data->StatusNotification[gun_index].evseId
  7948. , ShmOCPP20Data->StatusNotification[gun_index].connectorStatus
  7949. , ShmOCPP20Data->StatusNotification[gun_index].timestamp);
  7950. if((server_sign == TRUE) && isStateChanged)
  7951. {
  7952. LWS_Send(message);
  7953. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  7954. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7955. {
  7956. result = PASS;
  7957. }
  7958. }
  7959. else
  7960. {
  7961. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  7962. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  7963. result = PASS;
  7964. }
  7965. return result;
  7966. }
  7967. int sendTransactionEventRequest(int gun_index)
  7968. {
  7969. mtrace();
  7970. int result = FAIL;
  7971. char message[1024*20]={0};
  7972. char guid[37]={0};
  7973. char tempdata[128]={0};
  7974. uint8_t tempIndex;
  7975. json_object *TransactionEvent = json_object_new_object();
  7976. json_object *transactionInfo = json_object_new_object();
  7977. json_object *idToken = json_object_new_object();
  7978. json_object *evse = json_object_new_object();
  7979. json_object *meterValues = json_object_new_array();
  7980. char TempStopTransaction[256];
  7981. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  7982. DEBUG_INFO("sendTransactionEventRequest...\n");
  7983. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7984. {
  7985. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7986. {
  7987. tempIndex = ((gun_index==2) ? 1: 0);
  7988. }
  7989. else
  7990. {
  7991. tempIndex = gun_index;
  7992. }
  7993. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7994. {
  7995. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  7996. {
  7997. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  7998. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  7999. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  8000. else
  8001. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  8002. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  8003. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  8004. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  8005. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  8006. {
  8007. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  8008. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  8009. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  8010. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8011. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  8012. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  8013. {
  8014. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  8015. }
  8016. else
  8017. {
  8018. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  8019. }
  8020. }
  8021. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  8022. {
  8023. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8024. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  8025. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  8026. }
  8027. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  8028. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  8029. ) //S_PRECHARGE
  8030. {
  8031. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  8032. {
  8033. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  8034. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartUserId);
  8035. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", ShmOCPP20Data->Authorize.idToken.type);
  8036. storeTempStopTransaction(gun_index);
  8037. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8038. }
  8039. else
  8040. {
  8041. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8042. }
  8043. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  8044. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8045. }
  8046. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  8047. {
  8048. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8049. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  8050. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8051. }
  8052. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  8053. {
  8054. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  8055. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  8056. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8057. if((access(TempStopTransaction,F_OK))!=-1)
  8058. {
  8059. remove(TempStopTransaction); // remove file "TempStopTransaction"
  8060. }
  8061. }
  8062. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  8063. {
  8064. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8065. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  8066. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8067. }
  8068. 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
  8069. {
  8070. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8071. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8072. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8073. }
  8074. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  8075. {
  8076. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8077. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8078. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8079. }
  8080. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  8081. {
  8082. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8083. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8084. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8085. }
  8086. } //end of the same index
  8087. }//end of for CHAdeMO_QUANTITY
  8088. }
  8089. else if(gunType[gun_index] == GUN_TYPE_CCS)
  8090. {
  8091. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8092. {
  8093. tempIndex = ((gun_index==2) ? 1: 0);
  8094. }
  8095. else
  8096. {
  8097. tempIndex = gun_index;
  8098. }
  8099. for (int index = 0; index < CCS_QUANTITY; index++)
  8100. {
  8101. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8102. {
  8103. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  8104. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  8105. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  8106. else
  8107. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  8108. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  8109. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  8110. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  8111. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8112. {
  8113. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  8114. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  8115. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  8116. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8117. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  8118. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  8119. {
  8120. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  8121. }
  8122. else
  8123. {
  8124. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  8125. }
  8126. }
  8127. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  8128. {
  8129. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8130. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  8131. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  8132. }
  8133. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  8134. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  8135. ) //S_PRECHARGE
  8136. {
  8137. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  8138. {
  8139. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  8140. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartUserId);
  8141. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", ShmOCPP20Data->Authorize.idToken.type);
  8142. storeTempStopTransaction(gun_index);
  8143. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8144. }
  8145. else
  8146. {
  8147. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8148. }
  8149. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  8150. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8151. }
  8152. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  8153. {
  8154. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8155. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  8156. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8157. }
  8158. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  8159. {
  8160. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  8161. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  8162. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8163. if((access(TempStopTransaction,F_OK))!=-1)
  8164. {
  8165. remove(TempStopTransaction); // remove file "TempStopTransaction"
  8166. }
  8167. }
  8168. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  8169. {
  8170. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8171. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  8172. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8173. }
  8174. 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
  8175. {
  8176. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8177. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8178. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8179. }
  8180. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  8181. {
  8182. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8183. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8184. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8185. }
  8186. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  8187. {
  8188. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8189. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8190. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8191. }
  8192. } //end of the same index
  8193. } // end of for CCS_QUANTITY
  8194. }
  8195. else if(gunType[gun_index] == GUN_TYPE_GBT)
  8196. {
  8197. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8198. {
  8199. tempIndex = ((gun_index==2) ? 1: 0);
  8200. }
  8201. else
  8202. {
  8203. tempIndex = gun_index;
  8204. }
  8205. for (int index = 0; index < GB_QUANTITY; index++)
  8206. {
  8207. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8208. {
  8209. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  8210. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  8211. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  8212. else
  8213. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  8214. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  8215. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  8216. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  8217. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8218. {
  8219. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  8220. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  8221. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  8222. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8223. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  8224. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  8225. {
  8226. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  8227. }
  8228. else
  8229. {
  8230. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  8231. }
  8232. }
  8233. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  8234. {
  8235. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8236. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  8237. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  8238. }
  8239. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  8240. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  8241. ) //S_PRECHARGE
  8242. {
  8243. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  8244. {
  8245. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  8246. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartUserId);
  8247. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", ShmOCPP20Data->Authorize.idToken.type);
  8248. storeTempStopTransaction(gun_index);
  8249. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8250. }
  8251. else
  8252. {
  8253. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8254. }
  8255. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  8256. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8257. }
  8258. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  8259. {
  8260. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8261. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  8262. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8263. }
  8264. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  8265. {
  8266. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  8267. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  8268. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8269. if((access(TempStopTransaction,F_OK))!=-1)
  8270. {
  8271. remove(TempStopTransaction); // remove file "TempStopTransaction"
  8272. }
  8273. }
  8274. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  8275. {
  8276. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8277. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  8278. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8279. }
  8280. 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
  8281. {
  8282. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8283. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8284. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8285. }
  8286. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  8287. {
  8288. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8289. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8290. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8291. }
  8292. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  8293. {
  8294. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8295. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8296. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8297. }
  8298. } //end of the same index
  8299. } // end of for GB_QUANTITY
  8300. }
  8301. else if(gunType[gun_index] == GUN_TYPE_DO)
  8302. {
  8303. tempIndex = gun_index;
  8304. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8305. {
  8306. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8307. {
  8308. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  8309. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  8310. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  8311. else
  8312. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  8313. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  8314. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  8315. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  8316. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  8317. {
  8318. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  8319. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  8320. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  8321. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8322. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  8323. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  8324. {
  8325. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  8326. }
  8327. else
  8328. {
  8329. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  8330. }
  8331. }
  8332. else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  8333. {
  8334. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8335. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  8336. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  8337. }
  8338. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  8339. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  8340. ) //S_PRECHARGE
  8341. {
  8342. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  8343. {
  8344. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  8345. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartUserId);
  8346. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", ShmOCPP20Data->Authorize.idToken.type);
  8347. storeTempStopTransaction(gun_index);
  8348. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8349. }
  8350. else
  8351. {
  8352. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8353. }
  8354. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  8355. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8356. }
  8357. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  8358. {
  8359. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8360. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  8361. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8362. }
  8363. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  8364. {
  8365. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  8366. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  8367. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8368. if((access(TempStopTransaction,F_OK))!=-1)
  8369. {
  8370. remove(TempStopTransaction); // remove file "TempStopTransaction"
  8371. }
  8372. }
  8373. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  8374. {
  8375. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8376. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  8377. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8378. }
  8379. 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
  8380. {
  8381. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8382. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8383. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8384. }
  8385. 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
  8386. {
  8387. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8388. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8389. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8390. }
  8391. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  8392. {
  8393. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8394. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8395. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8396. }
  8397. } //end of the same index
  8398. }
  8399. }
  8400. else
  8401. {
  8402. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  8403. {
  8404. tempIndex = 2;
  8405. }
  8406. else
  8407. {
  8408. tempIndex = gun_index;
  8409. }
  8410. for (int index = 0; index < AC_QUANTITY; index++)
  8411. {
  8412. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8413. {
  8414. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  8415. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  8416. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  8417. else
  8418. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  8419. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  8420. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  8421. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  8422. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  8423. {
  8424. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  8425. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  8426. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  8427. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8428. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  8429. 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))
  8430. {
  8431. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  8432. }
  8433. else
  8434. {
  8435. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  8436. }
  8437. }
  8438. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  8439. {
  8440. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8441. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  8442. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  8443. }
  8444. else if ( ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  8445. ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  8446. ) //S_PRECHARGE
  8447. {
  8448. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  8449. {
  8450. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  8451. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartUserId);
  8452. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", ShmOCPP20Data->Authorize.idToken.type);
  8453. storeTempStopTransaction(gun_index);
  8454. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8455. }
  8456. else
  8457. {
  8458. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8459. }
  8460. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  8461. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8462. }
  8463. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  8464. {
  8465. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8466. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  8467. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8468. }
  8469. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  8470. {
  8471. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  8472. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  8473. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8474. if((access(TempStopTransaction,F_OK))!=-1)
  8475. {
  8476. remove(TempStopTransaction); // remove file "TempStopTransaction"
  8477. }
  8478. }
  8479. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  8480. {
  8481. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8482. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  8483. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8484. }
  8485. 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
  8486. {
  8487. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8488. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8489. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8490. }
  8491. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  8492. {
  8493. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8494. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8495. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8496. }
  8497. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  8498. {
  8499. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8500. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8501. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8502. }
  8503. }//end of the same index
  8504. }//end of for AC_QUANTITY
  8505. }
  8506. // Message
  8507. json_object_object_add(TransactionEvent, "eventType", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  8508. json_object_object_add(TransactionEvent, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].timestamp));
  8509. json_object_object_add(TransactionEvent, "triggerReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason));
  8510. json_object_object_add(TransactionEvent, "seqNo", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].seqNo));
  8511. json_object_object_add(TransactionEvent, "offline", json_object_new_boolean(ShmOCPP20Data->TransactionEvent[gun_index].offline));
  8512. if(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed > 0)
  8513. json_object_object_add(TransactionEvent, "numberOfPhasesUsed", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed));
  8514. if(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent > 0)
  8515. json_object_object_add(TransactionEvent, "cableMaxCurrent", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent));
  8516. if(ShmOCPP20Data->TransactionEvent[gun_index].reservationId > 0)
  8517. json_object_object_add(TransactionEvent, "reservationId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].reservationId));
  8518. json_object_object_add(transactionInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId));
  8519. json_object_object_add(transactionInfo, "chargingState", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState));
  8520. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging > 0)
  8521. json_object_object_add(transactionInfo, "timeSpentCharging", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging));
  8522. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason) > 0)
  8523. json_object_object_add(transactionInfo, "stoppedReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason));
  8524. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId > 0)
  8525. json_object_object_add(transactionInfo, "remoteStartId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId));
  8526. json_object_object_add(TransactionEvent, "transactionInfo", transactionInfo);
  8527. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken) > 0)
  8528. {
  8529. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
  8530. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type));
  8531. json_object_object_add(TransactionEvent, "idToken", idToken);
  8532. }
  8533. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.id));
  8534. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId));
  8535. json_object_object_add(TransactionEvent, "evse", evse);
  8536. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0].timestamp) > 0)
  8537. {
  8538. for(int idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue);idxMeter++)
  8539. {
  8540. json_object *meterValue = json_object_new_object();
  8541. json_object *sampledValues = json_object_new_array();
  8542. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].timestamp));
  8543. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  8544. {
  8545. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0) &&
  8546. ((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)))
  8547. {
  8548. json_object *sampledValue = json_object_new_object();
  8549. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  8550. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  8551. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  8552. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  8553. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  8554. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  8555. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  8556. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  8557. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  8558. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  8559. {
  8560. json_object *unitOfMeasure = json_object_new_object();
  8561. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  8562. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  8563. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  8564. }
  8565. json_object_array_add(sampledValues, sampledValue);
  8566. }
  8567. }
  8568. json_object_object_add(meterValue, "sampledValue", sampledValues);
  8569. json_object_array_add(meterValues, meterValue);
  8570. }
  8571. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  8572. }
  8573. random_uuid(guid);
  8574. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "TransactionEvent", json_object_to_json_string_ext(TransactionEvent, JSON_C_TO_STRING_PLAIN));
  8575. json_object_put(TransactionEvent);
  8576. sprintf(tempdata, "TransactionEvent,%d", gun_index);
  8577. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8578. {
  8579. result = PASS;
  8580. }
  8581. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  8582. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Started]) != NULL)
  8583. OCPP_insert_transaction_msg(YES, message);
  8584. else if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL)
  8585. OCPP_insert_transaction_msg(NO, message);
  8586. return result;
  8587. }
  8588. //==========================================
  8589. // send confirm routine
  8590. //==========================================
  8591. int sendCancelReservationConfirmation(char *uuid, unsigned char gun_index)
  8592. {
  8593. mtrace();
  8594. int result = FAIL;
  8595. char message[4096]={0};
  8596. json_object *CancelReservation = json_object_new_object();
  8597. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  8598. json_object_object_add(CancelReservation, "status", json_object_new_string((char*)ShmOCPP20Data->CancelReservation[gun_index].Response_status));
  8599. sprintf(message,"[%d,\"%s\",%s]"
  8600. ,MESSAGE_TYPE_CALLRESULT
  8601. ,uuid
  8602. ,json_object_to_json_string_ext(CancelReservation, JSON_C_TO_STRING_PLAIN));
  8603. json_object_put(CancelReservation);
  8604. ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationConf = OFF;
  8605. LWS_Send(message);
  8606. result = TRUE;
  8607. return result;
  8608. }
  8609. int sendCertificateSignedConfirmation(char *uuid)
  8610. {
  8611. mtrace();
  8612. int result = FAIL;
  8613. char message[4096]={0};
  8614. json_object *CertificateSigned = json_object_new_object();
  8615. json_object *statusInfo = json_object_new_object();
  8616. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8617. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_status));
  8618. if(strlen((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.reasonCode) > 0)
  8619. {
  8620. json_object_object_add(statusInfo, "reasonCode", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.reasonCode));
  8621. if(strlen((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.additionalInfo) > 0)
  8622. json_object_object_add(statusInfo, "statadditionalInfous", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.additionalInfo));
  8623. }
  8624. json_object_object_add(CertificateSigned, "statusInfo", statusInfo);
  8625. sprintf(message,"[%d,\"%s\",%s]"
  8626. ,MESSAGE_TYPE_CALLRESULT
  8627. ,uuid
  8628. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8629. json_object_put(CertificateSigned);
  8630. LWS_Send(message);
  8631. result = TRUE;
  8632. return result;
  8633. }
  8634. int sendChangeAvailabilityConfirmation(char *uuid, unsigned char gun_index)
  8635. {
  8636. mtrace();
  8637. int result = FAIL;
  8638. char message[4096]={0};
  8639. json_object *ChangeAvailability = json_object_new_object();
  8640. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  8641. json_object_object_add(ChangeAvailability, "status", json_object_new_string((char*)ShmOCPP20Data->ChangeAvailability[gun_index].Response_status));
  8642. sprintf(message,"[%d,\"%s\",%s]"
  8643. ,MESSAGE_TYPE_CALLRESULT
  8644. ,uuid
  8645. ,json_object_to_json_string_ext(ChangeAvailability, JSON_C_TO_STRING_PLAIN));
  8646. json_object_put(ChangeAvailability);
  8647. LWS_Send(message);
  8648. result = TRUE;
  8649. return result;
  8650. }
  8651. int sendClearCacheConfirmation(char *uuid)
  8652. {
  8653. mtrace();
  8654. int result = FAIL;
  8655. char message[4096]={0};
  8656. json_object *ClearCache = json_object_new_object();
  8657. DEBUG_INFO("sendClearCacheConfirmation...\n");
  8658. json_object_object_add(ClearCache, "status", json_object_new_string((char*)ShmOCPP20Data->ClearCache.Response_status));
  8659. sprintf(message,"[%d,\"%s\",%s]"
  8660. ,MESSAGE_TYPE_CALLRESULT
  8661. ,uuid
  8662. ,json_object_to_json_string_ext(ClearCache, JSON_C_TO_STRING_PLAIN));
  8663. json_object_put(ClearCache);
  8664. LWS_Send(message);
  8665. result = TRUE;
  8666. return result;
  8667. }
  8668. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  8669. {
  8670. mtrace();
  8671. int result = FAIL;
  8672. char message[500]={0};
  8673. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  8674. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8675. LWS_Send(message);
  8676. return result;
  8677. }
  8678. int sendClearDisplayMessageConfirmation(char *uuid)
  8679. {
  8680. mtrace();
  8681. int result = FAIL;
  8682. char message[4096]={0};
  8683. json_object *ClearDisplayMessage = json_object_new_object();
  8684. DEBUG_INFO("sendClearDisplayMessageConfirmation...\n");
  8685. json_object_object_add(ClearDisplayMessage, "status", json_object_new_string((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status));
  8686. sprintf(message,"[%d,\"%s\",%s]"
  8687. ,MESSAGE_TYPE_CALLRESULT
  8688. ,uuid
  8689. ,json_object_to_json_string_ext(ClearDisplayMessage, JSON_C_TO_STRING_PLAIN));
  8690. json_object_put(ClearDisplayMessage);
  8691. LWS_Send(message);
  8692. result = TRUE;
  8693. return result;
  8694. }
  8695. int sendClearVariableMonitoringConfirmation(char *uuid, unsigned char variableQuantity)
  8696. {
  8697. mtrace();
  8698. int result = FAIL;
  8699. char message[4096]={0};
  8700. json_object *ClearVariableMonitoring = json_object_new_object();
  8701. json_object *clearMonitoringResults = json_object_new_array();
  8702. DEBUG_INFO("sendClearVariableMonitoringConfirmation...\n");
  8703. for(int idx=0;idx<variableQuantity;idx++)
  8704. {
  8705. json_object *clearMonitoringResult = json_object_new_object();
  8706. json_object_object_add(clearMonitoringResult, "id", json_object_new_int(ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].id));
  8707. json_object_object_add(clearMonitoringResult, "status", json_object_new_string((char*)ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].status));
  8708. json_object_array_add(clearMonitoringResults, clearMonitoringResult);
  8709. }
  8710. json_object_object_add(ClearVariableMonitoring, "clearMonitoringResult", clearMonitoringResults);
  8711. sprintf(message,"[%d,\"%s\",%s]"
  8712. ,MESSAGE_TYPE_CALLRESULT
  8713. ,uuid
  8714. ,json_object_to_json_string_ext(ClearVariableMonitoring, JSON_C_TO_STRING_PLAIN));
  8715. json_object_put(ClearVariableMonitoring);
  8716. LWS_Send(message);
  8717. result = TRUE;
  8718. return result;
  8719. }
  8720. int sendCostUpdatedConfirmation(char *uuid)
  8721. {
  8722. mtrace();
  8723. int result = FAIL;
  8724. char message[4096]={0};
  8725. DEBUG_INFO("sendCostUpdatedConfirmation...\n");
  8726. sprintf(message,"[%d,\"%s\",{}]"
  8727. ,MESSAGE_TYPE_CALLRESULT
  8728. ,uuid);
  8729. LWS_Send(message);
  8730. result = TRUE;
  8731. return result;
  8732. }
  8733. int sendCustomerInformationConfirmation(char *uuid)
  8734. {
  8735. mtrace();
  8736. int result = FAIL;
  8737. char message[4096]={0};
  8738. json_object *CustomerInformation = json_object_new_object();
  8739. DEBUG_INFO("sendCustomerInformationConfirmation...\n");
  8740. json_object_object_add(CustomerInformation, "status", json_object_new_string((char*)ShmOCPP20Data->CustomerInformation.Response_status));
  8741. sprintf(message,"[%d,\"%s\",%s]"
  8742. ,MESSAGE_TYPE_CALLRESULT
  8743. ,uuid
  8744. ,json_object_to_json_string_ext(CustomerInformation, JSON_C_TO_STRING_PLAIN));
  8745. json_object_put(CustomerInformation);
  8746. LWS_Send(message);
  8747. result = TRUE;
  8748. return result;
  8749. }
  8750. int sendDataTransferConfirmation(char *uuid, unsigned char gun_index)
  8751. {
  8752. mtrace();
  8753. int result = FAIL;
  8754. char message[4096]={0};
  8755. json_object *DataTransfer = json_object_new_object();
  8756. DEBUG_INFO("sendDataTransferConfirmation...\n");
  8757. json_object_object_add(DataTransfer, "status", json_object_new_string((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_status));
  8758. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_data));
  8759. sprintf(message,"[%d,\"%s\",%s]"
  8760. ,MESSAGE_TYPE_CALLRESULT
  8761. ,uuid
  8762. ,json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  8763. json_object_put(DataTransfer);
  8764. LWS_Send(message);
  8765. result = TRUE;
  8766. return result;
  8767. }
  8768. int sendDeleteCertificateConfirmation(char *uuid)
  8769. {
  8770. mtrace();
  8771. int result = FAIL;
  8772. char message[4096]={0};
  8773. json_object *DeleteCertificate = json_object_new_object();
  8774. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8775. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP20Data->DeleteCertificate.Response_status));
  8776. sprintf(message,"[%d,\"%s\",%s]"
  8777. ,MESSAGE_TYPE_CALLRESULT
  8778. ,uuid
  8779. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8780. json_object_put(DeleteCertificate);
  8781. LWS_Send(message);
  8782. result = TRUE;
  8783. return result;
  8784. }
  8785. int sendGetBaseReportConfirmation(char *uuid)
  8786. {
  8787. mtrace();
  8788. int result = FAIL;
  8789. char message[4096]={0};
  8790. json_object *GetBaseReport = json_object_new_object();
  8791. DEBUG_INFO("sendGetBaseReportConfirmation...\n");
  8792. json_object_object_add(GetBaseReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetBaseReport.Response_status));
  8793. sprintf(message,"[%d,\"%s\",%s]"
  8794. ,MESSAGE_TYPE_CALLRESULT
  8795. ,uuid
  8796. ,json_object_to_json_string_ext(GetBaseReport, JSON_C_TO_STRING_PLAIN));
  8797. json_object_put(GetBaseReport);
  8798. LWS_Send(message);
  8799. result = TRUE;
  8800. return result;
  8801. }
  8802. int sendGetChargingProfilesConfirmation(char *uuid, unsigned char gun_index)
  8803. {
  8804. mtrace();
  8805. int result = FAIL;
  8806. char message[4096]={0};
  8807. json_object *GetChargingProfiles = json_object_new_object();
  8808. DEBUG_INFO("sendGetChargingProfilesConfirmation...\n");
  8809. json_object_object_add(GetChargingProfiles, "status", json_object_new_string((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status));
  8810. sprintf(message,"[%d,\"%s\",%s]"
  8811. ,MESSAGE_TYPE_CALLRESULT
  8812. ,uuid
  8813. ,json_object_to_json_string_ext(GetChargingProfiles, JSON_C_TO_STRING_PLAIN));
  8814. json_object_put(GetChargingProfiles);
  8815. LWS_Send(message);
  8816. result = TRUE;
  8817. return result;
  8818. }
  8819. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  8820. {
  8821. mtrace();
  8822. int result = FAIL;
  8823. char message[4096]={0};
  8824. int CompositeScheduleIndex = 0;
  8825. json_object *GetCompositeSchedule = json_object_new_object();
  8826. json_object *schedule = json_object_new_object();
  8827. json_object *chargingSchedule = json_object_new_object();
  8828. json_object *chargingSchedulePeriod = json_object_new_array();
  8829. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  8830. json_object_object_add(GetCompositeSchedule, "status", json_object_new_string(payload));
  8831. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  8832. if(nPeriod == 0)
  8833. {
  8834. if(strcmp((const char *)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime,"")!=0)
  8835. {
  8836. if(strlen((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule))
  8837. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule));
  8838. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration > 0)
  8839. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration));
  8840. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit));
  8841. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate > 0)
  8842. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate));
  8843. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.id));
  8844. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  8845. {
  8846. if(((ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  8847. (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  8848. {
  8849. json_object *Period = json_object_new_object();
  8850. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  8851. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  8852. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  8853. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  8854. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  8855. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  8856. json_object_array_add(chargingSchedulePeriod, Period);
  8857. }
  8858. }
  8859. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriod);
  8860. json_object_object_add(schedule, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime));
  8861. json_object_object_add(schedule, "chargingSchedule", chargingSchedule);
  8862. json_object_object_add(GetCompositeSchedule, "schedule", schedule);
  8863. }
  8864. }
  8865. else
  8866. {
  8867. if(strlen((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule))
  8868. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule));
  8869. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration > 0)
  8870. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration));
  8871. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit));
  8872. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate > 0)
  8873. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate));
  8874. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.id));
  8875. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  8876. {
  8877. if(((ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  8878. (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  8879. {
  8880. json_object *Period = json_object_new_object();
  8881. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  8882. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  8883. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  8884. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  8885. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  8886. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  8887. json_object_array_add(chargingSchedulePeriod, Period);
  8888. }
  8889. }
  8890. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriod);
  8891. json_object_object_add(schedule, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime));
  8892. json_object_object_add(schedule, "chargingSchedule", chargingSchedule);
  8893. json_object_object_add(GetCompositeSchedule, "schedule", schedule);
  8894. }
  8895. sprintf(message,"[%d,\"%s\",%s]"
  8896. ,MESSAGE_TYPE_CALLRESULT
  8897. ,uuid
  8898. ,json_object_to_json_string_ext(GetCompositeSchedule, JSON_C_TO_STRING_PLAIN));
  8899. json_object_put(GetCompositeSchedule);
  8900. LWS_Send(message);
  8901. result = TRUE;
  8902. return result;
  8903. }
  8904. int sendGetGetDisplayMessagesConfirmation(char *uuid)
  8905. {
  8906. mtrace();
  8907. int result = FAIL;
  8908. char message[4096]={0};
  8909. json_object *GetGetDisplayMessages = json_object_new_object();
  8910. DEBUG_INFO("sendGetGetDisplayMessagesConfirmation...\n");
  8911. json_object_object_add(GetGetDisplayMessages, "status", json_object_new_string((char*)ShmOCPP20Data->GetDisplayMessages.Response_status));
  8912. sprintf(message,"[%d,\"%s\",%s]"
  8913. ,MESSAGE_TYPE_CALLRESULT
  8914. ,uuid
  8915. ,json_object_to_json_string_ext(GetGetDisplayMessages, JSON_C_TO_STRING_PLAIN));
  8916. json_object_put(GetGetDisplayMessages);
  8917. LWS_Send(message);
  8918. result = TRUE;
  8919. return result;
  8920. }
  8921. int sendGetInstalledCertificateIdsConfirmation(char *uuid, unsigned char certQuantity)
  8922. {
  8923. mtrace();
  8924. int result = FAIL;
  8925. char message[4096]={0};
  8926. json_object *GetInstalledCertificateIds = json_object_new_object();
  8927. json_object *certificateHashDataChains = json_object_new_array();
  8928. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8929. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status));
  8930. for(int idx=0;idx<certQuantity;idx++)
  8931. {
  8932. json_object *cert = json_object_new_object();
  8933. json_object *certificateHashData = json_object_new_object();
  8934. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.hashAlgorithm));
  8935. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.issuerNameHash));
  8936. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.issuerKeyHash));
  8937. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.serialNumber));
  8938. json_object_object_add(cert, "certificateHashData", certificateHashData);
  8939. json_object_object_add(cert, "certificateType", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateType));
  8940. json_object_array_add(certificateHashDataChains, cert);
  8941. }
  8942. json_object_object_add(GetInstalledCertificateIds , "certificateHashDataChain", certificateHashDataChains);
  8943. sprintf(message,"[%d,\"%s\",%s]"
  8944. ,MESSAGE_TYPE_CALLRESULT
  8945. ,uuid
  8946. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8947. json_object_put(GetInstalledCertificateIds);
  8948. LWS_Send(message);
  8949. result = TRUE;
  8950. return result;
  8951. }
  8952. int sendGetLocalListVersionConfirmation(char *uuid)
  8953. {
  8954. mtrace();
  8955. int result = FAIL;
  8956. char message[4096]={0};
  8957. json_object *GetLocalListVersion = json_object_new_object();
  8958. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  8959. json_object_object_add(GetLocalListVersion, "versionNumber", json_object_new_int(ShmOCPP20Data->GetLocalListVersion.Response_versionNumber));
  8960. sprintf(message,"[%d,\"%s\",%s]"
  8961. ,MESSAGE_TYPE_CALLRESULT
  8962. ,uuid
  8963. ,json_object_to_json_string_ext(GetLocalListVersion, JSON_C_TO_STRING_PLAIN));
  8964. json_object_put(GetLocalListVersion);
  8965. LWS_Send(message);
  8966. result = TRUE;
  8967. return result;
  8968. }
  8969. int sendGetLogConfirmation(char *uuid)
  8970. {
  8971. mtrace();
  8972. int result = FAIL;
  8973. char message[4096]={0};
  8974. json_object *GetLog = json_object_new_object();
  8975. DEBUG_INFO("sendGetLogConfirmation...\n");
  8976. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP20Data->GetLog.Response_status));
  8977. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP20Data->GetLog.Response_filename));
  8978. sprintf(message,"[%d,\"%s\",%s]"
  8979. ,MESSAGE_TYPE_CALLRESULT
  8980. ,uuid
  8981. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8982. json_object_put(GetLog);
  8983. LWS_Send(message);
  8984. result = TRUE;
  8985. return result;
  8986. }
  8987. int sendGetMonitoringReportConfirmation(char *uuid)
  8988. {
  8989. mtrace();
  8990. int result = FAIL;
  8991. char message[4096]={0};
  8992. json_object *GetMonitoringReport = json_object_new_object();
  8993. DEBUG_INFO("sendGetMonitoringReportConfirmation...\n");
  8994. json_object_object_add(GetMonitoringReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetMonitoringReport.Response_status));
  8995. sprintf(message,"[%d,\"%s\",%s]"
  8996. ,MESSAGE_TYPE_CALLRESULT
  8997. ,uuid
  8998. ,json_object_to_json_string_ext(GetMonitoringReport, JSON_C_TO_STRING_PLAIN));
  8999. json_object_put(GetMonitoringReport);
  9000. LWS_Send(message);
  9001. result = TRUE;
  9002. return result;
  9003. }
  9004. int sendGetReportConfirmation(char *uuid)
  9005. {
  9006. mtrace();
  9007. int result = FAIL;
  9008. char message[4096]={0};
  9009. json_object *GetReport = json_object_new_object();
  9010. DEBUG_INFO("sendGetReportConfirmation...\n");
  9011. json_object_object_add(GetReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetReport.Response_status));
  9012. sprintf(message,"[%d,\"%s\",%s]"
  9013. ,MESSAGE_TYPE_CALLRESULT
  9014. ,uuid
  9015. ,json_object_to_json_string_ext(GetReport, JSON_C_TO_STRING_PLAIN));
  9016. json_object_put(GetReport);
  9017. LWS_Send(message);
  9018. result = TRUE;
  9019. return result;
  9020. }
  9021. int sendGetTransactionStatusConfirmation(char *uuid, unsigned char gun_index)
  9022. {
  9023. mtrace();
  9024. int result = FAIL;
  9025. char message[4096]={0};
  9026. json_object *GetTransactionStatus = json_object_new_object();
  9027. DEBUG_INFO("sendGetTransactionStatusConfirmation...\n");
  9028. json_object_object_add(GetTransactionStatus, "ongoingIndicator", json_object_new_boolean(ShmOCPP20Data->GetTransactionStatus[gun_index].Response_ongoingIndicator));
  9029. json_object_object_add(GetTransactionStatus, "messagesInQueue", json_object_new_boolean(ShmOCPP20Data->GetTransactionStatus[gun_index].Response_messagesInQueue));
  9030. sprintf(message,"[%d,\"%s\",%s]"
  9031. ,MESSAGE_TYPE_CALLRESULT
  9032. ,uuid
  9033. ,json_object_to_json_string_ext(GetTransactionStatus, JSON_C_TO_STRING_PLAIN));
  9034. json_object_put(GetTransactionStatus);
  9035. LWS_Send(message);
  9036. result = TRUE;
  9037. return result;
  9038. }
  9039. int sendGetVariablesConfirmation(char *uuid, unsigned char variableQuantity)
  9040. {
  9041. mtrace();
  9042. int result = FAIL;
  9043. char message[4096]={0};
  9044. json_object *GetVariables = json_object_new_object();
  9045. json_object *getVariableResults = json_object_new_array();
  9046. DEBUG_INFO("sendGetVariablesConfirmation...\n");
  9047. for(int idx=0;idx<variableQuantity;idx++)
  9048. {
  9049. json_object *variableResult = json_object_new_object();
  9050. json_object *component = json_object_new_object();
  9051. json_object *variable = json_object_new_object();
  9052. json_object *evse = json_object_new_object();
  9053. json_object_object_add(variableResult, "attributeType", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType));
  9054. json_object_object_add(variableResult, "attributeStatus", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus));
  9055. json_object_object_add(variableResult, "attributeValue", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue));
  9056. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.id));
  9057. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.connectorId));
  9058. json_object_object_add(component, "evse", evse);
  9059. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.name));
  9060. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.instance));
  9061. json_object_object_add(variableResult, "component", component);
  9062. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.name));
  9063. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.instance));
  9064. json_object_object_add(variableResult, "variable", variable);
  9065. json_object_array_add(getVariableResults, variableResult);
  9066. }
  9067. json_object_object_add(GetVariables , "getVariableResult", getVariableResults);
  9068. sprintf(message,"[%d,\"%s\",%s]"
  9069. ,MESSAGE_TYPE_CALLRESULT
  9070. ,uuid
  9071. ,json_object_to_json_string_ext(GetVariables, JSON_C_TO_STRING_PLAIN));
  9072. json_object_put(GetVariables);
  9073. LWS_Send(message);
  9074. result = TRUE;
  9075. return result;
  9076. }
  9077. int sendInstallCertificateConfirmation(char *uuid)
  9078. {
  9079. mtrace();
  9080. int result = FAIL;
  9081. char message[4096]={0};
  9082. json_object *InstallCertificate = json_object_new_object();
  9083. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  9084. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP20Data->InstallCertificate.Response_status));
  9085. sprintf(message,"[%d,\"%s\",%s]"
  9086. ,MESSAGE_TYPE_CALLRESULT
  9087. ,uuid
  9088. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  9089. json_object_put(InstallCertificate);
  9090. LWS_Send(message);
  9091. result = TRUE;
  9092. return result;
  9093. }
  9094. int sendPublishFirmwareConfirmation(char *uuid)
  9095. {
  9096. mtrace();
  9097. int result = FAIL;
  9098. char message[4096]={0};
  9099. json_object *PublishFirmware = json_object_new_object();
  9100. json_object_object_add(PublishFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->PublishFirmware.Response_status));
  9101. DEBUG_INFO("sendPublishFirmwareConfirmation...\n");
  9102. sprintf(message,"[%d,\"%s\",%s]"
  9103. ,MESSAGE_TYPE_CALLRESULT
  9104. ,uuid
  9105. ,json_object_to_json_string_ext(PublishFirmware, JSON_C_TO_STRING_PLAIN));
  9106. json_object_put(PublishFirmware);
  9107. LWS_Send(message);
  9108. result = TRUE;
  9109. return result;
  9110. }
  9111. int sendRemoteStartTransactionConfirmation(char *uuid, unsigned char gun_index)
  9112. {
  9113. mtrace();
  9114. int result = FAIL;
  9115. char message[4096]={0};
  9116. json_object *RemoteStartTransaction = json_object_new_object();
  9117. json_object_object_add(RemoteStartTransaction, "status", json_object_new_string((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status));
  9118. json_object_object_add(RemoteStartTransaction, "transactionId", json_object_new_string((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId));
  9119. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  9120. sprintf(message,"[%d,\"%s\",%s]"
  9121. ,MESSAGE_TYPE_CALLRESULT
  9122. ,uuid
  9123. ,json_object_to_json_string_ext(RemoteStartTransaction, JSON_C_TO_STRING_PLAIN));
  9124. json_object_put(RemoteStartTransaction);
  9125. LWS_Send(message);
  9126. result = TRUE;
  9127. return result;
  9128. }
  9129. int sendRemoteStopTransactionConfirmation(char *uuid, unsigned char gun_index)
  9130. {
  9131. mtrace();
  9132. int result = FAIL;
  9133. char message[4096]={0};
  9134. json_object *RemoteStopTransaction = json_object_new_object();
  9135. json_object_object_add(RemoteStopTransaction, "status", json_object_new_string((char*)ShmOCPP20Data->RequestStopTransaction[gun_index].Response_status));
  9136. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  9137. sprintf(message,"[%d,\"%s\",%s]"
  9138. ,MESSAGE_TYPE_CALLRESULT
  9139. ,uuid
  9140. ,json_object_to_json_string_ext(RemoteStopTransaction, JSON_C_TO_STRING_PLAIN));
  9141. json_object_put(RemoteStopTransaction);
  9142. LWS_Send(message);
  9143. result = TRUE;
  9144. return result;
  9145. }
  9146. int sendReserveNowConfirmation(char *uuid, unsigned char gun_index)
  9147. {
  9148. mtrace();
  9149. int result = FAIL;
  9150. char message[4096]={0};
  9151. json_object *ReserveNow = json_object_new_object();
  9152. json_object_object_add(ReserveNow, "status", json_object_new_string((char*)ShmOCPP20Data->ReserveNow[gun_index].Response_status));
  9153. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  9154. sprintf(message,"[%d,\"%s\",%s]"
  9155. ,MESSAGE_TYPE_CALLRESULT
  9156. ,uuid
  9157. ,json_object_to_json_string_ext(ReserveNow, JSON_C_TO_STRING_PLAIN));
  9158. json_object_put(ReserveNow);
  9159. LWS_Send(message);
  9160. result = TRUE;
  9161. ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf = OFF;
  9162. return result;
  9163. }
  9164. int sendResetConfirmation(char *uuid)
  9165. {
  9166. mtrace();
  9167. int result = FAIL;
  9168. char message[4096]={0};
  9169. json_object *Reset = json_object_new_object();
  9170. DEBUG_INFO("sendResetConfirmation...\n");
  9171. ShmOCPP20Data->MsMsg.bits.ResetConf = OFF;
  9172. json_object_object_add(Reset, "status", json_object_new_string((char*)ShmOCPP20Data->Reset.Response_status));
  9173. sprintf(message,"[%d,\"%s\",%s]"
  9174. ,MESSAGE_TYPE_CALLRESULT
  9175. ,uuid
  9176. ,json_object_to_json_string_ext(Reset, JSON_C_TO_STRING_PLAIN));
  9177. json_object_put(Reset);
  9178. LWS_Send(message);
  9179. if(strcmp((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]) == 0)
  9180. {
  9181. DB_updateBootType(BootReasonEnumType_RemoteReset);
  9182. }
  9183. else if(strcmp((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Scheduled]) == 0)
  9184. {
  9185. DB_updateBootType(BootReasonEnumType_ScheduledReset);
  9186. }
  9187. result = TRUE;
  9188. return result;
  9189. }
  9190. int sendSendLocalListConfirmation(char *uuid)
  9191. {
  9192. mtrace();
  9193. int result = FAIL;
  9194. char message[4096]={0};
  9195. json_object *SendLocalList = json_object_new_object();
  9196. json_object_object_add(SendLocalList, "status", json_object_new_string((char*)ShmOCPP20Data->SendLocalList.Response_status));
  9197. sprintf(message,"[%d,\"%s\",%s]"
  9198. ,MESSAGE_TYPE_CALLRESULT
  9199. ,uuid
  9200. ,json_object_to_json_string_ext(SendLocalList, JSON_C_TO_STRING_PLAIN));
  9201. json_object_put(SendLocalList);
  9202. LWS_Send(message);
  9203. result = TRUE;
  9204. return result;
  9205. }
  9206. int sendSetChargingProfileConfirmation(char *uuid, unsigned char gun_index)
  9207. {
  9208. mtrace();
  9209. int result = FAIL;
  9210. char message[4096]={0};
  9211. json_object *SetChargingProfile = json_object_new_object();
  9212. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  9213. json_object_object_add(SetChargingProfile, "status", json_object_new_string((char*)ShmOCPP20Data->SetChargingProfile[gun_index].Response_status));
  9214. sprintf(message,"[%d,\"%s\",%s]"
  9215. ,MESSAGE_TYPE_CALLRESULT
  9216. ,uuid
  9217. ,json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  9218. json_object_put(SetChargingProfile);
  9219. LWS_Send(message);
  9220. result = TRUE;
  9221. return result;
  9222. }
  9223. int sendSetDisplayMessagesConfirmation(char *uuid)
  9224. {
  9225. mtrace();
  9226. int result = FAIL;
  9227. char message[4096]={0};
  9228. json_object *SetDisplayMessage = json_object_new_object();
  9229. DEBUG_INFO("sendSetDisplayMessageConfirmation...\n");
  9230. json_object_object_add(SetDisplayMessage, "status", json_object_new_string((char*)ShmOCPP20Data->SetDisplayMessage.Response_status));
  9231. sprintf(message,"[%d,\"%s\",%s]"
  9232. ,MESSAGE_TYPE_CALLRESULT
  9233. ,uuid
  9234. ,json_object_to_json_string_ext(SetDisplayMessage, JSON_C_TO_STRING_PLAIN));
  9235. json_object_put(SetDisplayMessage);
  9236. LWS_Send(message);
  9237. result = TRUE;
  9238. return result;
  9239. }
  9240. int sendSetMonitoringBaseConfirmation(char *uuid)
  9241. {
  9242. mtrace();
  9243. int result = FAIL;
  9244. char message[4096]={0};
  9245. json_object *SetMonitoringBase = json_object_new_object();
  9246. DEBUG_INFO("sendSetMonitoringBaseConfirmation...\n");
  9247. json_object_object_add(SetMonitoringBase, "status", json_object_new_string((char*)ShmOCPP20Data->SetMonitoringBase.Response_status));
  9248. sprintf(message,"[%d,\"%s\",%s]"
  9249. ,MESSAGE_TYPE_CALLRESULT
  9250. ,uuid
  9251. ,json_object_to_json_string_ext(SetMonitoringBase, JSON_C_TO_STRING_PLAIN));
  9252. json_object_put(SetMonitoringBase);
  9253. LWS_Send(message);
  9254. result = TRUE;
  9255. return result;
  9256. }
  9257. int sendSetMonitoringLevelConfirmation(char *uuid)
  9258. {
  9259. mtrace();
  9260. int result = FAIL;
  9261. char message[4096]={0};
  9262. json_object *SetMonitoringLevel = json_object_new_object();
  9263. DEBUG_INFO("sendSetMonitoringLevelConfirmation...\n");
  9264. json_object_object_add(SetMonitoringLevel, "status", json_object_new_string((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status));
  9265. sprintf(message,"[%d,\"%s\",%s]"
  9266. ,MESSAGE_TYPE_CALLRESULT
  9267. ,uuid
  9268. ,json_object_to_json_string_ext(SetMonitoringLevel, JSON_C_TO_STRING_PLAIN));
  9269. json_object_put(SetMonitoringLevel);
  9270. LWS_Send(message);
  9271. result = TRUE;
  9272. return result;
  9273. }
  9274. int sendSetNetworkProfileConfirmation(char *uuid)
  9275. {
  9276. mtrace();
  9277. int result = FAIL;
  9278. char message[4096]={0};
  9279. json_object *SetNetworkProfile = json_object_new_object();
  9280. DEBUG_INFO("sendSetNetworkProfileConfirmation...\n");
  9281. json_object_object_add(SetNetworkProfile, "status", json_object_new_string((char*)ShmOCPP20Data->SetNetworkProfile.Response_status));
  9282. sprintf(message,"[%d,\"%s\",%s]"
  9283. ,MESSAGE_TYPE_CALLRESULT
  9284. ,uuid
  9285. ,json_object_to_json_string_ext(SetNetworkProfile, JSON_C_TO_STRING_PLAIN));
  9286. json_object_put(SetNetworkProfile);
  9287. LWS_Send(message);
  9288. result = TRUE;
  9289. return result;
  9290. }
  9291. int sendSetVariableMonitoringConfirmation(char *uuid, unsigned char variableQuantity)
  9292. {
  9293. mtrace();
  9294. int result = FAIL;
  9295. char message[4096]={0};
  9296. json_object *SetVariableMonitoring = json_object_new_object();
  9297. json_object *setMonitoringResults = json_object_new_array();
  9298. DEBUG_INFO("sendSetVariableMonitoringConfirmation...\n");
  9299. for(int idx=0;idx<variableQuantity;idx++)
  9300. {
  9301. json_object *variableMonitorResult = json_object_new_object();
  9302. json_object *component = json_object_new_object();
  9303. json_object *variable = json_object_new_object();
  9304. json_object *evse = json_object_new_object();
  9305. json_object_object_add(variableMonitorResult, "id", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].id));
  9306. json_object_object_add(variableMonitorResult, "type", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type));
  9307. json_object_object_add(variableMonitorResult, "severity", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].severity));
  9308. json_object_object_add(variableMonitorResult, "status", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status));
  9309. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.id));
  9310. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.connectorId));
  9311. json_object_object_add(component, "component", evse);
  9312. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.name));
  9313. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.instance));
  9314. json_object_object_add(variableMonitorResult, "component", component);
  9315. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.name));
  9316. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.instance));
  9317. json_object_object_add(variableMonitorResult, "variable", variable);
  9318. json_object_array_add(setMonitoringResults, variableMonitorResult);
  9319. }
  9320. json_object_object_add(SetVariableMonitoring , "setMonitoringResult", setMonitoringResults);
  9321. sprintf(message,"[%d,\"%s\",%s]"
  9322. ,MESSAGE_TYPE_CALLRESULT
  9323. ,uuid
  9324. ,json_object_to_json_string_ext(SetVariableMonitoring, JSON_C_TO_STRING_PLAIN));
  9325. json_object_put(SetVariableMonitoring);
  9326. LWS_Send(message);
  9327. result = TRUE;
  9328. return result;
  9329. }
  9330. int sendSetVariableConfirmation(char *uuid, unsigned char variableQuantity)
  9331. {
  9332. mtrace();
  9333. int result = FAIL;
  9334. char message[4096]={0};
  9335. json_object *SetVariable = json_object_new_object();
  9336. json_object *setVariableResults = json_object_new_array();
  9337. DEBUG_INFO("sendSetVariableConfirmation...\n");
  9338. for(int idx=0;idx<variableQuantity;idx++)
  9339. {
  9340. json_object *variableResult = json_object_new_object();
  9341. json_object *component = json_object_new_object();
  9342. json_object *variable = json_object_new_object();
  9343. json_object *evse = json_object_new_object();
  9344. json_object_object_add(variableResult, "attributeType", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType));
  9345. json_object_object_add(variableResult, "attributeStatus", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus));
  9346. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.id));
  9347. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.connectorId));
  9348. json_object_object_add(component, "component", evse);
  9349. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.name));
  9350. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.instance));
  9351. json_object_object_add(variableResult, "component", component);
  9352. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.name));
  9353. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.instance));
  9354. json_object_object_add(variableResult, "variable", variable);
  9355. json_object_array_add(setVariableResults, variableResult);
  9356. }
  9357. json_object_object_add(SetVariable , "setVariableResult", setVariableResults);
  9358. sprintf(message,"[%d,\"%s\",%s]"
  9359. ,MESSAGE_TYPE_CALLRESULT
  9360. ,uuid
  9361. ,json_object_to_json_string_ext(SetVariable, JSON_C_TO_STRING_PLAIN));
  9362. json_object_put(SetVariable);
  9363. LWS_Send(message);
  9364. result = TRUE;
  9365. return result;
  9366. }
  9367. int sendTriggerMessageConfirmation(char *uuid)
  9368. {
  9369. mtrace();
  9370. int result = FAIL;
  9371. char message[4096]={0};
  9372. json_object *TriggerMessage = json_object_new_object();
  9373. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  9374. json_object_object_add(TriggerMessage, "status", json_object_new_string((char*)ShmOCPP20Data->TriggerMessage.Response_status));
  9375. sprintf(message,"[%d,\"%s\",%s]",
  9376. MESSAGE_TYPE_CALLRESULT,
  9377. uuid,
  9378. json_object_to_json_string_ext(TriggerMessage, JSON_C_TO_STRING_PLAIN));
  9379. json_object_put(TriggerMessage);
  9380. LWS_Send(message);
  9381. result = TRUE;
  9382. return result;
  9383. }
  9384. int sendUnlockConnectorConfirmation(char *uuid, unsigned char gun_index)
  9385. {
  9386. mtrace();
  9387. int result = FAIL;
  9388. char message[4096]={0};
  9389. json_object *UnlockConnector = json_object_new_object();
  9390. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  9391. json_object_object_add(UnlockConnector, "status", json_object_new_string((char*)ShmOCPP20Data->UnlockConnector[gun_index].Response_status));
  9392. sprintf(message,"[%d,\"%s\",%s]",
  9393. MESSAGE_TYPE_CALLRESULT,
  9394. uuid,
  9395. json_object_to_json_string_ext(UnlockConnector, JSON_C_TO_STRING_PLAIN));
  9396. json_object_put(UnlockConnector);
  9397. LWS_Send(message);
  9398. result = TRUE;
  9399. ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf = OFF;
  9400. return result;
  9401. }
  9402. int sendUnpublishFirmwareConfirmation(char *uuid)
  9403. {
  9404. mtrace();
  9405. int result = FAIL;
  9406. char message[4096]={0};
  9407. json_object *UnpublishFirmware = json_object_new_object();
  9408. DEBUG_INFO("sendUnpublishFirmwareConfirmation...\n");
  9409. json_object_object_add(UnpublishFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->UnpublishFirmware.Response_status));
  9410. sprintf(message,"[%d,\"%s\",%s]"
  9411. ,MESSAGE_TYPE_CALLRESULT
  9412. ,uuid
  9413. ,json_object_to_json_string_ext(UnpublishFirmware, JSON_C_TO_STRING_PLAIN));
  9414. json_object_put(UnpublishFirmware);
  9415. LWS_Send(message);
  9416. result = TRUE;
  9417. return result;
  9418. }
  9419. int sendUpdateFirmwareConfirmation(char *uuid)
  9420. {
  9421. mtrace();
  9422. int result = FAIL;
  9423. char message[4096]={0};
  9424. json_object *UpdateFirmware = json_object_new_object();
  9425. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  9426. sprintf((char*)ShmOCPP20Data->UpdateFirmware.Response_status, "%s", UpdateFirmwareStatusEnumTypeStr[UpdateFirmwareStatusEnumType_Accepted]);
  9427. json_object_object_add(UpdateFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->UpdateFirmware.Response_status));
  9428. sprintf(message,"[%d,\"%s\",%s]"
  9429. ,MESSAGE_TYPE_CALLRESULT
  9430. ,uuid
  9431. ,json_object_to_json_string_ext(UpdateFirmware, JSON_C_TO_STRING_PLAIN));
  9432. json_object_put(UpdateFirmware);
  9433. LWS_Send(message);
  9434. result = TRUE;
  9435. return result;
  9436. }
  9437. int sendUnknownConfirmation(char *uuid)
  9438. {
  9439. mtrace();
  9440. int result = FAIL;
  9441. char message[256]={0};
  9442. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  9443. DEBUG_INFO("sendUnknownConfirmation...\n");
  9444. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  9445. LWS_Send(message);
  9446. result = TRUE;
  9447. return result;
  9448. }
  9449. //==========================================
  9450. // send CallError routine
  9451. //==========================================
  9452. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  9453. {
  9454. mtrace();
  9455. char message[220]={0};
  9456. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  9457. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  9458. LWS_Send(message);
  9459. }
  9460. //==========================================
  9461. // Handle server request routine Start
  9462. //==========================================
  9463. int handleCancelReservationRequest(char *uuid, char *payload)
  9464. {
  9465. mtrace();
  9466. int result = FAIL;
  9467. int gunNO = 0;
  9468. int reservationIdInt = -1;
  9469. DEBUG_INFO("handleCancelReservationRequest...\n");
  9470. json_object *CancelReservation;
  9471. CancelReservation = json_tokener_parse(payload);
  9472. if(!is_error(CancelReservation))
  9473. {
  9474. // Required data
  9475. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  9476. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  9477. }
  9478. json_object_put(CancelReservation);
  9479. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  9480. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->CancelReservation);idx++)
  9481. sprintf((char*)ShmOCPP20Data->CancelReservation[idx].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Rejected]);
  9482. if(reservationIdInt != -1)
  9483. {
  9484. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9485. //check Transaction active
  9486. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  9487. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9488. {
  9489. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  9490. {
  9491. sprintf((char*)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  9492. if(gunType[2] == GUN_TYPE_CHAdeMO)
  9493. {
  9494. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  9495. }
  9496. else
  9497. {
  9498. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  9499. }
  9500. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  9501. goto end;
  9502. }
  9503. }
  9504. for (int index = 0; index < CCS_QUANTITY; index++)
  9505. {
  9506. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  9507. {
  9508. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  9509. if(gunType[2] == GUN_TYPE_CCS)
  9510. {
  9511. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  9512. }
  9513. else
  9514. {
  9515. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  9516. }
  9517. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  9518. goto end;
  9519. }
  9520. }
  9521. for (int index = 0; index < GB_QUANTITY; index++)
  9522. {
  9523. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  9524. {
  9525. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  9526. if(gunType[2] == GUN_TYPE_GBT)
  9527. {
  9528. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  9529. }
  9530. else
  9531. {
  9532. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  9533. }
  9534. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  9535. goto end;
  9536. }
  9537. }
  9538. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9539. {
  9540. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  9541. {
  9542. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  9543. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  9544. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  9545. goto end;
  9546. }
  9547. }
  9548. for (int index = 0; index < AC_QUANTITY; index++)
  9549. {
  9550. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  9551. {
  9552. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  9553. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9554. {
  9555. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  9556. }
  9557. else
  9558. {
  9559. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  9560. }
  9561. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  9562. goto end;
  9563. }
  9564. }
  9565. }
  9566. //The reservationId does NOT match the reservationId
  9567. sendCancelReservationConfirmation(uuid, gunNO);
  9568. end:
  9569. // Fill in ocpp packet uuid
  9570. strcpy((char *)ShmOCPP20Data->CancelReservation[gunNO].guid, uuid);
  9571. return result;
  9572. }
  9573. int handleCertificateSignedRequest(char *uuid, char *payload)
  9574. {
  9575. mtrace();
  9576. int result = FAIL;
  9577. json_object *CertificateSigned;
  9578. DEBUG_INFO("handleCertificateSignedRequest...\n");
  9579. CertificateSigned = json_tokener_parse(payload);
  9580. if(!is_error(CertificateSigned))
  9581. {
  9582. memset(&ShmOCPP20Data->CertificateSigned, 0, sizeof(struct CertificateSigned_20));
  9583. memcpy(&ShmOCPP20Data->CertificateSigned.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->CertificateSigned.guid));
  9584. // Required data
  9585. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  9586. // Optional data
  9587. if(json_object_object_get(CertificateSigned, "certificateType") != NULL)
  9588. {
  9589. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateType, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateType")));
  9590. if(strcmp((char*)ShmOCPP20Data->CertificateSigned.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_ChargingStationCertificate]) == 0)
  9591. {
  9592. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  9593. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  9594. fclose(fp);
  9595. }
  9596. else if(strcmp((char*)ShmOCPP20Data->CertificateSigned.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0)
  9597. {
  9598. FILE *fp = fopen("/Storage/OCPP/certV2G.crt", "w");
  9599. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  9600. fclose(fp);
  9601. }
  9602. }
  9603. else
  9604. {
  9605. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  9606. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  9607. fclose(fp);
  9608. fp = fopen("/Storage/OCPP/certV2G.crt", "w");
  9609. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  9610. fclose(fp);
  9611. }
  9612. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9613. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Accepted]);
  9614. }
  9615. else
  9616. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Rejected]);
  9617. json_object_put(CertificateSigned);
  9618. sendCertificateSignedConfirmation(uuid);
  9619. return result;
  9620. }
  9621. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  9622. {
  9623. mtrace();
  9624. int result = FAIL;
  9625. int evseId = 0, gunIndex = 0;
  9626. char operationalStatus[16]={0};
  9627. char comfirmstr[20];
  9628. int specificId = FALSE;
  9629. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  9630. json_object *ChangeAvailability;
  9631. ChangeAvailability = json_tokener_parse(payload);
  9632. if(!is_error(ChangeAvailability))
  9633. {
  9634. // Required data
  9635. if(json_object_object_get(ChangeAvailability, "operationalStatus") != NULL)
  9636. sprintf((char*)operationalStatus, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "operationalStatus")));
  9637. if(json_object_object_get(ChangeAvailability, "evse") != NULL)
  9638. {
  9639. evseId = json_object_get_int(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "id"));
  9640. if(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "connectorId") != NULL)
  9641. gunIndex = json_object_get_int(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "connectorId"));
  9642. }
  9643. }
  9644. json_object_put(ChangeAvailability);
  9645. if((evseId != 0) && (evseId <= gunTotalNumber))
  9646. {
  9647. ShmOCPP20Data->ChangeAvailability[evseId - 1].evse.connectorId = evseId;
  9648. sprintf((char *)ShmOCPP20Data->ChangeAvailability[evseId - 1].operationalStatus, "%s", operationalStatus);
  9649. }
  9650. else if(evseId == 0)
  9651. {
  9652. for(int i=0; i < gunTotalNumber; i++)
  9653. {
  9654. ShmOCPP20Data->ChangeAvailability[i].evse.connectorId = evseId;
  9655. sprintf((char *)ShmOCPP20Data->ChangeAvailability[i].operationalStatus, "%s", operationalStatus);
  9656. }
  9657. }
  9658. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9659. {
  9660. ShmOCPP20Data->ChangeAvailability[gunIndex - 1].evse.connectorId = gunIndex;
  9661. sprintf((char *)ShmOCPP20Data->ChangeAvailability[gunIndex - 1].operationalStatus, "%s", operationalStatus);
  9662. }
  9663. else if(gunIndex == 0)
  9664. {
  9665. for(int i=0; i < gunTotalNumber; i++)
  9666. {
  9667. ShmOCPP20Data->ChangeAvailability[i].evse.connectorId = gunIndex;
  9668. sprintf((char *)ShmOCPP20Data->ChangeAvailability[i].operationalStatus, "%s", operationalStatus);
  9669. }
  9670. }
  9671. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  9672. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9673. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  9674. {
  9675. specificId = TRUE;
  9676. }
  9677. if(specificId == FALSE)
  9678. goto end;
  9679. if(strcmp((const char *)operationalStatus, OperationalStatusEnumTypeStr[OperationalStatusEnumType_Inoperative]) == 0)
  9680. {
  9681. //----------------------gunIndex is 0 ------------------------------------------------//
  9682. if(gunIndex == 0)
  9683. {
  9684. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9685. {
  9686. for(int i=0; i < gunTotalNumber; i++)
  9687. {
  9688. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9689. {
  9690. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  9691. {
  9692. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  9693. {
  9694. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9695. goto end;
  9696. }
  9697. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9698. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9699. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9700. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9701. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9702. {
  9703. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9704. goto end;
  9705. }
  9706. }
  9707. }//END FOR CHAdeMO_QUANTITY
  9708. for (int index = 0; index < CCS_QUANTITY; index++)
  9709. {
  9710. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  9711. {
  9712. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  9713. {
  9714. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9715. goto end;
  9716. }
  9717. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9718. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9719. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9720. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9721. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9722. {
  9723. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9724. goto end;
  9725. }
  9726. }
  9727. }//END FOR CCS_QUANTITY
  9728. for (int index = 0; index < GB_QUANTITY; index++)
  9729. {
  9730. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  9731. {
  9732. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  9733. {
  9734. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9735. goto end;
  9736. }
  9737. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9738. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9739. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9740. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9741. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9742. {
  9743. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9744. goto end;
  9745. }
  9746. }
  9747. }// END FOR GB_QUANTITY
  9748. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9749. {
  9750. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  9751. {
  9752. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  9753. {
  9754. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9755. goto end;
  9756. }
  9757. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  9758. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  9759. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  9760. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  9761. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9762. {
  9763. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9764. goto end;
  9765. }
  9766. }
  9767. }// END FOR DO_QUANTITY
  9768. for (int index = 0; index < AC_QUANTITY; index++)
  9769. {
  9770. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  9771. {
  9772. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  9773. {
  9774. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9775. goto end;
  9776. }
  9777. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9778. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9779. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9780. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9781. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9782. {
  9783. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9784. goto end;
  9785. }
  9786. }
  9787. }//END FOR AC_QUANTITY
  9788. }// END FOR gunTotalNumber
  9789. }
  9790. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  9791. {
  9792. for(int i=0; i < gunTotalNumber; i++)
  9793. {
  9794. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  9795. {
  9796. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9797. goto end;
  9798. }
  9799. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9800. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  9801. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  9802. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  9803. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9804. {
  9805. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9806. goto end;
  9807. }
  9808. }
  9809. }
  9810. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  9811. goto end;
  9812. }
  9813. //----------------------gunIndex is not 0 ------------------------------------------------//
  9814. //check Transaction active
  9815. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9816. {
  9817. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  9818. {
  9819. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  9820. {
  9821. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9822. goto end;
  9823. }
  9824. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9825. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9826. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9827. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9828. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9829. {
  9830. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9831. goto end;
  9832. }
  9833. else
  9834. {
  9835. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  9836. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  9837. goto end;
  9838. }
  9839. }
  9840. }//END FOR CHAdeMO_QUANTITY
  9841. for (int index = 0; index < CCS_QUANTITY; index++)
  9842. {
  9843. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  9844. {
  9845. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  9846. {
  9847. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9848. goto end;
  9849. }
  9850. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9851. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9852. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9853. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9854. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9855. {
  9856. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9857. goto end;
  9858. }
  9859. else
  9860. {
  9861. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  9862. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  9863. goto end;
  9864. }
  9865. }
  9866. }//END FOR CCS_QUANTITY
  9867. for (int index = 0; index < GB_QUANTITY; index++)
  9868. {
  9869. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  9870. {
  9871. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  9872. {
  9873. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9874. goto end;
  9875. }
  9876. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9877. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9878. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9879. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9880. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9881. {
  9882. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9883. goto end;
  9884. }
  9885. else
  9886. {
  9887. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  9888. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  9889. goto end;
  9890. }
  9891. }
  9892. }// END FOR GB_QUANTITY
  9893. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9894. {
  9895. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  9896. {
  9897. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  9898. {
  9899. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9900. goto end;
  9901. }
  9902. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  9903. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  9904. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  9905. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  9906. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9907. {
  9908. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9909. goto end;
  9910. }
  9911. else
  9912. {
  9913. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  9914. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  9915. goto end;
  9916. }
  9917. }
  9918. }// END FOR DO_QUANTITY
  9919. for (int index = 0; index < AC_QUANTITY; index++)
  9920. {
  9921. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC))
  9922. {
  9923. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  9924. {
  9925. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9926. goto end;
  9927. }
  9928. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9929. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9930. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9931. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9932. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9933. {
  9934. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9935. goto end;
  9936. }
  9937. else
  9938. {
  9939. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  9940. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  9941. goto end;
  9942. }
  9943. }
  9944. }//END FOR AC_QUANTITY
  9945. }//END FOR AvailabilityEnumTypeStr[Inoperative]
  9946. if(strcmp((const char *)operationalStatus, OperationalStatusEnumTypeStr[OperationalStatusEnumType_Operative]) == 0)
  9947. {
  9948. //----------------------gunIndex is 0 ------------------------------------------------//
  9949. if(gunIndex == 0)
  9950. {
  9951. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9952. {
  9953. for(int i=0; i < gunTotalNumber; i++)
  9954. {
  9955. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9956. {
  9957. 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
  9958. {
  9959. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9960. goto end;
  9961. }
  9962. }//END FOR CHAdeMO_QUANTITY
  9963. for (int index = 0; index < CCS_QUANTITY; index++)
  9964. {
  9965. 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
  9966. {
  9967. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9968. goto end;
  9969. }
  9970. }//END FOR CCS_QUANTITY
  9971. for (int index = 0; index < GB_QUANTITY; index++)
  9972. {
  9973. 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
  9974. {
  9975. //ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  9976. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9977. goto end;
  9978. }
  9979. }// END FOR GB_QUANTITY
  9980. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9981. {
  9982. 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
  9983. {
  9984. //ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  9985. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9986. goto end;
  9987. }
  9988. }// END FOR DO_QUANTITY
  9989. for (int index = 0; index < AC_QUANTITY; index++)
  9990. {
  9991. 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
  9992. {
  9993. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9994. goto end;
  9995. }
  9996. }//END FOR CHAdeMO_QUANTITY
  9997. }// END FOR gunTotalNumber
  9998. }
  9999. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  10000. {
  10001. for(int i=0; i < gunTotalNumber; i++)
  10002. {
  10003. for (int index = 0; index < AC_QUANTITY; index++)
  10004. {
  10005. 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
  10006. {
  10007. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  10008. goto end;
  10009. }
  10010. }//END FOR CHAdeMO_QUANTITY
  10011. } // END FOR gunTotalNumber
  10012. }
  10013. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  10014. goto end;
  10015. }
  10016. //----------------------gunIndex is not 0 ------------------------------------------------//
  10017. //check Transaction active
  10018. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  10019. {
  10020. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  10021. {
  10022. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  10023. goto end;
  10024. }
  10025. }//END FOR CHAdeMO_QUANTITY
  10026. for (int index = 0; index < CCS_QUANTITY; index++)
  10027. {
  10028. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  10029. {
  10030. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  10031. goto end;
  10032. }
  10033. }//END FOR CCS_QUANTITY
  10034. for (int index = 0; index < GB_QUANTITY; index++)
  10035. {
  10036. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  10037. {
  10038. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  10039. goto end;
  10040. }
  10041. }// END FOR GB_QUANTITY
  10042. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  10043. {
  10044. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  10045. {
  10046. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  10047. goto end;
  10048. }
  10049. }// END FOR DO_QUANTITY
  10050. for (int index = 0; index < AC_QUANTITY; index++)
  10051. {
  10052. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  10053. {
  10054. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  10055. goto end;
  10056. }
  10057. }//END FOR AC_QUANTITY
  10058. }//END FOR AvailabilityEnumTypeStr[Operative]
  10059. end:
  10060. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  10061. {
  10062. sprintf((char *)ShmOCPP20Data->ChangeAvailability[gunIndex - 1].Response_status, "%s", comfirmstr );
  10063. }
  10064. else
  10065. {
  10066. sprintf((char *)ShmOCPP20Data->ChangeAvailability[0].Response_status, "%s", comfirmstr );
  10067. }
  10068. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  10069. {
  10070. if(strstr(comfirmstr, ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected]) == NULL)
  10071. ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  10072. }
  10073. else if(gunIndex == 0)
  10074. {
  10075. if(strstr(comfirmstr, ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected]) == NULL)
  10076. {
  10077. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  10078. ShmOCPP20Data->CsMsg.bits[i].ChangeAvailabilityReq = ON;
  10079. }
  10080. }
  10081. sendChangeAvailabilityConfirmation(uuid, (gunIndex==0?gunIndex:gunIndex-1));
  10082. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10083. return result;
  10084. }
  10085. int handleClearCacheRequest(char *uuid, char *payload)
  10086. {
  10087. mtrace();
  10088. int result = FAIL;
  10089. char rmFileCmd[100]={0};
  10090. struct stat stats;
  10091. DEBUG_INFO("handleClearCacheRequest...\n");
  10092. stat("/Storage/OCPP", &stats);
  10093. // Check for directory existence
  10094. if (S_ISDIR(stats.st_mode) == 1)
  10095. {}
  10096. else
  10097. {
  10098. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  10099. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  10100. system(rmFileCmd);
  10101. }
  10102. /*
  10103. * TODO:
  10104. * 1. Clear cache from sqlite db
  10105. */
  10106. if(1)
  10107. {
  10108. DEBUG_INFO("open AuthorizationCache file failed\n");
  10109. sprintf((char*)ShmOCPP20Data->ClearCache.Response_status, "%s", ClearCacheStatusEnumTypeStr[ClearCacheStatusEnumType_Rejected] );
  10110. }
  10111. else
  10112. {
  10113. DEBUG_INFO("open AuthorizationCache file successful\n");
  10114. sprintf((char*)ShmOCPP20Data->ClearCache.Response_status, "%s", ClearCacheStatusEnumTypeStr[ClearCacheStatusEnumType_Accepted] );
  10115. }
  10116. sendClearCacheConfirmation(uuid);
  10117. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10118. return result;
  10119. }
  10120. int handleClearChargingProfileRequest(char *uuid, char *payload)
  10121. {
  10122. mtrace();
  10123. int result = FAIL;
  10124. int resultRename;
  10125. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  10126. char chargingProfilePurposeStr[26]={0};
  10127. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  10128. char tempchargingProfilePurposeStr[26]={0};
  10129. char sstr[160]={0};
  10130. char str[100]={0};
  10131. int c = 0;
  10132. char *loc;
  10133. char fname[200]={0};
  10134. char comfirmstr[20]={0};
  10135. char word[1600]={0};
  10136. int clearflag = FALSE;
  10137. int chargingProfileIdIsNULL = FALSE;
  10138. int connectorIsNULL = FALSE;
  10139. int chargingProfilePurposeIsNULL = FALSE;
  10140. int stackLevelIsNULL = FALSE;
  10141. //int GotoEnd = FALSE;
  10142. FILE *fptr1, *fptr2;
  10143. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  10144. int n_chargingProfile=0;
  10145. int isEmptyFile = FALSE;
  10146. char sLineWord[1600]={0};
  10147. char chargingProfiles[10][100]={0};
  10148. int ChargeProfileCount = 0;
  10149. int ch;
  10150. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  10151. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  10152. json_object *ClearChargingProfile;
  10153. ClearChargingProfile = json_tokener_parse(payload);
  10154. if(!is_error(ClearChargingProfile))
  10155. {
  10156. // Optional data
  10157. if(json_object_object_get(ClearChargingProfile, "chargingProfileId") != NULL)
  10158. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "chargingProfileId"));
  10159. else
  10160. chargingProfileIdIsNULL = TRUE;
  10161. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "evseId") != NULL)
  10162. connectorIdInt = json_object_get_int(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "evseId"));
  10163. else
  10164. connectorIsNULL = TRUE;
  10165. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "chargingProfilePurpose") != NULL)
  10166. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "chargingProfilePurpose")));
  10167. else
  10168. chargingProfilePurposeIsNULL = TRUE;
  10169. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "stackLevel") != NULL)
  10170. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "stackLevel"));
  10171. else
  10172. stackLevelIsNULL = TRUE;
  10173. }
  10174. json_object_put(ClearChargingProfile);
  10175. if(connectorIsNULL == FALSE)
  10176. {
  10177. switch(connectorIdInt)
  10178. {
  10179. case 0:
  10180. if(chargingProfilePurposeIsNULL == TRUE)
  10181. {
  10182. int l = 0;
  10183. strcpy(fname, ChargePointMaxProfile_JSON);
  10184. if((access(fname,F_OK))!=-1)
  10185. {
  10186. strcpy(chargingProfiles[l], fname);
  10187. l = l + 1;
  10188. }
  10189. strcpy(fname, TxDefaultProfile_0_JSON);
  10190. if((access(fname,F_OK))!=-1)
  10191. {
  10192. strcpy(chargingProfiles[l], fname);
  10193. l = l + 1;
  10194. }
  10195. ChargeProfileCount = l;
  10196. }
  10197. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  10198. {
  10199. strcpy(fname, ChargePointMaxProfile_JSON);
  10200. if((access(fname,F_OK))!=-1)
  10201. {
  10202. strcpy(chargingProfiles[0], fname);
  10203. ChargeProfileCount = 1;
  10204. }
  10205. }
  10206. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  10207. {
  10208. strcpy(fname, TxDefaultProfile_0_JSON);
  10209. if((access(fname,F_OK))!=-1)
  10210. {
  10211. strcpy(chargingProfiles[0], fname);
  10212. ChargeProfileCount = 1;
  10213. }
  10214. }
  10215. break;
  10216. default:
  10217. if(chargingProfilePurposeIsNULL == TRUE)
  10218. {
  10219. int m = 0;
  10220. memset(fname, 0, ARRAY_SIZE(fname));
  10221. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  10222. if((access(fname,F_OK))!=-1)
  10223. {
  10224. strcpy(chargingProfiles[m], fname);
  10225. m = m + 1;
  10226. }
  10227. memset(fname, 0, ARRAY_SIZE(fname));
  10228. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10229. if((access(fname,F_OK))!=-1)
  10230. {
  10231. strcpy(chargingProfiles[m], fname);
  10232. m = m + 1;
  10233. }
  10234. ChargeProfileCount = m;
  10235. }
  10236. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  10237. {
  10238. //strcpy(fname, TxDefaultProfile_1_JSON);
  10239. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  10240. if((access(fname,F_OK))!=-1)
  10241. {
  10242. strcpy(chargingProfiles[0], fname);
  10243. ChargeProfileCount = 1;
  10244. }
  10245. }
  10246. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  10247. {
  10248. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  10249. if((access(fname,F_OK))!=-1)
  10250. {
  10251. strcpy(chargingProfiles[0], fname);
  10252. ChargeProfileCount = 1;
  10253. }
  10254. }
  10255. //strcpy(fname, ChargePointMaxProfile_JSON );
  10256. break;
  10257. }
  10258. }
  10259. else // Check all Charging Profiles
  10260. {
  10261. int i = 0;
  10262. char fnametemp[200]={0};
  10263. ChargeProfileCount = 0;
  10264. //Check ChargePointMaxProfile.json exit
  10265. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  10266. {
  10267. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  10268. i = i + 1;
  10269. }
  10270. //Check TxDefaultProfile_0.json exit
  10271. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  10272. {
  10273. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  10274. i = i + 1;
  10275. }
  10276. //Check TxDefaultProfile_%d.json
  10277. for(int j=1; j <= gunTotalNumber; j++)
  10278. {
  10279. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10280. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  10281. if((access(fnametemp,F_OK))!=-1)
  10282. {
  10283. strcpy(chargingProfiles[i], fnametemp);
  10284. i = i + 1;
  10285. }
  10286. }
  10287. //Check TxProfile_%d.json
  10288. for(int j=1; j <= gunTotalNumber; j++)
  10289. {
  10290. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  10291. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  10292. if((access(fnametemp,F_OK))!=-1)
  10293. {
  10294. strcpy(chargingProfiles[i], fnametemp);
  10295. i = i + 1;
  10296. }
  10297. }
  10298. ChargeProfileCount = i;
  10299. }// End connectorIsNULL is TRUE
  10300. if(ChargeProfileCount == 0)
  10301. {
  10302. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  10303. goto end;
  10304. }
  10305. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  10306. {
  10307. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  10308. goto end;
  10309. }
  10310. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  10311. {
  10312. memset(str, 0, ARRAY_SIZE(str));
  10313. // clear temp file
  10314. sprintf(str,"rm -f %s",temp);
  10315. system(str);
  10316. for(int k=0; k < ChargeProfileCount; k++)
  10317. {
  10318. memset(str, 0, ARRAY_SIZE(str));
  10319. //clear file in C
  10320. sprintf(str,"rm -f %s",chargingProfiles[k]);
  10321. system(str);
  10322. }
  10323. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  10324. goto end;
  10325. }
  10326. else if(connectorIsNULL == TRUE)
  10327. {
  10328. for(int k=0; k < ChargeProfileCount; k++)
  10329. {
  10330. fptr1 = fopen(chargingProfiles[k], "r");
  10331. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  10332. //Check Charging Profile Count
  10333. while(fscanf(fptr1, "%s", word) != EOF)
  10334. {
  10335. //DEBUG_INFO("word=%s\n",word);
  10336. if(strstr(word, "chargingProfileId")!= NULL)
  10337. {
  10338. //DEBUG_INFO("test chargingProfileId \n");
  10339. n_chargingProfile = n_chargingProfile + 1;
  10340. //DEBUG_INFO("chargingProfileId Found\n");
  10341. }
  10342. }
  10343. rewind(fptr1);
  10344. //search Charging Profile Element
  10345. //int i= 0;
  10346. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  10347. {
  10348. //------------------------tempconnectorIdInt------------------------//
  10349. loc = strstr(sLineWord, "connectorId");
  10350. c = 0;
  10351. memset(sstr ,0, sizeof(sstr) );
  10352. while (loc[strlen("connectorId")+2+c] != ',')
  10353. {
  10354. sstr[c] = loc[strlen("connectorId")+2+c];
  10355. c++;
  10356. }
  10357. sstr[c] = '\0';
  10358. tempconnectorIdInt = atoi(sstr);
  10359. printf("file's gun number is %d\n", tempconnectorIdInt);
  10360. //--------------------------chargingProfileId--------------------//
  10361. c = 0;
  10362. loc = strstr(sLineWord, "chargingProfileId");
  10363. memset(sstr ,0, ARRAY_SIZE(sstr));
  10364. while (loc[strlen("chargingProfileId")+2+c] != ',')
  10365. {
  10366. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  10367. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10368. c++;
  10369. }
  10370. sstr[c] = '\0';
  10371. tempchargingProfileIdInt = atoi(sstr);
  10372. //stackLevel
  10373. c = 0;
  10374. loc = strstr(sLineWord, "stackLevel");
  10375. memset(sstr ,0, ARRAY_SIZE(sstr));
  10376. while (loc[strlen("stackLevel")+2+c] != ',')
  10377. {
  10378. sstr[c] = loc[strlen("stackLevel")+2+c];
  10379. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10380. c++;
  10381. }
  10382. sstr[c] = '\0';
  10383. tempstackLevelInt = atoi(sstr);
  10384. c = 0;
  10385. loc = strstr(sLineWord, "chargingProfilePurpose");
  10386. memset(sstr ,0, ARRAY_SIZE(sstr));
  10387. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  10388. {
  10389. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  10390. c++;
  10391. }
  10392. sstr[c] = '\0';
  10393. strcpy(tempchargingProfilePurposeStr, sstr);
  10394. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  10395. {
  10396. //------- not write to fptr2-------//
  10397. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  10398. //clearflag = TRUE;
  10399. }
  10400. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  10401. {
  10402. //------- not write to fptr2-------//
  10403. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  10404. }
  10405. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  10406. {
  10407. //------- not write to fptr2-------//
  10408. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  10409. }
  10410. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  10411. {
  10412. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  10413. }
  10414. else
  10415. {
  10416. fprintf(fptr2, sLineWord);//writing data into file
  10417. }
  10418. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  10419. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  10420. if(clearflag == TRUE)
  10421. {
  10422. fclose(fptr1);
  10423. fclose(fptr2);
  10424. sprintf(str,"rm -f %s",chargingProfiles[k]);
  10425. system(str);
  10426. // clear temp file
  10427. sprintf(str,"rm -f %s",temp);
  10428. system(str);
  10429. }
  10430. else
  10431. {
  10432. fclose(fptr1);
  10433. fclose(fptr2);
  10434. memset(str, 0, ARRAY_SIZE(str));
  10435. sprintf(str,"rm -f %s",chargingProfiles[k]);
  10436. system(str);
  10437. resultRename = rename(temp, chargingProfiles[k]);
  10438. if(resultRename == 0)
  10439. {
  10440. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  10441. }
  10442. else
  10443. {
  10444. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  10445. }
  10446. if(comfirmstr[0]== 0)
  10447. {
  10448. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  10449. }
  10450. //Check chargingProfile is empty file
  10451. /*------ Read the file ----------------*/
  10452. fptr1=fopen(chargingProfiles[k],"r");
  10453. ch=fgetc(fptr1);
  10454. rewind(fptr1);
  10455. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  10456. if(ch!=EOF)
  10457. {
  10458. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  10459. {
  10460. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  10461. if(sLineWord[0]=='\0')
  10462. {
  10463. isEmptyFile = TRUE;
  10464. break;
  10465. }
  10466. else
  10467. {
  10468. isEmptyFile = FALSE;
  10469. break;
  10470. }
  10471. }
  10472. }
  10473. else
  10474. isEmptyFile = TRUE;
  10475. fclose(fptr1);
  10476. if(isEmptyFile == TRUE)
  10477. {
  10478. memset(str, 0, ARRAY_SIZE(str));
  10479. sprintf(str,"rm -f %s",chargingProfiles[k]);
  10480. system(str);
  10481. }
  10482. }
  10483. }// End of while(int k=0; k < ChargePointCount; k++)
  10484. }
  10485. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  10486. {
  10487. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  10488. for(int k=0; k < ChargeProfileCount; k++)
  10489. {
  10490. fptr1 = fopen(chargingProfiles[k], "r");
  10491. fptr2 = fopen(temp, "w+");
  10492. //Check Charging Profile Count
  10493. while(fscanf(fptr1, "%s", word) != EOF)
  10494. {
  10495. //DEBUG_INFO("word=%s\n",word);
  10496. if(strstr(word, "chargingProfileId")!= NULL)
  10497. {
  10498. n_chargingProfile = n_chargingProfile + 1;
  10499. }
  10500. }
  10501. rewind(fptr1);
  10502. //search Charging Profile Element
  10503. //int i= 0;
  10504. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  10505. {
  10506. //*************************tempconnectorIdInt*********************************/
  10507. loc = strstr(sLineWord, "connectorId");
  10508. c = 0;
  10509. memset(sstr ,0, ARRAY_SIZE(sstr));
  10510. while (loc[strlen("connectorId")+2+c] != ',')
  10511. {
  10512. sstr[c] = loc[strlen("connectorId")+2+c];
  10513. c++;
  10514. }
  10515. sstr[c] = '\0';
  10516. tempconnectorIdInt = atoi(sstr);
  10517. //chargingProfileId
  10518. c = 0;
  10519. loc = strstr(sLineWord, "chargingProfileId");
  10520. memset(sstr ,0, ARRAY_SIZE(sstr));
  10521. while (loc[strlen("chargingProfileId")+2+c] != ',')
  10522. {
  10523. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  10524. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10525. c++;
  10526. }
  10527. sstr[c] = '\0';
  10528. tempchargingProfileIdInt = atoi(sstr);
  10529. //stackLevel
  10530. c = 0;
  10531. loc = strstr(sLineWord, "stackLevel");
  10532. memset(sstr ,0, ARRAY_SIZE(sstr));
  10533. while (loc[strlen("stackLevel")+2+c] != ',')
  10534. {
  10535. sstr[c] = loc[strlen("stackLevel")+2+c];
  10536. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10537. c++;
  10538. }
  10539. sstr[c] = '\0';
  10540. tempstackLevelInt = atoi(sstr);
  10541. c = 0;
  10542. loc = strstr(sLineWord, "chargingProfilePurpose");
  10543. memset(sstr ,0, ARRAY_SIZE(sstr));
  10544. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  10545. {
  10546. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  10547. c++;
  10548. }
  10549. sstr[c] = '\0';
  10550. strcpy(tempchargingProfilePurposeStr, sstr);
  10551. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  10552. {
  10553. //------- not write to fptr2-------//
  10554. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  10555. //clearflag = TRUE;
  10556. }
  10557. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  10558. {
  10559. //------- not write to fptr2-------//
  10560. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  10561. }
  10562. else if(stackLevelIsNULL == TRUE)
  10563. {
  10564. //Clear Whole File
  10565. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  10566. clearflag = TRUE;
  10567. break;
  10568. }
  10569. else
  10570. {
  10571. fprintf(fptr2, sLineWord);//writing data into file
  10572. }
  10573. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  10574. }
  10575. if(clearflag == TRUE)
  10576. {
  10577. fclose(fptr1);
  10578. fclose(fptr2);
  10579. sprintf(str,"rm -f %s",chargingProfiles[k]);
  10580. system(str);
  10581. // clear temp file
  10582. sprintf(str,"rm -f %s",temp);
  10583. system(str);
  10584. }
  10585. else
  10586. {
  10587. fclose(fptr1);
  10588. fclose(fptr2);
  10589. sprintf(str,"rm -f %s",chargingProfiles[k]);
  10590. system(str);
  10591. resultRename = rename(temp, chargingProfiles[k]);
  10592. if(resultRename == 0)
  10593. {
  10594. DEBUG_INFO("File ChargingProfile renamed successfully");
  10595. }
  10596. else
  10597. {
  10598. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  10599. }
  10600. if(comfirmstr[0]== 0)
  10601. {
  10602. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  10603. }
  10604. //Check chargingProfile is empty file
  10605. /*------ Read the file ----------------*/
  10606. fptr1=fopen(chargingProfiles[k],"r");
  10607. ch=fgetc(fptr1);
  10608. rewind(fptr1);
  10609. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  10610. if(ch!=EOF)
  10611. {
  10612. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  10613. {
  10614. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  10615. if(sLineWord[0]=='\0')
  10616. {
  10617. isEmptyFile = TRUE;
  10618. break;
  10619. }
  10620. else
  10621. {
  10622. isEmptyFile = FALSE;
  10623. break;
  10624. }
  10625. }
  10626. }
  10627. else
  10628. isEmptyFile = TRUE;
  10629. fclose(fptr1);
  10630. if(isEmptyFile == TRUE)
  10631. {
  10632. memset(str, 0, ARRAY_SIZE(str));
  10633. sprintf(str,"rm -f %s",chargingProfiles[k]);
  10634. system(str);
  10635. }
  10636. /*------- End of reading ---------------*/
  10637. }
  10638. } // while(int k=0; k < ChargeProfileCount; k++)
  10639. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  10640. end:
  10641. if(strcmp(comfirmstr, ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted]) == 0)
  10642. {
  10643. if(connectorIdInt == 0)
  10644. {
  10645. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10646. {
  10647. checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx], 0, TRUE);
  10648. }
  10649. }
  10650. else
  10651. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP20Data->SmartChargingProfile[connectorIdInt-1], 0, TRUE);
  10652. }
  10653. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  10654. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10655. return result;
  10656. }
  10657. int handleClearDisplayMessageRequest(char *uuid, char *payload)
  10658. {
  10659. mtrace();
  10660. int result = FAIL;
  10661. json_object *ClearDisplayMessage;
  10662. DEBUG_INFO("handleClearDisplayMessageRequest...\n");
  10663. sprintf((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status, ClearMessageStatusEnumTypeStr[ClearMessageStatusEnumType_Unknown]);
  10664. ClearDisplayMessage = json_tokener_parse(payload);
  10665. if(!is_error(ClearDisplayMessage))
  10666. {
  10667. // Required data
  10668. if(json_object_object_get(ClearDisplayMessage, "id") != NULL)
  10669. {
  10670. ShmOCPP20Data->ClearDisplayMessage.id = json_object_get_double(json_object_object_get(ClearDisplayMessage, "id"));
  10671. sprintf((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status, ClearMessageStatusEnumTypeStr[ClearMessageStatusEnumType_Accepted]);
  10672. }
  10673. }
  10674. json_object_put(ClearDisplayMessage);
  10675. sendCostUpdatedConfirmation(uuid);
  10676. return result;
  10677. }
  10678. int handleClearVariableMonitoringRequest(char *uuid, char *payload)
  10679. {
  10680. mtrace();
  10681. int result = FAIL;
  10682. json_object *ClearVariableMonitorin;
  10683. DEBUG_INFO("handleClearVariableMonitoringRequest...\n");
  10684. ClearVariableMonitorin = json_tokener_parse(payload);
  10685. if(!is_error(ClearVariableMonitorin))
  10686. {
  10687. // Required data
  10688. if(json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id")) <= ARRAY_SIZE(ShmOCPP20Data->ClearVariableMonitoring.id))
  10689. {
  10690. for(int idx=0;idx<json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id"));idx++)
  10691. {
  10692. ShmOCPP20Data->ClearVariableMonitoring.id[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(ClearVariableMonitorin, "id"), idx));
  10693. /*
  10694. * TODO:
  10695. * 1. Check response
  10696. */
  10697. ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].id = ShmOCPP20Data->ClearVariableMonitoring.id[idx];
  10698. strcpy((char*)ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].status, ClearMonitoringStatusEnumTypeStr[ClearMonitoringStatusEnumType_Accepted]);
  10699. }
  10700. sendClearVariableMonitoringConfirmation(uuid, json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id")));
  10701. }
  10702. }
  10703. json_object_put(ClearVariableMonitorin);
  10704. return result;
  10705. }
  10706. int handleCostUpdatedRequest(char *uuid, char *payload)
  10707. {
  10708. mtrace();
  10709. int result = FAIL;
  10710. json_object *CostUpdate;
  10711. DEBUG_INFO("handleCostUpdatedRequest...\n");
  10712. CostUpdate = json_tokener_parse(payload);
  10713. if(!is_error(CostUpdate))
  10714. {
  10715. // Required data
  10716. if(json_object_object_get(CostUpdate, "totalCost") != NULL)
  10717. {
  10718. ShmOCPP20Data->CostUpdated.totalCost = json_object_get_double(json_object_object_get(CostUpdate, "totalCost"));
  10719. }
  10720. if(json_object_object_get(CostUpdate, "transactionId") != NULL)
  10721. {
  10722. sprintf((char*)ShmOCPP20Data->CostUpdated.transactionId, "%s", json_object_get_string(json_object_object_get(CostUpdate, "transactionId")));
  10723. }
  10724. }
  10725. json_object_put(CostUpdate);
  10726. sendCostUpdatedConfirmation(uuid);
  10727. return result;
  10728. }
  10729. int handleCustomerInformationRequest(char *uuid, char *payload)
  10730. {
  10731. mtrace();
  10732. int result = FAIL;
  10733. json_object *CustomerInformation;
  10734. DEBUG_INFO("handleCustomerInformationRequest...\n");
  10735. CustomerInformation = json_tokener_parse(payload);
  10736. if(!is_error(CustomerInformation))
  10737. {
  10738. // Required data
  10739. if(json_object_object_get(CustomerInformation, "requestId") != NULL)
  10740. {
  10741. ShmOCPP20Data->CustomerInformation.requestId = json_object_get_int(json_object_object_get(CustomerInformation, "requestId"));
  10742. }
  10743. if(json_object_object_get(CustomerInformation, "report") != NULL)
  10744. {
  10745. ShmOCPP20Data->CustomerInformation.report = json_object_get_boolean(json_object_object_get(CustomerInformation, "report"));
  10746. }
  10747. if(json_object_object_get(CustomerInformation, "clear") != NULL)
  10748. {
  10749. ShmOCPP20Data->CustomerInformation.report = json_object_get_boolean(json_object_object_get(CustomerInformation, "clear"));
  10750. }
  10751. // Optional data
  10752. if(json_object_object_get(CustomerInformation, "idToken") != NULL)
  10753. {
  10754. if(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "idToken") != NULL)
  10755. {
  10756. sprintf((char*)ShmOCPP20Data->CustomerInformation.idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "idToken")));
  10757. }
  10758. if(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "type") != NULL)
  10759. {
  10760. sprintf((char*)ShmOCPP20Data->CustomerInformation.idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "type")));
  10761. }
  10762. }
  10763. if(json_object_object_get(CustomerInformation, "customerCertificate") != NULL)
  10764. {
  10765. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "hashAlgorithm") != NULL)
  10766. {
  10767. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "hashAlgorithm")));
  10768. }
  10769. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerNameHash") != NULL)
  10770. {
  10771. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerNameHash")));
  10772. }
  10773. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerKeyHash") != NULL)
  10774. {
  10775. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerKeyHash")));
  10776. }
  10777. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "serialNumber") != NULL)
  10778. {
  10779. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "serialNumber")));
  10780. }
  10781. }
  10782. strcpy((char*)ShmOCPP20Data->CustomerInformation.Response_status, CustomerInformationStatusEnumTypeStr[CustomerInformationStatusEnumType_Accepted]);
  10783. }
  10784. else
  10785. strcpy((char*)ShmOCPP20Data->CustomerInformation.Response_status, CustomerInformationStatusEnumTypeStr[CustomerInformationStatusEnumType_Rejected]);
  10786. json_object_put(CustomerInformation);
  10787. sendCustomerInformationConfirmation(uuid);
  10788. return result;
  10789. }
  10790. void createFirmwareVersionByDataTransfer(void)
  10791. {
  10792. json_object *FirmwareDataTransfer = json_object_new_object();
  10793. // AC & DC model
  10794. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  10795. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  10796. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  10797. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  10798. // DC model
  10799. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  10800. {
  10801. if((gunType[1] != GUN_TYPE_UNKNOWN) ||
  10802. (gunType[2] != GUN_TYPE_UNKNOWN) ||
  10803. (gunType[3] != GUN_TYPE_UNKNOWN))
  10804. {
  10805. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  10806. }
  10807. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]!='B') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='K') && (ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O'))
  10808. {
  10809. // DS DM DW
  10810. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  10811. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  10812. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  10813. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  10814. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  10815. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  10816. }
  10817. else
  10818. {
  10819. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  10820. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  10821. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  10822. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  10823. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  10824. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  10825. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  10826. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  10827. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  10828. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  10829. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  10830. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  10831. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  10832. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  10833. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  10834. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  10835. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  10836. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  10837. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  10838. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  10839. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  10840. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  10841. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  10842. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  10843. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  10844. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  10845. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  10846. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  10847. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  10848. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  10849. json_object_object_add(FirmwareDataTransfer, "D11_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  10850. }
  10851. }
  10852. // 4G model
  10853. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  10854. {
  10855. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  10856. }
  10857. sprintf((char*)ShmOCPP20Data->DataTransfer[0].vendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  10858. sprintf((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_FirmwareVersion");
  10859. sprintf((char*)ShmOCPP20Data->DataTransfer[0].data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  10860. json_object_put(FirmwareDataTransfer);
  10861. }
  10862. int handleDataTransferRequest(char *uuid, char *payload)
  10863. {
  10864. mtrace();
  10865. int result = PASS;
  10866. DEBUG_INFO("handleDataTransferRequest...\n");
  10867. if((uuid != NULL) && (payload != NULL))
  10868. {
  10869. json_object *DataTransfer;
  10870. DataTransfer = json_tokener_parse(payload);
  10871. if(!is_error(DataTransfer))
  10872. {
  10873. // Required data
  10874. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  10875. sprintf((char*)ShmOCPP20Data->DataTransfer[0].vendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  10876. // Optional data
  10877. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  10878. sprintf((char*)ShmOCPP20Data->DataTransfer[0].messageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  10879. if(json_object_object_get(DataTransfer, "data") != NULL)
  10880. sprintf((char*)ShmOCPP20Data->DataTransfer[0].data, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  10881. result = PASS;
  10882. }
  10883. json_object_put(DataTransfer);
  10884. if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_FirmwareVersion") != NULL)
  10885. {
  10886. // Send all moudle firmware version on EVSE
  10887. createFirmwareVersionByDataTransfer();
  10888. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  10889. }
  10890. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_Tmate") != NULL)
  10891. {
  10892. system("/usr/bin/run_tmate_restart.sh &");
  10893. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  10894. }
  10895. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "SetLEDBar") != NULL)
  10896. {
  10897. json_object *data;
  10898. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  10899. if(!is_error(data))
  10900. {
  10901. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  10902. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  10903. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  10904. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  10905. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  10906. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  10907. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  10908. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  10909. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  10910. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  10911. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  10912. }
  10913. else
  10914. {
  10915. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  10916. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  10917. }
  10918. json_object_put(data);
  10919. }
  10920. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_ConfigQR") != NULL)
  10921. {
  10922. json_object *data;
  10923. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  10924. if(!is_error(data))
  10925. {
  10926. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  10927. if(json_object_object_get(data, "Content_Type") != NULL)
  10928. {
  10929. 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))
  10930. {
  10931. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  10932. if(json_object_object_get(data, "Customization_Conent") != NULL)
  10933. {
  10934. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  10935. }
  10936. }
  10937. else
  10938. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  10939. }
  10940. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10941. }
  10942. else
  10943. {
  10944. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  10945. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  10946. }
  10947. json_object_put(data);
  10948. }
  10949. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_DsiplayLcdPage") != NULL)
  10950. {
  10951. json_object *data;
  10952. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  10953. if(!is_error(data))
  10954. {
  10955. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  10956. if(json_object_object_get(data, "Page_Index") != NULL)
  10957. {
  10958. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  10959. }
  10960. if(json_object_object_get(data, "Duration") != NULL)
  10961. {
  10962. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  10963. }
  10964. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  10965. }
  10966. else
  10967. {
  10968. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  10969. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  10970. }
  10971. json_object_put(data);
  10972. }
  10973. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_CpConfiguration") != NULL)
  10974. {
  10975. json_object *data;
  10976. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  10977. if(!is_error(data))
  10978. {
  10979. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  10980. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  10981. {
  10982. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  10983. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  10984. else
  10985. {
  10986. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  10987. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  10988. }
  10989. }
  10990. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  10991. {
  10992. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  10993. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  10994. else
  10995. {
  10996. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  10997. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  10998. }
  10999. }
  11000. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  11001. {
  11002. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  11003. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  11004. else
  11005. {
  11006. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  11007. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  11008. }
  11009. }
  11010. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  11011. {
  11012. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  11013. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  11014. else
  11015. {
  11016. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  11017. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  11018. }
  11019. }
  11020. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  11021. {
  11022. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  11023. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  11024. else
  11025. {
  11026. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  11027. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  11028. }
  11029. }
  11030. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  11031. {
  11032. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  11033. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  11034. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  11035. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  11036. else
  11037. {
  11038. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  11039. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  11040. }
  11041. }
  11042. if(strstr((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]) != NULL)
  11043. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  11044. }
  11045. else
  11046. {
  11047. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  11048. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  11049. }
  11050. json_object_put(data);
  11051. }
  11052. else
  11053. {
  11054. // Can not find valid message id
  11055. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_UnknownMessageId]);
  11056. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data,"vendorId: %s messageId: %s data: %s"
  11057. ,ShmOCPP20Data->DataTransfer[0].vendorId
  11058. ,ShmOCPP20Data->DataTransfer[0].messageId
  11059. ,ShmOCPP20Data->DataTransfer[0].data);
  11060. }
  11061. }
  11062. else
  11063. {
  11064. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_UnknownMessageId]);
  11065. result = FAIL;
  11066. }
  11067. sendDataTransferConfirmation(uuid, 0);
  11068. return result;
  11069. }
  11070. int handleDeleteCertificateRequest(char *uuid, char *payload)
  11071. {
  11072. mtrace();
  11073. int result = FAIL;
  11074. json_object *DeleteCertificate;
  11075. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  11076. DeleteCertificate = json_tokener_parse(payload);
  11077. if(!is_error(DeleteCertificate))
  11078. {
  11079. memset(&ShmOCPP20Data->DeleteCertificate, 0, sizeof(struct DeleteCertificate_20));
  11080. memcpy(&ShmOCPP20Data->DeleteCertificate.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->DeleteCertificate.guid));
  11081. // Required data
  11082. if(json_object_object_get(DeleteCertificate, "certificateHashData") != NULL)
  11083. {
  11084. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm") != NULL)
  11085. {
  11086. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  11087. }
  11088. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash") != NULL)
  11089. {
  11090. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  11091. }
  11092. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash") != NULL)
  11093. {
  11094. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  11095. }
  11096. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber") != NULL)
  11097. {
  11098. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  11099. }
  11100. /*
  11101. * TODO:
  11102. * 1. Delete certification and response
  11103. */
  11104. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, DeleteCertificateStatusEnumTypeStr[DeleteCertificateStatusEnumType_Accepted]);
  11105. }
  11106. }
  11107. else
  11108. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, DeleteCertificateStatusEnumTypeStr[DeleteCertificateStatusEnumType_Failed]);
  11109. json_object_put(DeleteCertificate);
  11110. sendDeleteCertificateConfirmation(uuid);
  11111. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11112. return result;
  11113. }
  11114. int handleGetBaseReportRequest(char *uuid, char *payload)
  11115. {
  11116. mtrace();
  11117. int result = FAIL;
  11118. json_object *GetBaseRepor;
  11119. DEBUG_INFO("handleGetBaseReportRequest...\n");
  11120. GetBaseRepor = json_tokener_parse(payload);
  11121. if(!is_error(GetBaseRepor))
  11122. {
  11123. memset(&ShmOCPP20Data->GetBaseReport, 0, sizeof(struct GetBaseReport_20));
  11124. memcpy(&ShmOCPP20Data->GetBaseReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetBaseReport.guid));
  11125. // Required data
  11126. if(json_object_object_get(GetBaseRepor, "requestId") != NULL)
  11127. {
  11128. ShmOCPP20Data->GetBaseReport.requestId = json_object_get_int(json_object_object_get(GetBaseRepor, "requestId"));
  11129. }
  11130. if(json_object_object_get(GetBaseRepor, "reportBase") != NULL)
  11131. {
  11132. sprintf((char*)ShmOCPP20Data->GetBaseReport.reportBase, "%s", json_object_get_string(json_object_object_get(GetBaseRepor, "reportBase")));
  11133. }
  11134. if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_SummaryInventory]) == 0)
  11135. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  11136. else
  11137. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  11138. }
  11139. else
  11140. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  11141. json_object_put(GetBaseRepor);
  11142. sendGetBaseReportConfirmation(uuid);
  11143. return result;
  11144. }
  11145. int handleGetChargingProfilesRequest(char *uuid, char *payload)
  11146. {
  11147. mtrace();
  11148. int result = FAIL;
  11149. int gun_index = -1;
  11150. json_object *GetChargingProfiles;
  11151. DEBUG_INFO("handleGetChargingProfilesRequest...\n");
  11152. GetChargingProfiles = json_tokener_parse(payload);
  11153. if(!is_error(GetChargingProfiles))
  11154. {
  11155. if(json_object_object_get(GetChargingProfiles, "evseId") != NULL)
  11156. {
  11157. 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;
  11158. }
  11159. if(gun_index >-1)
  11160. {
  11161. memset(&ShmOCPP20Data->GetChargingProfiles[gun_index], 0, sizeof(struct GetChargingProfiles_20));
  11162. memcpy(&ShmOCPP20Data->GetChargingProfiles[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetChargingProfiles[gun_index].guid));
  11163. // Required data
  11164. if(json_object_object_get(GetChargingProfiles, "requestId") != NULL)
  11165. {
  11166. ShmOCPP20Data->GetChargingProfiles[gun_index].requestId = json_object_get_int(json_object_object_get(GetChargingProfiles, "requestId"));
  11167. }
  11168. if(json_object_object_get(GetChargingProfiles, "chargingProfile") != NULL)
  11169. {
  11170. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfilePurpose") != NULL)
  11171. {
  11172. sprintf((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.chargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfilePurpose")));
  11173. }
  11174. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "stackLevel") != NULL)
  11175. {
  11176. ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "stackLevel"));
  11177. }
  11178. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingLimitSource") != NULL)
  11179. {
  11180. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingLimitSource"));idx++)
  11181. {
  11182. 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)));
  11183. }
  11184. }
  11185. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfileId") != NULL)
  11186. {
  11187. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfileId"));idx++)
  11188. {
  11189. 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));
  11190. }
  11191. }
  11192. }
  11193. strcpy((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status, GetChargingProfileStatusEnumTypeStr[GetChargingProfileStatusEnumType_Accepted]);
  11194. }
  11195. else
  11196. strcpy((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status, GetChargingProfileStatusEnumTypeStr[GetChargingProfileStatusEnumType_NoProfiles]);
  11197. }
  11198. json_object_put(GetChargingProfiles);
  11199. sendGetChargingProfilesConfirmation(uuid, gun_index);
  11200. return result;
  11201. }
  11202. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  11203. {
  11204. mtrace();
  11205. int result = FAIL;
  11206. int connectorIdInt, durationInt;
  11207. char chargingRateUnitStr[4]={0};
  11208. char comfirmstr[20];
  11209. int confirmPeriods = 0;
  11210. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  11211. json_object *GetCompositeSchedule;
  11212. GetCompositeSchedule = json_tokener_parse(payload);
  11213. if(!is_error(GetCompositeSchedule))
  11214. {
  11215. // Required data
  11216. if(json_object_object_get(GetCompositeSchedule, "evseId") != NULL)
  11217. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "evseId"));
  11218. else
  11219. connectorIdInt = -1;
  11220. if(json_object_object_get(GetCompositeSchedule, "duration"))
  11221. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  11222. else
  11223. durationInt = 86400;
  11224. // Optional data
  11225. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  11226. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  11227. }
  11228. json_object_put(GetCompositeSchedule);
  11229. memset(ShmOCPP20Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  11230. if((connectorIdInt == 0) ||
  11231. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  11232. {
  11233. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  11234. struct ChargingProfileType tmpProfile[1];
  11235. memset(&ShmOCPP20Data->GetCompositeSchedule[gun_index], 0, sizeof(struct GetCompositeSchedule_20));
  11236. memcpy(&ShmOCPP20Data->GetCompositeSchedule[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].guid));
  11237. if(strstr(chargingRateUnitStr, "W") != NULL)
  11238. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], 0, FALSE);
  11239. else
  11240. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], 0, TRUE);
  11241. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod);idx++)
  11242. {
  11243. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].chargingSchedule[0].chargingSchedulePeriod[idx].startPeriod);
  11244. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].chargingSchedule[0].chargingSchedulePeriod[idx].limit);
  11245. }
  11246. memcpy(&ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule, &tmpProfile[0].chargingSchedule[0], sizeof(struct CompositeScheduleType));
  11247. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod);idx++)
  11248. {
  11249. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].startPeriod);
  11250. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit);
  11251. if((ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].startPeriod==0) &&
  11252. (ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit==0) &&
  11253. (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))
  11254. {
  11255. confirmPeriods = idx;
  11256. break;
  11257. }
  11258. }
  11259. if((confirmPeriods == 0) && (tmpProfile[0].id > 0))
  11260. {
  11261. confirmPeriods += 1;
  11262. }
  11263. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  11264. }
  11265. else
  11266. {
  11267. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusEnumTypeStr[GenericStatusEnumType_Rejected]);
  11268. }
  11269. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  11270. return result;
  11271. }
  11272. int handleGetDisplayMessagesRequest(char *uuid, char *payload)
  11273. {
  11274. mtrace();
  11275. int result = FAIL;
  11276. json_object *GetDisplayMessages;
  11277. DEBUG_INFO("handleGetDisplayMessagesRequest...\n");
  11278. GetDisplayMessages = json_tokener_parse(payload);
  11279. if(!is_error(GetDisplayMessages))
  11280. {
  11281. memset(&ShmOCPP20Data->GetDisplayMessages, 0, sizeof(struct GetDisplayMessages_20));
  11282. memcpy(&ShmOCPP20Data->GetDisplayMessages.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetDisplayMessages.guid));
  11283. // Required data
  11284. if(json_object_object_get(GetDisplayMessages, "requestId") != NULL)
  11285. {
  11286. ShmOCPP20Data->GetDisplayMessages.requestId = json_object_get_int(json_object_object_get(GetDisplayMessages, "requestId"));
  11287. }
  11288. // Optional data
  11289. if(json_object_object_get(GetDisplayMessages, "priority") != NULL)
  11290. {
  11291. sprintf((char*)ShmOCPP20Data->GetDisplayMessages.priority, "%s", json_object_get_string(json_object_object_get(GetDisplayMessages, "priority")));
  11292. }
  11293. if(json_object_object_get(GetDisplayMessages, "state") != NULL)
  11294. {
  11295. sprintf((char*)ShmOCPP20Data->GetDisplayMessages.state, "%s", json_object_get_string(json_object_object_get(GetDisplayMessages, "state")));
  11296. }
  11297. if(json_object_array_length(json_object_object_get(GetDisplayMessages, "id")) <= ARRAY_SIZE(ShmOCPP20Data->GetDisplayMessages.id))
  11298. {
  11299. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetDisplayMessages, "id"));idx++)
  11300. {
  11301. ShmOCPP20Data->GetDisplayMessages.id[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(GetDisplayMessages, "id"), idx));
  11302. }
  11303. strcpy((char*)ShmOCPP20Data->GetDisplayMessages.Response_status, GetDisplayMessagesStatusEnumTypeStr[GetDisplayMessagesStatusEnumType_Accepted]);
  11304. ShmOCPP20Data->MsMsg.bits.GetDisplayMessagesReq = ON;
  11305. }
  11306. else
  11307. strcpy((char*)ShmOCPP20Data->GetDisplayMessages.Response_status, GetDisplayMessagesStatusEnumTypeStr[GetDisplayMessagesStatusEnumType_Unknown]);
  11308. }
  11309. json_object_put(GetDisplayMessages);
  11310. return result;
  11311. }
  11312. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  11313. {
  11314. mtrace();
  11315. int result = FAIL;
  11316. json_object *GetInstalledCertificateIds;
  11317. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  11318. GetInstalledCertificateIds = json_tokener_parse(payload);
  11319. if(!is_error(GetInstalledCertificateIds))
  11320. {
  11321. memset(&ShmOCPP20Data->GetInstalledCertificateIds, 0, sizeof(struct GetInstalledCertificateIds_20));
  11322. memcpy(&ShmOCPP20Data->GetInstalledCertificateIds.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetInstalledCertificateIds.guid));
  11323. // Optional data
  11324. if(json_object_array_length(json_object_object_get(GetInstalledCertificateIds, "certificateType")) <= ARRAY_SIZE(ShmOCPP20Data->GetInstalledCertificateIds.certificateType))
  11325. {
  11326. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetInstalledCertificateIds, "certificateType"));idx++)
  11327. {
  11328. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetInstalledCertificateIds, "certificateType"), idx)));
  11329. /*
  11330. * TODO:
  11331. * 1. Get installed certificate info for response
  11332. */
  11333. }
  11334. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  11335. }
  11336. else
  11337. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_NotFound]);
  11338. }
  11339. json_object_put(GetInstalledCertificateIds);
  11340. sendInstallCertificateConfirmation(uuid);
  11341. return result;
  11342. }
  11343. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  11344. {
  11345. mtrace();
  11346. int result = FAIL;
  11347. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  11348. if(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "FALSE") == 0)
  11349. {
  11350. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  11351. localversion = -1;
  11352. }
  11353. else
  11354. {
  11355. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  11356. DB_getListVerion();
  11357. }
  11358. ShmOCPP20Data->GetLocalListVersion.Response_versionNumber = localversion;
  11359. sendGetLocalListVersionConfirmation(uuid);
  11360. return result;
  11361. }
  11362. static char fnamePlusPath[100]={0};
  11363. static char fnamePWithNoPath[60]={0};
  11364. void checkUploadLog(void)
  11365. {
  11366. FILE *fp;
  11367. /* Open the command for reading. */
  11368. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  11369. if (fp == NULL) {
  11370. printf("Failed to run command\n" );
  11371. exit(1);
  11372. }
  11373. int ftppathlen = 0;
  11374. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  11375. int i = 0;
  11376. /* Read the output a line at a time - output it. */
  11377. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  11378. if(i==0)
  11379. {
  11380. ftppathlen = strlen(fnamePlusPath);
  11381. printf("%s\n", fnamePlusPath);
  11382. fnamePlusPath[ftppathlen]='\0';
  11383. break;
  11384. }
  11385. i= i+1;
  11386. }
  11387. /* close */
  11388. pclose(fp);
  11389. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  11390. {
  11391. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  11392. {
  11393. fnamePlusPath[k]='\0';
  11394. }
  11395. }
  11396. i=1;
  11397. //char fname[60]={0};
  11398. while(i < ftppathlen)
  11399. {
  11400. int len=ftppathlen-i;
  11401. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  11402. {
  11403. printf("compare '/' all right\n");
  11404. break;
  11405. }
  11406. i=i+1;
  11407. }
  11408. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  11409. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  11410. fnamePWithNoPath[i+1] = '\0';
  11411. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  11412. {
  11413. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  11414. {
  11415. fnamePWithNoPath[j]='\0';
  11416. }
  11417. }
  11418. FILE* fp1 = fopen(fnamePlusPath, "r");
  11419. if (fp1)
  11420. {
  11421. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  11422. // file exists
  11423. fclose(fp1);
  11424. }
  11425. else
  11426. {
  11427. // file doesn't exist
  11428. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  11429. }
  11430. }
  11431. void* GetLogProcess(void* data)
  11432. {
  11433. pthread_detach(pthread_self());
  11434. mtrace();
  11435. int requestId, retriesInt=0, retryIntervalInt=0;
  11436. char logType[32], remoteLocation[1024]={0}, oldestTimestamp[30]={0}, latestTimestamp[30]={0};
  11437. 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};
  11438. int port=0;
  11439. int isSuccess = FALSE;
  11440. char ftpbuf[1024]={0};
  11441. char cmdBuf[2048];
  11442. struct tm *tmNow;
  11443. time_t CurrentTime;
  11444. struct tm tmStart;
  11445. struct tm tmStop;
  11446. CurrentTime = time(NULL);
  11447. tmNow=localtime(&CurrentTime);
  11448. uint16_t targetYear, targetMonth;
  11449. json_object *GetLog;
  11450. DEBUG_INFO("GetGetProcess...\n");
  11451. GetLog = json_tokener_parse(data);
  11452. if(!is_error(GetLog))
  11453. {
  11454. // Required data
  11455. if(json_object_object_get(GetLog, "requestId") != NULL)
  11456. requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  11457. if(json_object_object_get(GetLog, "logType") != NULL)
  11458. sprintf(logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  11459. if(json_object_object_get(GetLog, "log") != NULL)
  11460. {
  11461. if(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation") != NULL)
  11462. sprintf(remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  11463. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  11464. sprintf(oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  11465. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  11466. sprintf(latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  11467. }
  11468. // Optional data
  11469. if(json_object_object_get(GetLog, "retries") != NULL)
  11470. retriesInt = json_object_get_int(json_object_object_get(GetLog, "retries"));
  11471. else
  11472. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  11473. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  11474. retryIntervalInt = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  11475. else
  11476. retryIntervalInt = 30;
  11477. }
  11478. json_object_put(GetLog);
  11479. ShmOCPP20Data->GetLog.requestId = requestId;
  11480. // Pack log to compress file
  11481. 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) &&
  11482. (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))
  11483. {
  11484. // Pack system log
  11485. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11486. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  11487. targetYear = tmStart.tm_year;
  11488. targetMonth = tmStart.tm_mon;
  11489. do
  11490. {
  11491. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11492. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11493. if(targetMonth+1>=13)
  11494. {
  11495. targetYear += 1;
  11496. targetMonth = 1;
  11497. }
  11498. else
  11499. {
  11500. targetMonth += 1;
  11501. }
  11502. }while((targetYear < (tmNow->tm_year+1900)) ||
  11503. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11504. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  11505. system(cmdBuf);
  11506. // Pack charging & event log
  11507. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11508. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  11509. targetYear = tmStart.tm_year;
  11510. targetMonth = tmStart.tm_mon;
  11511. do
  11512. {
  11513. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11514. if(targetMonth+1>=13)
  11515. {
  11516. targetYear += 1;
  11517. targetMonth = 1;
  11518. }
  11519. else
  11520. {
  11521. targetMonth += 1;
  11522. }
  11523. }while((targetYear < (tmNow->tm_year+1900)) ||
  11524. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11525. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  11526. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  11527. system(cmdBuf);
  11528. // Combine log file
  11529. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  11530. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  11531. }
  11532. else
  11533. {
  11534. system("exec /root/logPackTools 'log' 6");
  11535. }
  11536. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP20Data->GetLog.Response_filename);
  11537. system(cmdBuf);
  11538. checkUploadLog();
  11539. //****************location*******************/
  11540. if(strcmp(remoteLocation,"")==0)
  11541. {
  11542. DEBUG_INFO("remoteLocation is <Empty>!\n");
  11543. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  11544. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  11545. goto end;
  11546. }
  11547. memset(protocol, 0, ARRAY_SIZE(protocol));
  11548. memset(user, 0, ARRAY_SIZE(user) );
  11549. memset(password, 0, ARRAY_SIZE(password));
  11550. memset(host, 0, ARRAY_SIZE(host));
  11551. memset(path, 0, ARRAY_SIZE(path));
  11552. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11553. memset(host1, 0, ARRAY_SIZE(host1));
  11554. memset(path1, 0, ARRAY_SIZE(path1));
  11555. /*location: ftp://user:password@host:port/path*/
  11556. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  11557. if((access(fnamePlusPath,F_OK))!=-1)
  11558. {
  11559. DEBUG_INFO("fnamePlusPath exist.\n");
  11560. }
  11561. else
  11562. {
  11563. DEBUG_INFO("fnamePlusPath not exist!\n");
  11564. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  11565. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  11566. goto end;
  11567. }
  11568. if(strchr(remoteLocation,'@')==NULL)
  11569. {
  11570. sscanf(remoteLocation,
  11571. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11572. protocol, host, &port, path);
  11573. strcpy(user,"anonymous");
  11574. strcpy(password,"");
  11575. }
  11576. else
  11577. {
  11578. //DEBUG_INFO("pch=%s\n", pch);
  11579. sscanf(remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11580. protocol, user, password, host, &port, path);
  11581. }
  11582. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  11583. {
  11584. DEBUG_INFO("protocol is not ftp/http ! \n");
  11585. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  11586. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  11587. goto end;
  11588. }
  11589. if(strncmp(remoteLocation,"http", 4) == 0)
  11590. {
  11591. sscanf(remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11592. sprintf(ftppath,"/%s", path);
  11593. do
  11594. {
  11595. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploading]);
  11596. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  11597. sleep(3);
  11598. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, remoteLocation);
  11599. if(!isSuccess)
  11600. {
  11601. DEBUG_INFO("sendLogStatusNotificationRequest fail...retries: %d\n", retriesInt);
  11602. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  11603. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  11604. sleep(retryIntervalInt);
  11605. }
  11606. else
  11607. {
  11608. DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
  11609. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
  11610. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  11611. }
  11612. retriesInt--;
  11613. }while((isSuccess == 0)&&(retriesInt >= 0));
  11614. }
  11615. else
  11616. {
  11617. sscanf(host,"%[^/]%s",host1, path1);
  11618. if(strlen(path) > 0)
  11619. sprintf(ftppath,"/%s", path);
  11620. else
  11621. sprintf(ftppath,"/%s", path1);
  11622. int ftppathlen=strlen(ftppath);
  11623. int i=1;
  11624. char filenametemp[50];
  11625. while(i < ftppathlen)
  11626. {
  11627. int len=ftppathlen-i;
  11628. if(ftppath[len]== 47) // '/' ascll code: 47
  11629. {
  11630. DEBUG_INFO("find '/' all right\n");
  11631. break;
  11632. }
  11633. i=i+1;
  11634. }
  11635. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11636. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11637. filenametemp[i+1] = 0;
  11638. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  11639. if(port == 0)
  11640. port = 21;
  11641. do
  11642. {
  11643. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploading]);
  11644. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  11645. sleep(3);
  11646. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  11647. if(!isSuccess)
  11648. {
  11649. DEBUG_INFO("sendLogStatusNotificationRequest fail...retries: %d\n", retriesInt);
  11650. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  11651. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  11652. sleep(retryIntervalInt);
  11653. }
  11654. else
  11655. {
  11656. DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
  11657. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
  11658. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  11659. }
  11660. retriesInt--;
  11661. }while((!isSuccess)&&(retriesInt >= 0));
  11662. }
  11663. end:
  11664. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle;
  11665. pthread_exit(NULL);
  11666. }
  11667. int handleGetLogRequest(char *uuid, char *payload)
  11668. {
  11669. mtrace();
  11670. int result = FAIL;
  11671. char fName[258];
  11672. time_t CurrentTime;
  11673. struct tm *tm;
  11674. pthread_t th_Status;
  11675. CurrentTime = time(NULL);
  11676. tm = localtime(&CurrentTime);
  11677. 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);
  11678. sprintf((char*)ShmOCPP20Data->GetLog.Response_filename, "%s", fName);
  11679. sprintf((char*)ShmOCPP20Data->GetLog.Response_status, "%s", LogStatusEnumTypeStr[LogStatusEnumType_Accepted]);
  11680. sendGetLogConfirmation(uuid);
  11681. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  11682. return result;
  11683. }
  11684. int handleGetMonitoringReportRequest(char *uuid, char *payload)
  11685. {
  11686. mtrace();
  11687. int result = FAIL;
  11688. json_object *GetMonitoringReport;
  11689. DEBUG_INFO("handleGetMonitoringReportRequest...\n");
  11690. GetMonitoringReport = json_tokener_parse(payload);
  11691. if(!is_error(GetMonitoringReport))
  11692. {
  11693. memset(&ShmOCPP20Data->GetMonitoringReport, 0, sizeof(struct GetMonitoringReport_20));
  11694. memcpy(&ShmOCPP20Data->GetMonitoringReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.guid));
  11695. // Required data
  11696. if(json_object_object_get(GetMonitoringReport, "requestId") != NULL)
  11697. {
  11698. ShmOCPP20Data->GetMonitoringReport.requestId = json_object_get_int(json_object_object_get(GetMonitoringReport, "requestId"));
  11699. }
  11700. // Optional data
  11701. if(json_object_object_get(GetMonitoringReport, "monitoringCriteria") != NULL)
  11702. {
  11703. sprintf((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria, "%s", json_object_get_string(json_object_object_get(GetMonitoringReport, "monitoringCriteria")));
  11704. }
  11705. if(json_object_object_get(GetMonitoringReport, "componentVariable") != NULL)
  11706. {
  11707. if(json_object_array_length(json_object_object_get(GetMonitoringReport, "componentVariable")) <= ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.componentVariable))
  11708. {
  11709. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetMonitoringReport, "componentVariable"));idx++)
  11710. {
  11711. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component") != NULL)
  11712. {
  11713. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "name") != NULL)
  11714. {
  11715. 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")));
  11716. }
  11717. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "instance") != NULL)
  11718. {
  11719. 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")));
  11720. }
  11721. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "evse") != NULL)
  11722. {
  11723. 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)
  11724. {
  11725. 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"));
  11726. }
  11727. 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)
  11728. {
  11729. 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"));
  11730. }
  11731. }
  11732. }
  11733. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable") != NULL)
  11734. {
  11735. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "name") != NULL)
  11736. {
  11737. 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")));
  11738. }
  11739. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "instance") != NULL)
  11740. {
  11741. 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")));
  11742. }
  11743. }
  11744. }
  11745. }
  11746. }
  11747. }
  11748. json_object_put(GetMonitoringReport);
  11749. /*
  11750. * TODO:
  11751. * 1. Response result
  11752. */
  11753. strcpy((char*)ShmOCPP20Data->GetReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  11754. sendGetMonitoringReportConfirmation(uuid);
  11755. return result;
  11756. }
  11757. int handleGetReportRequest(char *uuid, char *payload)
  11758. {
  11759. mtrace();
  11760. int result = FAIL;
  11761. json_object *GetReport;
  11762. DEBUG_INFO("handleGetReportRequest...\n");
  11763. GetReport = json_tokener_parse(payload);
  11764. if(!is_error(GetReport))
  11765. {
  11766. memset(&ShmOCPP20Data->GetReport, 0, sizeof(struct GetReport_20));
  11767. memcpy(&ShmOCPP20Data->GetReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetReport.guid));
  11768. // Required data
  11769. if(json_object_object_get(GetReport, "requestId") != NULL)
  11770. {
  11771. ShmOCPP20Data->GetReport.requestId = json_object_get_int(json_object_object_get(GetReport, "requestId"));
  11772. }
  11773. // Optional data
  11774. if(json_object_object_get(GetReport, "componentCriteria") != NULL)
  11775. {
  11776. sprintf((char*)ShmOCPP20Data->GetReport.componentCriteria, "%s", json_object_get_string(json_object_object_get(GetReport, "componentCriteria")));
  11777. }
  11778. if(json_object_object_get(GetReport, "componentVariable") != NULL)
  11779. {
  11780. if(json_object_array_length(json_object_object_get(GetReport, "componentVariable")) <= ARRAY_SIZE(ShmOCPP20Data->GetReport.componentVariable))
  11781. {
  11782. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetReport, "componentVariable"));idx++)
  11783. {
  11784. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component") != NULL)
  11785. {
  11786. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "name") != NULL)
  11787. {
  11788. 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")));
  11789. }
  11790. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "instance") != NULL)
  11791. {
  11792. 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")));
  11793. }
  11794. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "evse") != NULL)
  11795. {
  11796. 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)
  11797. {
  11798. ShmOCPP20Data->GetReport.componentVariable[idx].component.evse.id = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "instance"), "id"));
  11799. }
  11800. 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)
  11801. {
  11802. ShmOCPP20Data->GetReport.componentVariable[idx].component.evse.connectorId = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "instance"), "connectorId"));
  11803. }
  11804. }
  11805. }
  11806. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable") != NULL)
  11807. {
  11808. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "name") != NULL)
  11809. {
  11810. 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")));
  11811. }
  11812. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "instance") != NULL)
  11813. {
  11814. 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")));
  11815. }
  11816. }
  11817. }
  11818. }
  11819. }
  11820. }
  11821. json_object_put(GetReport);
  11822. /*
  11823. * TODO:
  11824. * 1. Response result
  11825. */
  11826. strcpy((char*)ShmOCPP20Data->GetReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  11827. sendGetReportConfirmation(uuid);
  11828. return result;
  11829. }
  11830. int handleGetTransactionStatusRequest(char *uuid, char *payload)
  11831. {
  11832. mtrace();
  11833. int result = FAIL;
  11834. int8_t gun_index = -1;
  11835. json_object *GetTransactionStatus;
  11836. DEBUG_INFO("handleGetTransactionStatusRequest...\n");
  11837. GetTransactionStatus = json_tokener_parse(payload);
  11838. if(!is_error(GetTransactionStatus))
  11839. {
  11840. /*
  11841. * TODO:
  11842. * 1. Check transaction locate which connector
  11843. */
  11844. memset(&ShmOCPP20Data->GetTransactionStatus[gun_index], 0, sizeof(struct GetTransactionStatus_20));
  11845. memcpy(&ShmOCPP20Data->GetTransactionStatus[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetTransactionStatus[gun_index].guid));
  11846. if(json_object_object_get(GetTransactionStatus, "transactionId") != NULL)
  11847. {
  11848. sprintf((char*)ShmOCPP20Data->GetTransactionStatus[gun_index].transactionId, "%s", json_object_get_string(json_object_object_get(GetTransactionStatus, "transactionId")));
  11849. }
  11850. ShmOCPP20Data->GetTransactionStatus[gun_index].Response_messagesInQueue = FALSE;
  11851. ShmOCPP20Data->GetTransactionStatus[gun_index].Response_ongoingIndicator = FALSE;
  11852. }
  11853. json_object_put(GetTransactionStatus);
  11854. sendGetTransactionStatusConfirmation(uuid, gun_index);
  11855. return result;
  11856. }
  11857. int handleGetVariablesRequest(char *uuid, char *payload)
  11858. {
  11859. mtrace();
  11860. int result = FAIL;
  11861. json_object *GetVariables;
  11862. DEBUG_INFO("handleGetVariablesRequest...\n");
  11863. GetVariables = json_tokener_parse(payload);
  11864. if(!is_error(GetVariables))
  11865. {
  11866. memset(&ShmOCPP20Data->GetVariables, 0, sizeof(struct SetVariables_20));
  11867. memcpy(&ShmOCPP20Data->GetVariables.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetVariables.guid));
  11868. // Required data
  11869. if(json_object_array_length(json_object_object_get(GetVariables, "getVariableData")) <= ARRAY_SIZE(ShmOCPP20Data->GetVariables.getVariableData))
  11870. {
  11871. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetVariables, "getVariableData"));idx++)
  11872. {
  11873. if(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx) != NULL)
  11874. {
  11875. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "attributeType") != NULL)
  11876. {
  11877. 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")));
  11878. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, (char*)ShmOCPP20Data->GetVariables.getVariableData[idx].attributeType);
  11879. }
  11880. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component") != NULL)
  11881. {
  11882. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "name") != NULL)
  11883. {
  11884. 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")));
  11885. }
  11886. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "instance") != NULL)
  11887. {
  11888. 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")));
  11889. }
  11890. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "evse") != NULL)
  11891. {
  11892. 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)
  11893. {
  11894. 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"));
  11895. }
  11896. 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)
  11897. {
  11898. 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"));
  11899. }
  11900. }
  11901. memcpy(&ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component, &ShmOCPP20Data->GetVariables.getVariableData[idx].component, sizeof(struct ComponentType));
  11902. }
  11903. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable") != NULL)
  11904. {
  11905. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "name") != NULL)
  11906. {
  11907. 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")));
  11908. }
  11909. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "instance") != NULL)
  11910. {
  11911. 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")));
  11912. }
  11913. memcpy(&ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable , &ShmOCPP20Data->GetVariables.getVariableData[idx].variable, sizeof(struct VariableType));
  11914. }
  11915. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  11916. {
  11917. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name) == 0) &&
  11918. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.instance, (char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.instance) == 0) &&
  11919. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name) == 0) &&
  11920. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.instance, (char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.instance) == 0))
  11921. {
  11922. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_Accepted]);
  11923. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value);
  11924. break;
  11925. }
  11926. else
  11927. {
  11928. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_UnknownComponent]);
  11929. memset(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, 0x00, ARRAY_SIZE(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue));
  11930. }
  11931. }
  11932. }
  11933. }
  11934. }
  11935. sendGetVariablesConfirmation(uuid, json_object_array_length(json_object_object_get(GetVariables, "getVariableData")));
  11936. }
  11937. json_object_put(GetVariables);
  11938. return result;
  11939. }
  11940. int handleInstallCertificateRequest(char *uuid, char *payload)
  11941. {
  11942. mtrace();
  11943. int result = FAIL;
  11944. json_object *InstallCertificate;
  11945. DEBUG_INFO("handleInstallCertificateRequest...\n");
  11946. InstallCertificate = json_tokener_parse(payload);
  11947. if(!is_error(InstallCertificate))
  11948. {
  11949. memset(&ShmOCPP20Data->InstallCertificate, 0, sizeof(struct InstallCertificate_20));
  11950. memcpy(&ShmOCPP20Data->InstallCertificate.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->InstallCertificate.guid));
  11951. // Required data
  11952. if(json_object_object_get(InstallCertificate, "certificateType") != NULL)
  11953. {
  11954. sprintf((char*)ShmOCPP20Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  11955. }
  11956. if(json_object_object_get(InstallCertificate, "certificate") != NULL)
  11957. {
  11958. sprintf((char*)ShmOCPP20Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  11959. }
  11960. }
  11961. json_object_put(InstallCertificate);
  11962. /*
  11963. * TODO:
  11964. * 1. Install certification preocess and response
  11965. */
  11966. strcpy((char*)ShmOCPP20Data->InstallCertificate.Response_status, InstallCertificateStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  11967. sendInstallCertificateConfirmation(uuid);
  11968. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11969. return result;
  11970. }
  11971. int handlePublishFirmwareRequest(char *uuid, char *payload)
  11972. {
  11973. mtrace();
  11974. int result = FAIL;
  11975. json_object *PublishFirmware;
  11976. DEBUG_INFO("handlePublishFirmwareRequest...\n");
  11977. PublishFirmware = json_tokener_parse(payload);
  11978. if(!is_error(PublishFirmware))
  11979. {
  11980. memset(&ShmOCPP20Data->PublishFirmware, 0, sizeof(struct PublishFirmware_20));
  11981. memcpy(&ShmOCPP20Data->PublishFirmware.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->PublishFirmware.guid));
  11982. // Required data
  11983. if(json_object_object_get(PublishFirmware, "requestId") != NULL)
  11984. {
  11985. ShmOCPP20Data->PublishFirmware.requestId = json_object_get_int(json_object_object_get(PublishFirmware, "requestId"));
  11986. }
  11987. if(json_object_object_get(PublishFirmware, "checksum") != NULL)
  11988. {
  11989. sprintf((char*)ShmOCPP20Data->PublishFirmware.requestId, "%s", json_object_get_string(json_object_object_get(PublishFirmware, "checksum")));
  11990. }
  11991. // Optional data
  11992. if(json_object_object_get(PublishFirmware, "location") != NULL)
  11993. {
  11994. sprintf((char*)ShmOCPP20Data->PublishFirmware.location, "%s", json_object_get_string(json_object_object_get(PublishFirmware, "location")));
  11995. }
  11996. if(json_object_object_get(PublishFirmware, "retries") != NULL)
  11997. {
  11998. ShmOCPP20Data->PublishFirmware.retries = json_object_get_int(json_object_object_get(PublishFirmware, "retries"));
  11999. }
  12000. if(json_object_object_get(PublishFirmware, "retryInterval") != NULL)
  12001. {
  12002. ShmOCPP20Data->PublishFirmware.retryInterval = json_object_get_int(json_object_object_get(PublishFirmware, "retryInterval"));
  12003. }
  12004. }
  12005. json_object_put(PublishFirmware);
  12006. /*
  12007. * TODO:
  12008. * 1. Publish firmware preocess and response
  12009. */
  12010. strcpy((char*)ShmOCPP20Data->PublishFirmware.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  12011. sendPublishFirmwareConfirmation(uuid);
  12012. return result;
  12013. }
  12014. int handleRemoteStartTransactionRequest(char *uuid, char *payload)
  12015. {
  12016. mtrace();
  12017. int result = FAIL;
  12018. int8_t gun_index = -1;
  12019. uint8_t isPeriodOverMax = FALSE;
  12020. uint8_t isProfileOverMax = FALSE;
  12021. uint8_t isConnectorMismatch = FALSE;
  12022. uint8_t isTxProfile = FALSE;
  12023. uint8_t existProfileQuantity = 0;
  12024. uint8_t filename[128]={0};
  12025. uint8_t word[2048]={0};
  12026. FILE *filePtr;
  12027. json_object *RemoteStartTransaction;
  12028. DEBUG_INFO("handleRemoteStartTransactionRequest...\n");
  12029. RemoteStartTransaction = json_tokener_parse(payload);
  12030. if(!is_error(RemoteStartTransaction))
  12031. {
  12032. if(json_object_object_get(RemoteStartTransaction, "evseId") != NULL)
  12033. {
  12034. gun_index = json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"));
  12035. }
  12036. else
  12037. {
  12038. /*
  12039. * TODO:
  12040. * 1. Selected connector process
  12041. */
  12042. gun_index = 0;
  12043. }
  12044. memset(&ShmOCPP20Data->RequestStartTransaction[gun_index], 0, sizeof(struct RequestStartTransaction_20));
  12045. memcpy(&ShmOCPP20Data->RequestStartTransaction[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->RequestStartTransaction[gun_index].guid));
  12046. // Required data
  12047. if(json_object_object_get(RemoteStartTransaction, "remoteStartId") != NULL)
  12048. {
  12049. ShmOCPP20Data->RequestStartTransaction[gun_index].remoteStartId = json_object_get_int(json_object_object_get(RemoteStartTransaction, "remoteStartId"));
  12050. }
  12051. if(json_object_object_get(RemoteStartTransaction, "idToken") != NULL)
  12052. {
  12053. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken") != NULL)
  12054. {
  12055. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken")));
  12056. }
  12057. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type") != NULL)
  12058. {
  12059. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type")));
  12060. }
  12061. }
  12062. // Optional data
  12063. if(json_object_object_get(RemoteStartTransaction, "groupIdToken") != NULL)
  12064. {
  12065. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken") != NULL)
  12066. {
  12067. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken")));
  12068. }
  12069. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type") != NULL)
  12070. {
  12071. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type")));
  12072. }
  12073. }
  12074. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  12075. {
  12076. // Check periods is over max configuration
  12077. if(json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod")) > 10)
  12078. {
  12079. isPeriodOverMax = TRUE;
  12080. }
  12081. // Check periods is over max configuration
  12082. if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  12083. {
  12084. if(gun_index > 0)
  12085. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", gun_index);
  12086. else
  12087. isConnectorMismatch = TRUE;
  12088. if(!isConnectorMismatch)
  12089. {
  12090. filePtr = fopen((char*)filename, "r");
  12091. if (!filePtr)
  12092. {
  12093. DEBUG_INFO("%s not exist, create it.\n", filename);
  12094. filePtr = fopen((char*)filename, "w+");
  12095. }
  12096. else
  12097. {
  12098. //Check Charging Profile Count
  12099. while(fscanf(filePtr, "%s", word) != EOF)
  12100. {
  12101. //DEBUG_INFO("word=%s\n",word);
  12102. if(strstr((char*)word, "chargingProfileId")!= NULL)
  12103. {
  12104. existProfileQuantity += 1;
  12105. }
  12106. }
  12107. }
  12108. fclose(filePtr);
  12109. }
  12110. }
  12111. else
  12112. {
  12113. }
  12114. if(existProfileQuantity > 3)
  12115. isProfileOverMax = TRUE;
  12116. }
  12117. // Profile replace or add info
  12118. if((gun_index > 0) && !isPeriodOverMax && !isProfileOverMax && !isConnectorMismatch && !isTxProfile)
  12119. {
  12120. FILE *infile;
  12121. FILE *outfile;
  12122. char tmpProfileName[32];
  12123. char rmFileCmd[128];
  12124. char tempchargingProfilePurposeStr[30]={0};
  12125. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  12126. sprintf((char*)tmpProfileName, "/Storage/OCPP/tmpProfileRemote");
  12127. infile = fopen ((char*)filename, "r");
  12128. outfile = fopen ((char*)tmpProfileName, "w");
  12129. int d = fgetc(infile);
  12130. rewind(infile);
  12131. if(d == EOF)
  12132. {
  12133. // Profile is empty
  12134. fprintf(outfile,"%s\n", payload);
  12135. fclose(infile);
  12136. fclose(outfile);
  12137. sprintf(rmFileCmd,"rm -f %s",filename);
  12138. system(rmFileCmd);
  12139. rename((char*)tmpProfileName, (char*)filename);
  12140. }
  12141. else
  12142. {
  12143. // Profile is not empty
  12144. char buf[2048]={0};
  12145. int ChargingProfileAdded = FALSE;
  12146. while (fgets(buf, sizeof(buf), infile) != NULL)
  12147. {
  12148. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  12149. json_object *tmpChargingProfile;
  12150. tmpChargingProfile = json_tokener_parse(buf);
  12151. if(!is_error(tmpChargingProfile))
  12152. {
  12153. if(json_object_object_get(tmpChargingProfile, "evseId") != NULL)
  12154. {
  12155. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "evseId") );
  12156. }
  12157. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12158. {
  12159. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12160. {
  12161. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12162. }
  12163. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12164. {
  12165. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12166. }
  12167. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12168. {
  12169. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12170. }
  12171. }
  12172. }
  12173. json_object_put(tmpChargingProfile);
  12174. if((tempconnectorIdInt == gun_index) &&
  12175. (tempchargingProfileIdInt == json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "csChargingProfiles"), "chargingProfileId"))))
  12176. {
  12177. if((tempstackLevelInt == json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "csChargingProfiles"), "stackLevel"))) &&
  12178. (strcmp(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "csChargingProfiles"), "chargingProfilePurpose"))) == 0))
  12179. {
  12180. if(ChargingProfileAdded == FALSE)
  12181. {
  12182. fprintf(outfile,"%s\n",payload);
  12183. ChargingProfileAdded = TRUE;
  12184. }
  12185. }
  12186. else
  12187. {
  12188. if(tempstackLevelInt < json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "csChargingProfiles"), "stackLevel")))
  12189. {
  12190. if(ChargingProfileAdded == FALSE)
  12191. {
  12192. fprintf(outfile,"%s\n",buf);
  12193. fprintf(outfile,"%s\n",payload);
  12194. ChargingProfileAdded = TRUE;
  12195. }
  12196. else
  12197. {
  12198. fprintf(outfile,"%s\n",buf);
  12199. }
  12200. }
  12201. else
  12202. {
  12203. if(ChargingProfileAdded == FALSE)
  12204. {
  12205. fprintf(outfile,"%s\n",buf);
  12206. fprintf(outfile,"%s\n",payload);
  12207. ChargingProfileAdded = TRUE;
  12208. }
  12209. else
  12210. {
  12211. fprintf(outfile,"%s\n",buf);
  12212. }
  12213. }
  12214. }
  12215. }
  12216. else
  12217. {
  12218. if(tempchargingProfileIdInt < json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "csChargingProfiles"), "chargingProfileId")))
  12219. {
  12220. if(ChargingProfileAdded == FALSE)
  12221. {
  12222. fprintf(outfile,"%s\n",buf);
  12223. fprintf(outfile,"%s\n",payload);
  12224. ChargingProfileAdded = TRUE;
  12225. }
  12226. else
  12227. {
  12228. fprintf(outfile,"%s\n",buf);
  12229. }
  12230. }
  12231. else if(tempstackLevelInt < json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "csChargingProfiles"), "stackLevel")))
  12232. {
  12233. if(ChargingProfileAdded == FALSE)
  12234. {
  12235. fprintf(outfile,"%s\n",buf);
  12236. fprintf(outfile,"%s\n",payload);
  12237. ChargingProfileAdded = TRUE;
  12238. }
  12239. else
  12240. {
  12241. fprintf(outfile,"%s\n",buf);
  12242. }
  12243. }
  12244. else
  12245. {
  12246. if(ChargingProfileAdded == FALSE)
  12247. {
  12248. fprintf(outfile,"%s\n",buf);
  12249. fprintf(outfile,"%s\n",payload);
  12250. ChargingProfileAdded = TRUE;
  12251. }
  12252. else
  12253. {
  12254. fprintf(outfile,"%s\n",buf);
  12255. }
  12256. }
  12257. }
  12258. } // end of while loop
  12259. fclose(infile);
  12260. fclose(outfile);
  12261. sprintf(rmFileCmd,"rm -f %s",filename);
  12262. system(rmFileCmd);
  12263. rename((char*)tmpProfileName, (char*)filename);
  12264. }
  12265. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[(gun_index==0?gun_index:gun_index-1)].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted] );
  12266. random_uuid((char*)ShmOCPP20Data->RequestStartTransaction[(gun_index==0?gun_index:gun_index-1)].Response_transactionId);
  12267. result = PASS;
  12268. }
  12269. else
  12270. {
  12271. if(gun_index <= 0)
  12272. DEBUG_WARN("Connector id is wrong.\n");
  12273. if(isConnectorMismatch)
  12274. DEBUG_WARN("Connector id is mismatch.\n");
  12275. if(isPeriodOverMax)
  12276. DEBUG_WARN("Profile periods quantity is over spec.\n");
  12277. if(isProfileOverMax)
  12278. DEBUG_WARN("Profile quantity is over spec.\n");
  12279. if(!isTxProfile)
  12280. DEBUG_WARN("Profile purpose is not TxProfile.\n");
  12281. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[(gun_index==0?gun_index:gun_index-1)].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected] );
  12282. }
  12283. }
  12284. json_object_put(RemoteStartTransaction);
  12285. sendRemoteStartTransactionConfirmation(uuid, gun_index);
  12286. return result;
  12287. }
  12288. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  12289. {
  12290. mtrace();
  12291. int result = FAIL;
  12292. int match = FALSE;
  12293. int GunNO = 0;
  12294. int tempIndex = 0;
  12295. char transactionIdStr[37];
  12296. int transactionIdIsNULL= TRUE;
  12297. json_object *RemoteStopTransaction;
  12298. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  12299. if(server_pending == TRUE)
  12300. {
  12301. return 0;
  12302. }
  12303. RemoteStopTransaction = json_tokener_parse(payload);
  12304. if(!is_error(RemoteStopTransaction))
  12305. {
  12306. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  12307. {
  12308. sprintf(transactionIdStr, "%s", json_object_get_string(json_object_object_get(RemoteStopTransaction, "transactionId")));
  12309. transactionIdIsNULL = FALSE;
  12310. }
  12311. }
  12312. json_object_put(RemoteStopTransaction);
  12313. if(transactionIdIsNULL == FALSE)
  12314. {
  12315. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  12316. {
  12317. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, transactionIdStr) != NULL)
  12318. {
  12319. //check Transaction active
  12320. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  12321. {
  12322. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12323. {
  12324. tempIndex = ((gun_index==2) ? 1: 0);
  12325. }
  12326. else
  12327. {
  12328. tempIndex = gun_index;
  12329. }
  12330. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12331. {
  12332. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12333. {
  12334. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  12335. {
  12336. match = TRUE;
  12337. GunNO = gun_index;
  12338. }
  12339. }
  12340. }// END FOR CHAdeMO_QUANTITY
  12341. }
  12342. else if(gunType[gun_index] == GUN_TYPE_CCS)
  12343. {
  12344. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12345. {
  12346. tempIndex = ((gun_index==2) ? 1: 0);
  12347. }
  12348. else
  12349. {
  12350. tempIndex = gun_index;
  12351. }
  12352. for (int index = 0; index < CCS_QUANTITY; index++)
  12353. {
  12354. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12355. {
  12356. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  12357. {
  12358. match = TRUE;
  12359. GunNO = gun_index;
  12360. }
  12361. }
  12362. }// END FOR CCS_QUANTITY
  12363. }
  12364. else if(gunType[gun_index] == GUN_TYPE_GBT)
  12365. {
  12366. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12367. {
  12368. tempIndex = ((gun_index==2) ? 1: 0);
  12369. }
  12370. else
  12371. {
  12372. tempIndex = gun_index;
  12373. }
  12374. for (int index = 0; index < GB_QUANTITY; index++)
  12375. {
  12376. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12377. {
  12378. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  12379. {
  12380. match = TRUE;
  12381. GunNO = gun_index;
  12382. }
  12383. }
  12384. }// END FOR GB_QUANTITY
  12385. }
  12386. else if(gunType[gun_index] == GUN_TYPE_DO)
  12387. {
  12388. tempIndex = gun_index;
  12389. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12390. {
  12391. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12392. {
  12393. 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
  12394. {
  12395. match = TRUE;
  12396. GunNO = gun_index;
  12397. }
  12398. }
  12399. }// END FOR GB_QUANTITY
  12400. }
  12401. else
  12402. {
  12403. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12404. {
  12405. tempIndex = 2;
  12406. }
  12407. else
  12408. {
  12409. tempIndex = gun_index;
  12410. }
  12411. for (int index = 0; index < AC_QUANTITY; index++)
  12412. {
  12413. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12414. {
  12415. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  12416. {
  12417. match = TRUE;
  12418. GunNO = gun_index;
  12419. }
  12420. }
  12421. }// END FOR CHAdeMO_QUANTITY
  12422. } // END FOR AC ELSE
  12423. }// CHECK IF ResponseTransactionId == transactionIdInt
  12424. }//END FOR
  12425. if( match == TRUE)
  12426. {
  12427. ShmOCPP20Data->CsMsg.bits[GunNO].RequestStopTransactionReq = ON; // inform csu of StopTransaction
  12428. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  12429. }
  12430. else
  12431. {
  12432. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  12433. }
  12434. }
  12435. else
  12436. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  12437. sendRemoteStopTransactionConfirmation(uuid, GunNO);
  12438. return result;
  12439. }
  12440. int handleReserveNowRequest(char *uuid, char *payload)
  12441. {
  12442. mtrace();
  12443. int result = FAIL;
  12444. int connectorIdInt=0, reservationIdInt=0;
  12445. int tempIndex = 0;
  12446. json_object *ReserveNow;
  12447. DEBUG_INFO("handleReserveNowRequest ...\n");
  12448. ReserveNow = json_tokener_parse(payload);
  12449. if(!is_error(ReserveNow))
  12450. {
  12451. if(json_object_object_get(ReserveNow, "evseId") != NULL)
  12452. {
  12453. connectorIdInt = json_object_get_int(json_object_object_get(ReserveNow, "evseId"));
  12454. connectorIdInt = (connectorIdInt==0)?1:connectorIdInt;
  12455. memset(&ShmOCPP20Data->ReserveNow[connectorIdInt-1], 0x00, sizeof(struct ReserveNow_20));
  12456. ShmOCPP20Data->ReserveNow[connectorIdInt-1].evseId = json_object_get_int(json_object_object_get(ReserveNow, "evseId"));
  12457. }
  12458. // Required data
  12459. if(json_object_object_get(ReserveNow, "reservationId") != NULL)
  12460. ShmOCPP20Data->ReserveNow[connectorIdInt-1].id = json_object_get_int(json_object_object_get(ReserveNow, "reservationId"));
  12461. if(json_object_object_get(ReserveNow, "expiryDateTime") != NULL)
  12462. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].expiryDateTime, "%s", json_object_get_string(json_object_object_get(ReserveNow, "expiryDateTime")));
  12463. if(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "idToken") != NULL)
  12464. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "idToken")));
  12465. if(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "type") != NULL)
  12466. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "type")));
  12467. // Optional data
  12468. if(json_object_object_get(ReserveNow, "connectorType") != NULL)
  12469. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].connectorType, "%s", json_object_get_string(json_object_object_get(ReserveNow, "connectorType")));
  12470. if(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "idToken") != NULL)
  12471. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "idToken")));
  12472. if(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "type") != NULL)
  12473. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "type")));
  12474. result = PASS;
  12475. }
  12476. json_object_put(ReserveNow);
  12477. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  12478. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  12479. {
  12480. //check Transaction active
  12481. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  12482. {
  12483. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12484. {
  12485. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12486. }
  12487. else
  12488. {
  12489. tempIndex = connectorIdInt -1;
  12490. }
  12491. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12492. {
  12493. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12494. {
  12495. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12496. {
  12497. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12498. {
  12499. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12500. {
  12501. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  12502. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  12503. }
  12504. 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'))
  12505. {
  12506. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  12507. }
  12508. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12509. {
  12510. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  12511. }
  12512. else
  12513. {
  12514. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  12515. }
  12516. }
  12517. 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
  12518. {
  12519. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  12520. }
  12521. }
  12522. else
  12523. {
  12524. //replace reservation
  12525. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  12526. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  12527. }
  12528. }
  12529. } // END FOR CHAdeMO_QUANTITY
  12530. }
  12531. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  12532. {
  12533. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12534. {
  12535. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12536. }
  12537. else
  12538. {
  12539. tempIndex = connectorIdInt -1;
  12540. }
  12541. for (int index = 0; index < CCS_QUANTITY; index++)
  12542. {
  12543. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12544. {
  12545. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12546. {
  12547. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12548. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12549. {
  12550. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12551. {
  12552. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  12553. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  12554. }
  12555. 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'))
  12556. {
  12557. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  12558. }
  12559. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  12560. {
  12561. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  12562. }
  12563. else
  12564. {
  12565. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  12566. }
  12567. }
  12568. 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
  12569. {
  12570. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  12571. }
  12572. }
  12573. else
  12574. {
  12575. //replace reservation
  12576. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  12577. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  12578. }
  12579. }
  12580. } // END FOR CCS_QUANTITY
  12581. }
  12582. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  12583. {
  12584. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12585. {
  12586. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12587. }
  12588. else
  12589. {
  12590. tempIndex = connectorIdInt -1;
  12591. }
  12592. for (int index = 0; index < GB_QUANTITY; index++)
  12593. {
  12594. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12595. {
  12596. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12597. {
  12598. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12599. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12600. {
  12601. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12602. {
  12603. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  12604. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  12605. }
  12606. 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'))
  12607. {
  12608. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  12609. }
  12610. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12611. {
  12612. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  12613. }
  12614. else
  12615. {
  12616. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  12617. }
  12618. }
  12619. 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
  12620. {
  12621. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  12622. }
  12623. }
  12624. else
  12625. {
  12626. //replace reservation
  12627. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  12628. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  12629. }
  12630. }
  12631. }// END FOR GB_QUANTITY
  12632. }
  12633. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  12634. {
  12635. tempIndex = connectorIdInt -1;
  12636. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12637. {
  12638. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12639. {
  12640. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  12641. {
  12642. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12643. 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
  12644. {
  12645. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12646. {
  12647. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  12648. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  12649. }
  12650. 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'))
  12651. {
  12652. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  12653. }
  12654. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12655. {
  12656. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  12657. }
  12658. else
  12659. {
  12660. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  12661. }
  12662. }
  12663. 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
  12664. {
  12665. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  12666. }
  12667. }
  12668. else
  12669. {
  12670. //replace reservation
  12671. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  12672. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  12673. }
  12674. }
  12675. }// END FOR DO_QUANTITY
  12676. }
  12677. else
  12678. {
  12679. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12680. {
  12681. tempIndex = 2;
  12682. }
  12683. else
  12684. {
  12685. tempIndex = (connectorIdInt -1);
  12686. }
  12687. for (int index = 0; index < AC_QUANTITY; index++)
  12688. {
  12689. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12690. {
  12691. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12692. {
  12693. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12694. {
  12695. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12696. {
  12697. 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))
  12698. {
  12699. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  12700. }
  12701. else
  12702. {
  12703. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  12704. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  12705. }
  12706. }
  12707. 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'))
  12708. {
  12709. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  12710. }
  12711. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12712. {
  12713. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  12714. }
  12715. else
  12716. {
  12717. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  12718. }
  12719. }
  12720. 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
  12721. {
  12722. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  12723. }
  12724. }
  12725. else
  12726. {
  12727. //replace reservation
  12728. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  12729. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  12730. }
  12731. }
  12732. } // END FOR AC_QUANTITY
  12733. }
  12734. }
  12735. else if(connectorIdInt == 0)
  12736. {
  12737. //check Transaction active
  12738. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12739. {
  12740. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12741. {
  12742. 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'))
  12743. {
  12744. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  12745. goto end;
  12746. }
  12747. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12748. {
  12749. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  12750. goto end;
  12751. }
  12752. 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
  12753. {
  12754. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  12755. goto end;
  12756. }
  12757. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12758. {
  12759. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  12760. goto end;
  12761. }
  12762. }
  12763. }// END FOR CHAdeMO_QUANTITY
  12764. for (int index = 0; index < CCS_QUANTITY; index++)
  12765. {
  12766. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12767. {
  12768. 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'))
  12769. {
  12770. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  12771. goto end;
  12772. }
  12773. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  12774. {
  12775. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  12776. goto end;
  12777. }
  12778. 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
  12779. {
  12780. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  12781. goto end;
  12782. }
  12783. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12784. {
  12785. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  12786. goto end;
  12787. }
  12788. }
  12789. } // END FOR CCS_QUANTITY
  12790. for (int index = 0; index < GB_QUANTITY; index++)
  12791. {
  12792. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12793. {
  12794. 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'))
  12795. {
  12796. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  12797. goto end;
  12798. }
  12799. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12800. {
  12801. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  12802. goto end;
  12803. }
  12804. 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
  12805. {
  12806. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  12807. goto end;
  12808. }
  12809. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12810. {
  12811. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  12812. goto end;
  12813. }
  12814. }
  12815. } // END FOR GB_QUANTITY
  12816. for (int index = 0; index < AC_QUANTITY; index++)
  12817. {
  12818. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12819. {
  12820. 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'))
  12821. {
  12822. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  12823. goto end;
  12824. }
  12825. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12826. {
  12827. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  12828. goto end;
  12829. }
  12830. 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
  12831. {
  12832. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  12833. goto end;
  12834. }
  12835. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12836. {
  12837. 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))
  12838. {
  12839. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  12840. goto end;
  12841. }
  12842. }
  12843. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12844. {
  12845. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  12846. goto end;
  12847. }
  12848. }
  12849. }// END FOR AC_QUANTITY
  12850. //The connectorId is 0
  12851. ShmOCPP20Data->CsMsg.bits[0].ReserveNowReq = ON;
  12852. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  12853. strcpy((char *)ShmOCPP20Data->ReserveNow[0].guid, uuid);
  12854. result = TRUE;
  12855. return result;
  12856. }
  12857. else
  12858. {
  12859. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  12860. }
  12861. if(strcmp((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status,ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]) == 0)
  12862. {
  12863. strcpy((char *)ShmOCPP20Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12864. result = TRUE;
  12865. return result;
  12866. }
  12867. end:
  12868. sendReserveNowConfirmation(uuid, (connectorIdInt==0?connectorIdInt:connectorIdInt-1));
  12869. return result;
  12870. }
  12871. int handleResetRequest(char *uuid, char *payload)
  12872. {
  12873. mtrace();
  12874. int result = FAIL;
  12875. json_object *Reset = json_object_new_object();
  12876. DEBUG_INFO("handleResetRequest...\n");
  12877. Reset = json_tokener_parse(payload);
  12878. if(!is_error(Reset))
  12879. {
  12880. // Required data
  12881. if(json_object_object_get(Reset, "type") != NULL)
  12882. {
  12883. sprintf((char*)ShmOCPP20Data->Reset.type, "%s", json_object_get_string(json_object_object_get(Reset, "type")));
  12884. }
  12885. if(json_object_object_get(Reset, "evseId") != NULL)
  12886. {
  12887. ShmOCPP20Data->Reset.evseId = json_object_get_int(json_object_object_get(Reset, "evseId"));
  12888. }
  12889. }
  12890. json_object_put(Reset);
  12891. if((strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_Immediate])==0) || (strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_OnIdle])==0))
  12892. {
  12893. strcpy((char *)ShmOCPP20Data->Reset.guid, uuid);
  12894. strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]);
  12895. ShmOCPP20Data->MsMsg.bits.ResetReq = ON;
  12896. result = PASS;
  12897. }
  12898. else
  12899. {
  12900. strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Rejected]);
  12901. }
  12902. if(strlen((char*)ShmOCPP20Data->Reset.Response_status) > 0)
  12903. sendResetConfirmation(uuid);
  12904. return result;
  12905. }
  12906. int handleSendLocalListRequest(char *uuid, char *payload)
  12907. {
  12908. mtrace();
  12909. int result = FAIL;
  12910. char updateTypestr[15]={0};
  12911. int checkState_Faulted = FALSE;
  12912. json_object *SendLocalList;
  12913. DEBUG_INFO("handleSendLocalListRequest...\n");
  12914. if(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "FALSE") == 0)
  12915. {
  12916. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  12917. goto end;
  12918. }
  12919. SendLocalList = json_tokener_parse(payload);
  12920. if(!is_error(SendLocalList))
  12921. {
  12922. memset(&ShmOCPP20Data->SendLocalList, 0x00, sizeof(struct SendLocalList_20));
  12923. // Required data
  12924. if(json_object_object_get(SendLocalList, "versionNumber") != NULL)
  12925. {
  12926. ShmOCPP20Data->SendLocalList.versionNumber = json_object_get_int(json_object_object_get(SendLocalList, "versionNumber"));
  12927. }
  12928. if(json_object_object_get(SendLocalList, "updateType") != NULL)
  12929. sprintf((char*)ShmOCPP20Data->SendLocalList.updateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12930. // Optional data
  12931. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12932. {
  12933. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12934. {
  12935. // Required data
  12936. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idToken") != NULL)
  12937. {
  12938. 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")));
  12939. 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")));
  12940. }
  12941. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12942. {
  12943. 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")));
  12944. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "cacheExpiryDateTime") != NULL)
  12945. 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")));
  12946. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "chargingPriority") != NULL)
  12947. 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"));
  12948. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "groupIdToken") != NULL)
  12949. {
  12950. 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")));
  12951. 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")));
  12952. }
  12953. }
  12954. }
  12955. }
  12956. }
  12957. json_object_put(SendLocalList);
  12958. //check Charge Point state
  12959. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12960. {
  12961. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12962. {
  12963. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12964. }
  12965. }
  12966. for (int index = 0; index < CCS_QUANTITY; index++)
  12967. {
  12968. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12969. {
  12970. checkState_Faulted = TRUE; //OCPP Status
  12971. }
  12972. }
  12973. for (int index = 0; index < GB_QUANTITY; index++)
  12974. {
  12975. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12976. {
  12977. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12978. }
  12979. }
  12980. for (int index = 0; index < AC_QUANTITY; index++)
  12981. {
  12982. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12983. {
  12984. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12985. }
  12986. }
  12987. if(checkState_Faulted == TRUE)
  12988. {
  12989. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  12990. goto end;
  12991. }
  12992. // Check update type
  12993. if(strcmp(updateTypestr, UpdateEnumTypeStr[UpdateEnumType_Full]) == 0)
  12994. {
  12995. //Local list full update
  12996. DEBUG_INFO("Local list full update.\n");
  12997. DB_getListVerion();
  12998. if(ShmOCPP20Data->SendLocalList.versionNumber < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  12999. {
  13000. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  13001. goto end;
  13002. }
  13003. DB_cleanLocalList();
  13004. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->SendLocalList.localAuthorizationList);idx++)
  13005. DB_addLocalList(ShmOCPP20Data->SendLocalList.versionNumber, &ShmOCPP20Data->SendLocalList.localAuthorizationList[idx]);
  13006. }
  13007. else if(strcmp(updateTypestr, UpdateEnumTypeStr[UpdateEnumType_Differential]) == 0)
  13008. {
  13009. //Local list different update
  13010. DEBUG_INFO("Local list different update.\n");
  13011. DB_getListVerion();
  13012. if(ShmOCPP20Data->SendLocalList.versionNumber < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  13013. {
  13014. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_VersionMismatch]);
  13015. goto end;
  13016. }
  13017. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->SendLocalList.localAuthorizationList);idx++)
  13018. DB_addLocalList(ShmOCPP20Data->SendLocalList.versionNumber, &ShmOCPP20Data->SendLocalList.localAuthorizationList[idx]);
  13019. }
  13020. else
  13021. {
  13022. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  13023. goto end;
  13024. }
  13025. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Accepted]);
  13026. end:
  13027. sendSendLocalListConfirmation(uuid);
  13028. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13029. return result;
  13030. }
  13031. int handleSetChargingProfileRequest(char *uuid, char *payload)
  13032. {
  13033. mtrace();
  13034. int result = FAIL;
  13035. int8_t gun_index = -1;
  13036. uint8_t isPeriodOverMax = FALSE;
  13037. uint8_t isProfileOverMax = FALSE;
  13038. uint8_t isConnectorMismatch = FALSE;
  13039. uint8_t existProfileQuantity = 0;
  13040. uint8_t filename[128]={0};
  13041. uint8_t word[2048]={0};
  13042. FILE *filePtr;
  13043. json_object *SetChargingProfile;
  13044. DEBUG_INFO("handleSetChargingProfileRequest...\n");
  13045. SetChargingProfile = json_tokener_parse(payload);
  13046. if(!is_error(SetChargingProfile))
  13047. {
  13048. // Required data
  13049. if(json_object_object_get(SetChargingProfile, "evseId") != NULL)
  13050. {
  13051. gun_index = json_object_get_int(json_object_object_get(SetChargingProfile, "evseId"));
  13052. }
  13053. if(json_object_object_get(SetChargingProfile, "chargingProfile") != NULL)
  13054. {
  13055. // Check periods is over max configuration
  13056. if(json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod")) > 10)
  13057. {
  13058. isPeriodOverMax = TRUE;
  13059. }
  13060. // Check periods is over max configuration
  13061. if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL)
  13062. {
  13063. if(gun_index == 0)
  13064. {
  13065. sprintf((char*)filename, ChargePointMaxProfile_JSON);
  13066. filePtr = fopen((char*)filename, "r");
  13067. if (!filePtr)
  13068. {
  13069. DEBUG_INFO("%s not exist, create it.\n", ChargePointMaxProfile_JSON);
  13070. filePtr = fopen((char*)filename, "w+");
  13071. }
  13072. else
  13073. {
  13074. //Check Charging Profile Count
  13075. while(fscanf(filePtr, "%s", word) != EOF)
  13076. {
  13077. //DEBUG_INFO("word=%s\n",word);
  13078. if(strstr((char*)word, "chargingProfileId")!= NULL)
  13079. {
  13080. existProfileQuantity += 1;
  13081. }
  13082. }
  13083. }
  13084. fclose(filePtr);
  13085. }
  13086. else
  13087. isConnectorMismatch = TRUE;
  13088. }
  13089. else if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) != NULL)
  13090. {
  13091. if(gun_index < 5)
  13092. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", gun_index);
  13093. else
  13094. isConnectorMismatch = TRUE;
  13095. if(!isConnectorMismatch)
  13096. {
  13097. filePtr = fopen((char*)filename, "r");
  13098. if (!filePtr)
  13099. {
  13100. DEBUG_INFO("%s not exist, create it.\n", filename);
  13101. filePtr = fopen((char*)filename, "w+");
  13102. }
  13103. else
  13104. {
  13105. //Check Charging Profile Count
  13106. while(fscanf(filePtr, "%s", word) != EOF)
  13107. {
  13108. //DEBUG_INFO("word=%s\n",word);
  13109. if(strstr((char*)word, "chargingProfileId")!= NULL)
  13110. {
  13111. existProfileQuantity += 1;
  13112. }
  13113. }
  13114. }
  13115. fclose(filePtr);
  13116. }
  13117. }
  13118. else if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  13119. {
  13120. if(gun_index>0)
  13121. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", gun_index);
  13122. else
  13123. isConnectorMismatch = TRUE;
  13124. if(!isConnectorMismatch)
  13125. {
  13126. filePtr = fopen((char*)filename, "r");
  13127. if (!filePtr)
  13128. {
  13129. DEBUG_INFO("%s not exist, create it.\n", filename);
  13130. filePtr = fopen((char*)filename, "w+");
  13131. }
  13132. else
  13133. {
  13134. //Check Charging Profile Count
  13135. while(fscanf(filePtr, "%s", word) != EOF)
  13136. {
  13137. //DEBUG_INFO("word=%s\n",word);
  13138. if(strstr((char*)word, "chargingProfileId")!= NULL)
  13139. {
  13140. existProfileQuantity += 1;
  13141. }
  13142. }
  13143. }
  13144. fclose(filePtr);
  13145. }
  13146. }
  13147. else if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationExternalConstraints]) != NULL)
  13148. {
  13149. }
  13150. else
  13151. {
  13152. }
  13153. if(existProfileQuantity > 3)
  13154. isProfileOverMax = TRUE;
  13155. }
  13156. // Profile replace or add info
  13157. if((gun_index > -1) && !isPeriodOverMax && !isProfileOverMax && !isConnectorMismatch)
  13158. {
  13159. FILE *infile;
  13160. FILE *outfile;
  13161. char tmpProfileName[32];
  13162. char rmFileCmd[128];
  13163. char tempchargingProfilePurposeStr[30]={0};
  13164. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  13165. sprintf((char*)tmpProfileName, "/Storage/OCPP/tmpProfile");
  13166. infile = fopen ((char*)filename, "r");
  13167. outfile = fopen ((char*)tmpProfileName, "w");
  13168. int d = fgetc(infile);
  13169. rewind(infile);
  13170. if(d == EOF)
  13171. {
  13172. // Profile is empty
  13173. fprintf(outfile,"%s\n", payload);
  13174. fclose(infile);
  13175. fclose(outfile);
  13176. sprintf(rmFileCmd,"rm -f %s",filename);
  13177. system(rmFileCmd);
  13178. rename((char*)tmpProfileName, (char*)filename);
  13179. }
  13180. else
  13181. {
  13182. // Profile is not empty
  13183. char buf[2048]={0};
  13184. int ChargingProfileAdded = FALSE;
  13185. while (fgets(buf, sizeof(buf), infile) != NULL)
  13186. {
  13187. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  13188. json_object *tmpChargingProfile;
  13189. tmpChargingProfile = json_tokener_parse(buf);
  13190. if(!is_error(tmpChargingProfile))
  13191. {
  13192. if(json_object_object_get(tmpChargingProfile, "evseId") != NULL)
  13193. {
  13194. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "evseId") );
  13195. }
  13196. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  13197. {
  13198. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  13199. {
  13200. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  13201. }
  13202. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  13203. {
  13204. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  13205. }
  13206. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  13207. {
  13208. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  13209. }
  13210. }
  13211. }
  13212. json_object_put(tmpChargingProfile);
  13213. if((tempconnectorIdInt == gun_index) &&
  13214. (tempchargingProfileIdInt == json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"))))
  13215. {
  13216. if((tempstackLevelInt == json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"))) &&
  13217. (strcmp(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose"))) == 0))
  13218. {
  13219. //DEBUG_INFO("update set chargingProfile to file -0\n");
  13220. if(ChargingProfileAdded == FALSE)
  13221. {
  13222. fprintf(outfile,"%s\n",payload);
  13223. ChargingProfileAdded = TRUE;
  13224. }
  13225. }
  13226. else
  13227. {
  13228. if(tempstackLevelInt < json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel")))
  13229. {
  13230. if(ChargingProfileAdded == FALSE)
  13231. {
  13232. fprintf(outfile,"%s\n",buf);
  13233. fprintf(outfile,"%s\n",payload);
  13234. ChargingProfileAdded = TRUE;
  13235. }
  13236. else
  13237. {
  13238. fprintf(outfile,"%s\n",buf);
  13239. }
  13240. }
  13241. else
  13242. {
  13243. if(ChargingProfileAdded == FALSE)
  13244. {
  13245. fprintf(outfile,"%s\n",buf);
  13246. fprintf(outfile,"%s\n",payload);
  13247. ChargingProfileAdded = TRUE;
  13248. }
  13249. else
  13250. {
  13251. fprintf(outfile,"%s\n",buf);
  13252. }
  13253. }
  13254. }
  13255. }
  13256. else
  13257. {
  13258. if(tempchargingProfileIdInt < json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId")))
  13259. {
  13260. if(ChargingProfileAdded == FALSE)
  13261. {
  13262. fprintf(outfile,"%s\n",buf);
  13263. fprintf(outfile,"%s\n",payload);
  13264. ChargingProfileAdded = TRUE;
  13265. }
  13266. else
  13267. {
  13268. fprintf(outfile,"%s\n",buf);
  13269. }
  13270. }
  13271. else if(tempstackLevelInt < json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel")))
  13272. {
  13273. if(ChargingProfileAdded == FALSE)
  13274. {
  13275. fprintf(outfile,"%s\n",buf);
  13276. fprintf(outfile,"%s\n",payload);
  13277. ChargingProfileAdded = TRUE;
  13278. }
  13279. else
  13280. {
  13281. fprintf(outfile,"%s\n",buf);
  13282. }
  13283. }
  13284. else
  13285. {
  13286. if(ChargingProfileAdded == FALSE)
  13287. {
  13288. fprintf(outfile,"%s\n",buf);
  13289. fprintf(outfile,"%s\n",payload);
  13290. ChargingProfileAdded = TRUE;
  13291. }
  13292. else
  13293. {
  13294. fprintf(outfile,"%s\n",buf);
  13295. }
  13296. }
  13297. }
  13298. } // end of while loop
  13299. fclose(infile);
  13300. fclose(outfile);
  13301. sprintf(rmFileCmd,"rm -f %s",filename);
  13302. system(rmFileCmd);
  13303. rename((char*)tmpProfileName, (char*)filename);
  13304. }
  13305. sprintf((char*)ShmOCPP20Data->SetChargingProfile[(gun_index==0?gun_index:gun_index-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted] );
  13306. result = PASS;
  13307. }
  13308. else
  13309. {
  13310. if(gun_index == -1)
  13311. DEBUG_WARN("Connector id is wrong.\n");
  13312. if(isConnectorMismatch)
  13313. DEBUG_WARN("Connector id is mismatch.\n");
  13314. if(isPeriodOverMax)
  13315. DEBUG_WARN("Profile periods quantity is over spec.\n");
  13316. if(isProfileOverMax)
  13317. DEBUG_WARN("Profile quantity is over spec.\n");
  13318. sprintf((char*)ShmOCPP20Data->SetChargingProfile[(gun_index==0?gun_index:gun_index-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Rejected] );
  13319. }
  13320. }
  13321. json_object_put(SetChargingProfile);
  13322. if(strcmp((char*)ShmOCPP20Data->SetChargingProfile[(gun_index==0?gun_index:gun_index-1)].Response_status, ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted]) == 0)
  13323. {
  13324. if(gun_index == 0)
  13325. {
  13326. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  13327. {
  13328. checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx], 0, TRUE);
  13329. }
  13330. }
  13331. else
  13332. checkCompositeSchedule(gun_index, 86400, &ShmOCPP20Data->SmartChargingProfile[gun_index-1], 0, TRUE);
  13333. }
  13334. sendSetChargingProfileConfirmation(uuid, (gun_index==0?gun_index:gun_index-1));
  13335. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  13336. return result;
  13337. }
  13338. int handleSetDisplayMessagesRequest(char *uuid, char *payload)
  13339. {
  13340. mtrace();
  13341. int result = FAIL;
  13342. json_object *SetDisplayMessage;
  13343. DEBUG_INFO("handleSetDisplayMessageRequest...\n");
  13344. SetDisplayMessage = json_tokener_parse(payload);
  13345. if(!is_error(SetDisplayMessage))
  13346. {
  13347. memset(&ShmOCPP20Data->SetDisplayMessage, 0, sizeof(struct SetDisplayMessage_20));
  13348. memcpy(&ShmOCPP20Data->SetDisplayMessage.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetDisplayMessage.guid));
  13349. // Required data
  13350. if(json_object_object_get(SetDisplayMessage, "message") != NULL)
  13351. {
  13352. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "id") != NULL)
  13353. ShmOCPP20Data->SetDisplayMessage.message.id = json_object_get_int(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "id"));
  13354. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "priority") != NULL)
  13355. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.priority, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "priority")));
  13356. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "state") != NULL)
  13357. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.state, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "state")));
  13358. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "startDateTime") != NULL)
  13359. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.startDateTime, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "startDateTime")));
  13360. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "endDateTime") != NULL)
  13361. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.endDateTime, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "endDateTime")));
  13362. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "transactionId") != NULL)
  13363. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.transactionId, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "transactionId")));
  13364. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message") != NULL)
  13365. {
  13366. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "format") != NULL)
  13367. 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"), "transactionId"), "format")));
  13368. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "language") != NULL)
  13369. 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"), "transactionId"), "language")));
  13370. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "content") != NULL)
  13371. 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"), "transactionId"), "content")));
  13372. }
  13373. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display") != NULL)
  13374. {
  13375. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "name") != NULL)
  13376. 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")));
  13377. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "instance") != NULL)
  13378. 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")));
  13379. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse") != NULL)
  13380. {
  13381. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "id") != NULL)
  13382. 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"));
  13383. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "connectorId") != NULL)
  13384. 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"));
  13385. }
  13386. }
  13387. }
  13388. }
  13389. json_object_put(SetDisplayMessage);
  13390. strcpy((char*)ShmOCPP20Data->SetDisplayMessage.Response_status, DisplayMessageStatusEnumTypeStr[DisplayMessageStatusEnumType_Accepted]);
  13391. sendSetDisplayMessagesConfirmation(uuid);
  13392. // Announce CSU there is display request come from server
  13393. ShmOCPP20Data->MsMsg.bits.SetDisplayMessageReq = ON;
  13394. return result;
  13395. }
  13396. int handleSetMonitoringBaseRequest(char *uuid, char *payload)
  13397. {
  13398. mtrace();
  13399. int result = FAIL;
  13400. json_object *SetMonitoringBase;
  13401. DEBUG_INFO("handleSetMonitoringBaseRequest...\n");
  13402. SetMonitoringBase = json_tokener_parse(payload);
  13403. if(!is_error(SetMonitoringBase))
  13404. {
  13405. memset(&ShmOCPP20Data->SetMonitoringBase, 0, sizeof(struct SetMonitoringBase_20));
  13406. memcpy(&ShmOCPP20Data->SetMonitoringBase.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetMonitoringBase.guid));
  13407. // Required data
  13408. if(json_object_object_get(SetMonitoringBase, "monitoringBase") != NULL)
  13409. sprintf((char*)ShmOCPP20Data->SetMonitoringBase.monitoringBase, "%s",json_object_get_string(json_object_object_get(SetMonitoringBase, "monitoringBase")));
  13410. }
  13411. json_object_put(SetMonitoringBase);
  13412. /*
  13413. * TODO:
  13414. * 1. Configure monitor base and response
  13415. */
  13416. strcpy((char*)ShmOCPP20Data->SetMonitoringBase.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  13417. sendSetMonitoringBaseConfirmation(uuid);
  13418. return result;
  13419. }
  13420. int handleSetMonitoringLevelRequest(char *uuid, char *payload)
  13421. {
  13422. mtrace();
  13423. int result = FAIL;
  13424. json_object *SetMonitoringLevel;
  13425. DEBUG_INFO("handleSetMonitoringLevelRequest...\n");
  13426. SetMonitoringLevel = json_tokener_parse(payload);
  13427. if(!is_error(SetMonitoringLevel))
  13428. {
  13429. memset(&ShmOCPP20Data->SetMonitoringLevel, 0, sizeof(struct SetMonitoringLevel_20));
  13430. memcpy(&ShmOCPP20Data->SetMonitoringLevel.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetMonitoringLevel.guid));
  13431. // Required data
  13432. if(json_object_object_get(SetMonitoringLevel, "severity") != NULL)
  13433. ShmOCPP20Data->SetMonitoringLevel.severity = json_object_get_int(json_object_object_get(SetMonitoringLevel, "severity"));
  13434. }
  13435. json_object_put(SetMonitoringLevel);
  13436. /*
  13437. * TODO:
  13438. * Configure monitor status and response
  13439. */
  13440. strcpy((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  13441. sendSetMonitoringLevelConfirmation(uuid);
  13442. return result;
  13443. }
  13444. int handleSetNetworkProfileRequest(char *uuid, char *payload)
  13445. {
  13446. mtrace();
  13447. int result = FAIL;
  13448. json_object *SetNetworkProfile;
  13449. DEBUG_INFO("handleSetNetworkProfileRequest...\n");
  13450. SetNetworkProfile = json_tokener_parse(payload);
  13451. if(!is_error(SetNetworkProfile))
  13452. {
  13453. memset(&ShmOCPP20Data->SetNetworkProfile, 0, sizeof(struct SetNetworkProfile_20));
  13454. memcpy(&ShmOCPP20Data->SetNetworkProfile.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.guid));
  13455. // Required data
  13456. if(json_object_object_get(SetNetworkProfile, "configurationSlot") != NULL)
  13457. ShmOCPP20Data->SetNetworkProfile.configurationSlot = json_object_get_int(json_object_object_get(SetNetworkProfile, "configurationSlot"));
  13458. if(json_object_object_get(SetNetworkProfile, "connectionData") != NULL)
  13459. {
  13460. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppVersion") != NULL)
  13461. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppVersion")));
  13462. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport") != NULL)
  13463. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport")));
  13464. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl") != NULL)
  13465. {
  13466. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl")));
  13467. memcpy((char*)ShmOCPP20Data->OcppServerURL, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl));
  13468. }
  13469. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout") != NULL)
  13470. ShmOCPP20Data->SetNetworkProfile.connectionData.messageTimeout = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout"));
  13471. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppInterface") != NULL)
  13472. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppInterface, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppInterface")));
  13473. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn") != NULL)
  13474. {
  13475. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "server") != NULL)
  13476. 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")));
  13477. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "user") != NULL)
  13478. 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")));
  13479. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "group") != NULL)
  13480. 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")));
  13481. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "password") != NULL)
  13482. 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")));
  13483. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "key") != NULL)
  13484. 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")));
  13485. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "type") != NULL)
  13486. 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")));
  13487. }
  13488. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn") != NULL)
  13489. {
  13490. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apn") != NULL)
  13491. {
  13492. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn));
  13493. 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")));
  13494. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn);
  13495. }
  13496. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnUserName") != NULL)
  13497. {
  13498. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName));
  13499. 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")));
  13500. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName);
  13501. }
  13502. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnPassword") != NULL)
  13503. {
  13504. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword));
  13505. 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")));
  13506. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword);
  13507. }
  13508. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "simPin") != NULL)
  13509. 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"));
  13510. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "preferredNetwork") != NULL)
  13511. 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")));
  13512. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "useOnlyPreferredNetwork") != NULL)
  13513. 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"));
  13514. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnAuthentication") != NULL)
  13515. 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")));
  13516. }
  13517. DB_addNetworkProfile(ShmOCPP20Data->SetNetworkProfile.configurationSlot, (char*)json_object_get_string(json_object_object_get(SetNetworkProfile, "connectionData")));
  13518. }
  13519. }
  13520. json_object_put(SetNetworkProfile);
  13521. /*
  13522. * TODO:
  13523. * 1. Process network configuration and response
  13524. */
  13525. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP12]) == 0)
  13526. {
  13527. }
  13528. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP15]) == 0)
  13529. {
  13530. }
  13531. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP16]) == 0)
  13532. {
  13533. }
  13534. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP20]) == 0)
  13535. {
  13536. }
  13537. else
  13538. {
  13539. }
  13540. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, OCPPTransportEnumTypeStr[OCPPTransportEnumType_JSON]) == 0)
  13541. {
  13542. }
  13543. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, OCPPTransportEnumTypeStr[OCPPTransportEnumType_SOAP]) == 0)
  13544. {
  13545. }
  13546. else
  13547. {
  13548. }
  13549. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired0]) == 0)
  13550. {
  13551. }
  13552. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired1]) == 0)
  13553. {
  13554. }
  13555. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired2]) == 0)
  13556. {
  13557. }
  13558. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired3]) == 0)
  13559. {
  13560. }
  13561. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless0]) == 0)
  13562. {
  13563. }
  13564. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless1]) == 0)
  13565. {
  13566. }
  13567. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless2]) == 0)
  13568. {
  13569. }
  13570. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless3]) == 0)
  13571. {
  13572. }
  13573. else
  13574. {
  13575. }
  13576. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_IKEv2]) == 0)
  13577. {
  13578. }
  13579. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_IPSec]) == 0)
  13580. {
  13581. }
  13582. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_L2TP]) == 0)
  13583. {
  13584. }
  13585. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_PPTP]) == 0)
  13586. {
  13587. }
  13588. else
  13589. {
  13590. }
  13591. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_CHAP]) == 0)
  13592. {
  13593. }
  13594. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_NONE]) == 0)
  13595. {
  13596. }
  13597. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_PAP]) == 0)
  13598. {
  13599. }
  13600. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_AUTO]) == 0)
  13601. {
  13602. }
  13603. else
  13604. {
  13605. }
  13606. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Accepted]);
  13607. sendSetNetworkProfileConfirmation(uuid);
  13608. return result;
  13609. }
  13610. int handleSetVariableMonitoringRequest(char *uuid, char *payload)
  13611. {
  13612. mtrace();
  13613. int result = FAIL;
  13614. json_object *SetVariableMonitoring;
  13615. uint8_t variableQuantity = 0;
  13616. DEBUG_INFO("handleSetVariableMonitoringRequest...\n");
  13617. SetVariableMonitoring = json_tokener_parse(payload);
  13618. if(!is_error(SetVariableMonitoring))
  13619. {
  13620. memset(&ShmOCPP20Data->SetVariableMonitoring, 0, sizeof(struct SetVariableMonitoring_20));
  13621. memcpy(&ShmOCPP20Data->SetVariableMonitoring.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetVariableMonitoring.guid));
  13622. // Required data
  13623. for(int idx=0;idx<json_object_array_length(json_object_object_get(SetVariableMonitoring, "setMonitoringData"));idx++)
  13624. {
  13625. variableQuantity++;
  13626. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "id") != NULL)
  13627. {
  13628. 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"));
  13629. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].id = ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].id;
  13630. }
  13631. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "value") != NULL)
  13632. {
  13633. 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"));
  13634. }
  13635. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "type") != NULL)
  13636. {
  13637. 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")));
  13638. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type, (char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type);
  13639. }
  13640. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "severity") != NULL)
  13641. {
  13642. 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"));
  13643. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].severity = ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].severity;
  13644. }
  13645. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "transaction") != NULL)
  13646. {
  13647. 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"));
  13648. }
  13649. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "component") != NULL)
  13650. {
  13651. 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)
  13652. {
  13653. 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")));
  13654. }
  13655. 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)
  13656. {
  13657. 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")));
  13658. }
  13659. 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)
  13660. {
  13661. 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)
  13662. {
  13663. 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"));
  13664. }
  13665. 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)
  13666. {
  13667. 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"));
  13668. }
  13669. }
  13670. memcpy(&ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component, &ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].component, sizeof(struct ComponentType));
  13671. }
  13672. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "variable") != NULL)
  13673. {
  13674. 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)
  13675. {
  13676. 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")));
  13677. }
  13678. 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)
  13679. {
  13680. 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")));
  13681. }
  13682. memcpy(&ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable , &ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].variable, sizeof(struct VariableType));
  13683. }
  13684. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status, SetMonitoringStatusEnumTypeStr[SetMonitoringStatusEnumType_Accepted]);
  13685. }
  13686. }
  13687. json_object_put(SetVariableMonitoring);
  13688. sendSetVariableMonitoringConfirmation(uuid, variableQuantity);
  13689. return result;
  13690. }
  13691. int handleSetVariablesRequest(char *uuid, char *payload)
  13692. {
  13693. mtrace();
  13694. int result = FAIL;
  13695. json_object *SetVariables;
  13696. DEBUG_INFO("handleSetVariablesRequest...\n");
  13697. SetVariables = json_tokener_parse(payload);
  13698. if(!is_error(SetVariables))
  13699. {
  13700. memset(&ShmOCPP20Data->SetVariables, 0, sizeof(struct SetVariables_20));
  13701. memcpy(&ShmOCPP20Data->SetVariables.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetVariables.guid));
  13702. // Required data
  13703. for(int idx=0;idx<json_object_array_length(json_object_object_get(SetVariables, "setVariableData"));idx++)
  13704. {
  13705. if(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx) != NULL)
  13706. {
  13707. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component") != NULL)
  13708. {
  13709. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "name") != NULL)
  13710. {
  13711. 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")));
  13712. }
  13713. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "instance") != NULL)
  13714. {
  13715. 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")));
  13716. }
  13717. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "evse") != NULL)
  13718. {
  13719. 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)
  13720. {
  13721. ShmOCPP20Data->SetVariables.setVariableData[idx].component.evse.id = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "instance"), "id"));
  13722. }
  13723. 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)
  13724. {
  13725. ShmOCPP20Data->SetVariables.setVariableData[idx].component.evse.connectorId = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "instance"), "connectorId"));
  13726. }
  13727. }
  13728. memcpy(&ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component, &ShmOCPP20Data->SetVariables.setVariableData[idx].component, sizeof(struct ComponentType));
  13729. }
  13730. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable") != NULL)
  13731. {
  13732. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "name") != NULL)
  13733. {
  13734. 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")));
  13735. }
  13736. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "instance") != NULL)
  13737. {
  13738. 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")));
  13739. }
  13740. memcpy(&ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable , &ShmOCPP20Data->SetVariables.setVariableData[idx].variable, sizeof(struct VariableType));
  13741. }
  13742. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeType") != NULL)
  13743. {
  13744. 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")));
  13745. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeType);
  13746. }
  13747. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeValue") != NULL)
  13748. {
  13749. 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")));
  13750. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownComponent]);
  13751. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  13752. {
  13753. if((strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name) != NULL) &&
  13754. (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) &&
  13755. (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name) != NULL) &&
  13756. (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))
  13757. {
  13758. strcpy((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  13759. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[idx_var]);
  13760. if(((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL)) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "NetworkConfigurationPriority") != NULL))
  13761. {
  13762. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_RebootRequired]);
  13763. }
  13764. else
  13765. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  13766. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "WebSocketPingInterval") != NULL))
  13767. {
  13768. ChageWebSocketPingInterval(atoi((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value));
  13769. }
  13770. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "SecurityCtrlr") != NULL) &&
  13771. ((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "SecurityProfile") != NULL) || (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "BasicAuthPassword") != NULL)))
  13772. {
  13773. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  13774. SetOcppConnStatus(FALSE);
  13775. }
  13776. }
  13777. }
  13778. }
  13779. }
  13780. }
  13781. sendSetVariableConfirmation(uuid, json_object_array_length(json_object_object_get(SetVariables, "setVariableData")));
  13782. }
  13783. json_object_put(SetVariables);
  13784. return result;
  13785. }
  13786. int handleTriggerMessageRequest(char *uuid, char *payload)
  13787. {
  13788. mtrace();
  13789. int result = FAIL;
  13790. int connectorIdIsNULL = FALSE;
  13791. int connectorIdInt =0;
  13792. json_object *TriggerMessage;
  13793. DEBUG_INFO("handleTriggerMessageRequest\n");
  13794. TriggerMessage = json_tokener_parse(payload);
  13795. if(!is_error(TriggerMessage))
  13796. {
  13797. memset(&ShmOCPP20Data->TriggerMessage, 0, sizeof(struct TriggerMessage_20));
  13798. memcpy(&ShmOCPP20Data->TriggerMessage.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->TriggerMessage.guid));
  13799. // Required data
  13800. if(json_object_object_get(TriggerMessage, "requestedMessage") != NULL)
  13801. sprintf((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(TriggerMessage, "requestedMessage")));
  13802. // Optional data
  13803. if(json_object_object_get(TriggerMessage, "evse") != NULL)
  13804. {
  13805. // Required data
  13806. if(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "id") != NULL)
  13807. ShmOCPP20Data->TriggerMessage.evse.id = json_object_get_int(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "id"));
  13808. // Optional data
  13809. if(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "connectorId") != NULL)
  13810. {
  13811. ShmOCPP20Data->TriggerMessage.evse.connectorId = json_object_get_int(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "connectorId"));
  13812. connectorIdInt = ShmOCPP20Data->TriggerMessage.evse.connectorId;
  13813. }
  13814. else
  13815. connectorIdIsNULL = TRUE;
  13816. }
  13817. }
  13818. json_object_put(TriggerMessage);
  13819. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  13820. {
  13821. if((strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_BootNotification]) != 0) &&
  13822. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_LogStatusNotification]) != 0) &&
  13823. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_FirmwareStatusNotification]) != 0 ) &&
  13824. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_Heartbeat]) != 0) &&
  13825. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_MeterValues]) != 0) &&
  13826. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) != 0 ) &&
  13827. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignV2GCertificate]) != 0 ) &&
  13828. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_StatusNotification]) != 0 ) &&
  13829. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_TransactionEvent]) != 0 ) &&
  13830. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignCombinedCertificate]) != 0 ) &&
  13831. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_PublishFirmwareStatusNotification]) != 0 ))
  13832. {
  13833. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_NotImplemented] );
  13834. sendTriggerMessageConfirmation(uuid);
  13835. return TRUE;
  13836. }
  13837. else
  13838. {
  13839. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Accepted] );
  13840. sendTriggerMessageConfirmation(uuid);
  13841. }
  13842. }
  13843. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  13844. {
  13845. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Rejected] );
  13846. sendTriggerMessageConfirmation(uuid);
  13847. return TRUE;
  13848. }
  13849. //==========================
  13850. // Trigger message
  13851. //==========================
  13852. if( strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_FirmwareStatusNotification]) == 0)
  13853. {
  13854. if((strlen((char*)ShmOCPP20Data->FirmwareStatusNotification.status) == 0) ||
  13855. ((FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Downloading) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Downloaded) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Idle) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Installing)))
  13856. {
  13857. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle;
  13858. }
  13859. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  13860. }
  13861. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_LogStatusNotification]) == 0 )
  13862. {
  13863. if(strlen((char*)ShmOCPP20Data->LogStatusNotification.status) == 0)
  13864. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Idle]);
  13865. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13866. }
  13867. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_BootNotification]) == 0 )
  13868. {
  13869. if(DB_updateBootType(BootReasonEnumType_Triggered))
  13870. server_sign = FALSE;
  13871. }
  13872. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_Heartbeat]) == 0 )
  13873. {
  13874. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP20Data->BootNotification.Response_interval);
  13875. }
  13876. else if (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_MeterValues]) == 0 )
  13877. {
  13878. if(connectorIdIsNULL == FALSE)
  13879. {
  13880. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13881. {
  13882. cpinitateMsg.bits[connectorIdInt-1].TriggerMeterValueReq = ON;
  13883. }
  13884. }
  13885. else
  13886. {
  13887. for(int idx=0;idx< gunTotalNumber;idx++)
  13888. {
  13889. cpinitateMsg.bits[idx].TriggerMeterValueReq = ON;
  13890. }
  13891. }
  13892. }
  13893. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_StatusNotification]) == 0 )
  13894. {
  13895. if(connectorIdIsNULL == FALSE)
  13896. {
  13897. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13898. {
  13899. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = ON;
  13900. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13901. }
  13902. }
  13903. else
  13904. {
  13905. for(int idx=0;idx< gunTotalNumber;idx++)
  13906. {
  13907. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = ON;
  13908. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13909. }
  13910. }
  13911. }
  13912. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) == 0 )
  13913. {
  13914. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  13915. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13916. {
  13917. 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\" &");
  13918. }
  13919. }
  13920. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignV2GCertificate]) == 0 )
  13921. {
  13922. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  13923. if(access("/Storage/OCPP/certV2G.csr",F_OK) == -1)
  13924. {
  13925. 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\" &");
  13926. }
  13927. }
  13928. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_TransactionEvent]) == 0 )
  13929. {
  13930. if(connectorIdIsNULL == FALSE)
  13931. {
  13932. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13933. {
  13934. cpinitateMsg.bits[connectorIdInt -1].TransactionEventReq = ON;
  13935. }
  13936. }
  13937. else
  13938. {
  13939. for(int idx=0;idx< gunTotalNumber;idx++)
  13940. cpinitateMsg.bits[idx].TransactionEventReq = ON;
  13941. }
  13942. }
  13943. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignCombinedCertificate]) == 0 )
  13944. {
  13945. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  13946. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13947. {
  13948. 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\" &");
  13949. }
  13950. if(access("/Storage/OCPP/certV2G.csr",F_OK) == -1)
  13951. {
  13952. 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\" &");
  13953. }
  13954. }
  13955. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_PublishFirmwareStatusNotification]) == 0 )
  13956. {
  13957. ShmOCPP20Data->MsMsg.bits.PublishFirmwareReq = ON;
  13958. }
  13959. return result;
  13960. }
  13961. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13962. {
  13963. mtrace();
  13964. int result = FAIL;
  13965. int connectorIdInt =0;
  13966. int tempIndex = 0;
  13967. json_object *UnlockConnector;
  13968. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13969. UnlockConnector = json_tokener_parse(payload);
  13970. if(!is_error(UnlockConnector))
  13971. {
  13972. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13973. {
  13974. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13975. }
  13976. if(json_object_object_get(UnlockConnector, "evseId") != NULL)
  13977. {
  13978. ShmOCPP20Data->UnlockConnector[(connectorIdInt>0?connectorIdInt-1:0)].evseId = json_object_get_int(json_object_object_get(UnlockConnector, "evseId"));
  13979. }
  13980. }
  13981. json_object_put(UnlockConnector);
  13982. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13983. if(gunTotalNumber == 0)
  13984. {
  13985. sprintf((char*)ShmOCPP20Data->UnlockConnector[connectorIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  13986. goto end;
  13987. }
  13988. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13989. {
  13990. sprintf((char*)ShmOCPP20Data->UnlockConnector[connectorIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  13991. goto end;
  13992. }
  13993. else
  13994. {
  13995. memset(&ShmOCPP20Data->UnlockConnector[connectorIdInt-1], 0, sizeof(struct UnlockConnector_20));
  13996. memcpy(&ShmOCPP20Data->UnlockConnector[connectorIdInt-1].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->UnlockConnector[connectorIdInt-1].guid));
  13997. //check Transaction active
  13998. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13999. {
  14000. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14001. {
  14002. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  14003. }
  14004. else
  14005. {
  14006. tempIndex = connectorIdInt -1;
  14007. }
  14008. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14009. {
  14010. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  14011. {
  14012. //stop Transaction
  14013. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  14014. }
  14015. }
  14016. }
  14017. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  14018. {
  14019. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14020. {
  14021. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  14022. }
  14023. else
  14024. {
  14025. tempIndex = connectorIdInt -1;
  14026. }
  14027. for (int index = 0; index < CCS_QUANTITY; index++)
  14028. {
  14029. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  14030. {
  14031. //stop Transaction
  14032. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  14033. }
  14034. }
  14035. }
  14036. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  14037. {
  14038. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14039. {
  14040. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  14041. }
  14042. else
  14043. {
  14044. tempIndex = connectorIdInt -1;
  14045. }
  14046. for (int index = 0; index < GB_QUANTITY; index++)
  14047. {
  14048. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  14049. {
  14050. //stop Transaction
  14051. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  14052. }
  14053. }
  14054. }
  14055. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  14056. {
  14057. tempIndex = connectorIdInt -1;
  14058. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14059. {
  14060. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)))
  14061. {
  14062. //stop Transaction
  14063. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  14064. }
  14065. }
  14066. }
  14067. else
  14068. {
  14069. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14070. {
  14071. tempIndex = 2;
  14072. }
  14073. else
  14074. {
  14075. tempIndex = connectorIdInt-1;
  14076. }
  14077. for (int index = 0; index < AC_QUANTITY; index++)
  14078. {
  14079. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  14080. {
  14081. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  14082. }
  14083. }
  14084. }
  14085. ShmOCPP20Data->UnlockConnector[connectorIdInt-1].connectorId = connectorIdInt;
  14086. strcpy((char *)ShmOCPP20Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  14087. result = TRUE;
  14088. return result;
  14089. }
  14090. end:
  14091. //json_object_put(obj); --- remove temporally
  14092. sendUnlockConnectorConfirmation(uuid, connectorIdInt-1);
  14093. return result;
  14094. }
  14095. int handleUnpublishFirmwareRequest(char *uuid, char *payload)
  14096. {
  14097. mtrace();
  14098. int result = FAIL;
  14099. json_object *UnpublishFirmware;
  14100. DEBUG_INFO("handleUnpublishFirmwareRequest...\n");
  14101. UnpublishFirmware = json_tokener_parse(payload);
  14102. if(!is_error(UnpublishFirmware))
  14103. {
  14104. memset(&ShmOCPP20Data->UnpublishFirmware, 0, sizeof(struct UnpublishFirmware_20));
  14105. memcpy(&ShmOCPP20Data->UnpublishFirmware.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->UnpublishFirmware.guid));
  14106. // Required data
  14107. if(json_object_object_get(UnpublishFirmware, "checksum") != NULL)
  14108. sprintf((char*)ShmOCPP20Data->UnpublishFirmware.checksum, json_object_get_string(json_object_object_get(UnpublishFirmware, "checksum")));
  14109. }
  14110. json_object_put(UnpublishFirmware);
  14111. ShmOCPP20Data->MsMsg.bits.UnpublishFirmwareReq = ON;
  14112. /*
  14113. * TODO:
  14114. * 1. Check unpublished status
  14115. */
  14116. sprintf((char*)ShmOCPP20Data->UnpublishFirmware.Response_status, UnpublishFirmwareStatusEnumTypeStr[Unpublished_NoFirmware]);
  14117. sendUnpublishFirmwareConfirmation(uuid);
  14118. return result;
  14119. }
  14120. static char UpdateFirmwarepayloadData[512]={0};
  14121. void *UpdateFirmwareProcess(void *data)
  14122. {
  14123. pthread_detach(pthread_self());
  14124. mtrace();
  14125. int retriesInt =0, retryIntervalInt=0;
  14126. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  14127. int port=0;
  14128. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  14129. int isSuccess = 0;
  14130. char ftpbuf[1024];
  14131. char temp[1024];
  14132. char * pch;
  14133. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  14134. json_object *UpdateFirmware;
  14135. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  14136. if(!is_error(UpdateFirmware))
  14137. {
  14138. // Required data
  14139. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  14140. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  14141. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  14142. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  14143. // Optional data
  14144. if(json_object_object_get(UpdateFirmware, "retries"))
  14145. {
  14146. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  14147. }
  14148. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  14149. {
  14150. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  14151. }
  14152. }
  14153. json_object_put(UpdateFirmware);
  14154. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  14155. memset(path, 0, ARRAY_SIZE(path));
  14156. // Wait retrieveData
  14157. if(strlen(retrieveDatestr) > 10)
  14158. {
  14159. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadScheduled]);
  14160. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  14161. do
  14162. {
  14163. sleep(1);
  14164. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  14165. }
  14166. system("rm -f /mnt/*");
  14167. if(strncmp(locationstr,"http", 4) == 0)
  14168. {
  14169. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  14170. sprintf(ftppath,"/%s", path);
  14171. DEBUG_INFO("locationstr: %s\n", locationstr);
  14172. DEBUG_INFO("protocol: %s\n",protocol);
  14173. DEBUG_INFO("host: %s\n",host);
  14174. DEBUG_INFO("path: %s\n",path);
  14175. DEBUG_INFO("ftppath: %s\n",ftppath);
  14176. int ftppathlen=strlen(ftppath);
  14177. int i=1;
  14178. char filenametemp[50];
  14179. while(i < ftppathlen)
  14180. {
  14181. int len=ftppathlen-i;
  14182. if(ftppath[len]== 47) // '/' ascll code: 47
  14183. {
  14184. DEBUG_INFO("compare '/' all right\n");
  14185. break;
  14186. }
  14187. i=i+1;
  14188. }
  14189. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14190. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  14191. filenametemp[i+1] = 0;
  14192. do
  14193. {
  14194. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading]);
  14195. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  14196. sleep(3);
  14197. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  14198. if(!isSuccess)
  14199. {
  14200. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  14201. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  14202. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  14203. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  14204. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  14205. }
  14206. else
  14207. {
  14208. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]);
  14209. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  14210. }
  14211. retriesInt--;
  14212. }while((isSuccess == 0)&&(retriesInt >= 0));
  14213. }
  14214. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  14215. {
  14216. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14217. memset(temp, 0, ARRAY_SIZE(temp));
  14218. strcpy(ftpbuf, locationstr);
  14219. int ftppathlen=strlen(ftpbuf);
  14220. int i=1;
  14221. char filenametemp[50];
  14222. while(i < ftppathlen)
  14223. {
  14224. int len=ftppathlen-i;
  14225. if(ftpbuf[len]== 47) // '/' ascll code: 47
  14226. {
  14227. DEBUG_INFO(" compare '/' all right\n");
  14228. break;
  14229. }
  14230. i=i+1;
  14231. }
  14232. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  14233. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  14234. filenametemp[i+1] = 0;
  14235. strncpy(temp, ftpbuf, ftppathlen-i+1);
  14236. pch=strchr(temp,'@');
  14237. if(pch==NULL)
  14238. {
  14239. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  14240. protocol, host, &port, path);
  14241. strcpy(user,"anonymous");
  14242. strcpy(password,"");
  14243. }
  14244. else
  14245. {
  14246. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  14247. protocol, user, password, host, &port, path);
  14248. }
  14249. sscanf(host,"%[^/]%s",host1, path1);
  14250. sprintf(ftppath,"%s", path1);
  14251. if(port == 0)
  14252. {
  14253. port = 21;
  14254. }
  14255. do
  14256. {
  14257. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading]);
  14258. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  14259. sleep(3);
  14260. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  14261. if(!isSuccess)
  14262. {
  14263. //BulldogUtil.sleepMs(interval*1000);
  14264. DEBUG_INFO("Update firmware request and download file fail.\n");
  14265. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  14266. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  14267. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  14268. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  14269. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  14270. }
  14271. else
  14272. {
  14273. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]);
  14274. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  14275. }
  14276. retriesInt--;
  14277. }while((!isSuccess)&&(retriesInt >= 0));
  14278. }
  14279. else
  14280. {
  14281. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  14282. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  14283. sleep(1);
  14284. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  14285. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  14286. }
  14287. if(strstr((char*)ShmOCPP20Data->FirmwareStatusNotification.status, FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]) != NULL)ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq = ON;
  14288. pthread_exit(NULL);
  14289. }
  14290. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  14291. {
  14292. mtrace();
  14293. int result = FAIL;
  14294. pthread_t t;
  14295. sendUpdateFirmwareConfirmation(uuid);
  14296. memset(UpdateFirmwarepayloadData, 0, ARRAY_SIZE(UpdateFirmwarepayloadData));
  14297. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  14298. memset(&ShmOCPP20Data->UpdateFirmware, 0, sizeof(struct UpdateFirmware_20));
  14299. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  14300. ////pthread_join(t, NULL); //
  14301. //pthread_detach(t);
  14302. //sendUpdateFirmwareConfirmation(uuid);
  14303. ShmOCPP20Data->MsMsg.bits.UpdateFirmwareConf = ON;
  14304. return result;
  14305. }
  14306. int handleUnknownRequest(char *uuid, char *payload)
  14307. {
  14308. mtrace();
  14309. int result = FAIL;
  14310. DEBUG_INFO("handleUnknownRequest...\n");
  14311. sendUnknownConfirmation(uuid);
  14312. result = PASS;
  14313. return result;
  14314. }
  14315. //==========================================
  14316. // Handle server response routine
  14317. //==========================================
  14318. void handleAuthorizeResponse(char *payload, int gun_index)
  14319. {
  14320. mtrace();
  14321. DEBUG_INFO("handleAuthorizeResponse...\n");
  14322. json_object *Authorize;
  14323. Authorize = json_tokener_parse(payload);
  14324. if(!is_error(Authorize))
  14325. {
  14326. if(json_object_object_get(Authorize, "idTokenInfo") != NULL)
  14327. {
  14328. // Required data
  14329. sprintf((char *)(char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "status")));
  14330. // Optional data
  14331. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "cacheExpiryDateTime") != NULL)
  14332. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "cacheExpiryDateTime")));
  14333. else
  14334. memset(ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime));
  14335. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "chargingPriority") != NULL)
  14336. ShmOCPP20Data->Authorize.Response_idTokenInfo.chargingPriority = json_object_get_int(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "chargingPriority"));
  14337. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "language1") != NULL)
  14338. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.language1, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language1")));
  14339. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "evseId") != NULL)
  14340. {
  14341. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(Authorize, "idTagInfo"), "evseId"));idx++)
  14342. {
  14343. 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));
  14344. }
  14345. }
  14346. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "language2") != NULL)
  14347. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.language2, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language2")));
  14348. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "groupIdToken") != NULL)
  14349. {
  14350. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "idToken") != NULL)
  14351. 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")));
  14352. else
  14353. memset(ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken));
  14354. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "type") != NULL)
  14355. 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")));
  14356. }
  14357. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "personalMessage") != NULL)
  14358. {
  14359. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "format") != NULL)
  14360. 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")));
  14361. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "language") != NULL)
  14362. 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")));
  14363. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "content") != NULL)
  14364. 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")));
  14365. }
  14366. }
  14367. if(json_object_object_get(Authorize, "certificateStatus") != NULL)
  14368. {
  14369. strcpy((char *)ShmOCPP20Data->Authorize.Response_certificateStatus, json_object_get_string(json_object_object_get(Authorize, "certificateStatus")));
  14370. }
  14371. }
  14372. json_object_put(Authorize);
  14373. //Update idTag information to authorization cache if supported
  14374. if((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].value, "TRUE") == 0) &&
  14375. (strlen((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken) > 0) &&
  14376. (strlen((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime) >0) &&
  14377. strstr((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != NULL)
  14378. {
  14379. DB_addLocalCache(&ShmOCPP20Data->Authorize.idToken, &ShmOCPP20Data->Authorize.Response_idTokenInfo);
  14380. }
  14381. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  14382. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  14383. authorizeRetryTimes = 0;
  14384. }
  14385. void handleBootNotificationResponse(char *payload, int gun_index)
  14386. {
  14387. mtrace();
  14388. char statusStr[12]={0};
  14389. char currentTimeStr[30]={0};
  14390. int intervalInt = 0;
  14391. DEBUG_INFO("handleBootNotificationResponse...\n");
  14392. json_object *BootNotification;
  14393. BootNotification = json_tokener_parse(payload);
  14394. if(!is_error(BootNotification))
  14395. {
  14396. // Required data
  14397. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  14398. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  14399. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  14400. }
  14401. json_object_put(BootNotification);
  14402. DEBUG_INFO("statusStr: %s\n", statusStr);
  14403. ShmOCPP20Data->BootNotification.Response_interval = intervalInt;
  14404. BootNotificationInterval = intervalInt;
  14405. HeartBeatWaitTime = intervalInt;
  14406. //write back to ShmOCPP20Data->BootNotification
  14407. strcpy((char *)ShmOCPP20Data->BootNotification.Response_currentTime, currentTimeStr);
  14408. strcpy((char *)ShmOCPP20Data->BootNotification.Response_status, statusStr);
  14409. if((strcmp(statusStr, RegistrationStatusEnumTypeStr[RegistrationStatusEnumType_Accepted]) == 0 ))
  14410. {
  14411. server_sign = TRUE;
  14412. server_pending =FALSE;
  14413. DB_updateBootType(BootReasonEnumType_PowerUp);
  14414. }
  14415. else if(strcmp(statusStr, RegistrationStatusEnumTypeStr[RegistrationStatusEnumType_Pending]) == 0)
  14416. {
  14417. server_pending = TRUE;
  14418. }
  14419. syncDateTimeRTC(ShmOCPP20Data->BootNotification.Response_currentTime);
  14420. srand(time(NULL));
  14421. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP20Data->BootNotification.Response_interval-((rand()%8)+3));
  14422. SetOcppConnStatus(TRUE);
  14423. ShmOCPP20Data->SpMsg.bits.BootNotificationConf = ON;
  14424. }
  14425. void handleClearedChargingLimitResponse(char *payload, int gun_index)
  14426. {
  14427. mtrace();
  14428. json_object *ClearedChargingLimit;
  14429. DEBUG_INFO("handleClearedChargingLimitResponse...\n");
  14430. ClearedChargingLimit = json_tokener_parse(payload);
  14431. if(!is_error(ClearedChargingLimit))
  14432. {
  14433. // Required data
  14434. if(json_object_object_get(ClearedChargingLimit,"status") != NULL)
  14435. sprintf((char*)ShmOCPP20Data->ClearChargingProfile[gun_index].Response_status, json_object_get_string(json_object_object_get(ClearedChargingLimit,"status")));
  14436. }
  14437. json_object_put(ClearedChargingLimit);
  14438. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq = OFF;
  14439. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitConf = ON;
  14440. }
  14441. void handleDataTransferResponse(char *payload, int gun_index)
  14442. {
  14443. mtrace();
  14444. json_object *DataTrans;
  14445. DEBUG_INFO("handleDataTransferResponse...\n");
  14446. DataTrans = json_tokener_parse(payload);
  14447. if(!is_error(DataTrans))
  14448. {
  14449. // Required data
  14450. if(json_object_object_get(DataTrans,"status") != NULL)
  14451. sprintf((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_status, json_object_get_string(json_object_object_get(DataTrans,"status")));
  14452. // Optional data
  14453. if(json_object_object_get(DataTrans,"data") != NULL)
  14454. sprintf((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_data, json_object_get_string(json_object_object_get(DataTrans,"data")));
  14455. }
  14456. json_object_put(DataTrans);
  14457. ShmOCPP20Data->CpMsg.bits[gun_index].DataTransferReq = OFF;
  14458. ShmOCPP20Data->CpMsg.bits[gun_index].DataTransferConf = ON;
  14459. }
  14460. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  14461. {
  14462. mtrace();
  14463. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  14464. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = OFF;
  14465. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationConf = ON;
  14466. }
  14467. void handleGet15118EVCertificateResponse(char *payload, int gun_index)
  14468. {
  14469. mtrace();
  14470. json_object *Get15118EVCertificate;
  14471. DEBUG_INFO("handleGet15118EVCertificateResponse...\n");
  14472. Get15118EVCertificate = json_tokener_parse(payload);
  14473. if(!is_error(Get15118EVCertificate))
  14474. {
  14475. // Required data
  14476. if(json_object_object_get(Get15118EVCertificate,"status") != NULL)
  14477. sprintf((char*)ShmOCPP20Data->Get15118EVCertificate.Response_status, json_object_get_string(json_object_object_get(Get15118EVCertificate,"status")));
  14478. // Optional data
  14479. if(json_object_object_get(Get15118EVCertificate,"exiResponse") != NULL)
  14480. sprintf((char*)ShmOCPP20Data->Get15118EVCertificate.Response_exiResponse, json_object_get_string(json_object_object_get(Get15118EVCertificate,"exiResponse")));
  14481. }
  14482. json_object_put(Get15118EVCertificate);
  14483. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq = OFF;
  14484. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateConf = ON;
  14485. }
  14486. void hanldeGetCertificateStatusResponse(char *payload, int gun_index)
  14487. {
  14488. mtrace();
  14489. json_object *GetCertificateStatus;
  14490. DEBUG_INFO("hanldeGetCertificateStatusResponse...\n");
  14491. GetCertificateStatus = json_tokener_parse(payload);
  14492. if(!is_error(GetCertificateStatus))
  14493. {
  14494. // Required data
  14495. if(json_object_object_get(GetCertificateStatus,"status") != NULL)
  14496. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_status, json_object_get_string(json_object_object_get(GetCertificateStatus,"status")));
  14497. // Optional data
  14498. if(json_object_object_get(GetCertificateStatus,"ocspResult") != NULL)
  14499. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_ocspResult, json_object_get_string(json_object_object_get(GetCertificateStatus,"ocspResult")));
  14500. }
  14501. json_object_put(GetCertificateStatus);
  14502. ShmOCPP20Data->SpMsg.bits.GetCertificateStatusReq = OFF;
  14503. ShmOCPP20Data->SpMsg.bits.GetCertificateStatusConf = ON;
  14504. }
  14505. void handleHeartbeatResponse(char *payload, int gun_index)
  14506. {
  14507. mtrace();
  14508. DEBUG_INFO("handleHeartbeatResponse...\n");
  14509. json_object *Heartbeat;
  14510. Heartbeat = json_tokener_parse(payload);
  14511. if(!is_error(Heartbeat))
  14512. {
  14513. // Required data
  14514. if(json_object_object_get(Heartbeat,"currentTime") != NULL)
  14515. sprintf((char *)ShmOCPP20Data->Heartbeat.Response_currentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  14516. }
  14517. json_object_put(Heartbeat);
  14518. if(FirstHeartBeat == OFF)
  14519. {
  14520. FirstHeartBeat = ON;
  14521. DEBUG_INFO("FirstHeartBeat \n");
  14522. }
  14523. HeartBeatWithNOResponse = 0;
  14524. clientTime.Heartbeat=time((time_t*)NULL);
  14525. syncDateTimeRTC(ShmOCPP20Data->Heartbeat.Response_currentTime);
  14526. }
  14527. void hanldeLogStatusNotificationResponse(char *payload, int gun_index)
  14528. {
  14529. mtrace();
  14530. DEBUG_INFO("hanldeLogStatusNotificationResponse...\n");
  14531. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  14532. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationConf = ON;
  14533. }
  14534. void handleMeterValuesResponse(char *payload, int gun_index)
  14535. {
  14536. mtrace();
  14537. DEBUG_INFO("handleMeterValuesResponse...\n");
  14538. }
  14539. void handleNotifyChargingLimitResponse(char *payload, int gun_index)
  14540. {
  14541. mtrace();
  14542. DEBUG_INFO("handleNotifyChargingLimitResponse...\n");
  14543. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitReq = OFF;
  14544. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitConf = ON;
  14545. }
  14546. void hanldeNotifyCustomerInformationResponse(char *payload, int gun_index)
  14547. {
  14548. mtrace();
  14549. DEBUG_INFO("hanldeNotifyCustomerInformationResponse...\n");
  14550. }
  14551. void hanldeNotifyDisplayMessagesResponse(char *payload, int gun_index)
  14552. {
  14553. mtrace();
  14554. DEBUG_INFO("hanldeNotifyDisplayMessagesResponse...\n");
  14555. ShmOCPP20Data->SpMsg.bits.NotifyDisplayMessagesReq = OFF;
  14556. ShmOCPP20Data->SpMsg.bits.NotifyDisplayMessagesConf = ON;
  14557. }
  14558. void hanldeNotifyEVChargingNeedsResponse(char *payload, int gun_index)
  14559. {
  14560. mtrace();
  14561. json_object *NotifyEVChargingNeeds;
  14562. DEBUG_INFO("hanldeNotifyEVChargingNeedsResponse...\n");
  14563. NotifyEVChargingNeeds = json_tokener_parse(payload);
  14564. if(!is_error(NotifyEVChargingNeeds))
  14565. {
  14566. // Required data
  14567. if(json_object_object_get(NotifyEVChargingNeeds,"status") != NULL)
  14568. sprintf((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].Response_status, json_object_get_string(json_object_object_get(NotifyEVChargingNeeds,"status")));
  14569. }
  14570. json_object_put(NotifyEVChargingNeeds);
  14571. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitReq = OFF;
  14572. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitConf = ON;
  14573. }
  14574. void hanldeNotifyEVChargingScheduleResponse(char *payload, int gun_index)
  14575. {
  14576. mtrace();
  14577. json_object *NotifyEVChargingSchedule;
  14578. DEBUG_INFO("hanldeNotifyEVChargingScheduleResponse...\n");
  14579. NotifyEVChargingSchedule = json_tokener_parse(payload);
  14580. if(!is_error(NotifyEVChargingSchedule))
  14581. {
  14582. // Required data
  14583. if(json_object_object_get(NotifyEVChargingSchedule,"status") != NULL)
  14584. sprintf((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].Response_status, json_object_get_string(json_object_object_get(NotifyEVChargingSchedule,"status")));
  14585. }
  14586. json_object_put(NotifyEVChargingSchedule);
  14587. ShmOCPP20Data->SpMsg.bits.NotifyEVChargingScheduleReq = OFF;
  14588. ShmOCPP20Data->SpMsg.bits.NotifyEVChargingScheduleConf = ON;
  14589. }
  14590. void hanldeNotifyEventResponse(char *payload, int gun_index)
  14591. {
  14592. mtrace();
  14593. DEBUG_INFO("hanldeNotifyEventResponse...\n");
  14594. ShmOCPP20Data->SpMsg.bits.NotifyEventReq = OFF;
  14595. ShmOCPP20Data->SpMsg.bits.NotifyEventConf = ON;
  14596. }
  14597. void hanldeNotifyMonitoringReportResponse(char *payload, int gun_index)
  14598. {
  14599. mtrace();
  14600. DEBUG_INFO("hanldeNotifyMonitoringReportResponse...\n");
  14601. ShmOCPP20Data->SpMsg.bits.NotifyMonitoringReportReq = OFF;
  14602. ShmOCPP20Data->SpMsg.bits.NotifyMonitoringReportConf = ON;
  14603. }
  14604. void hanldeNotifyReportResponse(char *payload, int gun_index)
  14605. {
  14606. mtrace();
  14607. DEBUG_INFO("hanldeNotifyReportResponse...\n");
  14608. ShmOCPP20Data->SpMsg.bits.NotifyReportReq = OFF;
  14609. ShmOCPP20Data->SpMsg.bits.NotifyReportConf = ON;
  14610. }
  14611. void hanldePublishFirmwareStatusNotificationResponse(char *payload, int gun_index)
  14612. {
  14613. mtrace();
  14614. DEBUG_INFO("hanldePublishFirmwareStatusNotificationResponse...\n");
  14615. ShmOCPP20Data->CsMsg.bits[gun_index].PublishFirmwareStatusNotificationReq = OFF;
  14616. ShmOCPP20Data->CsMsg.bits[gun_index].PublishFirmwareStatusNotificationConf = ON;
  14617. }
  14618. void hanldeReportChargingProfilesResponse(char *payload, int gun_index)
  14619. {
  14620. mtrace();
  14621. DEBUG_INFO("hanldeReportChargingProfilesResponse...gun_index: %d\n", gun_index);
  14622. ShmOCPP20Data->SpMsg.bits.ReportChargingProfilesReq = OFF;
  14623. ShmOCPP20Data->SpMsg.bits.ReportChargingProfilesConf = ON;
  14624. }
  14625. void hanldeReservationStatusUpdateResponse(char *payload, int gun_index)
  14626. {
  14627. mtrace();
  14628. DEBUG_INFO("hanldeReservationStatusUpdateResponse...gun_index: %d\n", gun_index);
  14629. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = OFF;
  14630. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateConf = ON;
  14631. }
  14632. void hanldeSecurityEventNotificationResponse(char *payload, int gun_index)
  14633. {
  14634. mtrace();
  14635. DEBUG_INFO("hanldeSecurityEventNotificationResponse...\n");
  14636. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = OFF;
  14637. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationConf = ON;
  14638. }
  14639. void hanldeSignCertificateResponse(char *payload, int gun_index)
  14640. {
  14641. mtrace();
  14642. json_object *SignCertificate;
  14643. DEBUG_INFO("hanldeSignCertificateResponse...\n");
  14644. SignCertificate = json_tokener_parse(payload);
  14645. if(!is_error(SignCertificate))
  14646. {
  14647. // Required data
  14648. if(json_object_object_get(SignCertificate,"status") != NULL)
  14649. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_status, json_object_get_string(json_object_object_get(SignCertificate,"status")));
  14650. // Optional data
  14651. if(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "reasonCode") != NULL)
  14652. {
  14653. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_statusInfo.reasonCode, json_object_get_string(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "reasonCode")));
  14654. if(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "additionalInfo") != NULL)
  14655. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_statusInfo.additionalInfo, json_object_get_string(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "additionalInfo")));
  14656. }
  14657. }
  14658. json_object_put(SignCertificate);
  14659. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = OFF;
  14660. ShmOCPP20Data->SpMsg.bits.SignCertificateConf = ON;
  14661. }
  14662. void handleStatusNotificationResponse(char *payload, int gun_index)
  14663. {
  14664. mtrace();
  14665. DEBUG_INFO("handleStatusNotificationResponse...gun_index: %d\n", gun_index);
  14666. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  14667. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  14668. cpinitateMsg.bits[gun_index].StatusNotificationConf = ON;
  14669. }
  14670. void hanldeTransactionEvenResponse(char *payload, int gun_index)
  14671. {
  14672. mtrace();
  14673. json_object *TransactionEven;
  14674. DEBUG_INFO("hanldeTransactionEvenResponse...\n");
  14675. TransactionEven = json_tokener_parse(payload);
  14676. if(!is_error(TransactionEven))
  14677. {
  14678. // Required data
  14679. // Optional data
  14680. if(json_object_object_get(TransactionEven,"totalCost") != NULL)
  14681. ShmOCPP20Data->TransactionEvent[gun_index].Response_totalCost = json_object_get_double(json_object_object_get(TransactionEven,"totalCost"));
  14682. if(json_object_object_get(TransactionEven,"chargingPriority") != NULL)
  14683. ShmOCPP20Data->TransactionEvent[gun_index].Response_chargingPriority = json_object_get_int(json_object_object_get(TransactionEven,"chargingPriority"));
  14684. if(json_object_object_get(TransactionEven,"idTokenInfo") != NULL)
  14685. {
  14686. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "status") != NULL)
  14687. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "status")));
  14688. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "cacheExpiryDateTime") != NULL)
  14689. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.cacheExpiryDateTime, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "cacheExpiryDateTime")));
  14690. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "chargingPriority") != NULL)
  14691. ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.chargingPriority = json_object_get_int(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "chargingPriority"));
  14692. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "language1") != NULL)
  14693. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.language1, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "language1")));
  14694. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken") != NULL)
  14695. {
  14696. if(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "idToken") != NULL)
  14697. 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")));
  14698. if(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "type") != NULL)
  14699. 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")));
  14700. }
  14701. }
  14702. }
  14703. json_object_put(TransactionEven);
  14704. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = OFF;
  14705. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf = ON;
  14706. }
  14707. //==========================================
  14708. // Handle Error routine
  14709. //==========================================
  14710. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  14711. {
  14712. mtrace();
  14713. #ifdef SystemLogMessage
  14714. DEBUG_INFO("errorCode: %s\n", errorCode);
  14715. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  14716. DEBUG_INFO("errorDetails: %s\n", payload);
  14717. #endif
  14718. }
  14719. //===============================================
  14720. // Common routine
  14721. //===============================================
  14722. int initialConfigurationTable(void)
  14723. {
  14724. DEBUG_INFO("initialConfigurationTable...\n");
  14725. memset(&ShmOCPP20Data->ControllerComponentVariable[0], 0, ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable));
  14726. DB_variableIsCreate();
  14727. DB_variableLoadFromDb();
  14728. DB_getNetworkProfileFromDb();
  14729. return 0;
  14730. }
  14731. int TransactionMessageAttemptsGet(void)
  14732. {
  14733. return TransactionMessageAttemptsValue;
  14734. }
  14735. int FirstHeartBeatResponse(void)
  14736. {
  14737. return FirstHeartBeat;
  14738. }
  14739. int TransactionMessageRetryIntervalGet(void)
  14740. {
  14741. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP20Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14742. }
  14743. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  14744. {
  14745. int result = TRUE;
  14746. char rmFileCmd[100]={0};
  14747. char FilePath[100]={0};
  14748. char ftpbuf[200];
  14749. int systemresult;
  14750. //DEBUG_INFO("filename=%s\n",filename);
  14751. //DEBUG_INFO("url=%s\n",url);
  14752. sprintf(FilePath,"/mnt/%s",filename);
  14753. system("ping 8.8.8.8 &");
  14754. if((access(FilePath,F_OK))!=-1)
  14755. {
  14756. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14757. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14758. system(rmFileCmd);
  14759. }
  14760. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14761. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14762. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14763. systemresult = system(ftpbuf);
  14764. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14765. if(systemresult != 0)
  14766. {
  14767. DEBUG_INFO("http DownLoad error!\n");
  14768. result = FALSE;
  14769. }
  14770. system("pkill ping");
  14771. return result;
  14772. }
  14773. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  14774. {
  14775. int result = TRUE;
  14776. char rmFileCmd[100]={0};
  14777. char FilePath[100]={0};
  14778. char ftpbuf[200];
  14779. int systemresult;
  14780. //char temp[100];
  14781. sprintf(FilePath,"/mnt/%s",filename);
  14782. system("ping 8.8.8.8 &");
  14783. if((access(FilePath,F_OK))!=-1)
  14784. {
  14785. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14786. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14787. system(rmFileCmd);
  14788. }
  14789. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14790. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14791. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  14792. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14793. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14794. systemresult = system(ftpbuf);
  14795. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14796. if(systemresult != 0)
  14797. {
  14798. printf("wget error!\n");
  14799. result = FALSE;
  14800. }
  14801. system("pkill ping");
  14802. return result;
  14803. }
  14804. int httpUploadFile(char *location, char *path, char *filename,char *url)
  14805. {
  14806. char rmFileCmd[100]={0};
  14807. char FilePath[100]={0};
  14808. char buf[512];
  14809. int systemresult = 0;
  14810. //DEBUG_INFO("filename=%s\n",filename);
  14811. //DEBUG_INFO("url=%s\n",url);
  14812. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  14813. if((access(FilePath,F_OK))!=-1)
  14814. {
  14815. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14816. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14817. system(rmFileCmd);
  14818. }
  14819. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  14820. if(fp == NULL)
  14821. {
  14822. DEBUG_INFO("log is NULL\n");
  14823. return FALSE;
  14824. }
  14825. else
  14826. {
  14827. fprintf(fp, "%s\n", url);
  14828. fprintf(fp, "%s\n", filename);
  14829. fclose(fp);
  14830. }
  14831. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  14832. if(phpFP == NULL)
  14833. {
  14834. DEBUG_INFO("PHP upload fail.\n");
  14835. return FALSE;
  14836. }
  14837. else
  14838. {
  14839. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  14840. {
  14841. if(strstr(buf, "result") != NULL)
  14842. {
  14843. sscanf(buf, "result: %d", &systemresult);
  14844. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  14845. }
  14846. }
  14847. pclose(phpFP);
  14848. }
  14849. if(systemresult != 1)
  14850. {
  14851. DEBUG_INFO("HTTP upload error!\n");
  14852. return FALSE;
  14853. }
  14854. return TRUE;
  14855. }
  14856. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  14857. {
  14858. struct hostent* server;
  14859. char *IPbuffer;
  14860. char ftpbuf[200];
  14861. int systemresult;
  14862. // To retrieve host information
  14863. server = gethostbyname(location);
  14864. // To convert an Internet network
  14865. // address into ASCII string
  14866. IPbuffer = inet_ntoa(*((struct in_addr*)
  14867. server->h_addr_list[0]));
  14868. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14869. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  14870. /* format : ftpput -u username -p passwd IP target source*/
  14871. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  14872. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14873. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14874. systemresult = system(ftpbuf);
  14875. DEBUG_INFO("systemresult=%d\n",systemresult);
  14876. if(systemresult != 0)
  14877. {
  14878. DEBUG_INFO("ftpput error!\n");
  14879. return FALSE;
  14880. }
  14881. return TRUE;
  14882. }
  14883. //=========================================
  14884. // Routine
  14885. //=========================================
  14886. int GetOcppServerURL()
  14887. {
  14888. int result = FALSE;
  14889. struct yuarel url;
  14890. char urlStr[512];
  14891. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  14892. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  14893. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  14894. if((ShmOCPP20Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP20Data->OcppServerURL,"") != 0))
  14895. {
  14896. memcpy(urlStr, ShmOCPP20Data->OcppServerURL, ARRAY_SIZE(ShmOCPP20Data->OcppServerURL));
  14897. if(yuarel_parse(&url, urlStr) != -1)
  14898. {
  14899. sprintf(OcppProtocol, "%s", url.scheme);
  14900. sprintf(OcppHost, "%s", url.host);
  14901. if(url.path == NULL)
  14902. OcppTempPath[0] = '\0';
  14903. else
  14904. sprintf(OcppTempPath, "%s", url.path);
  14905. if(url.port == 0)
  14906. {
  14907. if(strcmp(OcppProtocol, "wss") == 0)
  14908. OcppPort = 443;
  14909. else
  14910. OcppPort = 80;
  14911. }
  14912. else
  14913. OcppPort = url.port;
  14914. result = TRUE;
  14915. }
  14916. }
  14917. else
  14918. {
  14919. strcpy(OcppHost,"");
  14920. }
  14921. return result;
  14922. }
  14923. int GetOcppPath()
  14924. {
  14925. int result = FALSE;
  14926. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  14927. {
  14928. if(OcppTempPath == NULL)
  14929. {
  14930. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14931. }
  14932. else
  14933. {
  14934. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14935. }
  14936. result = TRUE;
  14937. }
  14938. else if((ShmOCPP20Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP20Data->ChargeBoxId,"") != 0))
  14939. {
  14940. if(OcppTempPath == NULL)
  14941. {
  14942. sprintf(OcppPath,"/%s",ShmOCPP20Data->ChargeBoxId);
  14943. }
  14944. else
  14945. {
  14946. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP20Data->ChargeBoxId);
  14947. }
  14948. result = TRUE;
  14949. }
  14950. else
  14951. {
  14952. strcpy(OcppPath,"");
  14953. }
  14954. return result;
  14955. }
  14956. int GetOcppPort()
  14957. {
  14958. return OcppPort;
  14959. }
  14960. int GetOcppConnStatus(void)
  14961. {
  14962. return ShmOCPP20Data->OcppConnStatus;
  14963. }
  14964. void SetOcppConnStatus(uint8_t status)
  14965. {
  14966. ShmOCPP20Data->OcppConnStatus = status;
  14967. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  14968. }
  14969. int GetHeartBeatWithNOResponse(void)
  14970. {
  14971. return HeartBeatWithNOResponse;
  14972. }
  14973. void SetHeartBeatWithNOResponse(void)
  14974. {
  14975. HeartBeatWithNOResponse = 0;
  14976. }
  14977. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  14978. void storeTempStopTransaction(int gun_index)
  14979. {
  14980. char TempStopTransaction[256];
  14981. char message[1024*20]={0};
  14982. char guid[37]={0};
  14983. uint8_t tempIndex;
  14984. json_object *TransactionEvent = json_object_new_object();
  14985. json_object *transactionInfo = json_object_new_object();
  14986. json_object *idToken = json_object_new_object();
  14987. json_object *evse = json_object_new_object();
  14988. json_object *meterValues = json_object_new_array();
  14989. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14990. DEBUG_INFO("storeTempStopTransaction...\n");
  14991. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14992. {
  14993. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14994. {
  14995. tempIndex = ((gun_index==2) ? 1: 0);
  14996. }
  14997. else
  14998. {
  14999. tempIndex = gun_index;
  15000. }
  15001. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15002. {
  15003. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  15004. {
  15005. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  15006. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  15007. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  15008. else
  15009. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  15010. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  15011. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  15012. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  15013. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  15014. {
  15015. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  15016. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  15017. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  15018. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  15019. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  15020. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  15021. {
  15022. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  15023. }
  15024. else
  15025. {
  15026. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  15027. }
  15028. }
  15029. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  15030. {
  15031. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  15032. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  15033. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  15034. }
  15035. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  15036. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  15037. ) //S_PRECHARGE
  15038. {
  15039. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  15040. {
  15041. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  15042. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartUserId);
  15043. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", ShmOCPP20Data->Authorize.idToken.type);
  15044. }
  15045. if(ShmOCPP20Data->TransactionEvent[gun_index].eventType[0] == '\0')
  15046. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  15047. else
  15048. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  15049. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  15050. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  15051. }
  15052. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  15053. {
  15054. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  15055. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  15056. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  15057. }
  15058. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  15059. {
  15060. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  15061. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  15062. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  15063. }
  15064. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  15065. {
  15066. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  15067. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  15068. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  15069. }
  15070. 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
  15071. {
  15072. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  15073. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  15074. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  15075. }
  15076. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  15077. {
  15078. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  15079. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  15080. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  15081. }
  15082. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  15083. {
  15084. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  15085. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  15086. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  15087. }
  15088. } //end of the same index
  15089. }//end of for CHAdeMO_QUANTITY
  15090. }
  15091. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15092. {
  15093. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15094. {
  15095. tempIndex = ((gun_index==2) ? 1: 0);
  15096. }
  15097. else
  15098. {
  15099. tempIndex = gun_index;
  15100. }
  15101. for (int index = 0; index < CCS_QUANTITY; index++)
  15102. {
  15103. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15104. {
  15105. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  15106. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  15107. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  15108. else
  15109. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  15110. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  15111. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  15112. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  15113. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  15114. {
  15115. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  15116. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  15117. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  15118. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  15119. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  15120. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  15121. {
  15122. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  15123. }
  15124. else
  15125. {
  15126. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  15127. }
  15128. }
  15129. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  15130. {
  15131. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  15132. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  15133. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  15134. }
  15135. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  15136. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  15137. ) //S_PRECHARGE
  15138. {
  15139. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  15140. {
  15141. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  15142. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartUserId);
  15143. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", ShmOCPP20Data->Authorize.idToken.type);
  15144. }
  15145. if(ShmOCPP20Data->TransactionEvent[gun_index].eventType[0] == '\0')
  15146. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  15147. else
  15148. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  15149. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  15150. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  15151. }
  15152. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  15153. {
  15154. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  15155. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  15156. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  15157. }
  15158. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  15159. {
  15160. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  15161. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  15162. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  15163. }
  15164. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  15165. {
  15166. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  15167. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  15168. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  15169. }
  15170. 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
  15171. {
  15172. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  15173. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  15174. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  15175. }
  15176. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  15177. {
  15178. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  15179. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  15180. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  15181. }
  15182. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  15183. {
  15184. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  15185. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  15186. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  15187. }
  15188. } //end of the same index
  15189. } // end of for CCS_QUANTITY
  15190. }
  15191. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15192. {
  15193. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15194. {
  15195. tempIndex = ((gun_index==2) ? 1: 0);
  15196. }
  15197. else
  15198. {
  15199. tempIndex = gun_index;
  15200. }
  15201. for (int index = 0; index < GB_QUANTITY; index++)
  15202. {
  15203. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15204. {
  15205. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  15206. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  15207. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  15208. else
  15209. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  15210. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  15211. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  15212. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  15213. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  15214. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  15215. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  15216. } //end of the same index
  15217. } // end of for GB_QUANTITY
  15218. }
  15219. else if(gunType[gun_index] == GUN_TYPE_DO)
  15220. {
  15221. tempIndex = gun_index;
  15222. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15223. {
  15224. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15225. {
  15226. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  15227. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  15228. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  15229. else
  15230. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  15231. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  15232. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  15233. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  15234. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  15235. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  15236. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  15237. } //end of the same index
  15238. }
  15239. }
  15240. else
  15241. {
  15242. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15243. {
  15244. tempIndex = 2;
  15245. }
  15246. else
  15247. {
  15248. tempIndex = gun_index;
  15249. }
  15250. for (int index = 0; index < AC_QUANTITY; index++)
  15251. {
  15252. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15253. {
  15254. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  15255. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  15256. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  15257. else
  15258. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  15259. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  15260. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  15261. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  15262. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  15263. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  15264. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  15265. }//end of the same index
  15266. }//end of for AC_QUANTITY
  15267. }
  15268. // Message
  15269. json_object_object_add(TransactionEvent, "eventType", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  15270. json_object_object_add(TransactionEvent, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].timestamp));
  15271. json_object_object_add(TransactionEvent, "triggerReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason));
  15272. json_object_object_add(TransactionEvent, "seqNo", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].seqNo));
  15273. json_object_object_add(TransactionEvent, "offline", json_object_new_boolean(ShmOCPP20Data->TransactionEvent[gun_index].offline));
  15274. if(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed > 0)
  15275. json_object_object_add(TransactionEvent, "numberOfPhasesUsed", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed));
  15276. if(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent > 0)
  15277. json_object_object_add(TransactionEvent, "cableMaxCurrent", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent));
  15278. if(ShmOCPP20Data->TransactionEvent[gun_index].reservationId > 0)
  15279. json_object_object_add(TransactionEvent, "reservationId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].reservationId));
  15280. json_object_object_add(transactionInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId));
  15281. json_object_object_add(transactionInfo, "chargingState", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState));
  15282. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging > 0)
  15283. json_object_object_add(transactionInfo, "timeSpentCharging", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging));
  15284. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason) > 0)
  15285. json_object_object_add(transactionInfo, "stoppedReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason));
  15286. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId > 0)
  15287. json_object_object_add(transactionInfo, "remoteStartId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId));
  15288. json_object_object_add(TransactionEvent, "transactionInfo", transactionInfo);
  15289. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken) > 0)
  15290. {
  15291. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
  15292. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type));
  15293. json_object_object_add(TransactionEvent, "idToken", idToken);
  15294. }
  15295. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.id));
  15296. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId));
  15297. json_object_object_add(TransactionEvent, "evse", evse);
  15298. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0].timestamp) > 0)
  15299. {
  15300. for(int idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue);idxMeter++)
  15301. {
  15302. json_object *meterValue = json_object_new_object();
  15303. json_object *sampledValues = json_object_new_array();
  15304. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].timestamp));
  15305. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  15306. {
  15307. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0) &&
  15308. ((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)))
  15309. {
  15310. json_object *sampledValue = json_object_new_object();
  15311. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  15312. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  15313. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  15314. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  15315. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  15316. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  15317. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  15318. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  15319. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  15320. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  15321. {
  15322. json_object *unitOfMeasure = json_object_new_object();
  15323. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  15324. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  15325. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  15326. }
  15327. json_object_array_add(sampledValues, sampledValue);
  15328. }
  15329. }
  15330. json_object_object_add(meterValue, "sampledValue", sampledValues);
  15331. json_object_array_add(meterValues, meterValue);
  15332. }
  15333. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  15334. }
  15335. random_uuid(guid);
  15336. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL
  15337. , guid
  15338. , "TransactionEvent"
  15339. , json_object_to_json_string_ext(TransactionEvent, JSON_C_TO_STRING_PLAIN));
  15340. json_object_put(TransactionEvent);
  15341. // open file for writing
  15342. FILE *outfile;
  15343. outfile = fopen (TempStopTransaction, "w+");
  15344. //DEBUG_INFO("data = %s\n", queuedata);
  15345. fputs(message, outfile);
  15346. fputs("\n", outfile);
  15347. fclose (outfile);
  15348. }
  15349. void checkTempStopTransaction(int gun_index)
  15350. {
  15351. FILE *fptr1;
  15352. char ch;
  15353. char str[QUEUE_MESSAGE_LENGTH]={0};
  15354. char guid[37]={0};
  15355. char tempdata[65]={0};
  15356. char TempStopTransaction[256];
  15357. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  15358. fptr1 = fopen(TempStopTransaction, "r");
  15359. if (!fptr1)
  15360. {
  15361. //DEBUG_INFO("TempStopTransaction_%d not found or unable to open the input file!\n", (gun_index+1));
  15362. return ;
  15363. }
  15364. ch=fgetc(fptr1);
  15365. rewind(fptr1);
  15366. if(ch!=EOF)
  15367. {
  15368. // copy all contents to the temporary file except the specific line
  15369. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  15370. {
  15371. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  15372. if(str[0]=='\0')
  15373. {
  15374. break;
  15375. }
  15376. strncpy(guid, str+4, 36); //copy guid
  15377. sprintf(tempdata, "TransactionEvent,%d", (gun_index));
  15378. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  15379. {
  15380. //DEBUG_INFO("StopTransaction mapitem pass\n");
  15381. }
  15382. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  15383. memset(str,0,ARRAY_SIZE(str));
  15384. }
  15385. }
  15386. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  15387. fclose(fptr1);
  15388. remove(TempStopTransaction); // remove the original file
  15389. }
  15390. int GetWebSocketPingInterval(void)
  15391. {
  15392. return atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].value);
  15393. }
  15394. int GetServerSign(void)
  15395. {
  15396. return server_sign;
  15397. }
  15398. uint8_t GetOcppSecurityProfile()
  15399. {
  15400. return atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].value);
  15401. }
  15402. void GetOcppChargerBoxId(uint8_t *data)
  15403. {
  15404. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  15405. }
  15406. void GetOcppSecurityPassword(uint8_t *data)
  15407. {
  15408. sprintf((char*)data, "%s", ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].value);
  15409. }
  15410. void SetServerSign(int value)
  15411. {
  15412. server_sign = value;
  15413. }
  15414. int GetBootNotificationInterval(void)
  15415. {
  15416. return BootNotificationInterval;
  15417. }
  15418. int GetInternetConn(void)
  15419. {
  15420. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  15421. }
  15422. int GetBackendConnectionTimeout(void)
  15423. {
  15424. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  15425. }
  15426. int isConnectorInitMode(int gun_index)
  15427. {
  15428. int tempIndex = 0;
  15429. int result = TRUE;
  15430. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  15431. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  15432. {
  15433. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15434. {
  15435. tempIndex = ((gun_index==2) ? 1: 0);
  15436. }
  15437. else
  15438. {
  15439. tempIndex = gun_index;
  15440. }
  15441. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15442. {
  15443. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  15444. {
  15445. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15446. } //end of the same index
  15447. }//end of for CHAdeMO_QUANTITY
  15448. }
  15449. else if(gunType[gun_index] == GUN_TYPE_CCS)
  15450. {
  15451. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15452. {
  15453. tempIndex = ((gun_index==2) ? 1: 0);
  15454. }
  15455. else
  15456. {
  15457. tempIndex = gun_index;
  15458. }
  15459. for (int index = 0; index < CCS_QUANTITY; index++)
  15460. {
  15461. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  15462. {
  15463. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15464. } //end of the same index
  15465. } // end of for CCS_QUANTITY
  15466. }
  15467. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15468. {
  15469. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15470. {
  15471. tempIndex = ((gun_index==2) ? 1: 0);
  15472. }
  15473. else
  15474. {
  15475. tempIndex = gun_index;
  15476. }
  15477. for (int index = 0; index < GB_QUANTITY; index++)
  15478. {
  15479. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15480. {
  15481. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15482. } //end of the same index
  15483. } // end of for GB_QUANTITY
  15484. }
  15485. else if(gunType[gun_index] == GUN_TYPE_DO)
  15486. {
  15487. tempIndex = gun_index;
  15488. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15489. {
  15490. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15491. {
  15492. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15493. } //end of the same index
  15494. }
  15495. }
  15496. else
  15497. {
  15498. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15499. {
  15500. tempIndex = 2;
  15501. }
  15502. else
  15503. {
  15504. tempIndex = gun_index;
  15505. }
  15506. for (int index = 0; index < AC_QUANTITY; index++)
  15507. {
  15508. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15509. {
  15510. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15511. }//end of the same index
  15512. }//end of for AC_QUANTITY
  15513. }
  15514. return result;
  15515. }
  15516. void refreshProcDogTimer()
  15517. {
  15518. ShmOCPP20Data->procDogTime = time((time_t*)NULL);
  15519. }
  15520. void InitialSystemValue(void)
  15521. {
  15522. int connectorIndex = 0;
  15523. gunTotalNumber=0;
  15524. SystemInitial = 0;
  15525. localversion=0;
  15526. BootNotificationInterval = 10;
  15527. authorizeRetryTimes = 0;
  15528. GunStatusInterval = 10;
  15529. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].value);
  15530. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].value);
  15531. //Hear Beat
  15532. HeartBeatWithNOResponse = 0;
  15533. HeartBeatCountPerHour = 0;
  15534. HeartBeatWaitTime = atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value);;
  15535. FirstHeartBeat = 0;
  15536. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle; // Idle
  15537. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle; // Idle
  15538. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  15539. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  15540. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  15541. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  15542. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  15543. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  15544. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  15545. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  15546. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  15547. memset(gunType, 0, ARRAY_SIZE(gunType));
  15548. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15549. {
  15550. if((ShmSysConfigAndInfo->SysConfig.ModelName[1]=='B') ||
  15551. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='K') ||
  15552. (ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O'))
  15553. {
  15554. // DO series
  15555. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  15556. {
  15557. SystemInitial = SystemInitial + 1;
  15558. gunTotalNumber = gunTotalNumber + 1;
  15559. gunType[connectorIndex] = GUN_TYPE_DO;
  15560. connectorIndex = connectorIndex + 1;
  15561. }
  15562. }
  15563. else
  15564. {
  15565. // DM, DW, DS series
  15566. //check connector / socket type (index: 8, 9, 10)
  15567. for(int index=7; index <10 ; index++)
  15568. {
  15569. if(index != 8)
  15570. {
  15571. // DC Connector
  15572. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  15573. {
  15574. SystemInitial = SystemInitial + 1;
  15575. gunTotalNumber = gunTotalNumber + 1;
  15576. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  15577. connectorIndex = connectorIndex + 1;
  15578. }
  15579. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  15580. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  15581. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  15582. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  15583. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  15584. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  15585. {
  15586. SystemInitial = SystemInitial + 1;
  15587. gunTotalNumber = gunTotalNumber + 1;
  15588. gunType[connectorIndex] = GUN_TYPE_CCS;
  15589. connectorIndex = connectorIndex + 1;
  15590. }
  15591. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  15592. {
  15593. SystemInitial = SystemInitial + 1;
  15594. gunTotalNumber = gunTotalNumber + 1;
  15595. gunType[connectorIndex] = GUN_TYPE_GBT;
  15596. connectorIndex = connectorIndex + 1;
  15597. }
  15598. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  15599. {
  15600. SystemInitial = SystemInitial + 1;
  15601. gunTotalNumber = gunTotalNumber + 1;
  15602. gunType[connectorIndex] = GUN_TYPE_DO;
  15603. connectorIndex = connectorIndex + 1;
  15604. }
  15605. }
  15606. else
  15607. {
  15608. // AC Connector
  15609. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15610. {
  15611. SystemInitial = SystemInitial + 1;
  15612. gunTotalNumber = gunTotalNumber + 1;
  15613. gunType[connectorIndex] = GUN_TYPE_AC;
  15614. connectorIndex = connectorIndex + 1;
  15615. }
  15616. }
  15617. }
  15618. }
  15619. //DEBUG_INFO("DC ...\n");
  15620. }
  15621. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  15622. {
  15623. //check connector / socket type (index: 8, 9, 10)
  15624. for(int index=7; index <10 ; index++)
  15625. {
  15626. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15627. {
  15628. SystemInitial = SystemInitial + 1;
  15629. gunTotalNumber = gunTotalNumber + 1;
  15630. gunType[connectorIndex] = GUN_TYPE_AC;
  15631. connectorIndex = connectorIndex + 1;
  15632. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  15633. }
  15634. }
  15635. }
  15636. //Status && ConnectorPlugIn Setting
  15637. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15638. {
  15639. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  15640. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  15641. }
  15642. for (int index = 0; index < CCS_QUANTITY; index++)
  15643. {
  15644. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  15645. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  15646. }
  15647. for (int index = 0; index < GB_QUANTITY; index++)
  15648. {
  15649. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  15650. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  15651. }
  15652. for (int index = 0; index < AC_QUANTITY; index++)
  15653. {
  15654. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  15655. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  15656. }
  15657. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15658. {
  15659. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  15660. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  15661. }
  15662. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  15663. {
  15664. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  15665. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  15666. cpinitateMsg.bits[gun_index].StatusNotificationConf = OFF;
  15667. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  15668. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  15669. memset(&ShmOCPP20Data->StatusNotification[gun_index], 0x00, sizeof(struct StatusNotification_20));
  15670. }
  15671. clientTime.Heartbeat=time((time_t*)NULL);
  15672. sleep(1);
  15673. }
  15674. void LWS_Send(char *str)
  15675. {
  15676. //=====================================================
  15677. // Check InternetConn 0: disconnected, 1: connected
  15678. //====================================================
  15679. if(GetOcppConnStatus() == 0)
  15680. {
  15681. DEBUG_INFO("offline now !!!\n");
  15682. return;
  15683. }
  15684. // Only disable isWebsocketSendable operation initiated by charger
  15685. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15686. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15687. || (strstr((char*)str, "\"ClearedChargingLimit\"") != NULL)
  15688. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15689. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15690. || (strstr((char*)str, "\"Get15118EVCertificate\"") != NULL)
  15691. || (strstr((char*)str, "\"GetCertificateStatus\"") != NULL)
  15692. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15693. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15694. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15695. || (strstr((char*)str, "\"NotifyChargingLimit\"") != NULL)
  15696. || (strstr((char*)str, "\"NotifyCustomerInformation\"") != NULL)
  15697. || (strstr((char*)str, "\"NotifyDisplayMessages\"") != NULL)
  15698. || (strstr((char*)str, "\"NotifyEVChargingNeeds\"") != NULL)
  15699. || (strstr((char*)str, "\"NotifyEVChargingSchedule\"") != NULL)
  15700. || (strstr((char*)str, "\"NotifyEvent\"") != NULL)
  15701. || (strstr((char*)str, "\"NotifyMonitoringReport\"") != NULL)
  15702. || (strstr((char*)str, "\"NotifyReport\"") != NULL)
  15703. || (strstr((char*)str, "\"PublishFirmwareStatusNotification\"") != NULL)
  15704. || (strstr((char*)str, "\"ReportChargingProfiles\"") != NULL)
  15705. || (strstr((char*)str, "\"ReservationStatusUpdate\"") != NULL)
  15706. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15707. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15708. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15709. || (strstr((char*)str, "\"TransactionEven\"") != NULL))
  15710. {
  15711. isWebsocketSendable = OFF;
  15712. }
  15713. pthread_mutex_lock(&lock_send);
  15714. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15715. sprintf((char *)SendBuffer, "%s", str);
  15716. SendBufLen = strlen(str);
  15717. pthread_mutex_unlock(&lock_send);
  15718. lws_callback_on_writable(wsi_client);
  15719. //lws_service(context, 0);
  15720. //sleep(1);
  15721. }
  15722. void LWS_SendNow(char *str)
  15723. {
  15724. //=====================================================
  15725. // Check InternetConn 0: disconnected, 1: connected
  15726. //====================================================
  15727. if(GetOcppConnStatus() == 0)
  15728. {
  15729. DEBUG_INFO("offline now !!!\n");
  15730. return;
  15731. }
  15732. // Only disable isWebsocketSendable operation initiated by charger
  15733. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15734. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15735. || (strstr((char*)str, "\"ClearedChargingLimit\"") != NULL)
  15736. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15737. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15738. || (strstr((char*)str, "\"Get15118EVCertificate\"") != NULL)
  15739. || (strstr((char*)str, "\"GetCertificateStatus\"") != NULL)
  15740. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15741. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15742. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15743. || (strstr((char*)str, "\"NotifyChargingLimit\"") != NULL)
  15744. || (strstr((char*)str, "\"NotifyCustomerInformation\"") != NULL)
  15745. || (strstr((char*)str, "\"NotifyDisplayMessages\"") != NULL)
  15746. || (strstr((char*)str, "\"NotifyEVChargingNeeds\"") != NULL)
  15747. || (strstr((char*)str, "\"NotifyEVChargingSchedule\"") != NULL)
  15748. || (strstr((char*)str, "\"NotifyEvent\"") != NULL)
  15749. || (strstr((char*)str, "\"NotifyMonitoringReport\"") != NULL)
  15750. || (strstr((char*)str, "\"NotifyReport\"") != NULL)
  15751. || (strstr((char*)str, "\"PublishFirmwareStatusNotification\"") != NULL)
  15752. || (strstr((char*)str, "\"ReportChargingProfiles\"") != NULL)
  15753. || (strstr((char*)str, "\"ReservationStatusUpdate\"") != NULL)
  15754. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15755. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15756. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15757. || (strstr((char*)str, "\"TransactionEven\"") != NULL))
  15758. {
  15759. isWebsocketSendable = OFF;
  15760. }
  15761. pthread_mutex_lock(&lock_send);
  15762. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15763. sprintf((char *)SendBuffer, "%s", str);
  15764. SendBufLen = strlen(str);
  15765. pthread_mutex_unlock(&lock_send);
  15766. lws_callback_on_writable(wsi_client);
  15767. lws_service(context, 0);
  15768. //sleep(1);
  15769. }