MessageHandler.c 894 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442
  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. int TransactionMessageAttemptsGet(void);
  727. int TransactionMessageRetryIntervalGet(void);
  728. int GetOcppConnStatus(void);
  729. void SetOcppConnStatus(uint8_t status);
  730. int setKeyValue(char *key, char *value);
  731. void OCPP_get_TableAuthlocalAllData(void);
  732. void processUnkownKey(void);
  733. struct StructOCPPMeterValue
  734. {
  735. unsigned char TimeStamp[28];
  736. struct StructSampledValue SampledValue[10];
  737. };
  738. struct ClientTime
  739. {
  740. unsigned int Heartbeat;
  741. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  742. unsigned int StartTransaction;
  743. unsigned int StopTransaction;
  744. unsigned int MeterValues[CONNECTOR_QUANTITY];
  745. }clientTime;
  746. typedef union
  747. {
  748. //Operations Initiated by Central System
  749. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  750. struct
  751. {
  752. //CsMsgValue[0]
  753. unsigned char StatusNotificationReq:1; //bit 0,
  754. unsigned char StatusNotificationConf:1; //bit 1,
  755. unsigned char TriggerMeterValueReq:1; //bit 2,
  756. unsigned char TransactionEventReq:1; //bit 3,
  757. unsigned char SampleMeterReq:1; //bit 4,
  758. unsigned char ClockAlignMeterReq:1; //bit 5,
  759. unsigned char :2;
  760. }bits[CONNECTOR_QUANTITY];
  761. }CpinitiateMsg;
  762. CpinitiateMsg cpinitateMsg;
  763. //=========================================
  764. // Date time related function
  765. //=========================================
  766. void getNowDatetime(uint8_t *data)
  767. {
  768. time_t t = time(NULL);
  769. struct tm tm = *localtime(&t);
  770. 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);
  771. }
  772. //=========================================
  773. // Sqlite3 related function
  774. //=========================================
  775. int DB_Initial()
  776. {
  777. int result = PASS;
  778. char* errMsg = NULL;
  779. char *sqlOcppAuthCache = "create table if not exists ocpp20_auth_cache (idx integer primary key,"
  780. "idToken text UNIQUE,"
  781. "type text,"
  782. "status text,"
  783. "cacheExpiryDateTime text,"
  784. "chargingPriority integer,"
  785. "language1 text,"
  786. "evseId text,"
  787. "language2 text,"
  788. "groupIdToken_idToken text,"
  789. "groupIdToken_type text,"
  790. "personalMessage text);";
  791. char *sqlOcppAuthLocal = "create table if not exists ocpp20_auth_local (idx integer primary key,"
  792. "idToken text UNIQUE,"
  793. "type text,"
  794. "status text,"
  795. "cacheExpiryDateTime text,"
  796. "chargingPriority integer,"
  797. "language1 text,"
  798. "evseId text,"
  799. "language2 text,"
  800. "groupIdToken_idToken text,"
  801. "groupIdToken_type text,"
  802. "personalMessage text,"
  803. "version text);";
  804. char *sqlOcppVariable = "create table if not exists ocpp20_variable (idx integer primary key,"
  805. "componentName text NOT NULL ,"
  806. "componentInstance text, "
  807. "variableName text NOT NULL, "
  808. "variableInstance text, "
  809. "variableCharacteristicsDataType integer, "
  810. "variableCharacteristicsUnit text, "
  811. "variableCharacteristicsMaxLimit real,"
  812. "variableAttributesType text, "
  813. "variableAttributesTypeMutability text, "
  814. "variableAttributesTypeValue text, "
  815. "unique(componentName, componentInstance,variableName, variableInstance) on conflict replace);";
  816. char *sqlBootType = "create table if not exists ocpp20_boot_type (idx integer primary key,"
  817. "type text);";
  818. char *sqlNetworkProfile = "create table if not exists ocpp20_networkprofile (idx integer primary key,"
  819. "slot integer UNIQUE, connectionData text);";
  820. char *sqlTransaction = "create table if not exists ocpp20_transaction_record (idx integer primary key,"
  821. "occurDatetime text,"
  822. "message_type text,"
  823. "message_content text)";
  824. //sqlite3_config(SQLITE_CONFIG_URI, 1);
  825. if(sqlite3_open(OCPP_LOCAL_DB_FILE, &db))
  826. {
  827. result = FAIL;
  828. DEBUG_ERROR( "Can't open database: %s\n", sqlite3_errmsg(db));
  829. sqlite3_close(db);
  830. }
  831. else
  832. {
  833. DEBUG_INFO( "OCPP local database open successfully.\n");
  834. if (sqlite3_exec(db, sqlOcppAuthCache, 0, 0, &errMsg) != SQLITE_OK)
  835. {
  836. result = FAIL;
  837. DEBUG_ERROR( "Create OCPP 2.0 auth cache table error message: %s\n", errMsg);
  838. }
  839. else
  840. {
  841. DEBUG_INFO( "Create OCPP 2.0 auth cache table table successfully\n");
  842. }
  843. if (sqlite3_exec(db, sqlOcppAuthLocal, 0, 0, &errMsg) != SQLITE_OK)
  844. {
  845. result = FAIL;
  846. DEBUG_ERROR( "Create OCPP 2.0 auth list table error message: %s\n", errMsg);
  847. }
  848. else
  849. {
  850. DEBUG_INFO( "Create OCPP 2.0 auth list table successfully\n");
  851. }
  852. if (sqlite3_exec(db, sqlOcppVariable, 0, 0, &errMsg) != SQLITE_OK)
  853. {
  854. result = FAIL;
  855. DEBUG_ERROR( "Create OCPP 2.0 variable table error message: %s\n", errMsg);
  856. }
  857. else
  858. {
  859. DEBUG_INFO( "Create OCPP 2.0 variable table successfully\n");
  860. }
  861. if (sqlite3_exec(db, sqlBootType, 0, 0, &errMsg) != SQLITE_OK)
  862. {
  863. result = FAIL;
  864. DEBUG_ERROR( "Create OCPP 2.0 boot_type table error message: %s\n", errMsg);
  865. }
  866. else
  867. {
  868. DEBUG_INFO( "Create OCPP 2.0 boot_type table successfully\n");
  869. }
  870. if (sqlite3_exec(db, sqlNetworkProfile, 0, 0, &errMsg) != SQLITE_OK)
  871. {
  872. result = FAIL;
  873. DEBUG_ERROR( "Create OCPP 2.0 ocpp20_networkprofile table error message: %s\n", errMsg);
  874. }
  875. else
  876. {
  877. DEBUG_INFO( "Create OCPP 2.0 ocpp20_networkprofile table successfully\n");
  878. }
  879. if (sqlite3_exec(db, sqlTransaction, 0, 0, &errMsg) != SQLITE_OK)
  880. {
  881. result = FAIL;
  882. DEBUG_ERROR( "Create OCPP 2.0 ocpp20_transaction_record table error message: %s\n", errMsg);
  883. }
  884. else
  885. {
  886. DEBUG_INFO( "Create OCPP 2.0 ocpp20_transaction_record table successfully\n");
  887. }
  888. //sqlite3_close(db);
  889. }
  890. return result;
  891. }
  892. int DB_cbGetVersion(void *para, int columnCount, char **columnValue, char **columnName)
  893. {
  894. localversion = columnValue[12] ? atoi(columnValue[12]) : 0;
  895. return 0;
  896. }
  897. void DB_getListVerion()
  898. {
  899. char sql[256];
  900. char* errMsg = NULL;
  901. strcpy(sql, "select * from ocpp20_auth_local order by version desc, idx desc limit 1");
  902. /* Execute SQL statement */
  903. if( sqlite3_exec(db, sql, DB_cbGetVersion, 0, &errMsg) != SQLITE_OK )
  904. {
  905. DEBUG_INFO("SQL error: %s", errMsg);
  906. }
  907. }
  908. int DB_cbGetIdTag(void *para, int columnCount, char **columnValue, char **columnName)
  909. {
  910. sprintf((char*)idTagQuery.idToken.idToken,"%s", columnValue[1] ? columnValue[1] : "NULL");
  911. sprintf((char*)idTagQuery.idToken.type,"%s", columnValue[2] ? columnValue[2] : "NULL");
  912. sprintf((char*)idTagQuery.idTokenInfo.status,"%s", columnValue[3] ? columnValue[3] : "NULL");
  913. sprintf((char*)idTagQuery.idTokenInfo.cacheExpiryDateTime,"%s", columnValue[4] ? columnValue[4] : "NULL");
  914. idTagQuery.idTokenInfo.chargingPriority = columnValue[5] ? atoi(columnValue[5]) : -1;
  915. sprintf((char*)idTagQuery.idTokenInfo.language1,"%s", columnValue[6] ? columnValue[6] : "NULL");
  916. sprintf((char*)idTagQuery.idTokenInfo.language2,"%s", columnValue[8] ? columnValue[8] : "NULL");
  917. sprintf((char*)idTagQuery.idTokenInfo.groupIdToken.idToken,"%s", columnValue[9] ? columnValue[9] : "NULL");
  918. sprintf((char*)idTagQuery.idTokenInfo.groupIdToken.type,"%s", columnValue[10] ? columnValue[10] : "NULL");
  919. return 0;
  920. }
  921. void DB_getIdTag(char idTag[], uint8_t isQueryFromCache)
  922. {
  923. char sql[256];
  924. char* errMsg = NULL;
  925. memset(&idTagQuery, 0, sizeof(idTagQuery));
  926. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  927. if(isQueryFromCache)
  928. sprintf(sql,"select * from ocpp20_auth_cache where idToken='%s'", idTag);
  929. else
  930. sprintf(sql,"select * from ocpp20_auth_local where idToken='%s'", idTag);
  931. /* Execute SQL statement */
  932. if(sqlite3_exec(db, sql, DB_cbGetIdTag, 0, &errMsg) != SQLITE_OK )
  933. {
  934. DEBUG_INFO("SQL error: %s", errMsg);
  935. }
  936. }
  937. int DB_cbTableAuthlocalAllData(void *para, int columnCount, char **columnValue, char **columnName)
  938. {
  939. for (int i = 0; i < columnCount; i++)
  940. {
  941. DEBUG_INFO("%s = %s, ", columnName[i], columnValue[i]);
  942. }
  943. return 0;
  944. }
  945. void DB_get_TableAuthlocalAllData(void)
  946. {
  947. char sql[256];
  948. char* errMsg = NULL;
  949. sprintf(sql,"select * from ocpp20_auth_local;");
  950. /* Execute SQL statement */
  951. if(sqlite3_exec(db, sql, DB_cbTableAuthlocalAllData, 0,&errMsg) != SQLITE_OK)
  952. {
  953. DEBUG_INFO("SQL error: %s", errMsg);
  954. }
  955. }
  956. int DB_cbAddLocalListCache(void *para, int columnCount, char **columnValue, char **columnName)
  957. {
  958. for(int i = 0; i<columnCount; i++)
  959. {
  960. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  961. }
  962. return 0;
  963. }
  964. int DB_addLocalList(int listVersion, struct AuthorizationData *data)
  965. {
  966. int result = PASS;
  967. char sql[512];
  968. char* errMsg = NULL;
  969. 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;",
  970. data->idToken.idToken,
  971. data->idToken.type,
  972. data->idTokenInfo.status,
  973. data->idTokenInfo.cacheExpiryDateTime,
  974. data->idTokenInfo.chargingPriority,
  975. data->idTokenInfo.language1,
  976. data->idTokenInfo.language2,
  977. data->idTokenInfo.groupIdToken.idToken,
  978. data->idTokenInfo.groupIdToken.type,
  979. listVersion);
  980. //* Execute SQL statement */
  981. if(sqlite3_exec(db, sql, DB_cbAddLocalListCache, 0, &errMsg) != SQLITE_OK)
  982. {
  983. DEBUG_INFO("SQL error: %s\n", errMsg);
  984. result = FAIL;
  985. }
  986. else
  987. {
  988. memset(sql, 0, ARRAY_SIZE(sql));
  989. sprintf(sql, "UPDATE ocpp20_auth_local SET version=%d",listVersion);
  990. if( sqlite3_exec(db, sql, NULL, NULL, &errMsg) != SQLITE_OK )
  991. {
  992. DEBUG_INFO("SQL error: %s\n", errMsg);
  993. result = FAIL;
  994. }
  995. }
  996. return result;
  997. }
  998. int DB_addLocalCache(struct IdTokenType *idToken, struct IdTokenInfoType *idTokenInfo)
  999. {
  1000. int result = PASS;
  1001. char sql[512];
  1002. char* errMsg = NULL;
  1003. 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;",
  1004. idToken->idToken,
  1005. idToken->type,
  1006. idTokenInfo->status,
  1007. idTokenInfo->cacheExpiryDateTime,
  1008. idTokenInfo->chargingPriority,
  1009. idTokenInfo->language1,
  1010. idTokenInfo->language2,
  1011. idTokenInfo->groupIdToken.idToken,
  1012. idTokenInfo->groupIdToken.type);
  1013. //* Execute SQL statement */
  1014. if(sqlite3_exec(db, sql, DB_cbAddLocalListCache, 0, &errMsg) != SQLITE_OK)
  1015. {
  1016. DEBUG_INFO("SQL error: %s\n", errMsg);
  1017. result = FAIL;
  1018. }
  1019. return result;
  1020. }
  1021. int deleteIdTagcallback(void *para, int columnCount, char **columnValue, char **columnName)
  1022. {
  1023. // localversion = argv[5] ? atoi(columnValue[5]) : 0;
  1024. // printf("localversion=%d\n", localversion);
  1025. return 0;
  1026. }
  1027. void DB_deleteIdTag(char idTag[])
  1028. {
  1029. char sql[512];
  1030. char* errMsg = NULL;
  1031. sprintf(sql,"DELETE from ocpp20_auth_local where idToken='%s'; SELECT * from ocpp20_auth_local;", idTag);
  1032. //* Execute SQL statement */
  1033. if( sqlite3_exec(db, sql, deleteIdTagcallback, 0, &errMsg) != SQLITE_OK )
  1034. {
  1035. DEBUG_INFO("SQL error: %s", errMsg);
  1036. }
  1037. }
  1038. int DB_cleanLocalList()
  1039. {
  1040. int result = PASS;
  1041. char * sqlcleanLocalList = "delete from ocpp20_auth_cache";
  1042. char *errMsg = 0;
  1043. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1044. {
  1045. DEBUG_INFO("%s\n", errMsg);
  1046. result = FAIL;
  1047. }
  1048. return result;
  1049. }
  1050. int DB_cleanLocalCache()
  1051. {
  1052. int result = PASS;
  1053. char * sqlcleanLocalList = "delete from ocpp20_auth_local";
  1054. char *errMsg = 0;
  1055. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1056. {
  1057. DEBUG_INFO("%s\n", errMsg);
  1058. result = FAIL;
  1059. }
  1060. return result;
  1061. }
  1062. int BootTypecallback(void *para, int columnCount, char **columnValue, char **columnName)
  1063. {
  1064. sprintf((char*)ShmOCPP20Data->BootNotification.reason,"%s", columnValue[1] ? columnValue[1] : BootReasonEnumTypeStr[BootReasonEnumType_PowerUp]);
  1065. return 0;
  1066. }
  1067. void DB_getBooType()
  1068. {
  1069. char sql[256];
  1070. char* errMsg = NULL;
  1071. sprintf(sql,"select * from ocpp20_boot_type;");
  1072. /* Execute SQL statement */
  1073. if(sqlite3_exec(db, sql, BootTypecallback, 0, &errMsg) != SQLITE_OK )
  1074. {
  1075. DEBUG_INFO("SQL error: %s\n", errMsg);
  1076. }
  1077. }
  1078. int DB_cbUpdateBootType(void *para, int columnCount, char **columnValue, char **columnName)
  1079. {
  1080. for(int i = 0; i<columnCount; i++)
  1081. {
  1082. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1083. }
  1084. return 0;
  1085. }
  1086. int DB_updateBootType(BootReasonEnumType reason)
  1087. {
  1088. int result = PASS;
  1089. char sql[512];
  1090. char* errMsg = NULL;
  1091. sprintf(sql,"insert or replace into ocpp20_boot_type (idx, type) VALUES(1, '%s');", BootReasonEnumTypeStr[reason>BootReasonEnumType_Watchdog?BootReasonEnumType_PowerUp:reason]);
  1092. //* Execute SQL statement */
  1093. if(sqlite3_exec(db, sql, DB_cbUpdateBootType, 0, &errMsg) != SQLITE_OK)
  1094. {
  1095. DEBUG_INFO("SQL error: %s\n", errMsg);
  1096. result = FAIL;
  1097. }
  1098. return result;
  1099. }
  1100. int DB_cbVariableSaveToDb(void *para, int columnCount, char **columnValue, char **columnName)
  1101. {
  1102. for(int i = 0; i<columnCount; i++)
  1103. {
  1104. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1105. }
  1106. return 0;
  1107. }
  1108. int DB_variableSaveToDb(struct ReportDataType *variable)
  1109. {
  1110. int result = FAIL;
  1111. char sql[4096];
  1112. char* errMsg = NULL;
  1113. 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;",
  1114. variable->component.name,
  1115. variable->component.instance,
  1116. variable->variable.name,
  1117. variable->variable.instance,
  1118. variable->variableCharacteristics.dataType,
  1119. variable->variableCharacteristics.unit,
  1120. variable->variableCharacteristics.maxLimit,
  1121. variable->variableAttribute[0].type,
  1122. variable->variableAttribute[0].mutability,
  1123. variable->variableAttribute[0].value);
  1124. //* Execute SQL statement */
  1125. if(sqlite3_exec(db, sql, DB_cbVariableSaveToDb, 0, &errMsg) != SQLITE_OK)
  1126. {
  1127. DEBUG_INFO("SQL error: %s\n", errMsg);
  1128. result = FAIL;
  1129. }
  1130. return result;
  1131. }
  1132. int DB_cbVariableIsCreate(void *para, int columnCount, char **columnValue, char **columnName)
  1133. {
  1134. memset(&ShmOCPP20Data->ControllerComponentVariable[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable));
  1135. if(atoi(columnValue[0]) == 0)
  1136. {
  1137. DB_updateBootType(BootReasonEnumType_PowerUp);
  1138. // Create variable table content
  1139. /* AlignedDataCtrlr Required item */
  1140. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].component.name, "AlignedDataCtrlr");
  1141. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variable.name, "Enabled");
  1142. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1143. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1144. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1145. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1146. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled]);
  1147. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].component.name, "AlignedDataCtrlr");
  1148. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variable.name, "Available");
  1149. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1150. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1151. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1152. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].value, "TRUE");
  1153. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available]);
  1154. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].component.name, "AlignedDataCtrlr");
  1155. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variable.name, "Measurands");
  1156. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1157. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableCharacteristics.maxLimit = 10;
  1158. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1159. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1160. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1161. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC");
  1162. else
  1163. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage");
  1164. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands]);
  1165. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].component.name, "AlignedDataCtrlr");
  1166. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variable.name, "Interval");
  1167. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.unit, "Seconds");
  1168. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1169. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.minLimit = 10;
  1170. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1171. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1172. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value, "0");
  1173. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval]);
  1174. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].component.name, "AlignedDataCtrlr");
  1175. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variable.name, "SendDuringIdle");
  1176. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1177. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1178. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1179. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].value, "TRUE");
  1180. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle]);
  1181. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].component.name, "AlignedDataCtrlr");
  1182. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variable.name, "SignReadings");
  1183. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1184. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1185. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1186. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].value, "FALSE");
  1187. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings]);
  1188. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].component.name, "AlignedDataCtrlr");
  1189. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  1190. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1191. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableCharacteristics.maxLimit = 10;
  1192. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1193. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1194. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1195. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC");
  1196. else
  1197. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage");
  1198. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands]);
  1199. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].component.name, "AlignedDataCtrlr");
  1200. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  1201. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableCharacteristics.unit, "Seconds");
  1202. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1203. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1204. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1205. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].value, "0");
  1206. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval]);
  1207. /* AuthCtrlrVariable Required item */
  1208. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].component.name, "AuthCtrlr");
  1209. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variable.name, "Enabled");
  1210. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1211. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1212. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1213. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1214. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled]);
  1215. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].component.name, "AlignedDataCtrlr");
  1216. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variable.name, "AdditionalInfoItemsPerMessage");
  1217. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1218. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1219. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1220. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].value, "0");
  1221. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage]);
  1222. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].component.name, "AuthCtrlr");
  1223. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variable.name, "OfflineTxForUnknownIdEnabled");
  1224. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1225. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1226. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1227. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].value, "FALSE");
  1228. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled]);
  1229. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].component.name, "AuthCtrlr");
  1230. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variable.name, "AuthorizeRemoteStart");
  1231. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1232. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1233. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1234. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].value, "FALSE");
  1235. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart]);
  1236. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].component.name, "AuthCtrlr");
  1237. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variable.name, "LocalAuthorizeOffline");
  1238. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1239. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1240. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1241. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "TRUE");
  1242. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline]);
  1243. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].component.name, "AuthCtrlr");
  1244. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variable.name, "LocalPreAuthorize");
  1245. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1246. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1247. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1248. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].value, "TRUE");
  1249. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize]);
  1250. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].component.name, "AuthCtrlr");
  1251. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variable.name, "MasterPassGroupId");
  1252. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1253. ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableCharacteristics.maxLimit = 36;
  1254. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1255. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1256. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].value, " ");
  1257. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId]);
  1258. /* AuthCacheCtrlr Variable Required item*/
  1259. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].component.name, "AuthCacheCtrlr");
  1260. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variable.name, "Enabled");
  1261. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1262. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1263. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1264. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1265. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled]);
  1266. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].component.name, "AuthCacheCtrlr");
  1267. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variable.name, "Available");
  1268. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1269. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1270. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1271. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].value, "TRUE");
  1272. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available]);
  1273. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].component.name, "AuthCacheCtrlr");
  1274. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variable.name, "LifeTime");
  1275. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableCharacteristics.unit, "Seconds");
  1276. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1277. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1278. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1279. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].value, "TRUE");
  1280. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime]);
  1281. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].component.name, "AuthCacheCtrlr");
  1282. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variable.name, "Storage");
  1283. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1284. ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableCharacteristics.maxLimit = (1024*10);
  1285. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1286. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1287. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].value, "TRUE");
  1288. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage]);
  1289. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].component.name, "AuthCacheCtrlr");
  1290. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variable.name, "Policy");
  1291. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1292. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1293. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1294. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].value, "LRU,LFU");
  1295. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy]);
  1296. /* ClockCtrlr Variable Required item */
  1297. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].component.name, "ClockCtrlr");
  1298. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variable.name, "DateTime");
  1299. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_dateTime]);
  1300. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1301. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1302. getNowDatetime(ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].value);
  1303. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime]);
  1304. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].component.name, "ClockCtrlr");
  1305. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variable.name, "NtpSource");
  1306. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1307. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1308. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1309. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].value, "DHCP, manual");
  1310. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource]);
  1311. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].component.name, "ClockCtrlr");
  1312. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.name, "NtpServerUri");
  1313. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.instance, "1");
  1314. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1315. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1316. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1317. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].value, " ");
  1318. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri]);
  1319. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].component.name, "ClockCtrlr");
  1320. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variable.name, "TimeOffset");
  1321. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1322. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1323. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1324. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].value, "+00:00");
  1325. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset]);
  1326. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].component.name, "ClockCtrlr");
  1327. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variable.name, "NextTimeOffsetTransitionDateTime");
  1328. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_dateTime]);
  1329. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1330. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1331. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].value, " ");
  1332. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime]);
  1333. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].component.name, "ClockCtrlr");
  1334. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.name, "TimeOffset");
  1335. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.instance, "NextTransition");
  1336. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1337. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1338. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1339. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].value, "+00:00");
  1340. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset]);
  1341. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].component.name, "ClockCtrlr");
  1342. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variable.name, "TimeSource");
  1343. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_SequenceList]);
  1344. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1345. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1346. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].value, "Heartbeat,RealTimeClock");
  1347. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource]);
  1348. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].component.name, "ClockCtrlr");
  1349. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variable.name, "TimeZone");
  1350. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1351. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1352. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1353. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].value, "UTC");
  1354. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone]);
  1355. /* ChargingStation Required item */
  1356. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].component.name, "ChargingStation");
  1357. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variable.name, "Available");
  1358. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1359. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1360. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1361. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].value, "FALSE");
  1362. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available]);
  1363. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].component.name, "ChargingStation");
  1364. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variable.name, "AvailabilityState");
  1365. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1366. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1367. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1368. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].value, "Available,Occupied,Reserved,Unavailable,Faulted");
  1369. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState]);
  1370. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].component.name, "ChargingStation");
  1371. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variable.name, "SupplyPhases");
  1372. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1373. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1374. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1375. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].value, "3");
  1376. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases]);
  1377. /* Connector Required item */
  1378. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].component.name, "Connector");
  1379. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variable.name, "Available");
  1380. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1381. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1382. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1383. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].value, "FALSE");
  1384. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_Available]);
  1385. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].component.name, "Connector");
  1386. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variable.name, "ConnectorType");
  1387. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1388. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1389. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1390. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].value, " ");
  1391. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType]);
  1392. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].component.name, "Connector");
  1393. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variable.name, "SupplyPhases");
  1394. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1395. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1396. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1397. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].value, "3");
  1398. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases]);
  1399. /* CustomizationCtrlr Required item */
  1400. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].component.name, "CustomizationCtrlr");
  1401. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variable.name, "CustomImplementationEnabled");
  1402. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1403. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1404. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1405. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].value, "FALSE");
  1406. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled]);
  1407. /* DeviceDataCtrlr Required item */
  1408. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  1409. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.instance, "GetReport");
  1410. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1411. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1412. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1413. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1414. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].value, "10");
  1415. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage]);
  1416. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  1417. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.instance, "GetVariables");
  1418. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1419. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1420. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1421. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1422. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].value, "10");
  1423. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage]);
  1424. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].component.name, "DeviceDataCtrlr");
  1425. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.instance, "GetReport");
  1426. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.name, "BytesPerMessage");
  1427. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1428. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1429. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1430. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].value, "2048");
  1431. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage]);
  1432. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  1433. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.instance, "GetVariables");
  1434. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  1435. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1436. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1437. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1438. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].value, "2048");
  1439. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage]);
  1440. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].component.name, "DeviceDataCtrlr");
  1441. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variable.name, "ConfigurationValueSize");
  1442. ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableCharacteristics.maxLimit = 1000;
  1443. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1444. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1445. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1446. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].value, "10");
  1447. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize]);
  1448. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].component.name, "DeviceDataCtrlr");
  1449. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variable.name, "ReportingValueSize");
  1450. ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableCharacteristics.maxLimit = 2500;
  1451. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1452. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1453. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1454. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].value, "10");
  1455. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize]);
  1456. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  1457. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.instance, "SetVariables");
  1458. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1459. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1460. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1461. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1462. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].value, "10");
  1463. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage]);
  1464. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  1465. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.instance, "SetVariables");
  1466. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  1467. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1468. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1469. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1470. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].value, "2048");
  1471. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage]);
  1472. /* DisplayMessageCtrlr Required item */
  1473. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].component.name, "DisplayMessageCtrlr");
  1474. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variable.name, "Enabled");
  1475. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1476. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1477. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1478. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1479. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled]);
  1480. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].component.name, "DisplayMessageCtrlr");
  1481. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variable.name, "Available");
  1482. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1483. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1484. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1485. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].value, "FALSE");
  1486. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available]);
  1487. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].component.name, "DisplayMessageCtrlr");
  1488. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variable.name, "DisplayMessages");
  1489. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1490. ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableCharacteristics.maxLimit = 1;
  1491. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1492. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1493. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].value, "%s", "1");
  1494. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages]);
  1495. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].component.name, "DisplayMessageCtrlr");
  1496. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variable.name, "SupportedFormats");
  1497. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1498. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1499. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1500. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].value, " ");
  1501. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats]);
  1502. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].component.name, "DisplayMessageCtrlr");
  1503. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variable.name, "SupportedPriorities");
  1504. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1505. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1506. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1507. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].value, " ");
  1508. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities]);
  1509. /* EVSE Required item */
  1510. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].component.name, "EVSE");
  1511. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variable.name, "Available");
  1512. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1513. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1514. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1515. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].value, "FALSE");
  1516. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_Available]);
  1517. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].component.name, "EVSE");
  1518. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variable.name, "AvailabilityState");
  1519. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1520. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1521. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1522. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].value, "Available,Occupied,Reserved,Unavailable,Faulted");
  1523. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState]);
  1524. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].component.name, "EVSE");
  1525. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variable.name, "SupplyPhases");
  1526. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1527. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1528. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1529. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].value, "3");
  1530. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases]);
  1531. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].component.name, "EVSE");
  1532. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variable.name, "Power");
  1533. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_decimal]);
  1534. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1535. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1536. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].value, "7700");
  1537. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_Power]);
  1538. /* LocalAuthListCtrlr Required item */
  1539. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].component.name, "LocalAuthListCtrlr");
  1540. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variable.name, "Enabled");
  1541. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1542. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1543. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1544. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  1545. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled]);
  1546. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].component.name, "LocalAuthListCtrlr");
  1547. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variable.name, "Entries");
  1548. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1549. ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableCharacteristics.maxLimit = 5000;
  1550. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1551. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1552. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].value, "5000");
  1553. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries]);
  1554. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].component.name, "LocalAuthListCtrlr");
  1555. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variable.name, "Available");
  1556. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1557. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1558. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1559. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].value, "TRUE");
  1560. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available]);
  1561. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].component.name, "LocalAuthListCtrlr");
  1562. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1563. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.instance, "SendLocalList");
  1564. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1565. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1566. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1567. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].value, "50");
  1568. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage]);
  1569. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].component.name, "LocalAuthListCtrlr");
  1570. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.name, "BytesPerMessage");
  1571. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.instance, "SendLocalList");
  1572. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1573. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1574. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1575. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].value, "2048");
  1576. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage]);
  1577. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].component.name, "LocalAuthListCtrlr");
  1578. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variable.name, "Storage");
  1579. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1580. ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableCharacteristics.maxLimit = (1024*10);
  1581. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1582. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1583. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].value, "5000");
  1584. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage]);
  1585. /* MonitoringCtrlr Required item */
  1586. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].component.name, "MonitoringCtrlr");
  1587. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variable.instance, "Enabled");
  1588. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1589. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1590. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1591. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1592. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled]);
  1593. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].component.name, "MonitoringCtrlr");
  1594. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variable.instance, "Available");
  1595. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1596. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1597. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1598. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].value, "FALSE");
  1599. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available]);
  1600. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  1601. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.instance, "ClearVariableMonitoring");
  1602. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1603. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1604. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1605. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1606. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].value, "1");
  1607. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage]);
  1608. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  1609. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.instance, "SetVariableMonitoring");
  1610. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1611. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1612. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1613. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1614. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].value, "1");
  1615. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage]);
  1616. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  1617. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.instance, "ClearVariableMonitoring");
  1618. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  1619. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1620. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1621. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1622. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].value, "2048");
  1623. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage]);
  1624. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  1625. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.instance, "SetVariableMonitoring");
  1626. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  1627. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1628. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1629. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1630. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].value, "2048");
  1631. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage]);
  1632. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].component.name, "MonitoringCtrlr");
  1633. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variable.name, "OfflineQueuingSeverity");
  1634. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1635. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1636. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1637. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].value, "2048");
  1638. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity]);
  1639. /* OCPPCommCtrlr Required item */
  1640. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].component.name, "OCPPCommCtrlr");
  1641. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variable.name, "ActiveNetworkProfile");
  1642. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1643. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1644. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1645. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].value, "1");
  1646. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile]);
  1647. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].component.name, "OCPPCommCtrlr");
  1648. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.instance, "Default");
  1649. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.name, "MessageTimeout");
  1650. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableCharacteristics.unit, "Seconds");
  1651. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1652. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1653. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1654. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].value, "30");
  1655. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout]);
  1656. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].component.name, "OCPPCommCtrlr");
  1657. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variable.name, "FileTransferProtocols");
  1658. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1659. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1660. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1661. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].value, "FTP,FTPS,HTTP,HTTPS");
  1662. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols]);
  1663. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].component.name, "OCPPCommCtrlr");
  1664. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variable.name, "HeartbeatInterval");
  1665. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.unit, "Seconds");
  1666. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1667. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1668. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1669. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value, "30");
  1670. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval]);
  1671. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].component.name, "OCPPCommCtrlr");
  1672. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variable.name, "NetworkConfigurationPriority");
  1673. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_SequenceList]);
  1674. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1675. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1676. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value, "[0]");
  1677. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority]);
  1678. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].component.name, "OCPPCommCtrlr");
  1679. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variable.name, "NetworkProfileConnectionAttempts");
  1680. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1681. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1682. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1683. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].value, "3");
  1684. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts]);
  1685. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].component.name, "OCPPCommCtrlr");
  1686. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variable.name, "OfflineThreshold");
  1687. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableCharacteristics.unit, "Seconds");
  1688. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1689. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1690. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1691. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].value, "30");
  1692. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold]);
  1693. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].component.name, "OCPPCommCtrlr");
  1694. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variable.name, "QueueAllMessages");
  1695. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1696. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1697. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1698. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].value, "FALSE");
  1699. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages]);
  1700. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].component.name, "OCPPCommCtrlr");
  1701. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.instance, "TransactionEvent");
  1702. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.name, "MessageAttempts");
  1703. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableCharacteristics.unit, "Seconds");
  1704. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1705. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1706. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1707. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].value, "3");
  1708. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts]);
  1709. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].component.name, "OCPPCommCtrlr");
  1710. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.instance, "TransactionEvent");
  1711. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.name, "MessageAttemptInterval");
  1712. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableCharacteristics.unit, "Seconds");
  1713. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1714. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1715. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1716. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].value, "3");
  1717. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval]);
  1718. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].component.name, "OCPPCommCtrlr");
  1719. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variable.name, "UnlockOnEVSideDisconnect");
  1720. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1721. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1722. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1723. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].value, "TRUE");
  1724. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect]);
  1725. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].component.name, "OCPPCommCtrlr");
  1726. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variable.name, "WebSocketPingInterval");
  1727. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.unit, "Seconds");
  1728. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1729. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1730. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1731. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].value, "30");
  1732. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval]);
  1733. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].component.name, "OCPPCommCtrlr");
  1734. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variable.name, "ResetRetries");
  1735. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1736. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1737. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1738. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].value, "3");
  1739. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries]);
  1740. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].component.name, "OCPPCommCtrlr");
  1741. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variable.name, "PublicKeyWithSignedMeterValue");
  1742. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1743. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1744. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1745. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].value, "Never,OncePerTransaction,EveryMeterValue");
  1746. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue]);
  1747. /* ReservationCtrlr Required item */
  1748. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].component.name, "ReservationCtrlr");
  1749. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variable.name, "Enabled");
  1750. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1751. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1752. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1753. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  1754. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled]);
  1755. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].component.name, "ReservationCtrlr");
  1756. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variable.name, "Available");
  1757. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1758. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1759. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1760. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].value, "TRUE");
  1761. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available]);
  1762. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].component.name, "ReservationCtrlr");
  1763. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variable.name, "NonEvseSpecific");
  1764. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1765. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1766. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1767. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].value, "FALSE");
  1768. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific]);
  1769. /* SampledDataCtrlr Required item */
  1770. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].component.name, "SampledDataCtrlr");
  1771. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variable.name, "Enabled");
  1772. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1773. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1774. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1775. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  1776. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled]);
  1777. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].component.name, "SampledDataCtrlr");
  1778. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variable.name, "Available");
  1779. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1780. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1781. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1782. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].value, "TRUE");
  1783. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available]);
  1784. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].component.name, "SampledDataCtrlr");
  1785. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variable.name, "SignReadings");
  1786. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1787. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1788. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1789. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].value, "FALSE");
  1790. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings]);
  1791. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].component.name, "SampledDataCtrlr");
  1792. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  1793. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1794. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableCharacteristics.maxLimit = 10;
  1795. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1796. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1797. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1798. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC");
  1799. else
  1800. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage");
  1801. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands]);
  1802. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].component.name, "SampledDataCtrlr");
  1803. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  1804. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableCharacteristics.unit, "Seconds");
  1805. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1806. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1807. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1808. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].value, "0");
  1809. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval]);
  1810. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].component.name, "SampledDataCtrlr");
  1811. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variable.name, "TxStartedMeasurands");
  1812. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1813. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableCharacteristics.maxLimit = 10;
  1814. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1815. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1816. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].value, " ");
  1817. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands]);
  1818. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].component.name, "SampledDataCtrlr");
  1819. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variable.name, "TxUpdatedMeasurands");
  1820. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1821. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableCharacteristics.maxLimit = 10;
  1822. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1823. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1824. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1825. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC");
  1826. else
  1827. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage");
  1828. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands]);
  1829. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].component.name, "SampledDataCtrlr");
  1830. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variable.name, "TxUpdatedInterval");
  1831. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.unit, "Seconds");
  1832. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1833. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.minLimit = 10;
  1834. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1835. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1836. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value, "30");
  1837. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval]);
  1838. /* SecurityCtrlr Required item */
  1839. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].component.name, "SecurityCtrlr");
  1840. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variable.name, "BasicAuthPassword");
  1841. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1842. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableCharacteristics.maxLimit = 40;
  1843. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1844. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_WriteOnly]);
  1845. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].value, " ");
  1846. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword]);
  1847. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].component.name, "SecurityCtrlr");
  1848. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variable.name, "Identity");
  1849. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1850. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableCharacteristics.maxLimit = 48;
  1851. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1852. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1853. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].value, "Phihong Technology");
  1854. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity]);
  1855. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].component.name, "SecurityCtrlr");
  1856. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variable.name, "OrganizationName");
  1857. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1858. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1859. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1860. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].value, "Phihong");
  1861. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName]);
  1862. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].component.name, "SecurityCtrlr");
  1863. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variable.name, "CertificateEntries");
  1864. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1865. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableCharacteristics.maxLimit = 1;
  1866. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1867. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1868. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].value, "1");
  1869. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries]);
  1870. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].component.name, "SecurityCtrlr");
  1871. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variable.name, "SecurityProfile");
  1872. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1873. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1874. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1875. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].value, "0");
  1876. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile]);
  1877. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].component.name, "SecurityCtrlr");
  1878. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variable.name, "AdditionalRootCertificateCheck");
  1879. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1880. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1881. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1882. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].value, "FALSE");
  1883. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck]);
  1884. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].component.name, "SecurityCtrlr");
  1885. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variable.name, "MaxCertificateChainSize");
  1886. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1887. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableCharacteristics.maxLimit = 10000;
  1888. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1889. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1890. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].value, "10000");
  1891. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize]);
  1892. /* SmartChargingCtrlr Required item */
  1893. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].component.name, "SmartChargingCtrlr");
  1894. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variable.name, "Enabled");
  1895. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1896. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1897. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1898. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  1899. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled]);
  1900. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].component.name, "SmartChargingCtrlr");
  1901. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variable.name, "Available");
  1902. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1903. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1904. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1905. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].value, "TRUE");
  1906. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available]);
  1907. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].component.name, "SmartChargingCtrlr");
  1908. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variable.name, "ACPhaseSwitchingSupported");
  1909. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1910. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1911. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1912. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].value, "FALSE");
  1913. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported]);
  1914. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].component.name, "SmartChargingCtrlr");
  1915. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variable.name, "ProfileStackLevel");
  1916. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1917. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1918. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1919. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value, "0");
  1920. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel]);
  1921. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].component.name, "SmartChargingCtrlr");
  1922. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variable.name, "RateUnit");
  1923. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1924. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1925. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1926. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].value, "A,W");
  1927. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit]);
  1928. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].component.name, "SmartChargingCtrlr");
  1929. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variable.name, "PeriodsPerSchedule");
  1930. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1931. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1932. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1933. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].value, "10");
  1934. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule]);
  1935. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].component.name, "SmartChargingCtrlr");
  1936. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variable.name, "ExternalControlSignalsEnabled");
  1937. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1938. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1939. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1940. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].value, "FALSE");
  1941. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled]);
  1942. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].component.name, "SmartChargingCtrlr");
  1943. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variable.name, "NotifyChargingLimitWithSchedules");
  1944. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1945. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1946. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1947. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].value, "FALSE");
  1948. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules]);
  1949. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].component.name, "SmartChargingCtrlr");
  1950. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variable.name, "Phases3to1");
  1951. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1952. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1953. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1954. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].value, "FALSE");
  1955. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1]);
  1956. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].component.name, "SmartChargingCtrlr");
  1957. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variable.name, "Entries");
  1958. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1959. ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableCharacteristics.maxLimit = 10;
  1960. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1961. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1962. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value, "10");
  1963. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries]);
  1964. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].component.name, "SmartChargingCtrlr");
  1965. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variable.name, "LimitChangeSignificance");
  1966. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_decimal]);
  1967. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1968. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1969. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].value, "1");
  1970. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance]);
  1971. /* TariffCostCtrlr Required item */
  1972. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].component.name, "TariffCostCtrlr");
  1973. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.instance, "Tariff");
  1974. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.name, "Enabled");
  1975. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1976. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1977. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1978. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].value, "FALSE");
  1979. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled]);
  1980. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].component.name, "TariffCostCtrlr");
  1981. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.instance, "Tariff");
  1982. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.name, "Available");
  1983. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1984. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1985. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1986. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].value, "FALSE");
  1987. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_Available]);
  1988. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].component.name, "TariffCostCtrlr");
  1989. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variable.name, "TariffFallbackMessage");
  1990. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1991. ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableCharacteristics.maxLimit = 255;
  1992. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1993. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1994. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].value, " ");
  1995. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage]);
  1996. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].component.name, "TariffCostCtrlr");
  1997. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.instance, "Cost");
  1998. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.name, "Enabled");
  1999. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2000. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2001. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2002. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].value, "FALSE");
  2003. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled]);
  2004. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].component.name, "TariffCostCtrlr");
  2005. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.instance, "Cost");
  2006. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.name, "Available");
  2007. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2008. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2009. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2010. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].value, "FALSE");
  2011. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Available]);
  2012. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].component.name, "TariffCostCtrlr");
  2013. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variable.name, "TotalCostFallbackMessage");
  2014. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2015. ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableCharacteristics.maxLimit = 255;
  2016. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2017. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2018. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].value, " ");
  2019. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage]);
  2020. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].component.name, "TariffCostCtrlr");
  2021. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variable.name, "Currency");
  2022. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2023. ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableCharacteristics.maxLimit = 3;
  2024. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2025. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2026. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].value, "NTD");
  2027. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Currency]);
  2028. /* TxCtrlr Required item */
  2029. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2030. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variable.name, "ChargingBeforeAcceptedEnabled");
  2031. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2032. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2033. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2034. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].value, "FALSE");
  2035. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled]);
  2036. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].component.name, "TxCtrlr");
  2037. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variable.name, "EVConnectionTimeOut");
  2038. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableCharacteristics.unit, "Seconds");
  2039. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2040. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2041. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2042. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value, "180");
  2043. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut]);
  2044. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].component.name, "TxCtrlr");
  2045. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variable.name, "StopTxOnEVSideDisconnect");
  2046. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2047. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2048. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2049. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].value, "TRUE");
  2050. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect]);
  2051. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2052. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variable.name, "TxBeforeAcceptedEnabled");
  2053. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2054. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2055. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2056. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].value, "FALSE");
  2057. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled]);
  2058. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].component.name, "TxCtrlr");
  2059. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variable.name, "TxStartPoint");
  2060. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2061. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2062. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2063. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].value, "PowerPathClosed");
  2064. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint]);
  2065. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].component.name, "TxCtrlr");
  2066. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variable.name, "TxStopPoint");
  2067. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2068. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2069. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2070. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].value, "PowerPathClosed");
  2071. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint]);
  2072. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].component.name, "TxCtrlr");
  2073. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variable.name, "MaxEnergyOnInvalidId");
  2074. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2075. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableCharacteristics.unit, "Wh");
  2076. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2077. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2078. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].value, "0");
  2079. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId]);
  2080. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].component.name, "TxCtrlr");
  2081. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variable.name, "StopTxOnInvalidId");
  2082. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2083. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2084. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2085. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].value, "FALSE");
  2086. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId]);
  2087. }
  2088. else
  2089. {
  2090. // Variable name init
  2091. /* AlignedDataCtrlr Required item */
  2092. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].component.name, "AlignedDataCtrlr");
  2093. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variable.name, "Enabled");
  2094. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].component.name, "AlignedDataCtrlr");
  2095. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variable.name, "Available");
  2096. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].component.name, "AlignedDataCtrlr");
  2097. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variable.name, "Measurands");
  2098. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].component.name, "AlignedDataCtrlr");
  2099. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variable.name, "Interval");
  2100. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].component.name, "AlignedDataCtrlr");
  2101. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variable.name, "SendDuringIdle");
  2102. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].component.name, "AlignedDataCtrlr");
  2103. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variable.name, "SignReadings");
  2104. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].component.name, "AlignedDataCtrlr");
  2105. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2106. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].component.name, "AlignedDataCtrlr");
  2107. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2108. /* AuthCtrlrVariable Required item */
  2109. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].component.name, "AuthCtrlr");
  2110. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variable.name, "Enabled");
  2111. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].component.name, "AlignedDataCtrlr");
  2112. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variable.name, "AdditionalInfoItemsPerMessage");
  2113. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].component.name, "AuthCtrlr");
  2114. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variable.name, "OfflineTxForUnknownIdEnabled");
  2115. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].component.name, "AuthCtrlr");
  2116. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variable.name, "AuthorizeRemoteStart");
  2117. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].component.name, "AuthCtrlr");
  2118. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variable.name, "LocalAuthorizeOffline");
  2119. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].component.name, "AuthCtrlr");
  2120. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variable.name, "LocalPreAuthorize");
  2121. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].component.name, "AuthCtrlr");
  2122. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variable.name, "MasterPassGroupId");
  2123. /* AuthCacheCtrlr Variable Required item */
  2124. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].component.name, "AuthCacheCtrlr");
  2125. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variable.name, "Enabled");
  2126. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].component.name, "AuthCacheCtrlr");
  2127. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variable.name, "Available");
  2128. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].component.name, "AuthCacheCtrlr");
  2129. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variable.name, "LifeTime");
  2130. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].component.name, "AuthCacheCtrlr");
  2131. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variable.name, "Storage");
  2132. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].component.name, "AuthCacheCtrlr");
  2133. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variable.name, "Policy");
  2134. /* ClockCtrlr Variable Required item */
  2135. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].component.name, "ClockCtrlr");
  2136. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variable.name, "DateTime");
  2137. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].component.name, "ClockCtrlr");
  2138. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variable.name, "NtpSource");
  2139. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].component.name, "ClockCtrlr");
  2140. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.name, "NtpServerUri");
  2141. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.instance, "1");
  2142. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].component.name, "ClockCtrlr");
  2143. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variable.name, "TimeOffset");
  2144. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].component.name, "ClockCtrlr");
  2145. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variable.name, "NextTimeOffsetTransitionDateTime");
  2146. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].component.name, "ClockCtrlr");
  2147. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.name, "TimeOffset");
  2148. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.instance, "NextTransition");
  2149. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].component.name, "ClockCtrlr");
  2150. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variable.name, "TimeSource");
  2151. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].component.name, "ClockCtrlr");
  2152. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variable.name, "TimeZone");
  2153. /* ChargingStation Required item */
  2154. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].component.name, "ChargingStation");
  2155. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variable.name, "Available");
  2156. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].component.name, "ChargingStation");
  2157. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variable.name, "AvailabilityState");
  2158. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].component.name, "ChargingStation");
  2159. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variable.name, "SupplyPhases");
  2160. /* Connector Required item */
  2161. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].component.name, "Connector");
  2162. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variable.name, "Available");
  2163. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].component.name, "Connector");
  2164. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variable.name, "ConnectorType");
  2165. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].component.name, "Connector");
  2166. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variable.name, "SupplyPhases");
  2167. /* CustomizationCtrlr Required item */
  2168. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].component.name, "CustomizationCtrlr");
  2169. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variable.name, "CustomImplementationEnabled");
  2170. /* DeviceDataCtrlr Required item */
  2171. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2172. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.instance, "GetReport");
  2173. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2174. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2175. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.instance, "GetVariables");
  2176. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2177. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2178. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.instance, "GetReport");
  2179. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.name, "BytesPerMessage");
  2180. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2181. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.instance, "GetVariables");
  2182. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2183. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].component.name, "DeviceDataCtrlr");
  2184. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variable.name, "ConfigurationValueSize");
  2185. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].component.name, "DeviceDataCtrlr");
  2186. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variable.name, "ReportingValueSize");
  2187. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2188. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.instance, "SetVariables");
  2189. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2190. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2191. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.instance, "SetVariables");
  2192. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2193. /* DisplayMessageCtrlr Required item */
  2194. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].component.name, "DisplayMessageCtrlr");
  2195. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variable.name, "Enabled");
  2196. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].component.name, "DisplayMessageCtrlr");
  2197. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variable.name, "Available");
  2198. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].component.name, "DisplayMessageCtrlr");
  2199. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variable.name, "DisplayMessages");
  2200. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].component.name, "DisplayMessageCtrlr");
  2201. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variable.name, "SupportedFormats");
  2202. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].component.name, "DisplayMessageCtrlr");
  2203. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variable.name, "SupportedPriorities");
  2204. /* EVSE Required item */
  2205. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].component.name, "EVSE");
  2206. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variable.name, "Available");
  2207. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].component.name, "EVSE");
  2208. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variable.name, "AvailabilityState");
  2209. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].component.name, "EVSE");
  2210. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variable.name, "SupplyPhases");
  2211. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].component.name, "EVSE");
  2212. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variable.name, "Power");
  2213. /* LocalAuthListCtrlr Required item */
  2214. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].component.name, "LocalAuthListCtrlr");
  2215. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variable.name, "Enabled");
  2216. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].component.name, "LocalAuthListCtrlr");
  2217. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variable.name, "Entries");
  2218. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].component.name, "LocalAuthListCtrlr");
  2219. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variable.name, "Available");
  2220. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].component.name, "LocalAuthListCtrlr");
  2221. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2222. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.instance, "SendLocalList");
  2223. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].component.name, "LocalAuthListCtrlr");
  2224. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.name, "BytesPerMessage");
  2225. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.instance, "SendLocalList");
  2226. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].component.name, "LocalAuthListCtrlr");
  2227. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variable.name, "Storage");
  2228. /* MonitoringCtrlr Required item */
  2229. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].component.name, "MonitoringCtrlr");
  2230. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variable.instance, "Enabled");
  2231. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].component.name, "MonitoringCtrlr");
  2232. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variable.instance, "Available");
  2233. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2234. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.instance, "ClearVariableMonitoring");
  2235. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2236. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2237. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.instance, "SetVariableMonitoring");
  2238. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2239. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2240. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.instance, "ClearVariableMonitoring");
  2241. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2242. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2243. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.instance, "SetVariableMonitoring");
  2244. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2245. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].component.name, "MonitoringCtrlr");
  2246. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variable.name, "OfflineQueuingSeverity");
  2247. /* OCPPCommCtrlr Required item */
  2248. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].component.name, "OCPPCommCtrlr");
  2249. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variable.name, "ActiveNetworkProfile");
  2250. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].component.name, "OCPPCommCtrlr");
  2251. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.instance, "Default");
  2252. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.name, "MessageTimeout");
  2253. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].component.name, "OCPPCommCtrlr");
  2254. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variable.name, "FileTransferProtocols");
  2255. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].component.name, "OCPPCommCtrlr");
  2256. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variable.name, "HeartbeatInterval");
  2257. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].component.name, "OCPPCommCtrlr");
  2258. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variable.name, "NetworkConfigurationPriority");
  2259. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].component.name, "OCPPCommCtrlr");
  2260. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variable.name, "NetworkProfileConnectionAttempts");
  2261. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].component.name, "OCPPCommCtrlr");
  2262. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variable.name, "OfflineThreshold");
  2263. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].component.name, "OCPPCommCtrlr");
  2264. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variable.name, "QueueAllMessages");
  2265. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].component.name, "OCPPCommCtrlr");
  2266. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.instance, "TransactionEvent");
  2267. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.name, "MessageAttempts");
  2268. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].component.name, "OCPPCommCtrlr");
  2269. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.instance, "TransactionEvent");
  2270. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.name, "MessageAttemptInterval");
  2271. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].component.name, "OCPPCommCtrlr");
  2272. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variable.name, "UnlockOnEVSideDisconnect");
  2273. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].component.name, "OCPPCommCtrlr");
  2274. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variable.name, "WebSocketPingInterval");
  2275. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].component.name, "OCPPCommCtrlr");
  2276. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variable.name, "ResetRetries");
  2277. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].component.name, "OCPPCommCtrlr");
  2278. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variable.name, "PublicKeyWithSignedMeterValue");
  2279. /* ReservationCtrlr Required item */
  2280. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].component.name, "ReservationCtrlr");
  2281. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variable.name, "Enabled");
  2282. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].component.name, "ReservationCtrlr");
  2283. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variable.name, "Available");
  2284. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].component.name, "ReservationCtrlr");
  2285. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variable.name, "NonEvseSpecific");
  2286. /* SampledDataCtrlr Required item */
  2287. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].component.name, "SampledDataCtrlr");
  2288. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variable.name, "Enabled");
  2289. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].component.name, "SampledDataCtrlr");
  2290. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variable.name, "Available");
  2291. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].component.name, "SampledDataCtrlr");
  2292. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variable.name, "SignReadings");
  2293. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].component.name, "SampledDataCtrlr");
  2294. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2295. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].component.name, "SampledDataCtrlr");
  2296. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2297. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].component.name, "SampledDataCtrlr");
  2298. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variable.name, "TxStartedMeasurands");
  2299. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].component.name, "SampledDataCtrlr");
  2300. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variable.name, "TxUpdatedMeasurands");
  2301. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].component.name, "SampledDataCtrlr");
  2302. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variable.name, "TxUpdatedInterval");
  2303. /* SecurityCtrlr Required item */
  2304. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].component.name, "SecurityCtrlr");
  2305. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variable.name, "BasicAuthPassword");
  2306. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].component.name, "SecurityCtrlr");
  2307. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variable.name, "Identity");
  2308. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].component.name, "SecurityCtrlr");
  2309. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variable.name, "OrganizationName");
  2310. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].component.name, "SecurityCtrlr");
  2311. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variable.name, "CertificateEntries");
  2312. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].component.name, "SecurityCtrlr");
  2313. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variable.name, "SecurityProfile");
  2314. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].component.name, "SecurityCtrlr");
  2315. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variable.name, "AdditionalRootCertificateCheck");
  2316. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].component.name, "SecurityCtrlr");
  2317. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variable.name, "MaxCertificateChainSize");
  2318. /* SmartChargingCtrlr Required item */
  2319. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].component.name, "SmartChargingCtrlr");
  2320. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variable.name, "Enabled");
  2321. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].component.name, "SmartChargingCtrlr");
  2322. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variable.name, "Available");
  2323. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].component.name, "SmartChargingCtrlr");
  2324. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variable.name, "ACPhaseSwitchingSupported");
  2325. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].component.name, "SmartChargingCtrlr");
  2326. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variable.name, "ProfileStackLevel");
  2327. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].component.name, "SmartChargingCtrlr");
  2328. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variable.name, "RateUnit");
  2329. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].component.name, "SmartChargingCtrlr");
  2330. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variable.name, "PeriodsPerSchedule");
  2331. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].component.name, "SmartChargingCtrlr");
  2332. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variable.name, "ExternalControlSignalsEnabled");
  2333. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].component.name, "SmartChargingCtrlr");
  2334. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variable.name, "NotifyChargingLimitWithSchedules");
  2335. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].component.name, "SmartChargingCtrlr");
  2336. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variable.name, "Phases3to1");
  2337. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].component.name, "SmartChargingCtrlr");
  2338. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variable.name, "Entries");
  2339. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].component.name, "SmartChargingCtrlr");
  2340. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variable.name, "LimitChangeSignificance");
  2341. /* TariffCostCtrlr Required item */
  2342. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].component.name, "TariffCostCtrlr");
  2343. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.instance, "Tariff");
  2344. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.name, "Enabled");
  2345. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].component.name, "TariffCostCtrlr");
  2346. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.instance, "Tariff");
  2347. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.name, "Available");
  2348. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].component.name, "TariffCostCtrlr");
  2349. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variable.name, "TariffFallbackMessage");
  2350. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].component.name, "TariffCostCtrlr");
  2351. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.instance, "Cost");
  2352. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.name, "Enabled");
  2353. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].component.name, "TariffCostCtrlr");
  2354. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.instance, "Cost");
  2355. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.name, "Available");
  2356. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].component.name, "TariffCostCtrlr");
  2357. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variable.name, "TotalCostFallbackMessage");
  2358. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].component.name, "TariffCostCtrlr");
  2359. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variable.name, "Currency");
  2360. /* TxCtrlr Required item */
  2361. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2362. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variable.name, "ChargingBeforeAcceptedEnabled");
  2363. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].component.name, "TxCtrlr");
  2364. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variable.name, "EVConnectionTimeOut");
  2365. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].component.name, "TxCtrlr");
  2366. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variable.name, "StopTxOnEVSideDisconnect");
  2367. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2368. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variable.name, "TxBeforeAcceptedEnabled");
  2369. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].component.name, "TxCtrlr");
  2370. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variable.name, "TxStartPoint");
  2371. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].component.name, "TxCtrlr");
  2372. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variable.name, "TxStopPoint");
  2373. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].component.name, "TxCtrlr");
  2374. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variable.name, "MaxEnergyOnInvalidId");
  2375. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].component.name, "TxCtrlr");
  2376. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variable.name, "StopTxOnInvalidId");
  2377. }
  2378. return 0;
  2379. }
  2380. void DB_variableIsCreate()
  2381. {
  2382. char sql[512];
  2383. char* errMsg = NULL;
  2384. sprintf(sql,"select count(idx) as quantity from ocpp20_variable;");
  2385. /* Execute SQL statement */
  2386. if(sqlite3_exec(db, sql, DB_cbVariableIsCreate, 0, &errMsg) != SQLITE_OK )
  2387. {
  2388. DEBUG_INFO("SQL error: %s\n", errMsg);
  2389. }
  2390. }
  2391. int DB_cbVariableLoadFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  2392. {
  2393. for(int idx=0;idx<CtrlrVariable_CNT;idx++)
  2394. {
  2395. if((strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].component.name, columnValue[1]) == 0) &&
  2396. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].component.instance, columnValue[2]) == 0) &&
  2397. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variable.name, columnValue[3]) == 0) &&
  2398. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variable.instance, columnValue[4]) == 0))
  2399. {
  2400. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.dataType, "%s", columnValue[5]);
  2401. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.unit, "%s", columnValue[6]);
  2402. ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.maxLimit = strlen(columnValue[7])>0?atoi(columnValue[7]):255;
  2403. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].type, "%s", columnValue[8]);
  2404. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].mutability, "%s", columnValue[9]);
  2405. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].value, "%s", columnValue[10]);
  2406. }
  2407. }
  2408. return 0;
  2409. }
  2410. void DB_variableLoadFromDb()
  2411. {
  2412. char sql[512];
  2413. char* errMsg = NULL;
  2414. sprintf(sql,"select * from ocpp20_variable order by idx;");
  2415. /* Execute SQL statement */
  2416. if(sqlite3_exec(db, sql, DB_cbVariableLoadFromDb, 0, &errMsg) != SQLITE_OK )
  2417. {
  2418. DEBUG_INFO("SQL error: %s\n", errMsg);
  2419. }
  2420. }
  2421. int DB_cbGetNetworkProfileFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  2422. {
  2423. memset(&ShmOCPP20Data->NetworkConnectionProfile[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile));
  2424. if(columnCount > 0)
  2425. {
  2426. for(int idx=0;idx<columnCount;idx++)
  2427. {
  2428. json_object *SetNetworkProfile;
  2429. SetNetworkProfile = json_tokener_parse(columnValue[2]);
  2430. if(!is_error(SetNetworkProfile))
  2431. {
  2432. // Required data
  2433. if(json_object_object_get(SetNetworkProfile, "ocppVersion") != NULL)
  2434. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppVersion, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppVersion")));
  2435. if(json_object_object_get(SetNetworkProfile, "ocppTransport") != NULL)
  2436. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppTransport")));
  2437. if(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl") != NULL)
  2438. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl")));
  2439. if(json_object_object_get(SetNetworkProfile, "messageTimeout") != NULL)
  2440. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.messageTimeout = json_object_get_int(json_object_object_get(SetNetworkProfile, "messageTimeout"));
  2441. if(json_object_object_get(SetNetworkProfile, "ocppInterface") != NULL)
  2442. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppInterface, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppInterface")));
  2443. if(json_object_object_get(SetNetworkProfile, "vpn") != NULL)
  2444. {
  2445. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server") != NULL)
  2446. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.server, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server")));
  2447. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user") != NULL)
  2448. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.user, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user")));
  2449. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group") != NULL)
  2450. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.group, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group")));
  2451. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password") != NULL)
  2452. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.password, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password")));
  2453. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key") != NULL)
  2454. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.key, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key")));
  2455. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type") != NULL)
  2456. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type")));
  2457. }
  2458. if(json_object_object_get(SetNetworkProfile, "apn") != NULL)
  2459. {
  2460. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn") != NULL)
  2461. {
  2462. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn));
  2463. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn")));
  2464. }
  2465. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName") != NULL)
  2466. {
  2467. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName));
  2468. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName")));
  2469. }
  2470. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword") != NULL)
  2471. {
  2472. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword));
  2473. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword")));
  2474. }
  2475. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin") != NULL)
  2476. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.simPin = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin"));
  2477. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork") != NULL)
  2478. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.preferredNetwork, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork")));
  2479. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork") != NULL)
  2480. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.useOnlyPreferredNetwork = json_object_get_boolean(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork"));
  2481. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication") != NULL)
  2482. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnAuthentication, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication")));
  2483. }
  2484. }
  2485. json_object_put(SetNetworkProfile);
  2486. ShmOCPP20Data->NetworkConnectionProfile[idx].slot = atoi(columnValue[1]);
  2487. }
  2488. }
  2489. return 0;
  2490. }
  2491. void DB_getNetworkProfileFromDb()
  2492. {
  2493. char sql[512];
  2494. char* errMsg = NULL;
  2495. sprintf(sql,"select * from ocpp20_networkprofile order by slot;");
  2496. /* Execute SQL statement */
  2497. if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
  2498. {
  2499. DEBUG_INFO("SQL error: %s\n", errMsg);
  2500. }
  2501. }
  2502. int DB_addNetworkProfile(int slot, char *data)
  2503. {
  2504. int result = PASS;
  2505. char sql[512];
  2506. char* errMsg = NULL;
  2507. sprintf(sql,"insert or replace into ocpp20_networkprofile (slot, connectionData) VALUES('%d', '%s'); SELECT * from ocpp20_networkprofile order by slot;",
  2508. slot,
  2509. data);
  2510. //* Execute SQL statement */
  2511. if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK)
  2512. {
  2513. DEBUG_INFO("SQL error: %s\n", errMsg);
  2514. result = FAIL;
  2515. }
  2516. return result;
  2517. }
  2518. int DB_deleteNetworkProfile(int slot)
  2519. {
  2520. int result = PASS;
  2521. char sql[512];
  2522. char* errMsg = NULL;
  2523. sprintf(sql,"DELETE from ocpp20_networkprofile where slot=%d; SELECT * from ocpp20_networkprofile order by slot;", slot);
  2524. //* Execute SQL statement */
  2525. if( sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
  2526. {
  2527. DEBUG_INFO("SQL error: %s", errMsg);
  2528. result = FAIL;
  2529. }
  2530. return result;
  2531. }
  2532. int getCurrentYear()
  2533. {
  2534. int result = 0;
  2535. time_t CurrentTime;
  2536. struct tm *tm;
  2537. CurrentTime = time(NULL);
  2538. tm=localtime(&CurrentTime);
  2539. result = (tm->tm_year + 1900);
  2540. return result;
  2541. }
  2542. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  2543. {
  2544. int result = PASS;
  2545. char* errMsg = NULL;
  2546. char sqlStr[8192];
  2547. sprintf(sqlStr, "insert into ocpp20_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  2548. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  2549. {
  2550. result = FAIL;
  2551. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  2552. }
  2553. 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));
  2554. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  2555. {
  2556. result = FAIL;
  2557. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  2558. }
  2559. return result;
  2560. }
  2561. //==========================================
  2562. // Check time passed since today
  2563. //==========================================
  2564. long long DiffTimebWithNow(struct timeb ST)
  2565. {
  2566. //return milli-second
  2567. struct timeb ET;
  2568. long long StartTime,StopTime;
  2569. ftime(&ET);
  2570. StartTime=(long long)ST.time;
  2571. StopTime=(long long)ET.time;
  2572. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  2573. }
  2574. int getTimePassSinceToday()
  2575. {
  2576. int result = -1;
  2577. time_t t;
  2578. struct tm *tmStartToday;
  2579. struct timeb tbStartToday;
  2580. t=time(NULL);
  2581. tmStartToday=localtime(&t);
  2582. tmStartToday->tm_hour = 0;
  2583. tmStartToday->tm_min = 0;
  2584. tmStartToday->tm_sec = 0;
  2585. tbStartToday.time = mktime(tmStartToday);
  2586. tbStartToday.millitm = 0;
  2587. result = DiffTimebWithNow(tbStartToday)/1000;
  2588. return result;
  2589. }
  2590. int syncDateTimeRTC(uint8_t *data)
  2591. {
  2592. struct ParsingResult
  2593. {
  2594. int result;
  2595. int scanedElement;
  2596. int year;
  2597. int month;
  2598. int mday;
  2599. int hour;
  2600. int min;
  2601. int sec;
  2602. int tz_hour;
  2603. int tz_min;
  2604. float minSec;
  2605. }result;
  2606. struct tm tmOrg;
  2607. struct tm *tmTarget;
  2608. struct timeb tbTarget;
  2609. char buf[128];
  2610. memset(&result, 0x00, sizeof(struct ParsingResult));
  2611. result.result = PASS;
  2612. if(strstr((char*)data, ".") != NULL)
  2613. {
  2614. // Original data with mini second
  2615. if(strstr((char*)data, "Z") != NULL)
  2616. {
  2617. // Original data with Z
  2618. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  2619. &result.year,
  2620. &result.month,
  2621. &result.mday,
  2622. &result.hour,
  2623. &result.min,
  2624. &result.sec,
  2625. &result.minSec);
  2626. }
  2627. else
  2628. {
  2629. // Original data without Z
  2630. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  2631. &result.year,
  2632. &result.month,
  2633. &result.mday,
  2634. &result.hour,
  2635. &result.min,
  2636. &result.sec,
  2637. &result.minSec,
  2638. &result.tz_hour,
  2639. &result.tz_min);
  2640. }
  2641. }
  2642. else
  2643. {
  2644. // Original data without mini second
  2645. if(strstr((char*)data, "Z") != NULL)
  2646. {
  2647. // Original data with Z
  2648. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  2649. &result.year,
  2650. &result.month,
  2651. &result.mday,
  2652. &result.hour,
  2653. &result.min,
  2654. &result.sec);
  2655. }
  2656. else
  2657. {
  2658. // Original data without Z
  2659. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  2660. &result.year,
  2661. &result.month,
  2662. &result.mday,
  2663. &result.hour,
  2664. &result.min,
  2665. &result.sec,
  2666. &result.tz_hour,
  2667. &result.tz_min);
  2668. }
  2669. }
  2670. tmOrg.tm_year = result.year - 1900;
  2671. tmOrg.tm_mon = result.month - 1;
  2672. tmOrg.tm_mday = result.mday;
  2673. tmOrg.tm_hour = result.hour;
  2674. tmOrg.tm_min = result.min;
  2675. tmOrg.tm_sec = result.sec;
  2676. tmOrg.tm_gmtoff = 0;
  2677. tbTarget.time = mktime(&tmOrg);
  2678. tbTarget.timezone = 0;
  2679. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  2680. tmTarget = gmtime(&tbTarget.time);
  2681. 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);
  2682. //DEBUG_INFO(" org date time: %s\n", data);
  2683. //DEBUG_INFO("parse date time: %s\n", buf);
  2684. system(buf);
  2685. system("/sbin/hwclock -w --systohc");
  2686. if(result.scanedElement < 6)
  2687. result.result = FAIL;
  2688. return result.result;
  2689. }
  2690. //==========================================
  2691. // GetCompositeSchedule logic related function
  2692. //==========================================
  2693. int DiffTimebSec(struct timeb ST, struct timeb ET)
  2694. {
  2695. //return milli-second
  2696. unsigned int StartTime,StopTime;
  2697. StartTime=(unsigned int)ST.time;
  2698. StopTime=(unsigned int)ET.time;
  2699. return (StopTime-StartTime);
  2700. }
  2701. int DiffTimebWithNowSec(struct timeb ST)
  2702. {
  2703. //return milli-second
  2704. struct timeb ET;
  2705. unsigned int StartTime,StopTime;
  2706. ftime(&ET);
  2707. StartTime=(unsigned int)ST.time;
  2708. StopTime=(unsigned int)ET.time;
  2709. return (StopTime-StartTime);
  2710. }
  2711. int getStartStop(uint8_t *start, uint8_t *stop)
  2712. {
  2713. int result = -1;
  2714. struct tm tmStart;
  2715. struct timeb tbStart;
  2716. struct tm tmStop;
  2717. struct timeb tbStop;
  2718. 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) &&
  2719. (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))
  2720. {
  2721. //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);
  2722. //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);
  2723. tmStart.tm_year -= 1900;
  2724. tmStart.tm_mon -= 1;
  2725. tbStart.time = mktime(&tmStart);
  2726. tbStart.millitm = 0;
  2727. tmStop.tm_year -= 1900;
  2728. tmStop.tm_mon -= 1;
  2729. tbStop.time = mktime(&tmStop);
  2730. tbStop.millitm = 0;
  2731. result = DiffTimebSec(tbStart, tbStop);
  2732. //DEBUG_INFO("getStartStop(): %d\n", result);
  2733. }
  2734. else
  2735. {
  2736. DEBUG_WARN("Start or stop date parsing error.\r\n");
  2737. }
  2738. return result;
  2739. }
  2740. int isOvertNow(uint8_t *start)
  2741. {
  2742. int result = NO;
  2743. struct tm tmStart;
  2744. struct timeb tbStart;
  2745. 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))
  2746. {
  2747. //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);
  2748. tmStart.tm_year -= 1900;
  2749. tmStart.tm_mon -= 1;
  2750. tbStart.time = mktime(&tmStart);
  2751. tbStart.millitm = 0;
  2752. if(DiffTimebWithNowSec(tbStart) <= 0)
  2753. result = NO;
  2754. else
  2755. result = YES;
  2756. }
  2757. else
  2758. {
  2759. DEBUG_WARN("Start date parsing error.\n");
  2760. }
  2761. return result;
  2762. }
  2763. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  2764. {
  2765. int result = -1;
  2766. struct tm tmStart;
  2767. struct timeb tbStart;
  2768. struct tm tmStop;
  2769. struct timeb tbStop;
  2770. 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) &&
  2771. (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))
  2772. {
  2773. tmStart.tm_year -= 1900;
  2774. tmStart.tm_mon -= 1;
  2775. tbStart.time = mktime(&tmStart);
  2776. tbStart.millitm = 0;
  2777. tmStop.tm_year -= 1900;
  2778. tmStop.tm_mon -= 1;
  2779. tbStop.time = mktime(&tmStop);
  2780. tbStop.millitm = 0;
  2781. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  2782. }
  2783. return result;
  2784. }
  2785. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct ChargingProfileType *compositeProfile, uint8_t idxSchedule, uint8_t isUnitA)
  2786. {
  2787. FILE *fp;
  2788. char profileFileName[128];
  2789. char *line = NULL;
  2790. size_t len = 0;
  2791. time_t CurrentTime;
  2792. struct tm *tmComposite;
  2793. struct ChargingProfileType maxProfile;
  2794. struct ChargingProfileType defaultTxProfile;
  2795. struct ChargingProfileType txProfile;
  2796. struct ChargingSchedulePeriodType tmpPeriod;
  2797. uint8_t limitMax=0;
  2798. uint8_t limitDef=0;
  2799. uint8_t limitTx=0;
  2800. int compositePeriodIdx = 0;
  2801. CurrentTime = time(NULL);
  2802. tmComposite=localtime(&CurrentTime);
  2803. 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);
  2804. if(isUnitA)
  2805. sprintf((char*)compositeProfile->chargingSchedule[idxSchedule].chargingRateUnit, "A");
  2806. else
  2807. sprintf((char*)compositeProfile->chargingSchedule[idxSchedule].chargingRateUnit, "W");
  2808. compositeProfile->chargingSchedule[idxSchedule].duration = durationReq;
  2809. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  2810. {
  2811. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  2812. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  2813. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  2814. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 0;
  2815. }
  2816. compositeProfile->id = 0;
  2817. compositeProfile->stackLevel = 99 ;
  2818. sprintf((char*)compositeProfile->chargingProfileKind ,ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]);
  2819. maxProfile.id = -1;
  2820. defaultTxProfile.id = -1;
  2821. txProfile.id = -1;
  2822. maxProfile.chargingSchedule[idxSchedule].duration = -1;
  2823. defaultTxProfile.chargingSchedule[idxSchedule].duration = -1;
  2824. txProfile.chargingSchedule[idxSchedule].duration = -1;
  2825. system("rm -f /tmp/*.json");
  2826. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2827. /*
  2828. * Search valid charging profile
  2829. */
  2830. //DEBUG_INFO("====================================\n");
  2831. // Search tx profile
  2832. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2833. if((access(profileFileName, F_OK))!=-1)
  2834. {
  2835. fp = fopen(profileFileName, "r");
  2836. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  2837. {
  2838. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  2839. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  2840. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  2841. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  2842. }
  2843. txProfile.id = -1;
  2844. txProfile.stackLevel = -1;
  2845. while(getline(&line, &len, fp) != -1)
  2846. {
  2847. json_object *obj = NULL;
  2848. obj = json_tokener_parse(line);
  2849. if(is_error(obj))
  2850. {
  2851. DEBUG_ERROR("Parse txProfile from file error.\n");
  2852. }
  2853. else
  2854. {
  2855. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.id) &&
  2856. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.stackLevel)
  2857. )
  2858. {
  2859. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2860. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2861. )
  2862. {
  2863. struct tm tmFrom, tmTo;
  2864. struct timeb tbFrom, tbTo;
  2865. 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) &&
  2866. (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))
  2867. {
  2868. tmFrom.tm_year -= 1900;
  2869. tmFrom.tm_mon -= 1;
  2870. tbFrom.time = mktime(&tmFrom);
  2871. tmTo.tm_year -= 1900;
  2872. tmTo.tm_mon -= 1;
  2873. tbTo.time = mktime(&tmTo);
  2874. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2875. {
  2876. if(txProfile.id == -1)
  2877. DEBUG_INFO("TxProfile found.\n");
  2878. else
  2879. DEBUG_INFO("TxProfile updated.\n");
  2880. // Required item
  2881. txProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2882. txProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2883. sprintf((char*)txProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2884. if(isUnitA)
  2885. {
  2886. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  2887. 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++)
  2888. {
  2889. 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"));
  2890. 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?
  2891. 3:
  2892. 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")));
  2893. 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")));
  2894. }
  2895. }
  2896. else
  2897. {
  2898. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  2899. 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++)
  2900. {
  2901. 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"));
  2902. 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?
  2903. 3:
  2904. 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")));
  2905. 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));
  2906. }
  2907. }
  2908. // Optional item
  2909. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2910. {
  2911. sprintf((char*)txProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2912. }
  2913. else
  2914. {
  2915. sprintf((char*)txProfile.validFrom, " ");
  2916. }
  2917. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2918. {
  2919. sprintf((char*)txProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  2920. }
  2921. else
  2922. {
  2923. sprintf((char*)txProfile.validTo, " ");
  2924. }
  2925. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  2926. {
  2927. sprintf((char*)txProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  2928. }
  2929. else
  2930. {
  2931. sprintf((char*)txProfile.recurrencyKind, " ");
  2932. }
  2933. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  2934. {
  2935. sprintf((char*)txProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  2936. }
  2937. else
  2938. {
  2939. sprintf((char*)txProfile.transactionId, " ");
  2940. }
  2941. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  2942. {
  2943. txProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  2944. }
  2945. else
  2946. {
  2947. txProfile.chargingSchedule[idxSchedule].duration = 86400;
  2948. }
  2949. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  2950. {
  2951. 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")));
  2952. }
  2953. else
  2954. {
  2955. sprintf((char*)txProfile.chargingSchedule[idxSchedule].startSchedule, "%s", ((strstr((char*)ShmOCPP20Data->StatusNotification[(connectorId==0?0:connectorId-1)].connectorStatus, "Charging")==NULL) ? compositeProfile->chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp));
  2956. }
  2957. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  2958. {
  2959. txProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  2960. }
  2961. else
  2962. {
  2963. txProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  2964. }
  2965. }
  2966. }
  2967. }
  2968. else
  2969. {
  2970. if(txProfile.id == -1)
  2971. DEBUG_INFO("TxProfile found.\n");
  2972. else
  2973. DEBUG_INFO("TxProfile updated.\n");
  2974. // Required item
  2975. txProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2976. txProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2977. sprintf((char*)txProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2978. if(isUnitA)
  2979. {
  2980. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  2981. 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++)
  2982. {
  2983. 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"));
  2984. 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?
  2985. 3:
  2986. 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")));
  2987. 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")));
  2988. }
  2989. }
  2990. else
  2991. {
  2992. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  2993. 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++)
  2994. {
  2995. 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"));
  2996. 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?
  2997. 3:
  2998. 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")));
  2999. 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));
  3000. }
  3001. }
  3002. // Optional item
  3003. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3004. {
  3005. sprintf((char*)txProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3006. }
  3007. else
  3008. {
  3009. sprintf((char*)txProfile.validFrom, " ");
  3010. }
  3011. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3012. {
  3013. sprintf((char*)txProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3014. }
  3015. else
  3016. {
  3017. sprintf((char*)txProfile.validTo, " ");
  3018. }
  3019. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  3020. {
  3021. sprintf((char*)txProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  3022. }
  3023. else
  3024. {
  3025. sprintf((char*)txProfile.recurrencyKind, " ");
  3026. }
  3027. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3028. {
  3029. sprintf((char*)txProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  3030. }
  3031. else
  3032. {
  3033. sprintf((char*)txProfile.transactionId, " ");
  3034. }
  3035. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3036. {
  3037. txProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3038. }
  3039. else
  3040. {
  3041. txProfile.chargingSchedule[idxSchedule].duration = 86400;
  3042. }
  3043. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3044. {
  3045. 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")));
  3046. }
  3047. else
  3048. {
  3049. sprintf((char*)txProfile.chargingSchedule[idxSchedule].startSchedule, "%s", ((strstr((char*)ShmOCPP20Data->StatusNotification[(connectorId==0?0:connectorId-1)].connectorStatus, "Charging")==NULL) ? compositeProfile->chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp));
  3050. }
  3051. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3052. {
  3053. txProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3054. }
  3055. else
  3056. {
  3057. txProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3058. }
  3059. }
  3060. }
  3061. }
  3062. json_object_put(obj);
  3063. }
  3064. fclose(fp);
  3065. /*
  3066. if(txProfile.ChargingProfileId != -1)
  3067. {
  3068. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3069. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3070. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3071. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3072. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3073. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3074. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  3075. DEBUG_INFO("Profile start schedule: %s\n", txProfile.chargingSchedule[idxSchedule].StartSchedule);
  3076. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.chargingSchedule[idxSchedule].Duration);
  3077. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  3078. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.chargingSchedule[idxSchedule].MinChargingRate);
  3079. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  3080. {
  3081. if(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3082. {
  3083. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3084. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  3085. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3086. }
  3087. }
  3088. }
  3089. else
  3090. DEBUG_INFO("TxProfile not found.\n");*/
  3091. }
  3092. // Search default tx profile
  3093. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  3094. if((access(profileFileName, F_OK))==-1)
  3095. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  3096. if((access(profileFileName, F_OK))!=-1)
  3097. {
  3098. fp = fopen(profileFileName, "r");
  3099. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3100. {
  3101. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3102. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3103. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3104. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  3105. }
  3106. defaultTxProfile.id = -1;
  3107. defaultTxProfile.stackLevel = -1;
  3108. while(getline(&line, &len, fp) != -1)
  3109. {
  3110. json_object *obj = NULL;
  3111. obj = json_tokener_parse(line);
  3112. if(is_error(obj))
  3113. {
  3114. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  3115. }
  3116. else
  3117. {
  3118. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.id) &&
  3119. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.stackLevel)
  3120. )
  3121. {
  3122. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  3123. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3124. )
  3125. {
  3126. struct tm tmFrom, tmTo;
  3127. struct timeb tbFrom, tbTo;
  3128. 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) &&
  3129. (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))
  3130. {
  3131. tmFrom.tm_year -= 1900;
  3132. tmFrom.tm_mon -= 1;
  3133. tbFrom.time = mktime(&tmFrom);
  3134. tmTo.tm_year -= 1900;
  3135. tmTo.tm_mon -= 1;
  3136. tbTo.time = mktime(&tmTo);
  3137. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3138. {
  3139. if(defaultTxProfile.id == -1)
  3140. DEBUG_INFO("TxDefaultProfile found.\n");
  3141. else
  3142. DEBUG_INFO("TxDefaultProfile updated.\n");
  3143. // Required item
  3144. defaultTxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3145. defaultTxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3146. sprintf((char*)defaultTxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3147. if(isUnitA)
  3148. {
  3149. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3150. 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++)
  3151. {
  3152. 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"));
  3153. 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?
  3154. 3:
  3155. 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")));
  3156. 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")));
  3157. }
  3158. }
  3159. else
  3160. {
  3161. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3162. 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++)
  3163. {
  3164. 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"));
  3165. 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?
  3166. 3:
  3167. 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")));
  3168. 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));
  3169. }
  3170. }
  3171. // Optional item
  3172. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3173. {
  3174. sprintf((char*)defaultTxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3175. }
  3176. else
  3177. {
  3178. sprintf((char*)defaultTxProfile.validFrom, " ");
  3179. }
  3180. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3181. {
  3182. sprintf((char*)defaultTxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3183. }
  3184. else
  3185. {
  3186. sprintf((char*)defaultTxProfile.validTo, " ");
  3187. }
  3188. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  3189. {
  3190. sprintf((char*)defaultTxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  3191. }
  3192. else
  3193. {
  3194. sprintf((char*)defaultTxProfile.recurrencyKind, " ");
  3195. }
  3196. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3197. {
  3198. sprintf((char*)defaultTxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  3199. }
  3200. else
  3201. {
  3202. sprintf((char*)defaultTxProfile.transactionId, " ");
  3203. }
  3204. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3205. {
  3206. defaultTxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3207. }
  3208. else
  3209. {
  3210. defaultTxProfile.chargingSchedule[idxSchedule].duration = 86400;
  3211. }
  3212. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3213. {
  3214. 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")));
  3215. }
  3216. else
  3217. {
  3218. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", ((strstr((char*)ShmOCPP20Data->StatusNotification[(connectorId==0?0:connectorId-1)].connectorStatus, "Charging")==NULL) ? compositeProfile->chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp));
  3219. }
  3220. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3221. {
  3222. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3223. }
  3224. else
  3225. {
  3226. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3227. }
  3228. }
  3229. }
  3230. }
  3231. else
  3232. {
  3233. if(defaultTxProfile.id == -1)
  3234. DEBUG_INFO("TxDefaultProfile found.\n");
  3235. else
  3236. DEBUG_INFO("TxDefaultProfile updated.\n");
  3237. // Required item
  3238. defaultTxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3239. defaultTxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3240. sprintf((char*)defaultTxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3241. if(isUnitA)
  3242. {
  3243. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3244. 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++)
  3245. {
  3246. 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"));
  3247. 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?
  3248. 3:
  3249. 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")));
  3250. 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")));
  3251. }
  3252. }
  3253. else
  3254. {
  3255. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3256. 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++)
  3257. {
  3258. 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"));
  3259. 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?
  3260. 3:
  3261. 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")));
  3262. 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));
  3263. }
  3264. }
  3265. // Optional item
  3266. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3267. {
  3268. sprintf((char*)defaultTxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3269. }
  3270. else
  3271. {
  3272. sprintf((char*)defaultTxProfile.validFrom, " ");
  3273. }
  3274. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3275. {
  3276. sprintf((char*)defaultTxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3277. }
  3278. else
  3279. {
  3280. sprintf((char*)defaultTxProfile.validTo, " ");
  3281. }
  3282. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  3283. {
  3284. sprintf((char*)defaultTxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  3285. }
  3286. else
  3287. {
  3288. sprintf((char*)defaultTxProfile.recurrencyKind, " ");
  3289. }
  3290. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3291. {
  3292. sprintf((char*)defaultTxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  3293. }
  3294. else
  3295. {
  3296. sprintf((char*)defaultTxProfile.transactionId, " ");
  3297. }
  3298. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3299. {
  3300. defaultTxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3301. }
  3302. else
  3303. {
  3304. defaultTxProfile.chargingSchedule[idxSchedule].duration = 86400;
  3305. }
  3306. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3307. {
  3308. 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")));
  3309. }
  3310. else
  3311. {
  3312. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", ((strstr((char*)ShmOCPP20Data->StatusNotification[(connectorId==0?0:connectorId-1)].connectorStatus, "Charging")==NULL) ? compositeProfile->chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp));
  3313. }
  3314. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3315. {
  3316. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3317. }
  3318. else
  3319. {
  3320. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3321. }
  3322. }
  3323. }
  3324. }
  3325. json_object_put(obj);
  3326. }
  3327. fclose(fp);
  3328. /*
  3329. if(defaultTxProfile.ChargingProfileId != -1)
  3330. {
  3331. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3332. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3333. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3334. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3335. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3336. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3337. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3338. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].StartSchedule);
  3339. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.chargingSchedule[idxSchedule].Duration);
  3340. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  3341. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  3342. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  3343. {
  3344. if(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3345. {
  3346. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3347. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  3348. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3349. }
  3350. }
  3351. }
  3352. else
  3353. DEBUG_INFO("TxDefaultProfile not found.\n");
  3354. DEBUG_INFO("------------------------------------\n");*/
  3355. }
  3356. // Search max profile
  3357. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  3358. if((access(profileFileName, F_OK))!=-1)
  3359. {
  3360. fp = fopen(profileFileName, "r");
  3361. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3362. {
  3363. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3364. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3365. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3366. }
  3367. maxProfile.id = -1;
  3368. maxProfile.stackLevel = -1;
  3369. while(getline(&line, &len, fp) != -1)
  3370. {
  3371. json_object *obj = NULL;
  3372. obj = json_tokener_parse(line);
  3373. if(is_error(obj))
  3374. {
  3375. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  3376. }
  3377. else
  3378. {
  3379. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.id) &&
  3380. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.stackLevel)
  3381. )
  3382. {
  3383. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  3384. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3385. )
  3386. {
  3387. struct tm tmFrom, tmTo;
  3388. struct timeb tbFrom, tbTo;
  3389. 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) &&
  3390. (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))
  3391. {
  3392. tmFrom.tm_year -= 1900;
  3393. tmFrom.tm_mon -= 1;
  3394. tbFrom.time = mktime(&tmFrom);
  3395. tmTo.tm_year -= 1900;
  3396. tmTo.tm_mon -= 1;
  3397. tbTo.time = mktime(&tmTo);
  3398. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3399. {
  3400. if(maxProfile.id == -1)
  3401. DEBUG_INFO("MaxProfile found.\n");
  3402. else
  3403. DEBUG_INFO("MaxProfile updated.\n");
  3404. // Required item
  3405. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3406. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3407. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3408. if(isUnitA)
  3409. {
  3410. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3411. 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++)
  3412. {
  3413. 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"));
  3414. 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?
  3415. 3:
  3416. 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")));
  3417. 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")));
  3418. }
  3419. }
  3420. else
  3421. {
  3422. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3423. 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++)
  3424. {
  3425. 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"));
  3426. 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?
  3427. 3:
  3428. 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")));
  3429. 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));
  3430. }
  3431. }
  3432. // Optional item
  3433. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3434. {
  3435. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3436. }
  3437. else
  3438. {
  3439. sprintf((char*)maxProfile.validFrom, " ");
  3440. }
  3441. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3442. {
  3443. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3444. }
  3445. else
  3446. {
  3447. sprintf((char*)maxProfile.validTo, " ");
  3448. }
  3449. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  3450. {
  3451. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  3452. }
  3453. else
  3454. {
  3455. sprintf((char*)maxProfile.recurrencyKind, " ");
  3456. }
  3457. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3458. {
  3459. sprintf((char*)maxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  3460. }
  3461. else
  3462. {
  3463. sprintf((char*)maxProfile.transactionId, " ");
  3464. }
  3465. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3466. {
  3467. maxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3468. }
  3469. else
  3470. {
  3471. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  3472. }
  3473. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3474. {
  3475. 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")));
  3476. }
  3477. else
  3478. {
  3479. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", ((strstr((char*)ShmOCPP20Data->StatusNotification[(connectorId==0?0:connectorId-1)].connectorStatus, "Charging")==NULL) ? compositeProfile->chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp));
  3480. }
  3481. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3482. {
  3483. maxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3484. }
  3485. else
  3486. {
  3487. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3488. }
  3489. }
  3490. }
  3491. }
  3492. else
  3493. {
  3494. if(maxProfile.id == -1)
  3495. DEBUG_INFO("MaxProfile found.\n");
  3496. else
  3497. DEBUG_INFO("MaxProfile updated.\n");
  3498. // Required item
  3499. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3500. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3501. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3502. if(isUnitA)
  3503. {
  3504. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3505. 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++)
  3506. {
  3507. 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"));
  3508. 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?
  3509. 3:
  3510. 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")));
  3511. 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")));
  3512. }
  3513. }
  3514. else
  3515. {
  3516. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3517. 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++)
  3518. {
  3519. 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"));
  3520. 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?
  3521. 3:
  3522. 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")));
  3523. 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));
  3524. }
  3525. }
  3526. // Optional item
  3527. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3528. {
  3529. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3530. }
  3531. else
  3532. {
  3533. sprintf((char*)maxProfile.validFrom, " ");
  3534. }
  3535. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3536. {
  3537. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3538. }
  3539. else
  3540. {
  3541. sprintf((char*)maxProfile.validTo, " ");
  3542. }
  3543. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  3544. {
  3545. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  3546. }
  3547. else
  3548. {
  3549. sprintf((char*)maxProfile.recurrencyKind, " ");
  3550. }
  3551. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3552. {
  3553. sprintf((char*)maxProfile.transactionId,"%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  3554. }
  3555. else
  3556. {
  3557. sprintf((char*)maxProfile.transactionId, " ");
  3558. }
  3559. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3560. {
  3561. maxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3562. }
  3563. else
  3564. {
  3565. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  3566. }
  3567. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3568. {
  3569. 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")));
  3570. }
  3571. else
  3572. {
  3573. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].startSchedule, "%s", ((strstr((char*)ShmOCPP20Data->StatusNotification[(connectorId==0?0:connectorId-1)].connectorStatus, "Charging")==NULL) ? compositeProfile->chargingSchedule[idxSchedule].startSchedule : ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp));
  3574. }
  3575. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3576. {
  3577. maxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3578. }
  3579. else
  3580. {
  3581. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3582. }
  3583. }
  3584. }
  3585. }
  3586. json_object_put(obj);
  3587. }
  3588. fclose(fp);
  3589. /*
  3590. if(maxProfile.ChargingProfileId !=-1)
  3591. {
  3592. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3593. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3594. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3595. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3596. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3597. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3598. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3599. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.chargingSchedule[idxSchedule].StartSchedule);
  3600. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  3601. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  3602. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  3603. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  3604. {
  3605. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3606. {
  3607. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3608. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  3609. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3610. }
  3611. }
  3612. }
  3613. else
  3614. DEBUG_INFO("MaxProfile not found.\n");
  3615. DEBUG_INFO("------------------------------------\n");*/
  3616. }
  3617. /*
  3618. * Align found profile start schedule & periods
  3619. */
  3620. //DEBUG_INFO("====================================\n");
  3621. /*
  3622. // For local test usage, force modify found profile start schedule info
  3623. 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);
  3624. 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);
  3625. 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);
  3626. */
  3627. if(txProfile.id != -1)
  3628. {
  3629. if(strstr((char*)txProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  3630. {
  3631. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  3632. {
  3633. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  3634. 0:
  3635. (txProfile.chargingSchedule[idxSchedule].duration-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  3636. }
  3637. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3638. {
  3639. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3640. {
  3641. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  3642. 0:
  3643. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  3644. if(idxPeriod > 0)
  3645. {
  3646. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3647. {
  3648. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3649. }
  3650. }
  3651. }
  3652. }
  3653. }
  3654. else if(strstr((char*)txProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  3655. {
  3656. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  3657. {
  3658. txProfile.chargingSchedule[idxSchedule].duration = (strstr((char*)ShmOCPP20Data->StatusNotification[(connectorId==0?0:connectorId-1)].connectorStatus, "Charging")==NULL)?txProfile.chargingSchedule[idxSchedule].duration:((txProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  3659. 0:
  3660. (txProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  3661. }
  3662. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3663. {
  3664. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3665. {
  3666. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = (strstr((char*)ShmOCPP20Data->StatusNotification[(connectorId==0?0:connectorId-1)].connectorStatus, "Charging")==NULL)?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?
  3667. 0:
  3668. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  3669. if(idxPeriod > 0)
  3670. {
  3671. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3672. {
  3673. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3674. }
  3675. }
  3676. }
  3677. }
  3678. }
  3679. else
  3680. {
  3681. if(strstr((char*)txProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  3682. {
  3683. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  3684. {
  3685. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  3686. 0:
  3687. (txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  3688. }
  3689. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3690. {
  3691. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3692. {
  3693. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  3694. 0:
  3695. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  3696. if(idxPeriod > 0)
  3697. {
  3698. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3699. {
  3700. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3701. }
  3702. }
  3703. }
  3704. }
  3705. }
  3706. else
  3707. {
  3708. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  3709. {
  3710. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  3711. 0:
  3712. (txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  3713. }
  3714. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3715. {
  3716. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3717. {
  3718. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  3719. 0:
  3720. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  3721. if(idxPeriod > 0)
  3722. {
  3723. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3724. {
  3725. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3726. }
  3727. }
  3728. }
  3729. }
  3730. }
  3731. }
  3732. /*
  3733. DEBUG_INFO("txProfile after align.\n");
  3734. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3735. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3736. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3737. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3738. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3739. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3740. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  3741. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3742. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.chargingSchedule[idxSchedule].Duration);
  3743. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  3744. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.chargingSchedule[idxSchedule].MinChargingRate);
  3745. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  3746. {
  3747. if(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3748. {
  3749. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3750. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  3751. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3752. }
  3753. }*/
  3754. }
  3755. if(defaultTxProfile.id != -1)
  3756. {
  3757. if(strstr((char*)defaultTxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  3758. {
  3759. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  3760. {
  3761. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  3762. 0:
  3763. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  3764. }
  3765. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3766. {
  3767. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3768. {
  3769. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  3770. 0:
  3771. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  3772. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod < txProfile.chargingSchedule[idxSchedule].duration)
  3773. {
  3774. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod += (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  3775. }
  3776. if(idxPeriod > 0)
  3777. {
  3778. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3779. {
  3780. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3781. }
  3782. }
  3783. }
  3784. }
  3785. }
  3786. else if(strstr((char*)defaultTxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  3787. {
  3788. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  3789. {
  3790. defaultTxProfile.chargingSchedule[idxSchedule].duration = (strstr((char*)ShmOCPP20Data->StatusNotification[(connectorId==0?0:connectorId-1)].connectorStatus, "Charging")==NULL)?defaultTxProfile.chargingSchedule[idxSchedule].duration:((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  3791. 0:
  3792. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  3793. }
  3794. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3795. {
  3796. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3797. {
  3798. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = (strstr((char*)ShmOCPP20Data->StatusNotification[(connectorId==0?0:connectorId-1)].connectorStatus, "Charging")==NULL)?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?
  3799. 0:
  3800. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  3801. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod < txProfile.chargingSchedule[idxSchedule].duration)
  3802. {
  3803. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod += (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  3804. }
  3805. if(idxPeriod > 0)
  3806. {
  3807. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3808. {
  3809. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3810. }
  3811. }
  3812. }
  3813. }
  3814. }
  3815. else
  3816. {
  3817. if(strstr((char*)defaultTxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  3818. {
  3819. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  3820. {
  3821. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  3822. 0:
  3823. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  3824. }
  3825. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3826. {
  3827. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3828. {
  3829. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  3830. 0:
  3831. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  3832. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod < txProfile.chargingSchedule[idxSchedule].duration)
  3833. {
  3834. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod += (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  3835. }
  3836. if(idxPeriod > 0)
  3837. {
  3838. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3839. {
  3840. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3841. }
  3842. }
  3843. }
  3844. }
  3845. }
  3846. else
  3847. {
  3848. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  3849. {
  3850. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  3851. 0:
  3852. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  3853. }
  3854. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3855. {
  3856. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3857. {
  3858. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  3859. 0:
  3860. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  3861. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod < txProfile.chargingSchedule[idxSchedule].duration)
  3862. {
  3863. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod += (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  3864. }
  3865. if(idxPeriod > 0)
  3866. {
  3867. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3868. {
  3869. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3870. }
  3871. }
  3872. }
  3873. }
  3874. }
  3875. }
  3876. /*
  3877. DEBUG_INFO("defaultTxProfile after align.\n");
  3878. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3879. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3880. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3881. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3882. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3883. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3884. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3885. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3886. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.chargingSchedule[idxSchedule].Duration);
  3887. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  3888. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  3889. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  3890. {
  3891. if(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3892. {
  3893. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3894. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  3895. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3896. }
  3897. }
  3898. DEBUG_INFO("------------------------------------\n");*/
  3899. }
  3900. if(maxProfile.id != -1)
  3901. {
  3902. if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  3903. {
  3904. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3905. {
  3906. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  3907. 0:
  3908. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  3909. }
  3910. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3911. {
  3912. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3913. {
  3914. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  3915. 0:
  3916. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  3917. if(idxPeriod > 0)
  3918. {
  3919. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3920. {
  3921. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3922. }
  3923. }
  3924. }
  3925. }
  3926. }
  3927. else if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  3928. {
  3929. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3930. {
  3931. maxProfile.chargingSchedule[idxSchedule].duration = (strstr((char*)ShmOCPP20Data->StatusNotification[(connectorId==0?0:connectorId-1)].connectorStatus, "Charging")==NULL)?maxProfile.chargingSchedule[idxSchedule].duration:((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  3932. 0:
  3933. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[9].startSchedule)));
  3934. }
  3935. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3936. {
  3937. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3938. {
  3939. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = (strstr((char*)ShmOCPP20Data->StatusNotification[(connectorId==0?0:connectorId-1)].connectorStatus, "Charging")==NULL)?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?
  3940. 0:
  3941. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  3942. if(idxPeriod > 0)
  3943. {
  3944. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3945. {
  3946. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3947. }
  3948. }
  3949. }
  3950. }
  3951. }
  3952. else
  3953. {
  3954. if(strstr((char*)maxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  3955. {
  3956. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3957. {
  3958. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  3959. 0:
  3960. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  3961. }
  3962. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3963. {
  3964. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3965. {
  3966. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  3967. 0:
  3968. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  3969. if(idxPeriod > 0)
  3970. {
  3971. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3972. {
  3973. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3974. }
  3975. }
  3976. }
  3977. }
  3978. }
  3979. else
  3980. {
  3981. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3982. {
  3983. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  3984. 0:
  3985. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  3986. }
  3987. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3988. {
  3989. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3990. {
  3991. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  3992. 0:
  3993. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  3994. if(idxPeriod > 0)
  3995. {
  3996. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3997. {
  3998. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3999. }
  4000. }
  4001. }
  4002. }
  4003. }
  4004. }
  4005. /*
  4006. DEBUG_INFO("MaxProfile after align.\n");
  4007. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  4008. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  4009. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  4010. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  4011. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  4012. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  4013. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  4014. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  4015. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  4016. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4017. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4018. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4019. {
  4020. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4021. {
  4022. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4023. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4024. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4025. }
  4026. }
  4027. DEBUG_INFO("------------------------------------\n");*/
  4028. }
  4029. /*
  4030. * Merge to conposite schedule
  4031. */
  4032. //DEBUG_INFO("====================================\n");
  4033. // Find each profile period quantity
  4034. for(int idx=0;idx<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  4035. {
  4036. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  4037. limitMax = idx+1;
  4038. }
  4039. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  4040. {
  4041. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  4042. limitDef = idx+1;
  4043. }
  4044. for(int idx=0;idx<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  4045. {
  4046. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  4047. limitTx = idx+1;
  4048. }
  4049. // TxProfile found, composite schedule based on it
  4050. if(txProfile.id != -1)
  4051. {
  4052. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  4053. {
  4054. if((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit != -1) &&
  4055. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod < durationReq) &&
  4056. (txProfile.chargingSchedule[idxSchedule].duration > 0))
  4057. {
  4058. if(maxProfile.id != -1)
  4059. {
  4060. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4061. {
  4062. if((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod))
  4063. {
  4064. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  4065. {
  4066. tmpPeriod.startPeriod = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod;
  4067. tmpPeriod.numberPhases = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].numberPhases;
  4068. 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);
  4069. }
  4070. else
  4071. {
  4072. tmpPeriod.startPeriod = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod;
  4073. tmpPeriod.numberPhases = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].numberPhases;
  4074. tmpPeriod.limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit;
  4075. }
  4076. }
  4077. if(idxMaxPeriod == (limitMax-1))
  4078. {
  4079. if(tmpPeriod.limit != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  4080. {
  4081. if(tmpPeriod.startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4082. {
  4083. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4084. compositePeriodIdx++;
  4085. }
  4086. else
  4087. {
  4088. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4089. }
  4090. }
  4091. }
  4092. }
  4093. }
  4094. else
  4095. {
  4096. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4097. {
  4098. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod],sizeof(struct ChargingSchedulePeriodType));
  4099. compositePeriodIdx++;
  4100. }
  4101. else
  4102. {
  4103. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod],sizeof(struct ChargingSchedulePeriodType));
  4104. }
  4105. }
  4106. }
  4107. if(idxTxPeriod == (limitTx-1))
  4108. {
  4109. if(defaultTxProfile.id != -1)
  4110. {
  4111. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  4112. {
  4113. if((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod + (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod))) &&
  4114. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod < durationReq) &&
  4115. (defaultTxProfile.chargingSchedule[idxSchedule].duration>0))
  4116. {
  4117. if(maxProfile.id != -1)
  4118. {
  4119. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4120. {
  4121. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod)
  4122. {
  4123. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  4124. {
  4125. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  4126. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  4127. 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);
  4128. }
  4129. else
  4130. {
  4131. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  4132. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  4133. tmpPeriod.limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit;
  4134. }
  4135. if(tmpPeriod.limit != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  4136. {
  4137. if(tmpPeriod.startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4138. {
  4139. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4140. compositePeriodIdx++;
  4141. }
  4142. else
  4143. {
  4144. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4145. }
  4146. }
  4147. // Delete duplicate period
  4148. if(compositePeriodIdx > 1)
  4149. {
  4150. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  4151. {
  4152. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  4153. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  4154. compositePeriodIdx -= 1;
  4155. }
  4156. }
  4157. }
  4158. else
  4159. break;
  4160. }
  4161. }
  4162. else
  4163. {
  4164. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4165. {
  4166. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  4167. compositePeriodIdx++;
  4168. }
  4169. else
  4170. {
  4171. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  4172. }
  4173. }
  4174. }
  4175. }
  4176. }
  4177. }
  4178. }
  4179. }
  4180. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  4181. else if(defaultTxProfile.id != -1)
  4182. {
  4183. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  4184. {
  4185. if((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit != -1) &&
  4186. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod < durationReq) &&
  4187. (defaultTxProfile.chargingSchedule[idxSchedule].duration > 0))
  4188. {
  4189. if(maxProfile.id != -1)
  4190. {
  4191. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4192. {
  4193. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod)
  4194. {
  4195. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  4196. {
  4197. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  4198. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  4199. 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);
  4200. }
  4201. else
  4202. {
  4203. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  4204. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  4205. tmpPeriod.limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit;
  4206. }
  4207. if(tmpPeriod.limit != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  4208. {
  4209. if(tmpPeriod.startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4210. {
  4211. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4212. compositePeriodIdx++;
  4213. }
  4214. else
  4215. {
  4216. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4217. }
  4218. }
  4219. // Delete duplicate period
  4220. if(compositePeriodIdx > 1)
  4221. {
  4222. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  4223. {
  4224. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  4225. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  4226. compositePeriodIdx -= 1;
  4227. }
  4228. }
  4229. }
  4230. else
  4231. break;
  4232. }
  4233. }
  4234. else
  4235. {
  4236. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4237. {
  4238. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  4239. compositePeriodIdx++;
  4240. }
  4241. else
  4242. {
  4243. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  4244. }
  4245. }
  4246. }
  4247. }
  4248. }
  4249. // Fill other period by MaxProfile
  4250. if(maxProfile.id != -1)
  4251. {
  4252. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4253. {
  4254. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  4255. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  4256. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  4257. {
  4258. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod >= compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].startPeriod) &&
  4259. (maxProfile.chargingSchedule[idxSchedule].duration > compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].startPeriod))
  4260. {
  4261. tmpPeriod.startPeriod = (compositePeriodIdx==0)?0:compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].startPeriod;
  4262. tmpPeriod.numberPhases = compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].numberPhases;
  4263. tmpPeriod.limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit;
  4264. }
  4265. if((compositePeriodIdx > 0) && (maxProfile.chargingSchedule[idxSchedule].duration > compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].startPeriod))
  4266. {
  4267. 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;
  4268. tmpPeriod.numberPhases = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].numberPhases;
  4269. tmpPeriod.limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit;
  4270. }
  4271. if(tmpPeriod.limit != -1)
  4272. {
  4273. if(tmpPeriod.limit != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  4274. {
  4275. if(tmpPeriod.startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4276. {
  4277. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4278. compositePeriodIdx++;
  4279. }
  4280. else
  4281. {
  4282. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4283. }
  4284. }
  4285. // Delete duplicate period
  4286. if(compositePeriodIdx > 1)
  4287. {
  4288. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  4289. {
  4290. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  4291. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  4292. compositePeriodIdx -= 1;
  4293. }
  4294. }
  4295. }
  4296. }
  4297. }
  4298. }
  4299. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  4300. DEBUG_INFO("Schedule start: %s\n", compositeProfile->chargingSchedule[idxSchedule].startSchedule);
  4301. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->chargingSchedule[idxSchedule].duration);
  4302. DEBUG_INFO("Rate unit: %s\n", compositeProfile->chargingSchedule[idxSchedule].chargingRateUnit);
  4303. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4304. {
  4305. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod >= 0)
  4306. {
  4307. compositeProfile->id = 1;
  4308. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  4309. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit);
  4310. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases);
  4311. }
  4312. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit == -1)
  4313. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit =0;
  4314. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod == -1)
  4315. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod =0;
  4316. }
  4317. if(line)
  4318. free(line);
  4319. ShmOCPP20Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = ON;
  4320. }
  4321. //==========================================
  4322. // Init all share memory
  4323. //==========================================
  4324. int InitShareMemory()
  4325. {
  4326. int result = PASS;
  4327. int MeterSMId;
  4328. //creat ShmSysConfigAndInfo
  4329. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  4330. {
  4331. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  4332. result = FAIL;
  4333. }
  4334. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4335. {
  4336. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  4337. result = FAIL;
  4338. }
  4339. else
  4340. {}
  4341. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  4342. {
  4343. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  4344. result = FAIL;
  4345. }
  4346. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4347. {
  4348. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  4349. result = FAIL;
  4350. }
  4351. else
  4352. {}
  4353. //creat ShmPsuData
  4354. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  4355. {
  4356. DEBUG_ERROR("shmget ShmPsuData NG\n");
  4357. result = FAIL;
  4358. }
  4359. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4360. {
  4361. DEBUG_ERROR("shmat ShmPsuData NG\n");
  4362. result = FAIL;
  4363. }
  4364. else
  4365. {}
  4366. //creat ShmOCPP20Data
  4367. if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), 0777)) < 0)
  4368. {
  4369. DEBUG_ERROR("shmget ShmOCPP20Data NG\n");
  4370. result = FAIL;
  4371. }
  4372. else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4373. {
  4374. DEBUG_ERROR("shmat ShmOCPP20Data NG\n");
  4375. result = FAIL;
  4376. }
  4377. else
  4378. {}
  4379. /****************************** For Initial Settings************************************************/
  4380. /*
  4381. DEBUG_INFO("Authorize_20 size: %d\n", sizeof(struct Authorize_20));
  4382. DEBUG_INFO("BootNotification_20 size: %d\n", sizeof(struct BootNotification_20));
  4383. DEBUG_INFO("CancelReservation_20 size: %d\n", sizeof(struct CancelReservation_20));
  4384. DEBUG_INFO("CertificateSigned_20 size: %d\n", sizeof(struct CertificateSigned_20));
  4385. DEBUG_INFO("ChangeAvailability_20 size: %d\n", sizeof(struct ChangeAvailability_20));
  4386. DEBUG_INFO("ClearCache_20 size: %d\n", sizeof(struct ClearCache_20));
  4387. DEBUG_INFO("ClearChargingProfile_20 size: %d\n", sizeof(struct ClearChargingProfile_20));
  4388. DEBUG_INFO("ClearDisplayMessage_20 size: %d\n", sizeof(struct ClearDisplayMessage_20));
  4389. DEBUG_INFO("ClearedChargingLimit_20 size: %d\n", sizeof(struct ClearedChargingLimit_20));
  4390. DEBUG_INFO("ClearVariableMonitoring_20 size: %d\n", sizeof(struct ClearVariableMonitoring_20));
  4391. DEBUG_INFO("CostUpdated_20 size: %d\n", sizeof(struct CostUpdated_20));
  4392. DEBUG_INFO("CustomerInformation_20 size: %d\n", sizeof(struct CustomerInformation_20));
  4393. DEBUG_INFO("DeleteCertificate_20 size: %d\n", sizeof(struct DeleteCertificate_20));
  4394. DEBUG_INFO("FirmwareStatusNotification_20 size: %d\n", sizeof(struct FirmwareStatusNotification_20));
  4395. DEBUG_INFO("Get15118EVCertificate_20 size: %d\n", sizeof(struct Get15118EVCertificate_20));
  4396. DEBUG_INFO("GetBaseReport_20 size: %d\n", sizeof(struct GetBaseReport_20));
  4397. DEBUG_INFO("GetCertificateStatus_20 size: %d\n", sizeof(struct GetCertificateStatus_20));
  4398. DEBUG_INFO("GetChargingProfiles_20 size: %d\n", sizeof(struct GetChargingProfiles_20));
  4399. DEBUG_INFO("GetCompositeSchedule_20 size: %d\n", sizeof(struct GetCompositeSchedule_20));
  4400. DEBUG_INFO("GetDisplayMessages_20 size: %d\n", sizeof(struct GetDisplayMessages_20));
  4401. DEBUG_INFO("GetInstalledCertificateIds_20 size: %d\n", sizeof(struct GetInstalledCertificateIds_20));
  4402. DEBUG_INFO("GetLog_20 size: %d\n", sizeof(struct GetLog_20));
  4403. DEBUG_INFO("GetMonitoringReport_20 size: %d\n", sizeof(struct GetMonitoringReport_20));
  4404. DEBUG_INFO("GetReport_20 size: %d\n", sizeof(struct GetReport_20));
  4405. DEBUG_INFO("GetTransactionStatus_20 size: %d\n", sizeof(struct GetTransactionStatus_20));
  4406. DEBUG_INFO("GetVariables_20 size: %d\n", sizeof(struct GetVariables_20));
  4407. DEBUG_INFO("InstallCertificate_20 size: %d\n", sizeof(struct InstallCertificate_20));
  4408. DEBUG_INFO("LogStatusNotification_20 size: %d\n", sizeof(struct LogStatusNotification_20));
  4409. DEBUG_INFO("MeterValues_20 size: %d\n", sizeof(struct MeterValues_20));
  4410. DEBUG_INFO("NotifyChargingLimit_20 size: %d\n", sizeof(struct NotifyChargingLimit_20));
  4411. DEBUG_INFO("NotifyCustomerInformation_20 size: %d\n", sizeof(struct NotifyCustomerInformation_20));
  4412. DEBUG_INFO("NotifyDisplayMessages_20 size: %d\n", sizeof(struct NotifyDisplayMessages_20));
  4413. DEBUG_INFO("NotifyEVChargingNeeds_20 size: %d\n", sizeof(struct NotifyEVChargingNeeds_20));
  4414. DEBUG_INFO("NotifyEVChargingSchedule_20 size: %d\n", sizeof(struct NotifyEVChargingSchedule_20));
  4415. DEBUG_INFO("NotifyEvent_20 size: %d\n", sizeof(struct NotifyEvent_20));
  4416. DEBUG_INFO("NotifyMonitoringReport_20 size: %d\n", sizeof(struct NotifyMonitoringReport_20));
  4417. DEBUG_INFO("NotifyReport_20 size: %d\n", sizeof(struct NotifyReport_20));
  4418. DEBUG_INFO("PublishFirmware_20 size: %d\n", sizeof(struct PublishFirmware_20));
  4419. DEBUG_INFO("PublishFirmwareStatusNotification_20 size: %d\n", sizeof(struct PublishFirmwareStatusNotification_20));
  4420. DEBUG_INFO("ReportChargingProfiles_20 size: %d\n", sizeof(struct ReportChargingProfiles_20));
  4421. DEBUG_INFO("RequestStartTransaction_20 size: %d\n", sizeof(struct RequestStartTransaction_20));
  4422. DEBUG_INFO("RequestStopTransaction_20 size: %d\n", sizeof(struct RequestStopTransaction_20));
  4423. DEBUG_INFO("ReservationStatusUpdate_20 size: %d\n", sizeof(struct ReservationStatusUpdate_20));
  4424. DEBUG_INFO("ReserveNow_20 size: %d\n", sizeof(struct ReserveNow_20));
  4425. DEBUG_INFO("Reset_20 size: %d\n", sizeof(struct Reset_20));
  4426. DEBUG_INFO("SecurityEventNotification_20 size: %d\n", sizeof(struct SecurityEventNotification_20));
  4427. DEBUG_INFO("SendLocalList_20 size: %d\n", sizeof(struct SendLocalList_20));
  4428. DEBUG_INFO("SetChargingProfile_20 size: %d\n", sizeof(struct SetChargingProfile_20));
  4429. DEBUG_INFO("SetDisplayMessage_20 size: %d\n", sizeof(struct SetDisplayMessage_20));
  4430. DEBUG_INFO("SetMonitoringBase_20 size: %d\n", sizeof(struct SetMonitoringBase_20));
  4431. DEBUG_INFO("SetMonitoringLevel_20 size: %d\n", sizeof(struct SetMonitoringLevel_20));
  4432. DEBUG_INFO("SetNetworkProfile_20 size: %d\n", sizeof(struct SetNetworkProfile_20));
  4433. DEBUG_INFO("SetVariableMonitoring_20 size: %d\n", sizeof(struct SetVariableMonitoring_20));
  4434. DEBUG_INFO("SetVariables_20 size: %d\n", sizeof(struct SetVariables_20));
  4435. DEBUG_INFO("SignCertificate_20 size: %d\n", sizeof(struct SignCertificate_20));
  4436. DEBUG_INFO("StatusNotification_20 size: %d\n", sizeof(struct StatusNotification_20));
  4437. DEBUG_INFO("TransactionEvent_20 size: %d\n", sizeof(struct TransactionEvent_20));
  4438. DEBUG_INFO("TriggerMessage_20 size: %d\n", sizeof(struct TriggerMessage_20));
  4439. DEBUG_INFO("UnlockConnector_20 size: %d\n", sizeof(struct UnlockConnector_20));
  4440. DEBUG_INFO("UnpublishFirmware_20 size: %d\n", sizeof(struct UnpublishFirmware_20));
  4441. DEBUG_INFO("UpdateFirmware_20 size: %d\n", sizeof(struct UpdateFirmware_20));
  4442. DEBUG_INFO("ChargingProfileType size: %d\n", sizeof(struct ChargingProfileType));
  4443. */
  4444. return result;
  4445. }
  4446. int ProcessShareMemory()
  4447. {
  4448. if(InitShareMemory() == FAIL)
  4449. {
  4450. DEBUG_ERROR("InitShareMemory NG\n");
  4451. if(ShmStatusCodeData!=NULL)
  4452. {
  4453. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  4454. }
  4455. sleep(5);
  4456. return FAIL;
  4457. }
  4458. return PASS;
  4459. }
  4460. //---------------------common routine---------------------------//
  4461. void checkNetworkProfile(void)
  4462. {
  4463. memcpy(ShmOCPP20Data->OcppServerURL, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmOCPP20Data->OcppServerURL));
  4464. json_object *priority;
  4465. priority = json_tokener_parse((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value);
  4466. if(!is_error(priority))
  4467. {
  4468. for(uint8_t idxPriority=0;idxPriority<json_object_array_length(priority);idxPriority++)
  4469. {
  4470. for(uint8_t idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile);idx++)
  4471. {
  4472. if((ShmOCPP20Data->NetworkConnectionProfile[idx].slot == json_object_get_int(json_object_array_get_idx(priority, idxPriority))) &&
  4473. (strlen((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl) > 0) &&
  4474. (ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount < 3))
  4475. {
  4476. memcpy(ShmOCPP20Data->OcppServerURL, ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl));
  4477. ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount++;
  4478. break;
  4479. }
  4480. }
  4481. }
  4482. }
  4483. json_object_put(priority);
  4484. DEBUG_INFO("Get network profile URL: %s\n", ShmOCPP20Data->OcppServerURL);
  4485. }
  4486. void CheckSystemValue(void)
  4487. {
  4488. char filenmae[100]={0};
  4489. char str[100]={0};
  4490. int tempIndex = 0;
  4491. //===============================
  4492. // EVSE operation check
  4493. //===============================
  4494. //===============================
  4495. // Heartbeat check
  4496. //===============================
  4497. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  4498. {
  4499. clientTime.Heartbeat = time((time_t*)NULL);
  4500. if(server_sign == TRUE)
  4501. {
  4502. HeartBeatWaitTime = ShmOCPP20Data->BootNotification.Response_interval;
  4503. }
  4504. else
  4505. {
  4506. HeartBeatWaitTime = atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value);
  4507. }
  4508. }
  4509. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4510. {
  4511. //parameter for test
  4512. sendHeartbeatRequest(0);
  4513. //==============================================
  4514. // Reset Waiting Time
  4515. //==============================================
  4516. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  4517. }
  4518. //===============================
  4519. // CSU Trigger Authorize Request
  4520. //===============================
  4521. if(isWebsocketSendable &&
  4522. (server_sign == TRUE) &&
  4523. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON) &&
  4524. (authorizeRetryTimes < 3))
  4525. {
  4526. sendAuthorizeRequest(0);
  4527. authorizeRetryTimes = authorizeRetryTimes + 1;
  4528. if(authorizeRetryTimes < 3)
  4529. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  4530. }
  4531. else if((server_sign == TRUE) &&
  4532. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON) &&
  4533. (authorizeRetryTimes >= 3))
  4534. {
  4535. authorizeRetryTimes = 0;
  4536. SetOcppConnStatus(FALSE);
  4537. server_sign = FALSE;
  4538. }
  4539. else if((server_sign == FALSE) &&
  4540. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "TRUE") == 0) &&
  4541. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].value, "TRUE") == 0) &&
  4542. (ShmOCPP20Data->OcppConnStatus == OFF) &&
  4543. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON))
  4544. {
  4545. sendAuthorizeRequest(0);
  4546. }
  4547. if(isWebsocketSendable &&
  4548. (server_sign == TRUE) &&
  4549. (ShmOCPP20Data->GetMonitoringReport.requestId > 0))
  4550. {
  4551. for(uint8_t idxCriterion=0;idxCriterion<ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.monitoringCriteria);idxCriterion++)
  4552. {
  4553. if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_ThresholdMonitoring]) == 0)
  4554. {
  4555. /*
  4556. * TODO:
  4557. * 1. Report component that are ThresholdMonitoring
  4558. */
  4559. }
  4560. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_DeltaMonitoring]) == 0)
  4561. {
  4562. /*
  4563. * TODO:
  4564. * 1. Report component that are DeltaMonitoring
  4565. */
  4566. }
  4567. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_PeriodicMonitoring]) == 0)
  4568. {
  4569. /*
  4570. * TODO:
  4571. * 1. Report component that are PeriodicMonitoring
  4572. */
  4573. }
  4574. else
  4575. {
  4576. /*
  4577. * TODO:
  4578. * 1. Process unknown criteria condition
  4579. */
  4580. }
  4581. }
  4582. ShmOCPP20Data->GetMonitoringReport.requestId = 0;
  4583. }
  4584. if(isWebsocketSendable &&
  4585. (server_sign == TRUE) &&
  4586. (ShmOCPP20Data->GetReport.requestId > 0))
  4587. {
  4588. for(uint8_t idxCriterion=0;idxCriterion<ARRAY_SIZE(ShmOCPP20Data->GetReport.componentCriteria);idxCriterion++)
  4589. {
  4590. if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Active]) == 0)
  4591. {
  4592. /*
  4593. * TODO:
  4594. * 1. Report component that are active
  4595. */
  4596. }
  4597. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Available]) == 0)
  4598. {
  4599. /*
  4600. * TODO:
  4601. * 1. Report component that are available
  4602. */
  4603. }
  4604. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Enabled]) == 0)
  4605. {
  4606. /*
  4607. * TODO:
  4608. * 1. Report component that are enable
  4609. */
  4610. }
  4611. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Problem]) == 0)
  4612. {
  4613. /*
  4614. * TODO:
  4615. * 1. Report component that are problem
  4616. */
  4617. }
  4618. else
  4619. {
  4620. /*
  4621. * TODO:
  4622. * 1. Process unknown criteria condition
  4623. */
  4624. }
  4625. }
  4626. ShmOCPP20Data->GetReport.requestId = 0;
  4627. }
  4628. if(isWebsocketSendable &&
  4629. (server_sign == TRUE) &&
  4630. (ShmOCPP20Data->GetBaseReport.requestId > 0))
  4631. {
  4632. uint8_t reportIdx = 0;
  4633. ShmOCPP20Data->NotifyReport.requestId = ShmOCPP20Data->GetBaseReport.requestId;
  4634. if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_ConfigurationInventory]) == 0)
  4635. {
  4636. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  4637. {
  4638. if(reportIdx < ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData))
  4639. {
  4640. 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))
  4641. {
  4642. memcpy(&ShmOCPP20Data->NotifyReport.reportData[reportIdx], &ShmOCPP20Data->ControllerComponentVariable[idx_var], sizeof(struct ReportDataType));
  4643. reportIdx++;
  4644. }
  4645. }
  4646. else
  4647. {
  4648. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  4649. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  4650. ShmOCPP20Data->NotifyReport.seqNo += 1;
  4651. else
  4652. ShmOCPP20Data->NotifyReport.seqNo = 0;
  4653. sendNotifyReportRequest();
  4654. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  4655. reportIdx = 0;
  4656. }
  4657. }
  4658. }
  4659. else if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_FullInventory]) == 0)
  4660. {
  4661. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  4662. {
  4663. if(reportIdx < ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData))
  4664. {
  4665. memcpy(&ShmOCPP20Data->NotifyReport.reportData[reportIdx], &ShmOCPP20Data->ControllerComponentVariable[idx_var], sizeof(struct ReportDataType));
  4666. reportIdx++;
  4667. }
  4668. else
  4669. {
  4670. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  4671. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  4672. ShmOCPP20Data->NotifyReport.seqNo += 1;
  4673. else
  4674. ShmOCPP20Data->NotifyReport.seqNo = 0;
  4675. sendNotifyReportRequest();
  4676. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  4677. reportIdx = 0;
  4678. }
  4679. }
  4680. }
  4681. else
  4682. {
  4683. /*
  4684. * TODO:
  4685. * 1. Fill out summary inventory to response message, currently not support
  4686. */
  4687. }
  4688. if(reportIdx > 0)
  4689. {
  4690. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  4691. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  4692. ShmOCPP20Data->NotifyReport.seqNo += 1;
  4693. else
  4694. ShmOCPP20Data->NotifyReport.seqNo = 0;
  4695. sendNotifyReportRequest();
  4696. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  4697. reportIdx = 0;
  4698. }
  4699. ShmOCPP20Data->GetBaseReport.requestId = 0;
  4700. }
  4701. if(isWebsocketSendable &&
  4702. (server_sign == TRUE) &&
  4703. ShmOCPP20Data->SpMsg.bits.NotifyEventReq)
  4704. {
  4705. getNowDatetime(ShmOCPP20Data->NotifyEvent.generatedAt);
  4706. ShmOCPP20Data->NotifyEvent.tbc = FALSE;
  4707. if(ShmOCPP20Data->NotifyEvent.seqNo < INT_MAX)
  4708. ShmOCPP20Data->NotifyEvent.seqNo += 1;
  4709. else
  4710. ShmOCPP20Data->NotifyEvent.seqNo = 0;
  4711. sendNotifyEventRequest();
  4712. memset(&ShmOCPP20Data->NotifyEvent.eventData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)* sizeof(struct EventDataType ));
  4713. ShmOCPP20Data->SpMsg.bits.NotifyEventReq = OFF;
  4714. }
  4715. if(isWebsocketSendable &&
  4716. (server_sign == TRUE) &&
  4717. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq)
  4718. {
  4719. if(strcmp((char*)ShmOCPP20Data->Get15118EVCertificate.action, CertificateActionEnumTypeStr[CertificateActionEnumType_Install]) == 0)
  4720. {
  4721. /*
  4722. * TODO:
  4723. * 1.
  4724. */
  4725. }
  4726. else if(strcmp((char*)ShmOCPP20Data->Get15118EVCertificate.action, CertificateActionEnumTypeStr[CertificateActionEnumType_Update]) == 0)
  4727. {
  4728. /*
  4729. * TODO:
  4730. * 1.
  4731. */
  4732. }
  4733. else
  4734. {
  4735. /*
  4736. * TODO:
  4737. * 1.
  4738. */
  4739. }
  4740. sendGet15118EVCertificateRequest();
  4741. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq = OFF;
  4742. }
  4743. //===============================
  4744. // Each connector operation check
  4745. //===============================
  4746. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4747. {
  4748. //==========================================
  4749. // csu trigger DataTransferReq
  4750. //==========================================
  4751. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].DataTransferReq == ON))
  4752. {
  4753. sendDataTransferRequest(gun_index);
  4754. ShmOCPP20Data->CsMsg.bits[gun_index].DataTransferReq = OFF;
  4755. }
  4756. //===============================
  4757. // CSU Trigger Smart Charging Profilw
  4758. //===============================
  4759. if(ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq == ON)
  4760. {
  4761. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP20Data->SmartChargingProfile[gun_index], 0, TRUE);
  4762. ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq = OFF;
  4763. }
  4764. //==============================================
  4765. // Charger start transaction
  4766. //==============================================
  4767. /*
  4768. if((ShmOCPP20Data->CpMsg.bits[gun_index].StartTransactionReq == ON))
  4769. {
  4770. ShmOCPP20Data->CpMsg.bits[gun_index].StartTransactionReq = OFF;
  4771. sendStartTransactionRequest(gun_index);
  4772. clientTime.StartTransaction = time((time_t*)NULL);
  4773. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  4774. }*/
  4775. //==============================================
  4776. // Charger stop transaction
  4777. //==============================================
  4778. /*
  4779. if(((ShmOCPP20Data->CpMsg.bits[gun_index].StopTransactionReq == ON)))
  4780. {
  4781. ShmOCPP20Data->CpMsg.bits[gun_index].StopTransactionReq =OFF;
  4782. sendStopTransactionRequest(gun_index);
  4783. clientTime.StopTransaction = time((time_t*)NULL);
  4784. }*/
  4785. //==============================================
  4786. // Charger status notification & Transaction event report
  4787. //==============================================
  4788. //--- Check Mode Change ---//
  4789. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4790. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4791. {
  4792. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4793. {
  4794. tempIndex = ((gun_index==2) ? 1: 0);
  4795. }
  4796. else
  4797. {
  4798. tempIndex = gun_index;
  4799. }
  4800. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4801. {
  4802. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4803. {
  4804. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4805. {
  4806. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4807. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4808. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  4809. if((SystemInitial == 0) &&
  4810. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING) &&
  4811. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_COMPLETE))
  4812. {
  4813. cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
  4814. }
  4815. }
  4816. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  4817. {
  4818. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4819. if((access(filenmae,F_OK))!=-1)
  4820. {
  4821. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4822. sprintf(str,"rm -f %s",filenmae);
  4823. system(str);
  4824. }
  4825. }
  4826. #if 1 // for TempStopTransaction
  4827. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  4828. {
  4829. checkTempStopTransaction(gun_index);
  4830. }
  4831. #endif
  4832. }
  4833. }
  4834. }
  4835. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4836. {
  4837. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4838. {
  4839. tempIndex = ((gun_index==2) ? 1: 0);
  4840. }
  4841. else
  4842. {
  4843. tempIndex = gun_index;
  4844. }
  4845. for (int index = 0; index < CCS_QUANTITY; index++)
  4846. {
  4847. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4848. {
  4849. 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]*/ )
  4850. {
  4851. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4852. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4853. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  4854. if((SystemInitial == 0) &&
  4855. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_PREPARING) &&
  4856. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_COMPLETE))
  4857. {
  4858. cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
  4859. }
  4860. }
  4861. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  4862. {
  4863. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4864. if((access(filenmae,F_OK))!=-1)
  4865. {
  4866. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4867. sprintf(str,"rm -f %s",filenmae);
  4868. system(str);
  4869. }
  4870. }
  4871. #if 1 // for TempStopTransaction
  4872. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  4873. {
  4874. checkTempStopTransaction(gun_index);
  4875. }
  4876. #endif
  4877. }
  4878. }
  4879. }
  4880. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4881. {
  4882. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4883. {
  4884. tempIndex = ((gun_index==2) ? 1: 0);
  4885. }
  4886. else
  4887. {
  4888. tempIndex = gun_index;
  4889. }
  4890. for (int index = 0; index < GB_QUANTITY; index++)
  4891. {
  4892. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4893. {
  4894. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4895. {
  4896. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4897. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4898. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  4899. if((SystemInitial == 0) &&
  4900. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_PREPARING) &&
  4901. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_COMPLETE))
  4902. {
  4903. cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
  4904. }
  4905. }
  4906. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  4907. {
  4908. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4909. if((access(filenmae,F_OK))!=-1)
  4910. {
  4911. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4912. sprintf(str,"rm -f %s",filenmae);
  4913. system(str);
  4914. }
  4915. }
  4916. #if 1 // for TempStopTransaction
  4917. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  4918. {
  4919. checkTempStopTransaction(gun_index);
  4920. }
  4921. #endif
  4922. }
  4923. }
  4924. }
  4925. else if(gunType[gun_index] == GUN_TYPE_DO)
  4926. {
  4927. tempIndex = gun_index;
  4928. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4929. {
  4930. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4931. {
  4932. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  4933. {
  4934. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  4935. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  4936. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  4937. if((SystemInitial == 0) &&
  4938. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_PREPARING) &&
  4939. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_COMPLETE))
  4940. {
  4941. cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
  4942. }
  4943. }
  4944. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // complete
  4945. {
  4946. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4947. if((access(filenmae,F_OK))!=-1)
  4948. {
  4949. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4950. sprintf(str,"rm -f %s",filenmae);
  4951. system(str);
  4952. }
  4953. }
  4954. #if 1 // for TempStopTransaction
  4955. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) && (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  4956. {
  4957. checkTempStopTransaction(gun_index);
  4958. }
  4959. #endif
  4960. }
  4961. }
  4962. }
  4963. else
  4964. {
  4965. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4966. {
  4967. tempIndex = 2;
  4968. }
  4969. else
  4970. {
  4971. tempIndex = gun_index;
  4972. }
  4973. for (int index = 0; index < AC_QUANTITY; index++)
  4974. {
  4975. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4976. {
  4977. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  4978. {
  4979. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  4980. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  4981. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  4982. if((SystemInitial == 0) &&
  4983. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_PREPARING) &&
  4984. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_COMPLETE))
  4985. {
  4986. cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
  4987. }
  4988. }
  4989. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  4990. {
  4991. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4992. if((access(filenmae,F_OK))!=-1)
  4993. {
  4994. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4995. sprintf(str,"rm -f %s",filenmae);
  4996. system(str);
  4997. }
  4998. }
  4999. #if 1 // for TempStopTransaction
  5000. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  5001. {
  5002. checkTempStopTransaction(gun_index);
  5003. }
  5004. #endif
  5005. }
  5006. }// END
  5007. }
  5008. if(isWebsocketSendable && (server_sign == TRUE) &&
  5009. (cpinitateMsg.bits[gun_index].StatusNotificationReq == ON) &&
  5010. ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) )
  5011. {
  5012. if(SystemInitial > 0)
  5013. SystemInitial -= 1;
  5014. sendStatusNotificationRequest(gun_index);
  5015. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  5016. }
  5017. if(isWebsocketSendable && (server_sign == TRUE) && (cpinitateMsg.bits[gun_index].TransactionEventReq == ON))
  5018. {
  5019. sendTransactionEventRequest(gun_index);
  5020. cpinitateMsg.bits[gun_index].TransactionEventReq = OFF;
  5021. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0], 0x00, sizeof(struct MeterValueType));
  5022. }
  5023. //==============================================
  5024. // Meter report
  5025. //==============================================
  5026. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValueReq)
  5027. {
  5028. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Trigger);
  5029. cpinitateMsg.bits[gun_index].TriggerMeterValueReq = OFF;
  5030. }
  5031. // ClockAlign MeterValue
  5032. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value)))==0):FALSE))
  5033. {
  5034. //check Transaction active
  5035. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5036. {
  5037. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5038. {
  5039. tempIndex = ((gun_index==2) ? 1: 0);
  5040. }
  5041. else
  5042. {
  5043. tempIndex = gun_index;
  5044. }
  5045. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5046. {
  5047. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5048. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5049. {
  5050. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  5051. {
  5052. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  5053. }
  5054. }
  5055. }// End for CHAdeMO
  5056. }
  5057. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5058. {
  5059. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5060. {
  5061. tempIndex = ((gun_index==2) ? 1: 0);
  5062. }
  5063. else
  5064. {
  5065. tempIndex = gun_index;
  5066. }
  5067. for (int index = 0; index < CCS_QUANTITY; index++)
  5068. {
  5069. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5070. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5071. {
  5072. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  5073. {
  5074. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  5075. }
  5076. }
  5077. } // End for CCS
  5078. }
  5079. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5080. {
  5081. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5082. {
  5083. tempIndex = ((gun_index==2) ? 1: 0);
  5084. }
  5085. else
  5086. {
  5087. tempIndex = gun_index;
  5088. }
  5089. for (int index = 0; index < GB_QUANTITY; index++)
  5090. {
  5091. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5092. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5093. {
  5094. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  5095. {
  5096. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  5097. }
  5098. }
  5099. }// End for GB
  5100. }
  5101. else if(gunType[gun_index] == GUN_TYPE_DO)
  5102. {
  5103. tempIndex = gun_index;
  5104. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5105. {
  5106. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5107. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5108. {
  5109. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_CHARGING)
  5110. {
  5111. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  5112. }
  5113. }
  5114. }
  5115. }
  5116. else
  5117. {
  5118. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5119. {
  5120. tempIndex = 2;
  5121. }
  5122. else
  5123. {
  5124. tempIndex = gun_index;
  5125. }
  5126. for (int index = 0; index < AC_QUANTITY; index++)
  5127. {
  5128. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5129. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5130. {
  5131. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  5132. {
  5133. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  5134. }
  5135. }
  5136. }//End for AC
  5137. }
  5138. if(cpinitateMsg.bits[gun_index].ClockAlignMeterReq == ON)
  5139. {
  5140. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Clock);
  5141. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = OFF;
  5142. }
  5143. }
  5144. // Sample period MeterValue
  5145. if(((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value)- 1)))
  5146. {
  5147. //check Transaction active
  5148. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5149. {
  5150. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5151. {
  5152. tempIndex = ((gun_index==2) ? 1: 0);
  5153. }
  5154. else
  5155. {
  5156. tempIndex = gun_index;
  5157. }
  5158. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5159. {
  5160. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5161. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5162. {
  5163. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5164. {
  5165. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  5166. }
  5167. }
  5168. }// End for CHAdeMO
  5169. }
  5170. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5171. {
  5172. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5173. {
  5174. tempIndex = ((gun_index==2) ? 1: 0);
  5175. }
  5176. else
  5177. {
  5178. tempIndex = gun_index;
  5179. }
  5180. for (int index = 0; index < CCS_QUANTITY; index++)
  5181. {
  5182. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5183. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5184. {
  5185. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5186. {
  5187. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  5188. }
  5189. }
  5190. } // End for CCS
  5191. }
  5192. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5193. {
  5194. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5195. {
  5196. tempIndex = ((gun_index==2) ? 1: 0);
  5197. }
  5198. else
  5199. {
  5200. tempIndex = gun_index;
  5201. }
  5202. for (int index = 0; index < GB_QUANTITY; index++)
  5203. {
  5204. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5205. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5206. {
  5207. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5208. {
  5209. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  5210. }
  5211. }
  5212. }// End for GB
  5213. }
  5214. else if(gunType[gun_index] == GUN_TYPE_DO)
  5215. {
  5216. tempIndex = gun_index;
  5217. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5218. {
  5219. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5220. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5221. {
  5222. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  5223. {
  5224. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  5225. }
  5226. }
  5227. }
  5228. }
  5229. else
  5230. {
  5231. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5232. {
  5233. tempIndex = 2;
  5234. }
  5235. else
  5236. {
  5237. tempIndex = gun_index;
  5238. }
  5239. for (int index = 0; index < AC_QUANTITY; index++)
  5240. {
  5241. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5242. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5243. {
  5244. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5245. {
  5246. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  5247. }
  5248. }
  5249. }//End for AC
  5250. }
  5251. if(cpinitateMsg.bits[gun_index].SampleMeterReq == ON)
  5252. {
  5253. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic);
  5254. storeTempStopTransaction(gun_index);
  5255. cpinitateMsg.bits[gun_index].SampleMeterReq = OFF;
  5256. }
  5257. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  5258. }
  5259. //==============================================
  5260. // Check Connector reserved
  5261. //==============================================
  5262. //===============================
  5263. // Check if Reserve is expired
  5264. //===============================
  5265. if((server_sign == TRUE) && (ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime[0] != 0) )
  5266. {
  5267. double diff_t;
  5268. struct tm tp;
  5269. // current time
  5270. time_t t = time(NULL);
  5271. strptime((char *)ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime, "%Y-%m-%dT%H:%M:%S", &tp);
  5272. tp.tm_isdst = -1;
  5273. time_t utc = mktime(&tp);
  5274. diff_t = difftime(utc, t);
  5275. if(diff_t <= 0)
  5276. {
  5277. DEBUG_INFO("reserve expired.\n");
  5278. memset(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime,0,ARRAY_SIZE(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime));
  5279. }
  5280. }//END OF Check if Reserve is expired
  5281. //==========================================
  5282. // csu trigger FirmwareStatusNotificationReq
  5283. //==========================================
  5284. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq == ON))
  5285. {
  5286. sendFirmwareStatusNotificationRequest((char *)ShmOCPP20Data->FirmwareStatusNotification.status);
  5287. }
  5288. //==========================================
  5289. // csu cleared charging limit request
  5290. //==========================================
  5291. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq == ON))
  5292. {
  5293. sendClearedChargingLimitRequest(gun_index);
  5294. }
  5295. //==========================================
  5296. // csu trigger CancelReservationConf
  5297. //==========================================
  5298. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationConf == ON))
  5299. {
  5300. sendCancelReservationConfirmation((char *)ShmOCPP20Data->CancelReservation[gun_index].guid, gun_index);
  5301. }
  5302. //==========================================
  5303. // csu notify EV charging need request
  5304. //==========================================
  5305. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsReq == ON))
  5306. {
  5307. sendNotifyEVChargingNeedsRequest(gun_index);
  5308. }
  5309. //==========================================
  5310. // csu trigger ChangeAvailabilityConf
  5311. //==========================================
  5312. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == ON))
  5313. {
  5314. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP20Data->ChangeAvailability[gun_index].ResponseStatus);
  5315. }
  5316. //==========================================
  5317. // csu trigger UnlockConnectorConf
  5318. //==========================================
  5319. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf == ON))
  5320. {
  5321. sendUnlockConnectorConfirmation((char *)ShmOCPP20Data->UnlockConnector[gun_index].guid, gun_index);
  5322. }
  5323. //==========================================
  5324. // csu trigger ReserveNowConf
  5325. //==========================================
  5326. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf == ON))
  5327. {
  5328. sendReserveNowConfirmation((char *)ShmOCPP20Data->ReserveNow[gun_index].guid, gun_index);
  5329. }
  5330. //==========================================
  5331. // csu trigger ReserveNowConf
  5332. //==========================================
  5333. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq == ON))
  5334. {
  5335. sendReservationStatusUpdateRequest(gun_index);
  5336. }
  5337. //==========================================
  5338. // csu trigger LogStatusNotificationReq
  5339. //==========================================
  5340. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq == ON))
  5341. {
  5342. sendLogStatusNotificationRequest((char *)ShmOCPP20Data->LogStatusNotification.status);
  5343. }
  5344. //==========================================
  5345. // csu trigger SignCertificateReq
  5346. //==========================================
  5347. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.SignCertificateReq == ON))
  5348. {
  5349. if((access("/Storage/OCPP/certCP.csr",F_OK) != -1) &&
  5350. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) == 0) )
  5351. {
  5352. sendSignCertificateRequest(CertificateSignedStatusEnumType_ChargingStationCertificate);
  5353. }
  5354. else if((access("/Storage/OCPP/certV2G.csr",F_OK) != -1) &&
  5355. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0))
  5356. {
  5357. sendSignCertificateRequest(CertificateSignedStatusEnumType_V2GCertificate);
  5358. }
  5359. }
  5360. }
  5361. }
  5362. //==========================================
  5363. // send request routine
  5364. //==========================================
  5365. int sendAuthorizeRequest(int gun_index)
  5366. {
  5367. mtrace();
  5368. int result = FAIL;
  5369. char message[4096]={0};
  5370. char guid[37];
  5371. char tempdata[128]={0};
  5372. json_object *Authorize = json_object_new_object();
  5373. json_object *idToken = json_object_new_object();
  5374. DEBUG_INFO("sendAuthorizeRequest...\n");
  5375. memset(&(ShmOCPP20Data->Authorize.Response_idTokenInfo),0,sizeof(struct IdTokenInfoType));
  5376. //Local Authorize
  5377. if ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].value, "TRUE")==0) && (ShmOCPP20Data->OcppConnStatus == 0))
  5378. {
  5379. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  5380. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "");
  5381. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, "");
  5382. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]);
  5383. result = PASS;
  5384. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  5385. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  5386. authorizeRetryTimes = 0;
  5387. return result;
  5388. }
  5389. 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)) ||
  5390. ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].value, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "TRUE") == 0)))
  5391. {
  5392. // Query idtag from cache
  5393. DB_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId, TRUE);
  5394. // Query idtag from list
  5395. if((strcmp((char*)idTagQuery.idToken.idToken,"") == 0) || (strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0) )
  5396. DB_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId, FALSE);
  5397. if((strcmp((char*)idTagQuery.idToken.idToken,"") == 0) || (strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0) )
  5398. {
  5399. if(strcmp((char*)idTagQuery.idToken.idToken,"") == 0)
  5400. {
  5401. DEBUG_INFO("Card %s does not find in list or cache\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5402. }
  5403. if(strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0)
  5404. {
  5405. DEBUG_INFO("Card %s does not accepted in list and cache\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5406. }
  5407. // Return authorize result if does not connect to server
  5408. if(!ShmOCPP20Data->OcppConnStatus)
  5409. {
  5410. DEBUG_INFO("Local Authorization Fail.\n");
  5411. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "");
  5412. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5413. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Invalid]);
  5414. DEBUG_INFO("ShmOCPP20Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
  5415. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  5416. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  5417. authorizeRetryTimes = 0;
  5418. return result;
  5419. }
  5420. }
  5421. else
  5422. {
  5423. DEBUG_INFO("Local Authorization get result.\n");
  5424. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, (char*)idTagQuery.idTokenInfo.cacheExpiryDateTime);
  5425. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5426. if(isOvertNow((uint8_t*)&idTagQuery.idTokenInfo.cacheExpiryDateTime[0]))
  5427. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Expired]);
  5428. else
  5429. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, (char*)idTagQuery.idTokenInfo.status);
  5430. DEBUG_INFO("ShmOCPP20Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
  5431. result = PASS;
  5432. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  5433. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  5434. authorizeRetryTimes = 0;
  5435. return result;
  5436. }
  5437. }
  5438. //get data from shared memory
  5439. strcpy((char *)ShmOCPP20Data->Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5440. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.idToken));
  5441. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.type));
  5442. json_object_object_add(Authorize, "idToken", idToken);
  5443. random_uuid(guid);
  5444. sprintf(message,"[%d,\"%s\",\"Authorize\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(Authorize, JSON_C_TO_STRING_PLAIN));
  5445. json_object_put(Authorize);
  5446. LWS_Send(message);
  5447. sprintf(tempdata, "Authorize,%d", gun_index);
  5448. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5449. {
  5450. result = PASS;
  5451. }
  5452. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  5453. return result;
  5454. }
  5455. int sendBootNotificationRequest()
  5456. {
  5457. mtrace();
  5458. int result = FAIL;
  5459. char message[4096]={0};
  5460. char guid[37]={0};
  5461. char tempdata[128]={0};
  5462. json_object *BootNotification = json_object_new_object();
  5463. json_object *chargingStation = json_object_new_object();
  5464. json_object *modem = json_object_new_object();
  5465. DEBUG_INFO("sendBootNotificationRequest...\n");
  5466. // Fill BootNotification fields
  5467. DB_getBooType();
  5468. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.model, "%s", ShmSysConfigAndInfo->SysConfig.ModelName);
  5469. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.vendorName, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5470. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.serialNumber, "%s", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5471. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.firmwareVersion, "%s", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5472. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.modem.iccid, "%s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5473. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.modem.imsi, "%s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5474. if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
  5475. {
  5476. json_object_object_add(modem, "iccid", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.modem.iccid));
  5477. json_object_object_add(modem, "imsi", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.modem.imsi));
  5478. json_object_object_add(chargingStation, "modem", modem);
  5479. }
  5480. json_object_object_add(chargingStation, "model", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.model));
  5481. json_object_object_add(chargingStation, "vendorName", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.vendorName));
  5482. json_object_object_add(chargingStation, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.serialNumber));
  5483. json_object_object_add(chargingStation, "firmwareVersion", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.firmwareVersion));
  5484. json_object_object_add(BootNotification, "chargingStation", chargingStation);
  5485. json_object_object_add(BootNotification, "reason", json_object_new_string((char*)ShmOCPP20Data->BootNotification.reason));
  5486. random_uuid(guid);
  5487. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", json_object_to_json_string_ext(BootNotification, JSON_C_TO_STRING_PLAIN));
  5488. json_object_put(BootNotification);
  5489. LWS_Send(message);
  5490. sprintf(tempdata, "BootNotification,0");
  5491. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5492. {
  5493. result = PASS;
  5494. }
  5495. return result;
  5496. }
  5497. int sendClearedChargingLimitRequest(int gun_index)
  5498. {
  5499. mtrace();
  5500. int result = FAIL;
  5501. char message[4096]={0};
  5502. char guid[37]={0};
  5503. char tempdata[128]={0};
  5504. json_object *ClearedChargingLimit = json_object_new_object();
  5505. DEBUG_INFO("sendClearedChargingLimitRequest...\n");
  5506. json_object_object_add(ClearedChargingLimit, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->ClearedChargingLimit[gun_index].chargingLimitSource));
  5507. json_object_object_add(ClearedChargingLimit, "evseId", json_object_new_int(ShmOCPP20Data->ClearedChargingLimit[gun_index].evseId));
  5508. random_uuid(guid);
  5509. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ClearedChargingLimit", json_object_to_json_string_ext(ClearedChargingLimit, JSON_C_TO_STRING_PLAIN));
  5510. json_object_put(ClearedChargingLimit);
  5511. LWS_Send(message);
  5512. sprintf(tempdata, "ClearedChargingLimit,%d", gun_index);
  5513. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5514. {
  5515. result = PASS;
  5516. }
  5517. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq = OFF;
  5518. return result;
  5519. }
  5520. int sendDataTransferRequest(int gun_index)
  5521. {
  5522. mtrace();
  5523. char message[1000]={0};
  5524. char guid[37]={0};
  5525. char tempdata[65]={0};
  5526. int result = FAIL;
  5527. DEBUG_INFO("sendDataTransferRequest...\n");
  5528. random_uuid(guid);
  5529. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5530. MESSAGE_TYPE_CALL,
  5531. guid,
  5532. ShmOCPP20Data->DataTransfer[gun_index].vendorId,
  5533. ShmOCPP20Data->DataTransfer[gun_index].messageId,
  5534. ShmOCPP20Data->DataTransfer[gun_index].data);
  5535. LWS_Send(message);
  5536. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5537. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5538. {
  5539. result = PASS;
  5540. }
  5541. return result;
  5542. }
  5543. int sendFirmwareStatusNotificationRequest(char *status)
  5544. {
  5545. mtrace();
  5546. int result = FAIL;
  5547. char message[110]={0};
  5548. char guid[37]={0};
  5549. char tempdata[65]={0};
  5550. json_object *FirmwareStatusNotification = json_object_new_object();
  5551. DEBUG_INFO("sendFirmwareStatusNotificationRequest...\n");
  5552. sprintf((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", (const char *)status);
  5553. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  5554. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->FirmwareStatusNotification.status));
  5555. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->FirmwareStatusNotification.requestId));
  5556. random_uuid(guid);
  5557. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  5558. json_object_put(FirmwareStatusNotification);
  5559. LWS_SendNow(message);
  5560. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5561. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5562. {
  5563. result = PASS;
  5564. }
  5565. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = OFF;
  5566. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationConf = OFF;
  5567. //record status
  5568. if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded])==0)
  5569. {
  5570. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Downloaded;
  5571. }
  5572. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed])==0)
  5573. {
  5574. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadFailed;
  5575. }
  5576. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading])==0)
  5577. {
  5578. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Downloading;
  5579. }
  5580. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadScheduled])==0)
  5581. {
  5582. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadScheduled;
  5583. }
  5584. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadPaused])==0)
  5585. {
  5586. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadPaused;
  5587. }
  5588. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle])==0)
  5589. {
  5590. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle;
  5591. }
  5592. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallationFailed])==0)
  5593. {
  5594. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallationFailed;
  5595. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  5596. }
  5597. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Installing])==0)
  5598. {
  5599. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Installing;
  5600. }
  5601. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Installed])==0)
  5602. {
  5603. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Installed;
  5604. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  5605. }
  5606. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallRebooting])==0)
  5607. {
  5608. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallRebooting;
  5609. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  5610. }
  5611. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallScheduled])==0)
  5612. {
  5613. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallScheduled;
  5614. }
  5615. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallVerificationFailed])==0)
  5616. {
  5617. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallVerificationFailed;
  5618. }
  5619. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InvalidSignature])==0)
  5620. {
  5621. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InvalidSignature;
  5622. }
  5623. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_SignatureVerified])==0)
  5624. {
  5625. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_SignatureVerified;
  5626. }
  5627. return result;
  5628. }
  5629. int sendGet15118EVCertificateRequest()
  5630. {
  5631. mtrace();
  5632. int result = FAIL;
  5633. char message[4096]={0};
  5634. char guid[37]={0};
  5635. char tempdata[128]={0};
  5636. json_object *Get15118EVCertificate = json_object_new_object();
  5637. DEBUG_INFO("sendGet15118EVCertificateRequest...\n");
  5638. json_object_object_add(Get15118EVCertificate, "iso15118SchemaVersion", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.iso15118SchemaVersion));
  5639. json_object_object_add(Get15118EVCertificate, "action", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.action));
  5640. json_object_object_add(Get15118EVCertificate, "exiRequest", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.exiRequest));
  5641. random_uuid(guid);
  5642. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "Get15118EVCertificate", json_object_to_json_string_ext(Get15118EVCertificate, JSON_C_TO_STRING_PLAIN));
  5643. json_object_put(Get15118EVCertificate);
  5644. LWS_Send(message);
  5645. sprintf(tempdata, "Get15118EVCertificate,0");
  5646. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5647. {
  5648. result = PASS;
  5649. }
  5650. return result;
  5651. }
  5652. int sendGetCertificateStatusRequest()
  5653. {
  5654. mtrace();
  5655. int result = FAIL;
  5656. char message[4096]={0};
  5657. char guid[37]={0};
  5658. char tempdata[128]={0};
  5659. json_object *GetCertificateStatus = json_object_new_object();
  5660. json_object *ocspRequestData = json_object_new_object();
  5661. DEBUG_INFO("sendGetCertificateStatusRequest...\n");
  5662. json_object_object_add(ocspRequestData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.hashAlgorithm));
  5663. json_object_object_add(ocspRequestData, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.issuerNameHash));
  5664. json_object_object_add(ocspRequestData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.issuerKeyHash));
  5665. json_object_object_add(ocspRequestData, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.serialNumber));
  5666. json_object_object_add(ocspRequestData, "responderURL", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.responderURL));
  5667. json_object_object_add(GetCertificateStatus, "ocspRequestData", ocspRequestData);
  5668. random_uuid(guid);
  5669. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "GetCertificateStatus", json_object_to_json_string_ext(GetCertificateStatus, JSON_C_TO_STRING_PLAIN));
  5670. json_object_put(GetCertificateStatus);
  5671. LWS_Send(message);
  5672. sprintf(tempdata, "GetCertificateStatus,0");
  5673. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5674. {
  5675. result = PASS;
  5676. }
  5677. return result;
  5678. }
  5679. int sendHeartbeatRequest()
  5680. {
  5681. mtrace();
  5682. int result = FAIL;
  5683. char message[40096]={0};
  5684. char guid[37]={0};
  5685. char tempdata[128]={0};
  5686. DEBUG_INFO("sendHeartbeatRequest...\n");
  5687. random_uuid(guid);
  5688. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  5689. , MESSAGE_TYPE_CALL
  5690. , guid );
  5691. LWS_Send(message);
  5692. sprintf(tempdata, "Heartbeat,%d", 0);
  5693. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5694. {
  5695. result = PASS;
  5696. }
  5697. return result;
  5698. }
  5699. int sendLogStatusNotificationRequest(char *status)
  5700. {
  5701. mtrace();
  5702. int result = FAIL;
  5703. char message[4096]={0};
  5704. char guid[37]={0};
  5705. char tempdata[128]={0};
  5706. json_object *LogStatusNotification = json_object_new_object();
  5707. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  5708. ShmOCPP20Data->LogStatusNotification.requestId = ShmOCPP20Data->GetLog.requestId;
  5709. sprintf((char *)ShmOCPP20Data->LogStatusNotification.status,"%s",(const char *)status);
  5710. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->LogStatusNotification.status));
  5711. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->LogStatusNotification.requestId));
  5712. random_uuid(guid);
  5713. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  5714. json_object_put(LogStatusNotification);
  5715. LWS_SendNow(message);
  5716. sprintf(tempdata, "LogStatusNotification,%d", 0);
  5717. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5718. {
  5719. result = PASS;
  5720. }
  5721. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  5722. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationConf = OFF;
  5723. //record status
  5724. if(strcmp(status,"BadMessage")==0)
  5725. {
  5726. LogStatusNotificationStatus = UploadLogStatusEnumType_BadMessage;
  5727. }
  5728. else if(strcmp(status,"Idle")==0)
  5729. {
  5730. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle;
  5731. }
  5732. else if(strcmp(status,"NotSupportedOperation")==0)
  5733. {
  5734. LogStatusNotificationStatus = UploadLogStatusEnumType_NotSupportedOperation;
  5735. }
  5736. else if(strcmp(status,"PermissionDenied")==0)
  5737. {
  5738. LogStatusNotificationStatus = UploadLogStatusEnumType_PermissionDenied;
  5739. }
  5740. else if(strcmp(status,"Uploaded")==0)
  5741. {
  5742. LogStatusNotificationStatus = UploadLogStatusEnumType_Uploaded;
  5743. }
  5744. else if(strcmp(status,"UploadFailure")==0)
  5745. {
  5746. LogStatusNotificationStatus = UploadLogStatusEnumType_UploadFailure;
  5747. }
  5748. else if(strcmp(status,"Uploading")==0)
  5749. {
  5750. LogStatusNotificationStatus = UploadLogStatusEnumType_Uploading;
  5751. }
  5752. return result;
  5753. }
  5754. int sendMeterValuesRequest(int gun_index, ReadingContextEnumType dataType)
  5755. {
  5756. mtrace();
  5757. int result = FAIL;
  5758. char guid[37]={0};
  5759. char tempdata[65]={0};
  5760. int tempIndex = 0;
  5761. json_object *MeterValueReq = json_object_new_object();
  5762. json_object *meterValues = json_object_new_array();
  5763. json_object *sampledValues = json_object_new_array();
  5764. DEBUG_INFO("sendMeterValuesRequest...\n");
  5765. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5766. //set value
  5767. ShmOCPP20Data->MeterValues[gun_index].evseId = gun_index + 1; // gun start from 1~
  5768. //UTC Date time
  5769. struct timeval tmnow;
  5770. struct tm *tm;
  5771. char buf[28];//, usec_buf[6];
  5772. gettimeofday(&tmnow, NULL);
  5773. time_t t;
  5774. t = time(NULL);
  5775. /*UTC time and date*/
  5776. tm = gmtime(&t);
  5777. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5778. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].timestamp, buf);
  5779. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5780. //idx_sample=0;
  5781. //********************************(1)Current.Import L1************************************************/
  5782. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5783. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5784. {
  5785. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5786. {
  5787. tempIndex = ((gun_index==2) ? 1: 0);
  5788. }
  5789. else
  5790. {
  5791. tempIndex = gun_index;
  5792. }
  5793. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5794. {
  5795. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5796. {
  5797. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent;
  5798. }
  5799. }
  5800. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5801. }
  5802. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5803. {
  5804. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5805. {
  5806. tempIndex = ((gun_index==2) ? 1: 0);
  5807. }
  5808. else
  5809. {
  5810. tempIndex = gun_index;
  5811. }
  5812. for (int index = 0; index < CCS_QUANTITY; index++)
  5813. {
  5814. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5815. {
  5816. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent;
  5817. }
  5818. }
  5819. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5820. }
  5821. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5822. {
  5823. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5824. {
  5825. tempIndex = ((gun_index==2) ? 1: 0);
  5826. }
  5827. else
  5828. {
  5829. tempIndex = gun_index;
  5830. }
  5831. for (int index = 0; index < GB_QUANTITY; index++)
  5832. {
  5833. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5834. {
  5835. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent;
  5836. }
  5837. }
  5838. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5839. }
  5840. else if(gunType[gun_index] == GUN_TYPE_DO)
  5841. {
  5842. tempIndex = gun_index;
  5843. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5844. {
  5845. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5846. {
  5847. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent;
  5848. }
  5849. }
  5850. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5851. }
  5852. else
  5853. {
  5854. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5855. {
  5856. tempIndex = 2;
  5857. }
  5858. else
  5859. {
  5860. tempIndex = gun_index;
  5861. }
  5862. for (int index = 0; index < AC_QUANTITY; index++)
  5863. {
  5864. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5865. {
  5866. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent;
  5867. }
  5868. }
  5869. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  5870. }
  5871. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].context, ReadingContextEnumTypeStr[dataType]);
  5872. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  5873. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  5874. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].unitOfMeasure.uint , "A");
  5875. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].unitOfMeasure.multiplier = 0;
  5876. //idx_sample=1;
  5877. //********************************(2)Energy.Active.Import.Register ************************************************/
  5878. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5879. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5880. {
  5881. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5882. {
  5883. tempIndex = ((gun_index==2) ? 1: 0);
  5884. }
  5885. else
  5886. {
  5887. tempIndex = gun_index;
  5888. }
  5889. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5890. {
  5891. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5892. {
  5893. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5894. }
  5895. }
  5896. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5897. }
  5898. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5899. {
  5900. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5901. {
  5902. tempIndex = ((gun_index==2) ? 1: 0);
  5903. }
  5904. else
  5905. {
  5906. tempIndex = gun_index;
  5907. }
  5908. for (int index = 0; index < CCS_QUANTITY; index++)
  5909. {
  5910. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5911. {
  5912. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5913. }
  5914. }
  5915. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5916. }
  5917. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5918. {
  5919. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5920. {
  5921. tempIndex = ((gun_index==2) ? 1: 0);
  5922. }
  5923. else
  5924. {
  5925. tempIndex = gun_index;
  5926. }
  5927. for (int index = 0; index < GB_QUANTITY; index++)
  5928. {
  5929. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5930. {
  5931. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  5932. }
  5933. }
  5934. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5935. }
  5936. else if(gunType[gun_index] == GUN_TYPE_DO)
  5937. {
  5938. tempIndex = gun_index;
  5939. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5940. {
  5941. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5942. {
  5943. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  5944. }
  5945. }
  5946. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5947. }
  5948. else
  5949. {
  5950. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5951. {
  5952. tempIndex = 2;
  5953. }
  5954. else
  5955. {
  5956. tempIndex = gun_index;
  5957. }
  5958. for (int index = 0; index < AC_QUANTITY; index++)
  5959. {
  5960. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5961. {
  5962. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  5963. }
  5964. }
  5965. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  5966. }
  5967. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].context, ReadingContextEnumTypeStr[dataType]);
  5968. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]);
  5969. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  5970. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].unitOfMeasure.uint , "kWh");
  5971. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.multiplier = 0;
  5972. //idx_sample=2;
  5973. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  5974. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5975. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5976. {
  5977. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5978. {
  5979. tempIndex = ((gun_index==2) ? 1: 0);
  5980. }
  5981. else
  5982. {
  5983. tempIndex = gun_index;
  5984. }
  5985. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5986. {
  5987. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5988. {
  5989. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  5990. }
  5991. } // END OF FOR CHAdeMO_QUANTITY
  5992. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5993. }
  5994. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5995. {
  5996. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5997. {
  5998. tempIndex = ((gun_index==2) ? 1: 0);
  5999. }
  6000. else
  6001. {
  6002. tempIndex = gun_index;
  6003. }
  6004. for (int index = 0; index < CCS_QUANTITY; index++)
  6005. {
  6006. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6007. {
  6008. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  6009. }
  6010. } // END OF CCS_QUANTITY
  6011. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6012. }
  6013. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6014. {
  6015. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6016. {
  6017. tempIndex = ((gun_index==2) ? 1: 0);
  6018. }
  6019. else
  6020. {
  6021. tempIndex = gun_index;
  6022. }
  6023. for (int index = 0; index < GB_QUANTITY; index++)
  6024. {
  6025. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6026. {
  6027. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  6028. }
  6029. } // END OF GB_QUANTITY
  6030. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6031. }
  6032. else if(gunType[gun_index] == GUN_TYPE_DO)
  6033. {
  6034. tempIndex = gun_index;
  6035. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6036. {
  6037. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6038. {
  6039. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy;
  6040. }
  6041. }
  6042. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6043. }
  6044. else
  6045. {
  6046. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6047. {
  6048. tempIndex = 2;
  6049. }
  6050. else
  6051. {
  6052. tempIndex = gun_index;
  6053. }
  6054. for (int index = 0; index < AC_QUANTITY; index++)
  6055. {
  6056. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6057. {
  6058. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  6059. }
  6060. }
  6061. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  6062. }
  6063. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].context, ReadingContextEnumTypeStr[dataType]);
  6064. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]);
  6065. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  6066. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.uint , "kWh");
  6067. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.multiplier = 0;
  6068. //idx_sample=3;
  6069. //********************************(4)Power.Active.Import************************************************/
  6070. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6071. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6072. {
  6073. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6074. {
  6075. tempIndex = ((gun_index==2) ? 1: 0);
  6076. }
  6077. else
  6078. {
  6079. tempIndex = gun_index;
  6080. }
  6081. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6082. {
  6083. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6084. {
  6085. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower;
  6086. }
  6087. } // END OF FOR
  6088. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6089. }
  6090. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6091. {
  6092. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6093. {
  6094. tempIndex = ((gun_index==2) ? 1: 0);
  6095. }
  6096. else
  6097. {
  6098. tempIndex = gun_index;
  6099. }
  6100. for (int index = 0; index < CCS_QUANTITY; index++)
  6101. {
  6102. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6103. {
  6104. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower;
  6105. }
  6106. }
  6107. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6108. }
  6109. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6110. {
  6111. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6112. {
  6113. tempIndex = ((gun_index==2) ? 1: 0);
  6114. }
  6115. else
  6116. {
  6117. tempIndex = gun_index;
  6118. }
  6119. for (int index = 0; index < GB_QUANTITY; index++)
  6120. {
  6121. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6122. {
  6123. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6124. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower;
  6125. }
  6126. }
  6127. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6128. }
  6129. else if(gunType[gun_index] == GUN_TYPE_DO)
  6130. {
  6131. tempIndex = gun_index;
  6132. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6133. {
  6134. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6135. {
  6136. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6137. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower;
  6138. }
  6139. }
  6140. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6141. }
  6142. else
  6143. {
  6144. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6145. {
  6146. tempIndex = 2;
  6147. }
  6148. else
  6149. {
  6150. tempIndex = gun_index;
  6151. }
  6152. for (int index = 0; index < AC_QUANTITY; index++)
  6153. {
  6154. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6155. {
  6156. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower;
  6157. }
  6158. }
  6159. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  6160. }
  6161. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].context, ReadingContextEnumTypeStr[dataType]);
  6162. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]);
  6163. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  6164. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].unitOfMeasure.uint , "kW");
  6165. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].unitOfMeasure.multiplier = 0;
  6166. //idx_sample=4;
  6167. //***********************************************(5)VOLTAGE L1******************************************************/
  6168. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6169. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6170. {
  6171. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6172. {
  6173. tempIndex = ((gun_index==2) ? 1: 0);
  6174. }
  6175. else
  6176. {
  6177. tempIndex = gun_index;
  6178. }
  6179. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6180. {
  6181. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6182. {
  6183. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage;
  6184. }
  6185. }
  6186. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6187. }
  6188. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6189. {
  6190. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6191. {
  6192. tempIndex = ((gun_index==2) ? 1: 0);
  6193. }
  6194. else
  6195. {
  6196. tempIndex = gun_index;
  6197. }
  6198. for (int index = 0; index < CCS_QUANTITY; index++)
  6199. {
  6200. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6201. {
  6202. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage;
  6203. }
  6204. }
  6205. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6206. }
  6207. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6208. {
  6209. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6210. {
  6211. tempIndex = ((gun_index==2) ? 1: 0);
  6212. }
  6213. else
  6214. {
  6215. tempIndex = gun_index;
  6216. }
  6217. for (int index = 0; index < GB_QUANTITY; index++)
  6218. {
  6219. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6220. {
  6221. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage;
  6222. }
  6223. }
  6224. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6225. }
  6226. else if(gunType[gun_index] == GUN_TYPE_DO)
  6227. {
  6228. tempIndex = gun_index;
  6229. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6230. {
  6231. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6232. {
  6233. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage;
  6234. }
  6235. }
  6236. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6237. }
  6238. else
  6239. {
  6240. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6241. {
  6242. tempIndex = 2;
  6243. }
  6244. else
  6245. {
  6246. tempIndex = gun_index;
  6247. }
  6248. for (int index = 0; index < AC_QUANTITY; index++)
  6249. {
  6250. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6251. {
  6252. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage;
  6253. }
  6254. }
  6255. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  6256. }
  6257. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].context, ReadingContextEnumTypeStr[dataType]);
  6258. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  6259. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  6260. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].unitOfMeasure.uint , "V");
  6261. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].unitOfMeasure.multiplier = 0;
  6262. //***********************************************(6)SOC******************************************************/
  6263. 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))
  6264. {
  6265. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6266. {
  6267. tempIndex = ((gun_index==2) ? 1: 0);
  6268. }
  6269. else
  6270. {
  6271. tempIndex = gun_index;
  6272. }
  6273. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6274. {
  6275. //tempIndex = ((gun_index==2) ? 1: 0);
  6276. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6277. {
  6278. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6279. {
  6280. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  6281. }
  6282. }
  6283. }
  6284. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6285. {
  6286. //tempIndex = ((gun_index==2) ? 1: 0);
  6287. for (int index = 0; index < CCS_QUANTITY; index++)
  6288. {
  6289. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6290. {
  6291. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  6292. }
  6293. }
  6294. }
  6295. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6296. {
  6297. //tempIndex = ((gun_index==2) ? 1: 0);
  6298. for (int index = 0; index < GB_QUANTITY; index++)
  6299. {
  6300. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6301. {
  6302. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  6303. }
  6304. }
  6305. }
  6306. else if(gunType[gun_index] == GUN_TYPE_DO)
  6307. {
  6308. //tempIndex = ((gun_index==2) ? 1: 0);
  6309. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6310. {
  6311. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6312. {
  6313. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  6314. }
  6315. }
  6316. }
  6317. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].context, ReadingContextEnumTypeStr[dataType]);
  6318. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].measurand, MeasurandEnumTypeStr[MeasurandEnumType_SoC]);
  6319. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6320. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].location, LocationEnumTypeStr[LocationEnumType_EV]);
  6321. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].unitOfMeasure.uint , "Percent");
  6322. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].unitOfMeasure.multiplier = 0;
  6323. }
  6324. //********************************(7)Current.Import L2************************************************/
  6325. // Only for AC 3 phase
  6326. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  6327. {
  6328. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6329. {
  6330. tempIndex = 2;
  6331. }
  6332. else
  6333. {
  6334. tempIndex = gun_index;
  6335. }
  6336. for (int index = 0; index < AC_QUANTITY; index++)
  6337. {
  6338. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6339. {
  6340. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2;
  6341. }
  6342. }
  6343. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].phase, PhaseEnumTypeStr[PhaseEnumType_L2_N]);
  6344. }
  6345. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].context, ReadingContextEnumTypeStr[dataType]);
  6346. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  6347. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  6348. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].unitOfMeasure.uint , "A");
  6349. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].unitOfMeasure.multiplier = 0;
  6350. //********************************(8)Current.Import L3************************************************/
  6351. // Only for AC 3 phase
  6352. if( (gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  6353. {
  6354. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6355. {
  6356. tempIndex = 2;
  6357. }
  6358. else
  6359. {
  6360. tempIndex = gun_index;
  6361. }
  6362. for (int index = 0; index < AC_QUANTITY; index++)
  6363. {
  6364. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6365. {
  6366. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3;
  6367. }
  6368. }
  6369. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6370. }
  6371. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].context, ReadingContextEnumTypeStr[dataType]);
  6372. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  6373. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  6374. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].unitOfMeasure.uint , "A");
  6375. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].unitOfMeasure.multiplier = 0;
  6376. //***********************************************(9)VOLTAGE L2******************************************************/
  6377. if( (gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  6378. {
  6379. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6380. {
  6381. tempIndex = 2;
  6382. }
  6383. else
  6384. {
  6385. tempIndex = gun_index;
  6386. }
  6387. for (int index = 0; index < AC_QUANTITY; index++)
  6388. {
  6389. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6390. {
  6391. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2;
  6392. }
  6393. }
  6394. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].phase, PhaseEnumTypeStr[PhaseEnumType_L2_N]);
  6395. }
  6396. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].context, ReadingContextEnumTypeStr[dataType]);
  6397. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  6398. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  6399. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].unitOfMeasure.uint , "V");
  6400. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].unitOfMeasure.multiplier = 0;
  6401. //***********************************************(10)VOLTAGE L3******************************************************/
  6402. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  6403. {
  6404. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6405. {
  6406. tempIndex = 2;
  6407. }
  6408. else
  6409. {
  6410. tempIndex = gun_index;
  6411. }
  6412. for (int index = 0; index < AC_QUANTITY; index++)
  6413. {
  6414. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6415. {
  6416. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3;
  6417. }
  6418. }
  6419. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6420. }
  6421. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].context, ReadingContextEnumTypeStr[dataType]);
  6422. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  6423. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  6424. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].unitOfMeasure.uint , "V");
  6425. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].unitOfMeasure.multiplier = 0;
  6426. // Message create ====================================================================================================
  6427. random_uuid(guid);
  6428. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->MeterValues[gun_index].meterValue);idxMeter++)
  6429. {
  6430. json_object *meterValue = json_object_new_object();
  6431. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  6432. {
  6433. if(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].value > 0)
  6434. {
  6435. json_object *sampledValue = json_object_new_object();
  6436. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  6437. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  6438. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  6439. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  6440. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  6441. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  6442. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  6443. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  6444. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  6445. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  6446. {
  6447. json_object *unitOfMeasure = json_object_new_object();
  6448. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  6449. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  6450. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  6451. }
  6452. json_object_array_add(sampledValues, sampledValue);
  6453. }
  6454. }
  6455. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].timestamp));
  6456. json_object_object_add(meterValue, "sampledValue", sampledValues);
  6457. json_object_array_add(meterValues, meterValue);
  6458. idxMeter++;
  6459. }
  6460. json_object_object_add(MeterValueReq, "meterValue", meterValues);
  6461. json_object_object_add(MeterValueReq, "evseId", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].evseId));
  6462. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6463. ,gun_index + 1
  6464. ,MESSAGE_TYPE_CALL
  6465. ,guid
  6466. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6467. json_object_put(MeterValueReq);
  6468. if((strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]) == 0) ||
  6469. (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]) == 0) ||
  6470. (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]) == 0))
  6471. {
  6472. // Transaction meter value send by TransactionEvent message
  6473. memcpy(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0], &ShmOCPP20Data->MeterValues[gun_index].meterValue[0], sizeof(struct MeterValueType));
  6474. cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
  6475. result = PASS;
  6476. }
  6477. else
  6478. {
  6479. // Put request guid to hash map
  6480. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6481. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6482. {
  6483. result = PASS;
  6484. }
  6485. if((dataType != ReadingContextEnumType_Trigger) &&
  6486. (dataType != ReadingContextEnumType_Sample_Clock))
  6487. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6488. else
  6489. {
  6490. if(FirstHeartBeat)
  6491. LWS_Send(queuedata +2);
  6492. }
  6493. }
  6494. return result;
  6495. }
  6496. int sendNotifyChargingLimitRequest(int gun_index)
  6497. {
  6498. mtrace();
  6499. int result = FAIL;
  6500. char message[4096]={0};
  6501. char guid[37]={0};
  6502. char tempdata[128]={0};
  6503. json_object *NotifyChargingLimit = json_object_new_object();
  6504. json_object *chargingLimit = json_object_new_object();
  6505. DEBUG_INFO("sendNotifyChargingLimitRequest...\n");
  6506. json_object_object_add(NotifyChargingLimit, "evseId", json_object_new_int(ShmOCPP20Data->NotifyChargingLimit[gun_index].evseId));
  6507. json_object_object_add(chargingLimit, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->NotifyChargingLimit[gun_index].chargingLimit.chargingLimitSource));
  6508. json_object_object_add(chargingLimit, "chargingLimitSource", json_object_new_boolean(ShmOCPP20Data->NotifyChargingLimit[gun_index].chargingLimit.isGridCritical));
  6509. json_object_object_add(NotifyChargingLimit, "chargingLimit", NotifyChargingLimit);
  6510. random_uuid(guid);
  6511. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyChargingLimit", json_object_to_json_string_ext(NotifyChargingLimit, JSON_C_TO_STRING_PLAIN));
  6512. json_object_put(NotifyChargingLimit);
  6513. LWS_Send(message);
  6514. sprintf(tempdata, "NotifyChargingLimit,%d", gun_index);
  6515. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6516. {
  6517. result = PASS;
  6518. }
  6519. return result;
  6520. }
  6521. int sendNotifyCustomerInformationRequest()
  6522. {
  6523. mtrace();
  6524. int result = FAIL;
  6525. char message[4096]={0};
  6526. char guid[37]={0};
  6527. char tempdata[128]={0};
  6528. json_object *NotifyCustomerInformation = json_object_new_object();
  6529. DEBUG_INFO("sendNotifyCustomerInformationRequest...\n");
  6530. json_object_object_add(NotifyCustomerInformation, "data", json_object_new_string((char*)ShmOCPP20Data->NotifyCustomerInformation.data));
  6531. json_object_object_add(NotifyCustomerInformation, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyCustomerInformation.tbc));
  6532. json_object_object_add(NotifyCustomerInformation, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyCustomerInformation.seqNo));
  6533. json_object_object_add(NotifyCustomerInformation, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyCustomerInformation.generatedAt));
  6534. json_object_object_add(NotifyCustomerInformation, "requestId", json_object_new_int(ShmOCPP20Data->NotifyCustomerInformation.requestId));
  6535. random_uuid(guid);
  6536. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyCustomerInformation", json_object_to_json_string_ext(NotifyCustomerInformation, JSON_C_TO_STRING_PLAIN));
  6537. json_object_put(NotifyCustomerInformation);
  6538. LWS_Send(message);
  6539. sprintf(tempdata, "NotifyCustomerInformation,0");
  6540. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6541. {
  6542. result = PASS;
  6543. }
  6544. return result;
  6545. }
  6546. int sendNotifyDisplayMessagesRequest()
  6547. {
  6548. mtrace();
  6549. int result = FAIL;
  6550. char message[4096]={0};
  6551. char guid[37]={0};
  6552. char tempdata[128]={0};
  6553. json_object *NotifyDisplayMessages = json_object_new_object();
  6554. json_object *messageInfos = json_object_new_array();
  6555. DEBUG_INFO("sendNotifyDisplayMessagesRequest...\n");
  6556. json_object_object_add(NotifyDisplayMessages, "requestId", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.requestId));
  6557. json_object_object_add(NotifyDisplayMessages, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyDisplayMessages.tbc));
  6558. for(int idxMsg=0;idxMsg<ARRAY_SIZE(ShmOCPP20Data->NotifyDisplayMessages.messageInfo);idxMsg++)
  6559. {
  6560. if(strlen((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.content) > 0)
  6561. {
  6562. json_object *messageInfo = json_object_new_object();
  6563. json_object *message = json_object_new_object();
  6564. json_object *display = json_object_new_object();
  6565. json_object *evse = json_object_new_object();
  6566. json_object_object_add(messageInfo, "id", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].id));
  6567. json_object_object_add(messageInfo, "priority", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].priority));
  6568. json_object_object_add(messageInfo, "state", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].state));
  6569. json_object_object_add(messageInfo, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].startDateTime));
  6570. json_object_object_add(messageInfo, "endDateTime", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].endDateTime));
  6571. json_object_object_add(messageInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].transactionId));
  6572. json_object_object_add(message, "format", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.format));
  6573. json_object_object_add(message, "language", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.language));
  6574. json_object_object_add(message, "content", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.content));
  6575. json_object_object_add(messageInfo, "message", message);
  6576. json_object_object_add(display, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.name));
  6577. json_object_object_add(display, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.instance));
  6578. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.evse.id));
  6579. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.evse.connectorId));
  6580. json_object_object_add(display, "evse",evse);
  6581. json_object_object_add(messageInfo, "evse", display);
  6582. json_object_array_add(messageInfos, messageInfo);
  6583. }
  6584. }
  6585. json_object_object_add(NotifyDisplayMessages, "messageInfo", messageInfos);
  6586. random_uuid(guid);
  6587. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyDisplayMessages", json_object_to_json_string_ext(NotifyDisplayMessages, JSON_C_TO_STRING_PLAIN));
  6588. json_object_put(NotifyDisplayMessages);
  6589. LWS_Send(message);
  6590. sprintf(tempdata, "NotifyDisplayMessages,0");
  6591. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6592. {
  6593. result = PASS;
  6594. }
  6595. return result;
  6596. }
  6597. int sendNotifyEVChargingNeedsRequest(int gun_index)
  6598. {
  6599. mtrace();
  6600. int result = FAIL;
  6601. char message[4096]={0};
  6602. char guid[37]={0};
  6603. char tempdata[128]={0};
  6604. json_object *NotifyEVChargingNeeds = json_object_new_object();
  6605. json_object *chargingNeeds = json_object_new_object();
  6606. json_object *acChargingParameters = json_object_new_object();
  6607. json_object *dcChargingParameters = json_object_new_object();
  6608. DEBUG_INFO("sendNotifyEVChargingNeedsRequest...\n");
  6609. json_object_object_add(NotifyEVChargingNeeds, "maxScheduleTuples", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].maxScheduleTuples));
  6610. json_object_object_add(NotifyEVChargingNeeds, "evseId", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].evseId));
  6611. json_object_object_add(chargingNeeds, "requestedEnergyTransfer", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.requestedEnergyTransfer));
  6612. json_object_object_add(chargingNeeds, "departureTime", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.departureTime));
  6613. json_object_object_add(acChargingParameters, "energyAmount", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.energyAmount));
  6614. json_object_object_add(acChargingParameters, "evMinCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMinCurrent));
  6615. json_object_object_add(acChargingParameters, "evMaxCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMaxCurrent));
  6616. json_object_object_add(acChargingParameters, "evMaxVoltage", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMaxVoltage));
  6617. json_object_object_add(chargingNeeds, "acChargingParameters", acChargingParameters);
  6618. json_object_object_add(dcChargingParameters, "evMaxCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxCurrent));
  6619. json_object_object_add(dcChargingParameters, "evMaxVoltage", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxVoltage));
  6620. json_object_object_add(dcChargingParameters, "energyAmount", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.energyAmount));
  6621. json_object_object_add(dcChargingParameters, "evMaxPower", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxPower));
  6622. json_object_object_add(dcChargingParameters, "stateOfCharge", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.stateOfCharge));
  6623. json_object_object_add(dcChargingParameters, "evEnergyCapacity", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evEnergyCapacity));
  6624. json_object_object_add(dcChargingParameters, "fullSoC", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.fullSoC));
  6625. json_object_object_add(dcChargingParameters, "bulkSoC", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.bulkSoC));
  6626. json_object_object_add(chargingNeeds, "dcChargingParameters", dcChargingParameters);
  6627. json_object_object_add(NotifyEVChargingNeeds, "chargingNeeds", chargingNeeds);
  6628. random_uuid(guid);
  6629. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEVChargingNeeds", json_object_to_json_string_ext(NotifyEVChargingNeeds, JSON_C_TO_STRING_PLAIN));
  6630. json_object_put(NotifyEVChargingNeeds);
  6631. LWS_Send(message);
  6632. sprintf(tempdata, "NotifyEVChargingNeeds,%d", gun_index);
  6633. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6634. {
  6635. result = PASS;
  6636. }
  6637. return result;
  6638. }
  6639. int sendNotifyEVChargingScheduleRequest(int gun_index)
  6640. {
  6641. mtrace();
  6642. int result = FAIL;
  6643. char message[4096]={0};
  6644. char guid[37]={0};
  6645. char tempdata[128]={0};
  6646. json_object *NotifyEVChargingSchedule = json_object_new_object();
  6647. json_object *chargingSchedule = json_object_new_object();
  6648. json_object *periods = json_object_new_array();
  6649. DEBUG_INFO("sendNotifyEVChargingScheduleRequest...\n");
  6650. json_object_object_add(NotifyEVChargingSchedule, "timeBase", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].timeBase));
  6651. json_object_object_add(NotifyEVChargingSchedule, "evseId", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].evseId));
  6652. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.startSchedule));
  6653. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.duration));
  6654. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingRateUnit));
  6655. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.minChargingRate));
  6656. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.id));
  6657. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  6658. {
  6659. if(((ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  6660. (ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  6661. {
  6662. json_object *Period = json_object_new_object();
  6663. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  6664. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  6665. if(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  6666. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  6667. if(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  6668. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  6669. json_object_array_add(periods, Period);
  6670. }
  6671. }
  6672. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", periods);
  6673. json_object_object_add(NotifyEVChargingSchedule, "chargingSchedule", chargingSchedule);
  6674. random_uuid(guid);
  6675. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEVChargingSchedule", json_object_to_json_string_ext(NotifyEVChargingSchedule, JSON_C_TO_STRING_PLAIN));
  6676. json_object_put(NotifyEVChargingSchedule);
  6677. LWS_Send(message);
  6678. sprintf(tempdata, "NotifyEVChargingSchedule,%d", gun_index);
  6679. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6680. {
  6681. result = PASS;
  6682. }
  6683. return result;
  6684. }
  6685. int sendNotifyEventRequest()
  6686. {
  6687. mtrace();
  6688. int result = FAIL;
  6689. char message[4096]={0};
  6690. char guid[37]={0};
  6691. char tempdata[128]={0};
  6692. json_object *NotifyEvent = json_object_new_object();
  6693. json_object *eventDatas = json_object_new_array();
  6694. DEBUG_INFO("sendNotifyEventRequest...\n");
  6695. json_object_object_add(NotifyEvent, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.generatedAt));
  6696. json_object_object_add(NotifyEvent, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyEvent.tbc));
  6697. json_object_object_add(NotifyEvent, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyEvent.seqNo));
  6698. for(int idxEvent=0;idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData);idxEvent++)
  6699. {
  6700. if(strlen((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp) > 0)
  6701. {
  6702. json_object *eventData = json_object_new_object();
  6703. json_object *component = json_object_new_object();
  6704. json_object *evse = json_object_new_object();
  6705. json_object *variable = json_object_new_object();
  6706. json_object_object_add(eventData, "eventId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId));
  6707. json_object_object_add(eventData, "timestamp", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp));
  6708. json_object_object_add(eventData, "trigger", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger));
  6709. json_object_object_add(eventData, "cause", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cause));
  6710. json_object_object_add(eventData, "actualValue", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue));
  6711. json_object_object_add(eventData, "techCode", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode));
  6712. json_object_object_add(eventData, "techInfo", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo));
  6713. json_object_object_add(eventData, "cleared", json_object_new_boolean(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared));
  6714. json_object_object_add(eventData, "transactionId", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].transactionId));
  6715. json_object_object_add(eventData, "variableMonitoringId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variableMonitoringId));
  6716. json_object_object_add(eventData, "eventNotificationType", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType));
  6717. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name));
  6718. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.instance));
  6719. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.id));
  6720. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId));
  6721. json_object_object_add(component, "evse",evse);
  6722. json_object_object_add(eventData, "component", component);
  6723. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name));
  6724. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.instance));
  6725. json_object_object_add(eventData, "variable", variable);
  6726. json_object_array_add(eventDatas, eventData);
  6727. }
  6728. }
  6729. json_object_object_add(NotifyEvent, "eventData", eventDatas);
  6730. random_uuid(guid);
  6731. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEvent", json_object_to_json_string_ext(NotifyEvent, JSON_C_TO_STRING_PLAIN));
  6732. json_object_put(NotifyEvent);
  6733. LWS_Send(message);
  6734. sprintf(tempdata, "NotifyEvent,0");
  6735. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6736. {
  6737. result = PASS;
  6738. }
  6739. return result;
  6740. }
  6741. int sendNotifyMonitoringReportRequest()
  6742. {
  6743. mtrace();
  6744. int result = FAIL;
  6745. char message[4096]={0};
  6746. char guid[37]={0};
  6747. char tempdata[128]={0};
  6748. json_object *NotifyMonitoringReport = json_object_new_object();
  6749. json_object *monitors = json_object_new_array();
  6750. DEBUG_INFO("sendNotifyMonitoringReportRequest...\n");
  6751. json_object_object_add(NotifyMonitoringReport, "requestId", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.requestId));
  6752. json_object_object_add(NotifyMonitoringReport, "tbc", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.tbc));
  6753. json_object_object_add(NotifyMonitoringReport, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.seqNo));
  6754. json_object_object_add(NotifyMonitoringReport, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.generatedAt));
  6755. for(int idxMonitor=0;idxMonitor<ARRAY_SIZE(ShmOCPP20Data->NotifyMonitoringReport.monitor);idxMonitor++)
  6756. {
  6757. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.name) > 0)
  6758. {
  6759. json_object *monitor = json_object_new_object();
  6760. json_object *component = json_object_new_object();
  6761. json_object *evse = json_object_new_object();
  6762. json_object *variable = json_object_new_object();
  6763. json_object *variableMonitorings = json_object_new_array();
  6764. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.name));
  6765. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.instance));
  6766. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.evse.id));
  6767. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.evse.connectorId));
  6768. json_object_object_add(component, "evse",evse);
  6769. json_object_object_add(monitor, "component", component);
  6770. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variable.name));
  6771. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variable.instance));
  6772. json_object_object_add(monitor, "variable", variable);
  6773. for(int idxVar=0;idxVar<ARRAY_SIZE(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring);idxVar++)
  6774. {
  6775. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].type) > 0)
  6776. {
  6777. json_object *variableMonitoring = json_object_new_object();
  6778. json_object_object_add(variableMonitoring, "id", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].id));
  6779. json_object_object_add(variableMonitoring, "value", json_object_new_double(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].value));
  6780. json_object_object_add(variableMonitoring, "type", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].type));
  6781. json_object_object_add(variableMonitoring, "severity", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].severity));
  6782. json_object_object_add(variableMonitoring, "transaction", json_object_new_boolean(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].transaction));
  6783. json_object_array_add(variableMonitorings, variableMonitoring);
  6784. }
  6785. }
  6786. json_object_object_add(monitor, "variableMonitoring", variableMonitorings);
  6787. json_object_array_add(monitors, monitor);
  6788. }
  6789. }
  6790. json_object_object_add(NotifyMonitoringReport, "monitor", monitors);
  6791. random_uuid(guid);
  6792. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyMonitoringReport", json_object_to_json_string_ext(NotifyMonitoringReport, JSON_C_TO_STRING_PLAIN));
  6793. json_object_put(NotifyMonitoringReport);
  6794. LWS_Send(message);
  6795. sprintf(tempdata, "NotifyMonitoringReport,0");
  6796. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6797. {
  6798. result = PASS;
  6799. }
  6800. return result;
  6801. }
  6802. int sendNotifyReportRequest()
  6803. {
  6804. mtrace();
  6805. int result = FAIL;
  6806. char message[4096]={0};
  6807. char guid[37]={0};
  6808. char tempdata[128]={0};
  6809. json_object *NotifyReport = json_object_new_object();
  6810. json_object *reportDatas = json_object_new_array();
  6811. DEBUG_INFO("sendNotifyReportRequest...\n");
  6812. json_object_object_add(NotifyReport, "requestId", json_object_new_int(ShmOCPP20Data->NotifyReport.requestId));
  6813. json_object_object_add(NotifyReport, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.generatedAt));
  6814. json_object_object_add(NotifyReport, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyReport.tbc));
  6815. json_object_object_add(NotifyReport, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyReport.seqNo));
  6816. for(int idxReport=0;idxReport<ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData);idxReport++)
  6817. {
  6818. if(strlen((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.name) > 0)
  6819. {
  6820. json_object *reportData = json_object_new_object();
  6821. json_object *component = json_object_new_object();
  6822. json_object *evse = json_object_new_object();
  6823. json_object *variable = json_object_new_object();
  6824. json_object *variableAttributes = json_object_new_array();
  6825. json_object *variableCharacteristics = json_object_new_object();
  6826. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.name));
  6827. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.instance));
  6828. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyReport.reportData[idxReport].component.evse.id));
  6829. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyReport.reportData[idxReport].component.evse.connectorId));
  6830. json_object_object_add(component, "evse",evse);
  6831. json_object_object_add(reportData, "component", component);
  6832. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variable.name));
  6833. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variable.instance));
  6834. json_object_object_add(reportData, "variable",variable);
  6835. json_object_object_add(variableCharacteristics, "unit", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.unit));
  6836. json_object_object_add(variableCharacteristics, "dataType", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.dataType));
  6837. json_object_object_add(variableCharacteristics, "minLimit", json_object_new_double(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.minLimit));
  6838. json_object_object_add(variableCharacteristics, "maxLimit", json_object_new_double(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.maxLimit));
  6839. json_object_object_add(reportData, "variableCharacteristics",variableCharacteristics);
  6840. for(int idxAttr=0;idxAttr<ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute);idxAttr++)
  6841. {
  6842. if(strlen((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].value) > 0)
  6843. {
  6844. json_object *variableAttribute = json_object_new_object();
  6845. json_object_object_add(variableAttribute, "type", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].type));
  6846. json_object_object_add(variableAttribute, "value", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].value));
  6847. json_object_object_add(variableAttribute, "mutability", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].mutability));
  6848. json_object_object_add(variableAttribute, "persistent", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].persistent));
  6849. json_object_object_add(variableAttribute, "constant", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].constant));
  6850. json_object_array_add(variableAttributes, variableAttribute);
  6851. }
  6852. }
  6853. json_object_object_add(reportData, "variableAttribute", variableAttributes);
  6854. json_object_array_add(reportDatas, reportData);
  6855. }
  6856. }
  6857. json_object_object_add(NotifyReport, "reportData", reportDatas);
  6858. random_uuid(guid);
  6859. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyReport", json_object_to_json_string_ext(NotifyReport, JSON_C_TO_STRING_PLAIN));
  6860. json_object_put(NotifyReport);
  6861. LWS_SendNow(message);
  6862. sprintf(tempdata, "NotifyReport,0");
  6863. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6864. {
  6865. result = PASS;
  6866. }
  6867. return result;
  6868. }
  6869. int sendPublishFirmwareStatusNotificationRequest()
  6870. {
  6871. mtrace();
  6872. int result = FAIL;
  6873. char message[4096]={0};
  6874. char guid[37]={0};
  6875. char tempdata[128]={0};
  6876. json_object *PublishFirmwareStatusNotification = json_object_new_object();
  6877. json_object *locations = json_object_new_array();
  6878. DEBUG_INFO("sendPublishFirmwareStatusNotificationRequest...\n");
  6879. json_object_object_add(PublishFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->PublishFirmwareStatusNotificatio.status));
  6880. json_object_object_add(PublishFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->PublishFirmwareStatusNotificatio.requestId));
  6881. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->PublishFirmwareStatusNotificatio.location);idx++)
  6882. {
  6883. json_object_array_add(locations, json_object_new_string((char*)ShmOCPP20Data->PublishFirmwareStatusNotificatio.location[idx]));
  6884. }
  6885. json_object_object_add(PublishFirmwareStatusNotification, "location", locations);
  6886. random_uuid(guid);
  6887. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "PublishFirmwareStatusNotification", json_object_to_json_string_ext(PublishFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6888. json_object_put(PublishFirmwareStatusNotification);
  6889. LWS_Send(message);
  6890. sprintf(tempdata, "PublishFirmwareStatusNotification,0");
  6891. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6892. {
  6893. result = PASS;
  6894. }
  6895. return result;
  6896. }
  6897. int sendReportChargingProfilesRequest(int gun_index)
  6898. {
  6899. mtrace();
  6900. int result = FAIL;
  6901. char message[4096]={0};
  6902. char guid[37]={0};
  6903. char tempdata[128]={0};
  6904. json_object *ReportChargingProfiles = json_object_new_object();
  6905. json_object *chargingProfiles = json_object_new_array();
  6906. DEBUG_INFO("sendReportChargingProfilesRequest...\n");
  6907. json_object_object_add(ReportChargingProfiles, "requestId", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].requestId));
  6908. json_object_object_add(ReportChargingProfiles, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingLimitSource));
  6909. json_object_object_add(ReportChargingProfiles, "tbc", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].tbc));
  6910. json_object_object_add(ReportChargingProfiles, "evseId", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].evseId));
  6911. for(int idxProfile=0;idxProfile<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile);idxProfile++)
  6912. {
  6913. json_object *chargingProfile = json_object_new_object();
  6914. json_object *chargingSchedules = json_object_new_array();
  6915. json_object_object_add(chargingProfile, "id", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].id));
  6916. json_object_object_add(chargingProfile, "stackLevel", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].stackLevel));
  6917. json_object_object_add(chargingProfile, "chargingProfilePurpose", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingProfilePurpose));
  6918. json_object_object_add(chargingProfile, "chargingProfileKind", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingProfileKind));
  6919. json_object_object_add(chargingProfile, "recurrencyKind", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].recurrencyKind));
  6920. json_object_object_add(chargingProfile, "validFrom", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].validFrom));
  6921. json_object_object_add(chargingProfile, "validTo", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].validTo));
  6922. json_object_object_add(chargingProfile, "transactionId", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].transactionId));
  6923. for(int idxSchedule=0;idxSchedule<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule);idxSchedule++)
  6924. {
  6925. json_object *chargingSchedule = json_object_new_object();
  6926. json_object *chargingSchedulePeriods = json_object_new_array();
  6927. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].startSchedule));
  6928. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].duration));
  6929. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingRateUnit));
  6930. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].minChargingRate));
  6931. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].id));
  6932. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  6933. {
  6934. json_object *chargingSchedulePeriod = json_object_new_object();
  6935. json_object_object_add(chargingSchedulePeriod, "startPeriod", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod));
  6936. json_object_object_add(chargingSchedulePeriod, "limit", json_object_new_double(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit));
  6937. json_object_object_add(chargingSchedulePeriod, "numberPhases", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  6938. json_object_object_add(chargingSchedulePeriod, "phaseToUse", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse));
  6939. json_object_array_add(chargingSchedulePeriods, chargingSchedulePeriod);
  6940. }
  6941. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriods);
  6942. json_object_array_add(chargingSchedules, chargingSchedule);
  6943. }
  6944. json_object_object_add(chargingProfile, "chargingSchedule", chargingSchedules);
  6945. json_object_array_add(chargingProfiles, chargingProfile);
  6946. }
  6947. json_object_object_add(ReportChargingProfiles, "chargingProfile", chargingProfiles);
  6948. random_uuid(guid);
  6949. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ReportChargingProfiles", json_object_to_json_string_ext(ReportChargingProfiles, JSON_C_TO_STRING_PLAIN));
  6950. json_object_put(ReportChargingProfiles);
  6951. LWS_Send(message);
  6952. sprintf(tempdata, "ReportChargingProfiles,%d", gun_index);
  6953. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6954. {
  6955. result = PASS;
  6956. }
  6957. return result;
  6958. }
  6959. int sendReservationStatusUpdateRequest(int gun_index)
  6960. {
  6961. mtrace();
  6962. int result = FAIL;
  6963. char message[4096]={0};
  6964. char guid[37]={0};
  6965. char tempdata[128]={0};
  6966. json_object *ReservationStatusUpdate = json_object_new_object();
  6967. DEBUG_INFO("sendReservationStatusUpdateRequest...\n");
  6968. json_object_object_add(ReservationStatusUpdate, "reservationId", json_object_new_int(ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationId));
  6969. json_object_object_add(ReservationStatusUpdate, "reservationUpdateStatus", json_object_new_string((char*)ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationUpdateStatus));
  6970. random_uuid(guid);
  6971. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ReservationStatusUpdate", json_object_to_json_string_ext(ReservationStatusUpdate, JSON_C_TO_STRING_PLAIN));
  6972. json_object_put(ReservationStatusUpdate);
  6973. LWS_Send(message);
  6974. sprintf(tempdata, "ReservationStatusUpdate,%d", gun_index);
  6975. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6976. {
  6977. result = PASS;
  6978. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = OFF;
  6979. }
  6980. return result;
  6981. }
  6982. int sendSecurityEventNotificationRequest()
  6983. {
  6984. mtrace();
  6985. int result = FAIL;
  6986. char message[4096]={0};
  6987. char guid[37]={0};
  6988. char tempdata[128]={0};
  6989. json_object *SecurityEventNotification = json_object_new_object();
  6990. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  6991. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.type));
  6992. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.timestamp));
  6993. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.techInfo));
  6994. random_uuid(guid);
  6995. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  6996. json_object_put(SecurityEventNotification);
  6997. LWS_Send(message);
  6998. sprintf(tempdata, "SecurityEventNotification,0");
  6999. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7000. {
  7001. result = PASS;
  7002. }
  7003. return result;
  7004. }
  7005. int sendSignCertificateRequest(CertificateSigningUseEnumType certType)
  7006. {
  7007. mtrace();
  7008. int result = FAIL;
  7009. char message[4096]={0};
  7010. char guid[37]={0};
  7011. char tempdata[128]={0};
  7012. json_object *SignCertificate = json_object_new_object();
  7013. DEBUG_INFO("sendSignCertificateRequest...\n");
  7014. // Read csr file content
  7015. memset(ShmOCPP20Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP20Data->SignCertificate.csr));
  7016. FILE *fp=fopen(((certType == CertificateSignedStatusEnumType_V2GCertificate)?"/Storage/OCPP/certV2G.csr":"/Storage/OCPP/certCP.csr"),"r");
  7017. char *line = NULL;
  7018. size_t len = 0;
  7019. while(getline(&line, &len, fp) != -1)
  7020. {
  7021. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7022. {
  7023. memcpy(&ShmOCPP20Data->SignCertificate.csr[strlen((char*)ShmOCPP20Data->SignCertificate.csr)], line, (strlen(line)-1));
  7024. }
  7025. }
  7026. fclose(fp);
  7027. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP20Data->SignCertificate.csr));
  7028. sprintf((char*)ShmOCPP20Data->SignCertificate.certificateType, CertificateSigningUseEnumTypeStr[certType]);
  7029. json_object_object_add(SignCertificate, "certificateType", json_object_new_string((char*)ShmOCPP20Data->SignCertificate.certificateType));
  7030. random_uuid(guid);
  7031. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7032. json_object_put(SignCertificate);
  7033. LWS_Send(message);
  7034. sprintf(tempdata, "SignCertificate,0");
  7035. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7036. {
  7037. result = PASS;
  7038. }
  7039. return result;
  7040. }
  7041. int sendStatusNotificationRequest(int gun_index)
  7042. {
  7043. mtrace();
  7044. int result = FAIL;
  7045. char message[600]={0};
  7046. char guid[37];
  7047. int currentStatus = 0;
  7048. struct timeval tmnow;
  7049. struct tm *tm;
  7050. char buf[28];//, usec_buf[6];
  7051. char tempdata[65]={0};
  7052. int tempIndex = 0;
  7053. uint8_t isStateChanged = TRUE;
  7054. DEBUG_INFO("sendStatusNotificationRequest...\n");
  7055. gettimeofday(&tmnow, NULL);
  7056. time_t t;
  7057. t = time(NULL);
  7058. /*UTC time and date*/
  7059. tm = gmtime(&t);
  7060. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  7061. #if 0 // remove temporally
  7062. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  7063. strcat(buf,".");
  7064. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  7065. strcat(buf,usec_buf);
  7066. #endif
  7067. printf("%s",buf);
  7068. ShmOCPP20Data->StatusNotification[gun_index].evseId = (gun_index + 1);
  7069. ShmOCPP20Data->StatusNotification[gun_index].connectorId = (gun_index + 1);
  7070. strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].timestamp, buf);
  7071. //strcpy(ShmOCPP20Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  7072. /*
  7073. enum _SYSTEM_STATUS
  7074. {
  7075. S_BOOTING = 0,
  7076. S_IDLE, = 1
  7077. S_AUTHORIZING, =2
  7078. S_REASSIGN_CHECK, =3
  7079. S_REASSIGN, =4
  7080. S_PRECHARGE, =5
  7081. S_PREPARING_FOR_EV, =6
  7082. S_PREPARING_FOR_EVSE, =7
  7083. S_CHARGING, =8
  7084. S_TERMINATING, =9
  7085. S_COMPLETE, =10
  7086. S_ALARM, =11
  7087. S_FAULT =12
  7088. }
  7089. */
  7090. //check Transaction active
  7091. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  7092. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7093. {
  7094. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7095. {
  7096. tempIndex = ((gun_index==2) ? 1: 0);
  7097. }
  7098. else
  7099. {
  7100. tempIndex = gun_index;
  7101. }
  7102. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7103. {
  7104. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  7105. {
  7106. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  7107. {
  7108. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  7109. {
  7110. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  7111. }
  7112. else
  7113. {
  7114. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  7115. }
  7116. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  7117. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  7118. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  7119. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  7120. }
  7121. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  7122. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  7123. ) //S_PRECHARGE
  7124. {
  7125. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  7126. }
  7127. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  7128. {
  7129. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  7130. }
  7131. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  7132. {
  7133. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  7134. }
  7135. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  7136. {
  7137. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  7138. }
  7139. 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
  7140. {
  7141. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  7142. }
  7143. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  7144. {
  7145. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  7146. }
  7147. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  7148. {
  7149. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  7150. }
  7151. } //end of the same index
  7152. }//end of for CHAdeMO_QUANTITY
  7153. }
  7154. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7155. {
  7156. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7157. {
  7158. tempIndex = ((gun_index==2) ? 1: 0);
  7159. }
  7160. else
  7161. {
  7162. tempIndex = gun_index;
  7163. }
  7164. for (int index = 0; index < CCS_QUANTITY; index++)
  7165. {
  7166. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7167. {
  7168. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7169. {
  7170. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  7171. {
  7172. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  7173. }
  7174. else
  7175. {
  7176. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  7177. }
  7178. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  7179. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  7180. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  7181. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  7182. }
  7183. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  7184. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  7185. ) //S_PRECHARGE
  7186. {
  7187. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  7188. }
  7189. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  7190. {
  7191. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  7192. }
  7193. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  7194. {
  7195. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  7196. }
  7197. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  7198. {
  7199. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  7200. }
  7201. 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
  7202. {
  7203. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status : Unavailable
  7204. }
  7205. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  7206. {
  7207. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  7208. }
  7209. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  7210. {
  7211. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  7212. }
  7213. } //end of the same index
  7214. } // end of for CCS_QUANTITY
  7215. }
  7216. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7217. {
  7218. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7219. {
  7220. tempIndex = ((gun_index==2) ? 1: 0);
  7221. }
  7222. else
  7223. {
  7224. tempIndex = gun_index;
  7225. }
  7226. for (int index = 0; index < GB_QUANTITY; index++)
  7227. {
  7228. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7229. {
  7230. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7231. {
  7232. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  7233. {
  7234. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  7235. }
  7236. else
  7237. {
  7238. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  7239. }
  7240. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  7241. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  7242. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  7243. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  7244. }
  7245. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  7246. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  7247. ) //S_PRECHARGE
  7248. {
  7249. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  7250. }
  7251. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  7252. {
  7253. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  7254. }
  7255. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  7256. {
  7257. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  7258. }
  7259. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  7260. {
  7261. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  7262. }
  7263. 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
  7264. {
  7265. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  7266. }
  7267. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  7268. {
  7269. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  7270. }
  7271. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  7272. {
  7273. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  7274. }
  7275. } //end of the same index
  7276. } // end of for GB_QUANTITY
  7277. }
  7278. else if(gunType[gun_index] == GUN_TYPE_DO)
  7279. {
  7280. tempIndex = gun_index;
  7281. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7282. {
  7283. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7284. {
  7285. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7286. {
  7287. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  7288. {
  7289. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  7290. }
  7291. else
  7292. {
  7293. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  7294. }
  7295. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  7296. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  7297. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  7298. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  7299. }
  7300. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  7301. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  7302. ) //S_PRECHARGE
  7303. {
  7304. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  7305. }
  7306. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  7307. {
  7308. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  7309. }
  7310. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  7311. {
  7312. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  7313. }
  7314. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  7315. {
  7316. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  7317. }
  7318. 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
  7319. {
  7320. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  7321. }
  7322. 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
  7323. {
  7324. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  7325. }
  7326. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  7327. {
  7328. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  7329. }
  7330. } //end of the same index
  7331. }
  7332. }
  7333. else
  7334. {
  7335. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7336. {
  7337. tempIndex = 2;
  7338. }
  7339. else
  7340. {
  7341. tempIndex = gun_index;
  7342. }
  7343. for (int index = 0; index < AC_QUANTITY; index++)
  7344. {
  7345. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7346. {
  7347. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  7348. {
  7349. 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))
  7350. {
  7351. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  7352. }
  7353. else
  7354. {
  7355. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  7356. }
  7357. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  7358. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  7359. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  7360. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  7361. }
  7362. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  7363. {
  7364. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  7365. }
  7366. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  7367. {
  7368. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  7369. }
  7370. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  7371. {
  7372. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  7373. }
  7374. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  7375. {
  7376. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  7377. }
  7378. 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
  7379. {
  7380. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  7381. }
  7382. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  7383. {
  7384. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  7385. }
  7386. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  7387. {
  7388. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  7389. }
  7390. }//end of the same index
  7391. }//end of for AC_QUANTITY
  7392. }
  7393. //it's option
  7394. if((strstr((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]) != NULL) &&
  7395. !ShmOCPP20Data->CsMsg.bits[gun_index].TriggerMessageReq)
  7396. {
  7397. isStateChanged = FALSE;
  7398. }
  7399. ShmOCPP20Data->CsMsg.bits[gun_index].TriggerMessageReq = 0;
  7400. strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]);
  7401. random_uuid(guid);
  7402. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"evseId\":%d,\"connectorStatus\":\"%s\",\"timestamp\":\"%s\"}]"
  7403. , MESSAGE_TYPE_CALL
  7404. , guid
  7405. , ShmOCPP20Data->StatusNotification[gun_index].connectorId
  7406. , ShmOCPP20Data->StatusNotification[gun_index].evseId
  7407. , ShmOCPP20Data->StatusNotification[gun_index].connectorStatus
  7408. , ShmOCPP20Data->StatusNotification[gun_index].timestamp);
  7409. if((server_sign == TRUE) && isStateChanged)
  7410. {
  7411. LWS_Send(message);
  7412. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  7413. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7414. {
  7415. result = PASS;
  7416. }
  7417. }
  7418. else
  7419. {
  7420. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  7421. result = PASS;
  7422. }
  7423. return result;
  7424. }
  7425. int sendTransactionEventRequest(int gun_index)
  7426. {
  7427. mtrace();
  7428. int result = FAIL;
  7429. char message[1024*20]={0};
  7430. char guid[37]={0};
  7431. char tempdata[128]={0};
  7432. uint8_t tempIndex;
  7433. json_object *TransactionEvent = json_object_new_object();
  7434. json_object *transactionInfo = json_object_new_object();
  7435. json_object *idToken = json_object_new_object();
  7436. json_object *evse = json_object_new_object();
  7437. json_object *meterValues = json_object_new_array();
  7438. char TempStopTransaction[256];
  7439. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  7440. DEBUG_INFO("sendTransactionEventRequest...\n");
  7441. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7442. {
  7443. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7444. {
  7445. tempIndex = ((gun_index==2) ? 1: 0);
  7446. }
  7447. else
  7448. {
  7449. tempIndex = gun_index;
  7450. }
  7451. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7452. {
  7453. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  7454. {
  7455. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  7456. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  7457. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  7458. else
  7459. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  7460. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  7461. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  7462. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  7463. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  7464. {
  7465. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  7466. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  7467. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  7468. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7469. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  7470. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  7471. {
  7472. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  7473. }
  7474. else
  7475. {
  7476. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  7477. }
  7478. }
  7479. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  7480. {
  7481. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7482. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  7483. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  7484. }
  7485. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  7486. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  7487. ) //S_PRECHARGE
  7488. {
  7489. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  7490. {
  7491. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  7492. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartUserId);
  7493. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", ShmOCPP20Data->Authorize.idToken.type);
  7494. storeTempStopTransaction(gun_index);
  7495. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7496. }
  7497. else
  7498. {
  7499. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7500. }
  7501. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  7502. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7503. }
  7504. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  7505. {
  7506. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7507. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  7508. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7509. }
  7510. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  7511. {
  7512. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  7513. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  7514. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7515. if((access(TempStopTransaction,F_OK))!=-1)
  7516. {
  7517. remove(TempStopTransaction); // remove file "TempStopTransaction"
  7518. }
  7519. }
  7520. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  7521. {
  7522. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7523. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  7524. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7525. }
  7526. 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
  7527. {
  7528. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7529. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7530. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7531. }
  7532. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  7533. {
  7534. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7535. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7536. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7537. }
  7538. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  7539. {
  7540. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7541. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7542. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7543. }
  7544. } //end of the same index
  7545. }//end of for CHAdeMO_QUANTITY
  7546. }
  7547. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7548. {
  7549. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7550. {
  7551. tempIndex = ((gun_index==2) ? 1: 0);
  7552. }
  7553. else
  7554. {
  7555. tempIndex = gun_index;
  7556. }
  7557. for (int index = 0; index < CCS_QUANTITY; index++)
  7558. {
  7559. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7560. {
  7561. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  7562. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  7563. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  7564. else
  7565. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  7566. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  7567. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  7568. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  7569. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7570. {
  7571. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  7572. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  7573. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  7574. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7575. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  7576. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  7577. {
  7578. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  7579. }
  7580. else
  7581. {
  7582. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  7583. }
  7584. }
  7585. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  7586. {
  7587. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7588. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  7589. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  7590. }
  7591. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  7592. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  7593. ) //S_PRECHARGE
  7594. {
  7595. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  7596. {
  7597. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  7598. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartUserId);
  7599. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", ShmOCPP20Data->Authorize.idToken.type);
  7600. storeTempStopTransaction(gun_index);
  7601. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7602. }
  7603. else
  7604. {
  7605. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7606. }
  7607. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  7608. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7609. }
  7610. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  7611. {
  7612. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7613. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  7614. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7615. }
  7616. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  7617. {
  7618. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  7619. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  7620. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7621. if((access(TempStopTransaction,F_OK))!=-1)
  7622. {
  7623. remove(TempStopTransaction); // remove file "TempStopTransaction"
  7624. }
  7625. }
  7626. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  7627. {
  7628. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7629. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  7630. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7631. }
  7632. 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
  7633. {
  7634. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7635. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7636. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7637. }
  7638. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  7639. {
  7640. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7641. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7642. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7643. }
  7644. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  7645. {
  7646. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7647. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7648. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7649. }
  7650. } //end of the same index
  7651. } // end of for CCS_QUANTITY
  7652. }
  7653. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7654. {
  7655. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7656. {
  7657. tempIndex = ((gun_index==2) ? 1: 0);
  7658. }
  7659. else
  7660. {
  7661. tempIndex = gun_index;
  7662. }
  7663. for (int index = 0; index < GB_QUANTITY; index++)
  7664. {
  7665. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7666. {
  7667. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  7668. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  7669. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  7670. else
  7671. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  7672. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  7673. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  7674. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  7675. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7676. {
  7677. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  7678. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  7679. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  7680. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7681. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  7682. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  7683. {
  7684. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  7685. }
  7686. else
  7687. {
  7688. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  7689. }
  7690. }
  7691. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  7692. {
  7693. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7694. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  7695. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  7696. }
  7697. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  7698. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  7699. ) //S_PRECHARGE
  7700. {
  7701. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  7702. {
  7703. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  7704. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartUserId);
  7705. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", ShmOCPP20Data->Authorize.idToken.type);
  7706. storeTempStopTransaction(gun_index);
  7707. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7708. }
  7709. else
  7710. {
  7711. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7712. }
  7713. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  7714. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7715. }
  7716. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  7717. {
  7718. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7719. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  7720. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7721. }
  7722. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  7723. {
  7724. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  7725. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  7726. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7727. if((access(TempStopTransaction,F_OK))!=-1)
  7728. {
  7729. remove(TempStopTransaction); // remove file "TempStopTransaction"
  7730. }
  7731. }
  7732. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  7733. {
  7734. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7735. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  7736. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7737. }
  7738. 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
  7739. {
  7740. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7741. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7742. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7743. }
  7744. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  7745. {
  7746. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7747. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7748. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7749. }
  7750. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  7751. {
  7752. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7753. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7754. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7755. }
  7756. } //end of the same index
  7757. } // end of for GB_QUANTITY
  7758. }
  7759. else if(gunType[gun_index] == GUN_TYPE_DO)
  7760. {
  7761. tempIndex = gun_index;
  7762. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7763. {
  7764. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7765. {
  7766. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  7767. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  7768. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  7769. else
  7770. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  7771. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  7772. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  7773. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  7774. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7775. {
  7776. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  7777. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  7778. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  7779. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7780. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  7781. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  7782. {
  7783. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  7784. }
  7785. else
  7786. {
  7787. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  7788. }
  7789. }
  7790. else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  7791. {
  7792. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7793. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  7794. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  7795. }
  7796. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  7797. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  7798. ) //S_PRECHARGE
  7799. {
  7800. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  7801. {
  7802. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  7803. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartUserId);
  7804. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", ShmOCPP20Data->Authorize.idToken.type);
  7805. storeTempStopTransaction(gun_index);
  7806. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7807. }
  7808. else
  7809. {
  7810. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7811. }
  7812. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  7813. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7814. }
  7815. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  7816. {
  7817. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7818. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  7819. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7820. }
  7821. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  7822. {
  7823. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  7824. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  7825. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7826. if((access(TempStopTransaction,F_OK))!=-1)
  7827. {
  7828. remove(TempStopTransaction); // remove file "TempStopTransaction"
  7829. }
  7830. }
  7831. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  7832. {
  7833. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7834. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  7835. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7836. }
  7837. 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
  7838. {
  7839. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7840. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7841. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7842. }
  7843. 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
  7844. {
  7845. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7846. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7847. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7848. }
  7849. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  7850. {
  7851. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7852. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7853. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7854. }
  7855. } //end of the same index
  7856. }
  7857. }
  7858. else
  7859. {
  7860. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7861. {
  7862. tempIndex = 2;
  7863. }
  7864. else
  7865. {
  7866. tempIndex = gun_index;
  7867. }
  7868. for (int index = 0; index < AC_QUANTITY; index++)
  7869. {
  7870. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7871. {
  7872. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  7873. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  7874. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  7875. else
  7876. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  7877. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  7878. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  7879. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  7880. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  7881. {
  7882. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  7883. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  7884. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  7885. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7886. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  7887. 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))
  7888. {
  7889. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  7890. }
  7891. else
  7892. {
  7893. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  7894. }
  7895. }
  7896. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  7897. {
  7898. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7899. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  7900. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  7901. }
  7902. else if ( ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  7903. ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  7904. ) //S_PRECHARGE
  7905. {
  7906. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  7907. {
  7908. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  7909. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartUserId);
  7910. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", ShmOCPP20Data->Authorize.idToken.type);
  7911. storeTempStopTransaction(gun_index);
  7912. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7913. }
  7914. else
  7915. {
  7916. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7917. }
  7918. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  7919. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7920. }
  7921. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  7922. {
  7923. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7924. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  7925. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7926. }
  7927. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  7928. {
  7929. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  7930. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  7931. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7932. if((access(TempStopTransaction,F_OK))!=-1)
  7933. {
  7934. remove(TempStopTransaction); // remove file "TempStopTransaction"
  7935. }
  7936. }
  7937. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  7938. {
  7939. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7940. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  7941. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7942. }
  7943. 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
  7944. {
  7945. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7946. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7947. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7948. }
  7949. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  7950. {
  7951. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7952. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7953. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7954. }
  7955. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  7956. {
  7957. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7958. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7959. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7960. }
  7961. }//end of the same index
  7962. }//end of for AC_QUANTITY
  7963. }
  7964. // Message
  7965. json_object_object_add(TransactionEvent, "eventType", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  7966. json_object_object_add(TransactionEvent, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].timestamp));
  7967. json_object_object_add(TransactionEvent, "triggerReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason));
  7968. json_object_object_add(TransactionEvent, "seqNo", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].seqNo));
  7969. json_object_object_add(TransactionEvent, "offline", json_object_new_boolean(ShmOCPP20Data->TransactionEvent[gun_index].offline));
  7970. if(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed > 0)
  7971. json_object_object_add(TransactionEvent, "numberOfPhasesUsed", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed));
  7972. if(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent > 0)
  7973. json_object_object_add(TransactionEvent, "cableMaxCurrent", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent));
  7974. if(ShmOCPP20Data->TransactionEvent[gun_index].reservationId > 0)
  7975. json_object_object_add(TransactionEvent, "reservationId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].reservationId));
  7976. json_object_object_add(transactionInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId));
  7977. json_object_object_add(transactionInfo, "chargingState", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState));
  7978. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging > 0)
  7979. json_object_object_add(transactionInfo, "timeSpentCharging", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging));
  7980. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason) > 0)
  7981. json_object_object_add(transactionInfo, "stoppedReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason));
  7982. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId > 0)
  7983. json_object_object_add(transactionInfo, "remoteStartId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId));
  7984. json_object_object_add(TransactionEvent, "transactionInfo", transactionInfo);
  7985. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken) > 0)
  7986. {
  7987. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
  7988. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type));
  7989. json_object_object_add(TransactionEvent, "idToken", idToken);
  7990. }
  7991. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.id));
  7992. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId));
  7993. json_object_object_add(TransactionEvent, "evse", evse);
  7994. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0].timestamp) > 0)
  7995. {
  7996. for(int idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue);idxMeter++)
  7997. {
  7998. json_object *meterValue = json_object_new_object();
  7999. json_object *sampledValues = json_object_new_array();
  8000. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].timestamp));
  8001. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  8002. {
  8003. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0) &&
  8004. ((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)))
  8005. {
  8006. json_object *sampledValue = json_object_new_object();
  8007. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  8008. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  8009. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  8010. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  8011. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  8012. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  8013. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  8014. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  8015. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  8016. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  8017. {
  8018. json_object *unitOfMeasure = json_object_new_object();
  8019. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  8020. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  8021. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  8022. }
  8023. json_object_array_add(sampledValues, sampledValue);
  8024. }
  8025. }
  8026. json_object_object_add(meterValue, "sampledValue", sampledValues);
  8027. json_object_array_add(meterValues, meterValue);
  8028. }
  8029. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  8030. }
  8031. random_uuid(guid);
  8032. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "TransactionEvent", json_object_to_json_string_ext(TransactionEvent, JSON_C_TO_STRING_PLAIN));
  8033. json_object_put(TransactionEvent);
  8034. sprintf(tempdata, "TransactionEvent,%d", gun_index);
  8035. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8036. {
  8037. result = PASS;
  8038. }
  8039. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  8040. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Started]) != NULL)
  8041. OCPP_insert_transaction_msg(YES, message);
  8042. else if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL)
  8043. OCPP_insert_transaction_msg(NO, message);
  8044. return result;
  8045. }
  8046. //==========================================
  8047. // send confirm routine
  8048. //==========================================
  8049. int sendCancelReservationConfirmation(char *uuid, unsigned char gun_index)
  8050. {
  8051. mtrace();
  8052. int result = FAIL;
  8053. char message[4096]={0};
  8054. json_object *CancelReservation = json_object_new_object();
  8055. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  8056. json_object_object_add(CancelReservation, "status", json_object_new_string((char*)ShmOCPP20Data->CancelReservation[gun_index].Response_status));
  8057. sprintf(message,"[%d,\"%s\",%s]"
  8058. ,MESSAGE_TYPE_CALLRESULT
  8059. ,uuid
  8060. ,json_object_to_json_string_ext(CancelReservation, JSON_C_TO_STRING_PLAIN));
  8061. json_object_put(CancelReservation);
  8062. ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationConf = OFF;
  8063. LWS_Send(message);
  8064. result = TRUE;
  8065. return result;
  8066. }
  8067. int sendCertificateSignedConfirmation(char *uuid)
  8068. {
  8069. mtrace();
  8070. int result = FAIL;
  8071. char message[4096]={0};
  8072. json_object *CertificateSigned = json_object_new_object();
  8073. json_object *statusInfo = json_object_new_object();
  8074. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8075. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_status));
  8076. if(strlen((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.reasonCode) > 0)
  8077. {
  8078. json_object_object_add(statusInfo, "reasonCode", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.reasonCode));
  8079. if(strlen((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.additionalInfo) > 0)
  8080. json_object_object_add(statusInfo, "statadditionalInfous", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.additionalInfo));
  8081. }
  8082. json_object_object_add(CertificateSigned, "statusInfo", statusInfo);
  8083. sprintf(message,"[%d,\"%s\",%s]"
  8084. ,MESSAGE_TYPE_CALLRESULT
  8085. ,uuid
  8086. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8087. json_object_put(CertificateSigned);
  8088. LWS_Send(message);
  8089. result = TRUE;
  8090. return result;
  8091. }
  8092. int sendChangeAvailabilityConfirmation(char *uuid, unsigned char gun_index)
  8093. {
  8094. mtrace();
  8095. int result = FAIL;
  8096. char message[4096]={0};
  8097. json_object *ChangeAvailability = json_object_new_object();
  8098. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  8099. json_object_object_add(ChangeAvailability, "status", json_object_new_string((char*)ShmOCPP20Data->ChangeAvailability[gun_index].Response_status));
  8100. sprintf(message,"[%d,\"%s\",%s]"
  8101. ,MESSAGE_TYPE_CALLRESULT
  8102. ,uuid
  8103. ,json_object_to_json_string_ext(ChangeAvailability, JSON_C_TO_STRING_PLAIN));
  8104. json_object_put(ChangeAvailability);
  8105. LWS_Send(message);
  8106. result = TRUE;
  8107. return result;
  8108. }
  8109. int sendClearCacheConfirmation(char *uuid)
  8110. {
  8111. mtrace();
  8112. int result = FAIL;
  8113. char message[4096]={0};
  8114. json_object *ClearCache = json_object_new_object();
  8115. DEBUG_INFO("sendClearCacheConfirmation...\n");
  8116. json_object_object_add(ClearCache, "status", json_object_new_string((char*)ShmOCPP20Data->ClearCache.Response_status));
  8117. sprintf(message,"[%d,\"%s\",%s]"
  8118. ,MESSAGE_TYPE_CALLRESULT
  8119. ,uuid
  8120. ,json_object_to_json_string_ext(ClearCache, JSON_C_TO_STRING_PLAIN));
  8121. json_object_put(ClearCache);
  8122. LWS_Send(message);
  8123. result = TRUE;
  8124. return result;
  8125. }
  8126. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  8127. {
  8128. mtrace();
  8129. int result = FAIL;
  8130. char message[500]={0};
  8131. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  8132. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8133. LWS_Send(message);
  8134. return result;
  8135. }
  8136. int sendClearDisplayMessageConfirmation(char *uuid)
  8137. {
  8138. mtrace();
  8139. int result = FAIL;
  8140. char message[4096]={0};
  8141. json_object *ClearDisplayMessage = json_object_new_object();
  8142. DEBUG_INFO("sendClearDisplayMessageConfirmation...\n");
  8143. json_object_object_add(ClearDisplayMessage, "status", json_object_new_string((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status));
  8144. sprintf(message,"[%d,\"%s\",%s]"
  8145. ,MESSAGE_TYPE_CALLRESULT
  8146. ,uuid
  8147. ,json_object_to_json_string_ext(ClearDisplayMessage, JSON_C_TO_STRING_PLAIN));
  8148. json_object_put(ClearDisplayMessage);
  8149. LWS_Send(message);
  8150. result = TRUE;
  8151. return result;
  8152. }
  8153. int sendClearVariableMonitoringConfirmation(char *uuid, unsigned char variableQuantity)
  8154. {
  8155. mtrace();
  8156. int result = FAIL;
  8157. char message[4096]={0};
  8158. json_object *ClearVariableMonitoring = json_object_new_object();
  8159. json_object *clearMonitoringResults = json_object_new_array();
  8160. DEBUG_INFO("sendClearVariableMonitoringConfirmation...\n");
  8161. for(int idx=0;idx<variableQuantity;idx++)
  8162. {
  8163. json_object *clearMonitoringResult = json_object_new_object();
  8164. json_object_object_add(clearMonitoringResult, "id", json_object_new_int(ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].id));
  8165. json_object_object_add(clearMonitoringResult, "status", json_object_new_string((char*)ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].status));
  8166. json_object_array_add(clearMonitoringResults, clearMonitoringResult);
  8167. }
  8168. json_object_object_add(ClearVariableMonitoring, "clearMonitoringResult", clearMonitoringResults);
  8169. sprintf(message,"[%d,\"%s\",%s]"
  8170. ,MESSAGE_TYPE_CALLRESULT
  8171. ,uuid
  8172. ,json_object_to_json_string_ext(ClearVariableMonitoring, JSON_C_TO_STRING_PLAIN));
  8173. json_object_put(ClearVariableMonitoring);
  8174. LWS_Send(message);
  8175. result = TRUE;
  8176. return result;
  8177. }
  8178. int sendCostUpdatedConfirmation(char *uuid)
  8179. {
  8180. mtrace();
  8181. int result = FAIL;
  8182. char message[4096]={0};
  8183. DEBUG_INFO("sendCostUpdatedConfirmation...\n");
  8184. sprintf(message,"[%d,\"%s\",{}]"
  8185. ,MESSAGE_TYPE_CALLRESULT
  8186. ,uuid);
  8187. LWS_Send(message);
  8188. result = TRUE;
  8189. return result;
  8190. }
  8191. int sendCustomerInformationConfirmation(char *uuid)
  8192. {
  8193. mtrace();
  8194. int result = FAIL;
  8195. char message[4096]={0};
  8196. json_object *CustomerInformation = json_object_new_object();
  8197. DEBUG_INFO("sendCustomerInformationConfirmation...\n");
  8198. json_object_object_add(CustomerInformation, "status", json_object_new_string((char*)ShmOCPP20Data->CustomerInformation.Response_status));
  8199. sprintf(message,"[%d,\"%s\",%s]"
  8200. ,MESSAGE_TYPE_CALLRESULT
  8201. ,uuid
  8202. ,json_object_to_json_string_ext(CustomerInformation, JSON_C_TO_STRING_PLAIN));
  8203. json_object_put(CustomerInformation);
  8204. LWS_Send(message);
  8205. result = TRUE;
  8206. return result;
  8207. }
  8208. int sendDataTransferConfirmation(char *uuid, unsigned char gun_index)
  8209. {
  8210. mtrace();
  8211. int result = FAIL;
  8212. char message[4096]={0};
  8213. json_object *DataTransfer = json_object_new_object();
  8214. DEBUG_INFO("sendDataTransferConfirmation...\n");
  8215. json_object_object_add(DataTransfer, "status", json_object_new_string((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_status));
  8216. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_data));
  8217. sprintf(message,"[%d,\"%s\",%s]"
  8218. ,MESSAGE_TYPE_CALLRESULT
  8219. ,uuid
  8220. ,json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  8221. json_object_put(DataTransfer);
  8222. LWS_Send(message);
  8223. result = TRUE;
  8224. return result;
  8225. }
  8226. int sendDeleteCertificateConfirmation(char *uuid)
  8227. {
  8228. mtrace();
  8229. int result = FAIL;
  8230. char message[4096]={0};
  8231. json_object *DeleteCertificate = json_object_new_object();
  8232. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8233. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP20Data->DeleteCertificate.Response_status));
  8234. sprintf(message,"[%d,\"%s\",%s]"
  8235. ,MESSAGE_TYPE_CALLRESULT
  8236. ,uuid
  8237. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8238. json_object_put(DeleteCertificate);
  8239. LWS_Send(message);
  8240. result = TRUE;
  8241. return result;
  8242. }
  8243. int sendGetBaseReportConfirmation(char *uuid)
  8244. {
  8245. mtrace();
  8246. int result = FAIL;
  8247. char message[4096]={0};
  8248. json_object *GetBaseReport = json_object_new_object();
  8249. DEBUG_INFO("sendGetBaseReportConfirmation...\n");
  8250. json_object_object_add(GetBaseReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetBaseReport.Response_status));
  8251. sprintf(message,"[%d,\"%s\",%s]"
  8252. ,MESSAGE_TYPE_CALLRESULT
  8253. ,uuid
  8254. ,json_object_to_json_string_ext(GetBaseReport, JSON_C_TO_STRING_PLAIN));
  8255. json_object_put(GetBaseReport);
  8256. LWS_Send(message);
  8257. result = TRUE;
  8258. return result;
  8259. }
  8260. int sendGetChargingProfilesConfirmation(char *uuid, unsigned char gun_index)
  8261. {
  8262. mtrace();
  8263. int result = FAIL;
  8264. char message[4096]={0};
  8265. json_object *GetChargingProfiles = json_object_new_object();
  8266. DEBUG_INFO("sendGetChargingProfilesConfirmation...\n");
  8267. json_object_object_add(GetChargingProfiles, "status", json_object_new_string((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status));
  8268. sprintf(message,"[%d,\"%s\",%s]"
  8269. ,MESSAGE_TYPE_CALLRESULT
  8270. ,uuid
  8271. ,json_object_to_json_string_ext(GetChargingProfiles, JSON_C_TO_STRING_PLAIN));
  8272. json_object_put(GetChargingProfiles);
  8273. LWS_Send(message);
  8274. result = TRUE;
  8275. return result;
  8276. }
  8277. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  8278. {
  8279. mtrace();
  8280. int result = FAIL;
  8281. char message[4096]={0};
  8282. int CompositeScheduleIndex = 0;
  8283. json_object *GetCompositeSchedule = json_object_new_object();
  8284. json_object *schedule = json_object_new_object();
  8285. json_object *chargingSchedule = json_object_new_object();
  8286. json_object *chargingSchedulePeriod = json_object_new_array();
  8287. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  8288. json_object_object_add(GetCompositeSchedule, "status", json_object_new_string(payload));
  8289. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  8290. if(nPeriod == 0)
  8291. {
  8292. if(strcmp((const char *)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime,"")!=0)
  8293. {
  8294. if(strlen((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule))
  8295. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule));
  8296. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration > 0)
  8297. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration));
  8298. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit));
  8299. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate > 0)
  8300. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate));
  8301. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.id));
  8302. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  8303. {
  8304. if(((ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  8305. (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  8306. {
  8307. json_object *Period = json_object_new_object();
  8308. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  8309. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  8310. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  8311. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  8312. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  8313. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  8314. json_object_array_add(chargingSchedulePeriod, Period);
  8315. }
  8316. }
  8317. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriod);
  8318. json_object_object_add(schedule, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime));
  8319. json_object_object_add(schedule, "chargingSchedule", chargingSchedule);
  8320. json_object_object_add(GetCompositeSchedule, "schedule", schedule);
  8321. }
  8322. }
  8323. else
  8324. {
  8325. if(strlen((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule))
  8326. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule));
  8327. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration > 0)
  8328. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration));
  8329. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit));
  8330. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate > 0)
  8331. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate));
  8332. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.id));
  8333. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  8334. {
  8335. if(((ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  8336. (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  8337. {
  8338. json_object *Period = json_object_new_object();
  8339. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  8340. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  8341. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  8342. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  8343. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  8344. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  8345. json_object_array_add(chargingSchedulePeriod, Period);
  8346. }
  8347. }
  8348. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriod);
  8349. json_object_object_add(schedule, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime));
  8350. json_object_object_add(schedule, "chargingSchedule", chargingSchedule);
  8351. json_object_object_add(GetCompositeSchedule, "schedule", schedule);
  8352. }
  8353. sprintf(message,"[%d,\"%s\",%s]"
  8354. ,MESSAGE_TYPE_CALLRESULT
  8355. ,uuid
  8356. ,json_object_to_json_string_ext(GetCompositeSchedule, JSON_C_TO_STRING_PLAIN));
  8357. json_object_put(GetCompositeSchedule);
  8358. LWS_Send(message);
  8359. result = TRUE;
  8360. return result;
  8361. }
  8362. int sendGetGetDisplayMessagesConfirmation(char *uuid)
  8363. {
  8364. mtrace();
  8365. int result = FAIL;
  8366. char message[4096]={0};
  8367. json_object *GetGetDisplayMessages = json_object_new_object();
  8368. DEBUG_INFO("sendGetGetDisplayMessagesConfirmation...\n");
  8369. json_object_object_add(GetGetDisplayMessages, "status", json_object_new_string((char*)ShmOCPP20Data->GetDisplayMessages.Response_status));
  8370. sprintf(message,"[%d,\"%s\",%s]"
  8371. ,MESSAGE_TYPE_CALLRESULT
  8372. ,uuid
  8373. ,json_object_to_json_string_ext(GetGetDisplayMessages, JSON_C_TO_STRING_PLAIN));
  8374. json_object_put(GetGetDisplayMessages);
  8375. LWS_Send(message);
  8376. result = TRUE;
  8377. return result;
  8378. }
  8379. int sendGetInstalledCertificateIdsConfirmation(char *uuid, unsigned char certQuantity)
  8380. {
  8381. mtrace();
  8382. int result = FAIL;
  8383. char message[4096]={0};
  8384. json_object *GetInstalledCertificateIds = json_object_new_object();
  8385. json_object *certificateHashDataChains = json_object_new_array();
  8386. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8387. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status));
  8388. for(int idx=0;idx<certQuantity;idx++)
  8389. {
  8390. json_object *cert = json_object_new_object();
  8391. json_object *certificateHashData = json_object_new_object();
  8392. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.hashAlgorithm));
  8393. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.issuerNameHash));
  8394. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.issuerKeyHash));
  8395. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.serialNumber));
  8396. json_object_object_add(cert, "certificateHashData", certificateHashData);
  8397. json_object_object_add(cert, "certificateType", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateType));
  8398. json_object_array_add(certificateHashDataChains, cert);
  8399. }
  8400. json_object_object_add(GetInstalledCertificateIds , "certificateHashDataChain", certificateHashDataChains);
  8401. sprintf(message,"[%d,\"%s\",%s]"
  8402. ,MESSAGE_TYPE_CALLRESULT
  8403. ,uuid
  8404. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8405. json_object_put(GetInstalledCertificateIds);
  8406. LWS_Send(message);
  8407. result = TRUE;
  8408. return result;
  8409. }
  8410. int sendGetLocalListVersionConfirmation(char *uuid)
  8411. {
  8412. mtrace();
  8413. int result = FAIL;
  8414. char message[4096]={0};
  8415. json_object *GetLocalListVersion = json_object_new_object();
  8416. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  8417. json_object_object_add(GetLocalListVersion, "versionNumber", json_object_new_int(ShmOCPP20Data->GetLocalListVersion.Response_versionNumber));
  8418. sprintf(message,"[%d,\"%s\",%s]"
  8419. ,MESSAGE_TYPE_CALLRESULT
  8420. ,uuid
  8421. ,json_object_to_json_string_ext(GetLocalListVersion, JSON_C_TO_STRING_PLAIN));
  8422. json_object_put(GetLocalListVersion);
  8423. LWS_Send(message);
  8424. result = TRUE;
  8425. return result;
  8426. }
  8427. int sendGetLogConfirmation(char *uuid)
  8428. {
  8429. mtrace();
  8430. int result = FAIL;
  8431. char message[4096]={0};
  8432. json_object *GetLog = json_object_new_object();
  8433. DEBUG_INFO("sendGetLogConfirmation...\n");
  8434. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP20Data->GetLog.Response_status));
  8435. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP20Data->GetLog.Response_filename));
  8436. sprintf(message,"[%d,\"%s\",%s]"
  8437. ,MESSAGE_TYPE_CALLRESULT
  8438. ,uuid
  8439. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8440. json_object_put(GetLog);
  8441. LWS_Send(message);
  8442. result = TRUE;
  8443. return result;
  8444. }
  8445. int sendGetMonitoringReportConfirmation(char *uuid)
  8446. {
  8447. mtrace();
  8448. int result = FAIL;
  8449. char message[4096]={0};
  8450. json_object *GetMonitoringReport = json_object_new_object();
  8451. DEBUG_INFO("sendGetMonitoringReportConfirmation...\n");
  8452. json_object_object_add(GetMonitoringReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetMonitoringReport.Response_status));
  8453. sprintf(message,"[%d,\"%s\",%s]"
  8454. ,MESSAGE_TYPE_CALLRESULT
  8455. ,uuid
  8456. ,json_object_to_json_string_ext(GetMonitoringReport, JSON_C_TO_STRING_PLAIN));
  8457. json_object_put(GetMonitoringReport);
  8458. LWS_Send(message);
  8459. result = TRUE;
  8460. return result;
  8461. }
  8462. int sendGetReportConfirmation(char *uuid)
  8463. {
  8464. mtrace();
  8465. int result = FAIL;
  8466. char message[4096]={0};
  8467. json_object *GetReport = json_object_new_object();
  8468. DEBUG_INFO("sendGetReportConfirmation...\n");
  8469. json_object_object_add(GetReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetReport.Response_status));
  8470. sprintf(message,"[%d,\"%s\",%s]"
  8471. ,MESSAGE_TYPE_CALLRESULT
  8472. ,uuid
  8473. ,json_object_to_json_string_ext(GetReport, JSON_C_TO_STRING_PLAIN));
  8474. json_object_put(GetReport);
  8475. LWS_Send(message);
  8476. result = TRUE;
  8477. return result;
  8478. }
  8479. int sendGetTransactionStatusConfirmation(char *uuid, unsigned char gun_index)
  8480. {
  8481. mtrace();
  8482. int result = FAIL;
  8483. char message[4096]={0};
  8484. json_object *GetTransactionStatus = json_object_new_object();
  8485. DEBUG_INFO("sendGetTransactionStatusConfirmation...\n");
  8486. json_object_object_add(GetTransactionStatus, "ongoingIndicator", json_object_new_boolean(ShmOCPP20Data->GetTransactionStatus[gun_index].Response_ongoingIndicator));
  8487. json_object_object_add(GetTransactionStatus, "messagesInQueue", json_object_new_boolean(ShmOCPP20Data->GetTransactionStatus[gun_index].Response_messagesInQueue));
  8488. sprintf(message,"[%d,\"%s\",%s]"
  8489. ,MESSAGE_TYPE_CALLRESULT
  8490. ,uuid
  8491. ,json_object_to_json_string_ext(GetTransactionStatus, JSON_C_TO_STRING_PLAIN));
  8492. json_object_put(GetTransactionStatus);
  8493. LWS_Send(message);
  8494. result = TRUE;
  8495. return result;
  8496. }
  8497. int sendGetVariablesConfirmation(char *uuid, unsigned char variableQuantity)
  8498. {
  8499. mtrace();
  8500. int result = FAIL;
  8501. char message[4096]={0};
  8502. json_object *GetVariables = json_object_new_object();
  8503. json_object *getVariableResults = json_object_new_array();
  8504. DEBUG_INFO("sendGetVariablesConfirmation...\n");
  8505. for(int idx=0;idx<variableQuantity;idx++)
  8506. {
  8507. json_object *variableResult = json_object_new_object();
  8508. json_object *component = json_object_new_object();
  8509. json_object *variable = json_object_new_object();
  8510. json_object *evse = json_object_new_object();
  8511. json_object_object_add(variableResult, "attributeType", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType));
  8512. json_object_object_add(variableResult, "attributeStatus", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus));
  8513. json_object_object_add(variableResult, "attributeValue", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue));
  8514. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.id));
  8515. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.connectorId));
  8516. json_object_object_add(component, "evse", evse);
  8517. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.name));
  8518. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.instance));
  8519. json_object_object_add(variableResult, "component", component);
  8520. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.name));
  8521. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.instance));
  8522. json_object_object_add(variableResult, "variable", variable);
  8523. json_object_array_add(getVariableResults, variableResult);
  8524. }
  8525. json_object_object_add(GetVariables , "getVariableResult", getVariableResults);
  8526. sprintf(message,"[%d,\"%s\",%s]"
  8527. ,MESSAGE_TYPE_CALLRESULT
  8528. ,uuid
  8529. ,json_object_to_json_string_ext(GetVariables, JSON_C_TO_STRING_PLAIN));
  8530. json_object_put(GetVariables);
  8531. LWS_Send(message);
  8532. result = TRUE;
  8533. return result;
  8534. }
  8535. int sendInstallCertificateConfirmation(char *uuid)
  8536. {
  8537. mtrace();
  8538. int result = FAIL;
  8539. char message[4096]={0};
  8540. json_object *InstallCertificate = json_object_new_object();
  8541. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8542. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP20Data->InstallCertificate.Response_status));
  8543. sprintf(message,"[%d,\"%s\",%s]"
  8544. ,MESSAGE_TYPE_CALLRESULT
  8545. ,uuid
  8546. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8547. json_object_put(InstallCertificate);
  8548. LWS_Send(message);
  8549. result = TRUE;
  8550. return result;
  8551. }
  8552. int sendPublishFirmwareConfirmation(char *uuid)
  8553. {
  8554. mtrace();
  8555. int result = FAIL;
  8556. char message[4096]={0};
  8557. json_object *PublishFirmware = json_object_new_object();
  8558. json_object_object_add(PublishFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->PublishFirmware.Response_status));
  8559. DEBUG_INFO("sendPublishFirmwareConfirmation...\n");
  8560. sprintf(message,"[%d,\"%s\",%s]"
  8561. ,MESSAGE_TYPE_CALLRESULT
  8562. ,uuid
  8563. ,json_object_to_json_string_ext(PublishFirmware, JSON_C_TO_STRING_PLAIN));
  8564. json_object_put(PublishFirmware);
  8565. LWS_Send(message);
  8566. result = TRUE;
  8567. return result;
  8568. }
  8569. int sendRemoteStartTransactionConfirmation(char *uuid, unsigned char gun_index)
  8570. {
  8571. mtrace();
  8572. int result = FAIL;
  8573. char message[4096]={0};
  8574. json_object *RemoteStartTransaction = json_object_new_object();
  8575. json_object_object_add(RemoteStartTransaction, "status", json_object_new_string((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status));
  8576. json_object_object_add(RemoteStartTransaction, "transactionId", json_object_new_string((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId));
  8577. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  8578. sprintf(message,"[%d,\"%s\",%s]"
  8579. ,MESSAGE_TYPE_CALLRESULT
  8580. ,uuid
  8581. ,json_object_to_json_string_ext(RemoteStartTransaction, JSON_C_TO_STRING_PLAIN));
  8582. json_object_put(RemoteStartTransaction);
  8583. LWS_Send(message);
  8584. result = TRUE;
  8585. return result;
  8586. }
  8587. int sendRemoteStopTransactionConfirmation(char *uuid, unsigned char gun_index)
  8588. {
  8589. mtrace();
  8590. int result = FAIL;
  8591. char message[4096]={0};
  8592. json_object *RemoteStopTransaction = json_object_new_object();
  8593. json_object_object_add(RemoteStopTransaction, "status", json_object_new_string((char*)ShmOCPP20Data->RequestStopTransaction[gun_index].Response_status));
  8594. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  8595. sprintf(message,"[%d,\"%s\",%s]"
  8596. ,MESSAGE_TYPE_CALLRESULT
  8597. ,uuid
  8598. ,json_object_to_json_string_ext(RemoteStopTransaction, JSON_C_TO_STRING_PLAIN));
  8599. json_object_put(RemoteStopTransaction);
  8600. LWS_Send(message);
  8601. result = TRUE;
  8602. return result;
  8603. }
  8604. int sendReserveNowConfirmation(char *uuid, unsigned char gun_index)
  8605. {
  8606. mtrace();
  8607. int result = FAIL;
  8608. char message[4096]={0};
  8609. json_object *ReserveNow = json_object_new_object();
  8610. json_object_object_add(ReserveNow, "status", json_object_new_string((char*)ShmOCPP20Data->ReserveNow[gun_index].Response_status));
  8611. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  8612. sprintf(message,"[%d,\"%s\",%s]"
  8613. ,MESSAGE_TYPE_CALLRESULT
  8614. ,uuid
  8615. ,json_object_to_json_string_ext(ReserveNow, JSON_C_TO_STRING_PLAIN));
  8616. json_object_put(ReserveNow);
  8617. LWS_Send(message);
  8618. result = TRUE;
  8619. ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf = OFF;
  8620. return result;
  8621. }
  8622. int sendResetConfirmation(char *uuid)
  8623. {
  8624. mtrace();
  8625. int result = FAIL;
  8626. char message[4096]={0};
  8627. json_object *Reset = json_object_new_object();
  8628. DEBUG_INFO("sendResetConfirmation...\n");
  8629. ShmOCPP20Data->MsMsg.bits.ResetConf = OFF;
  8630. json_object_object_add(Reset, "status", json_object_new_string((char*)ShmOCPP20Data->Reset.Response_status));
  8631. sprintf(message,"[%d,\"%s\",%s]"
  8632. ,MESSAGE_TYPE_CALLRESULT
  8633. ,uuid
  8634. ,json_object_to_json_string_ext(Reset, JSON_C_TO_STRING_PLAIN));
  8635. json_object_put(Reset);
  8636. LWS_Send(message);
  8637. if(strcmp((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]) == 0)
  8638. {
  8639. DB_updateBootType(BootReasonEnumType_RemoteReset);
  8640. }
  8641. else if(strcmp((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Scheduled]) == 0)
  8642. {
  8643. DB_updateBootType(BootReasonEnumType_ScheduledReset);
  8644. }
  8645. result = TRUE;
  8646. return result;
  8647. }
  8648. int sendSendLocalListConfirmation(char *uuid)
  8649. {
  8650. mtrace();
  8651. int result = FAIL;
  8652. char message[4096]={0};
  8653. json_object *SendLocalList = json_object_new_object();
  8654. json_object_object_add(SendLocalList, "status", json_object_new_string((char*)ShmOCPP20Data->SendLocalList.Response_status));
  8655. sprintf(message,"[%d,\"%s\",%s]"
  8656. ,MESSAGE_TYPE_CALLRESULT
  8657. ,uuid
  8658. ,json_object_to_json_string_ext(SendLocalList, JSON_C_TO_STRING_PLAIN));
  8659. json_object_put(SendLocalList);
  8660. LWS_Send(message);
  8661. result = TRUE;
  8662. return result;
  8663. }
  8664. int sendSetChargingProfileConfirmation(char *uuid, unsigned char gun_index)
  8665. {
  8666. mtrace();
  8667. int result = FAIL;
  8668. char message[4096]={0};
  8669. json_object *SetChargingProfile = json_object_new_object();
  8670. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  8671. json_object_object_add(SetChargingProfile, "status", json_object_new_string((char*)ShmOCPP20Data->SetChargingProfile[gun_index].Response_status));
  8672. sprintf(message,"[%d,\"%s\",%s]"
  8673. ,MESSAGE_TYPE_CALLRESULT
  8674. ,uuid
  8675. ,json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  8676. json_object_put(SetChargingProfile);
  8677. LWS_Send(message);
  8678. result = TRUE;
  8679. return result;
  8680. }
  8681. int sendSetDisplayMessagesConfirmation(char *uuid)
  8682. {
  8683. mtrace();
  8684. int result = FAIL;
  8685. char message[4096]={0};
  8686. json_object *SetDisplayMessage = json_object_new_object();
  8687. DEBUG_INFO("sendSetDisplayMessageConfirmation...\n");
  8688. json_object_object_add(SetDisplayMessage, "status", json_object_new_string((char*)ShmOCPP20Data->SetDisplayMessage.Response_status));
  8689. sprintf(message,"[%d,\"%s\",%s]"
  8690. ,MESSAGE_TYPE_CALLRESULT
  8691. ,uuid
  8692. ,json_object_to_json_string_ext(SetDisplayMessage, JSON_C_TO_STRING_PLAIN));
  8693. json_object_put(SetDisplayMessage);
  8694. LWS_Send(message);
  8695. result = TRUE;
  8696. return result;
  8697. }
  8698. int sendSetMonitoringBaseConfirmation(char *uuid)
  8699. {
  8700. mtrace();
  8701. int result = FAIL;
  8702. char message[4096]={0};
  8703. json_object *SetMonitoringBase = json_object_new_object();
  8704. DEBUG_INFO("sendSetMonitoringBaseConfirmation...\n");
  8705. json_object_object_add(SetMonitoringBase, "status", json_object_new_string((char*)ShmOCPP20Data->SetMonitoringBase.Response_status));
  8706. sprintf(message,"[%d,\"%s\",%s]"
  8707. ,MESSAGE_TYPE_CALLRESULT
  8708. ,uuid
  8709. ,json_object_to_json_string_ext(SetMonitoringBase, JSON_C_TO_STRING_PLAIN));
  8710. json_object_put(SetMonitoringBase);
  8711. LWS_Send(message);
  8712. result = TRUE;
  8713. return result;
  8714. }
  8715. int sendSetMonitoringLevelConfirmation(char *uuid)
  8716. {
  8717. mtrace();
  8718. int result = FAIL;
  8719. char message[4096]={0};
  8720. json_object *SetMonitoringLevel = json_object_new_object();
  8721. DEBUG_INFO("sendSetMonitoringLevelConfirmation...\n");
  8722. json_object_object_add(SetMonitoringLevel, "status", json_object_new_string((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status));
  8723. sprintf(message,"[%d,\"%s\",%s]"
  8724. ,MESSAGE_TYPE_CALLRESULT
  8725. ,uuid
  8726. ,json_object_to_json_string_ext(SetMonitoringLevel, JSON_C_TO_STRING_PLAIN));
  8727. json_object_put(SetMonitoringLevel);
  8728. LWS_Send(message);
  8729. result = TRUE;
  8730. return result;
  8731. }
  8732. int sendSetNetworkProfileConfirmation(char *uuid)
  8733. {
  8734. mtrace();
  8735. int result = FAIL;
  8736. char message[4096]={0};
  8737. json_object *SetNetworkProfile = json_object_new_object();
  8738. DEBUG_INFO("sendSetNetworkProfileConfirmation...\n");
  8739. json_object_object_add(SetNetworkProfile, "status", json_object_new_string((char*)ShmOCPP20Data->SetNetworkProfile.Response_status));
  8740. sprintf(message,"[%d,\"%s\",%s]"
  8741. ,MESSAGE_TYPE_CALLRESULT
  8742. ,uuid
  8743. ,json_object_to_json_string_ext(SetNetworkProfile, JSON_C_TO_STRING_PLAIN));
  8744. json_object_put(SetNetworkProfile);
  8745. LWS_Send(message);
  8746. result = TRUE;
  8747. return result;
  8748. }
  8749. int sendSetVariableMonitoringConfirmation(char *uuid, unsigned char variableQuantity)
  8750. {
  8751. mtrace();
  8752. int result = FAIL;
  8753. char message[4096]={0};
  8754. json_object *SetVariableMonitoring = json_object_new_object();
  8755. json_object *setMonitoringResults = json_object_new_array();
  8756. DEBUG_INFO("sendSetVariableMonitoringConfirmation...\n");
  8757. for(int idx=0;idx<variableQuantity;idx++)
  8758. {
  8759. json_object *variableMonitorResult = json_object_new_object();
  8760. json_object *component = json_object_new_object();
  8761. json_object *variable = json_object_new_object();
  8762. json_object *evse = json_object_new_object();
  8763. json_object_object_add(variableMonitorResult, "id", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].id));
  8764. json_object_object_add(variableMonitorResult, "type", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type));
  8765. json_object_object_add(variableMonitorResult, "severity", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].severity));
  8766. json_object_object_add(variableMonitorResult, "status", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status));
  8767. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.id));
  8768. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.connectorId));
  8769. json_object_object_add(component, "component", evse);
  8770. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.name));
  8771. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.instance));
  8772. json_object_object_add(variableMonitorResult, "component", component);
  8773. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.name));
  8774. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.instance));
  8775. json_object_object_add(variableMonitorResult, "variable", variable);
  8776. json_object_array_add(setMonitoringResults, variableMonitorResult);
  8777. }
  8778. json_object_object_add(SetVariableMonitoring , "setMonitoringResult", setMonitoringResults);
  8779. sprintf(message,"[%d,\"%s\",%s]"
  8780. ,MESSAGE_TYPE_CALLRESULT
  8781. ,uuid
  8782. ,json_object_to_json_string_ext(SetVariableMonitoring, JSON_C_TO_STRING_PLAIN));
  8783. json_object_put(SetVariableMonitoring);
  8784. LWS_Send(message);
  8785. result = TRUE;
  8786. return result;
  8787. }
  8788. int sendSetVariableConfirmation(char *uuid, unsigned char variableQuantity)
  8789. {
  8790. mtrace();
  8791. int result = FAIL;
  8792. char message[4096]={0};
  8793. json_object *SetVariable = json_object_new_object();
  8794. json_object *setVariableResults = json_object_new_array();
  8795. DEBUG_INFO("sendSetVariableConfirmation...\n");
  8796. for(int idx=0;idx<variableQuantity;idx++)
  8797. {
  8798. json_object *variableResult = json_object_new_object();
  8799. json_object *component = json_object_new_object();
  8800. json_object *variable = json_object_new_object();
  8801. json_object *evse = json_object_new_object();
  8802. json_object_object_add(variableResult, "attributeType", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType));
  8803. json_object_object_add(variableResult, "attributeStatus", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus));
  8804. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.id));
  8805. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.connectorId));
  8806. json_object_object_add(component, "component", evse);
  8807. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.name));
  8808. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.instance));
  8809. json_object_object_add(variableResult, "component", component);
  8810. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.name));
  8811. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.instance));
  8812. json_object_object_add(variableResult, "variable", variable);
  8813. json_object_array_add(setVariableResults, variableResult);
  8814. }
  8815. json_object_object_add(SetVariable , "setVariableResult", setVariableResults);
  8816. sprintf(message,"[%d,\"%s\",%s]"
  8817. ,MESSAGE_TYPE_CALLRESULT
  8818. ,uuid
  8819. ,json_object_to_json_string_ext(SetVariable, JSON_C_TO_STRING_PLAIN));
  8820. json_object_put(SetVariable);
  8821. LWS_Send(message);
  8822. result = TRUE;
  8823. return result;
  8824. }
  8825. int sendTriggerMessageConfirmation(char *uuid)
  8826. {
  8827. mtrace();
  8828. int result = FAIL;
  8829. char message[4096]={0};
  8830. json_object *TriggerMessage = json_object_new_object();
  8831. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8832. json_object_object_add(TriggerMessage, "status", json_object_new_string((char*)ShmOCPP20Data->TriggerMessage.Response_status));
  8833. sprintf(message,"[%d,\"%s\",%s]",
  8834. MESSAGE_TYPE_CALLRESULT,
  8835. uuid,
  8836. json_object_to_json_string_ext(TriggerMessage, JSON_C_TO_STRING_PLAIN));
  8837. json_object_put(TriggerMessage);
  8838. LWS_Send(message);
  8839. result = TRUE;
  8840. return result;
  8841. }
  8842. int sendUnlockConnectorConfirmation(char *uuid, unsigned char gun_index)
  8843. {
  8844. mtrace();
  8845. int result = FAIL;
  8846. char message[4096]={0};
  8847. json_object *UnlockConnector = json_object_new_object();
  8848. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8849. json_object_object_add(UnlockConnector, "status", json_object_new_string((char*)ShmOCPP20Data->UnlockConnector[gun_index].Response_status));
  8850. sprintf(message,"[%d,\"%s\",%s]",
  8851. MESSAGE_TYPE_CALLRESULT,
  8852. uuid,
  8853. json_object_to_json_string_ext(UnlockConnector, JSON_C_TO_STRING_PLAIN));
  8854. json_object_put(UnlockConnector);
  8855. LWS_Send(message);
  8856. result = TRUE;
  8857. ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf = OFF;
  8858. return result;
  8859. }
  8860. int sendUnpublishFirmwareConfirmation(char *uuid)
  8861. {
  8862. mtrace();
  8863. int result = FAIL;
  8864. char message[4096]={0};
  8865. json_object *UnpublishFirmware = json_object_new_object();
  8866. DEBUG_INFO("sendUnpublishFirmwareConfirmation...\n");
  8867. json_object_object_add(UnpublishFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->UnpublishFirmware.Response_status));
  8868. sprintf(message,"[%d,\"%s\",%s]"
  8869. ,MESSAGE_TYPE_CALLRESULT
  8870. ,uuid
  8871. ,json_object_to_json_string_ext(UnpublishFirmware, JSON_C_TO_STRING_PLAIN));
  8872. json_object_put(UnpublishFirmware);
  8873. LWS_Send(message);
  8874. result = TRUE;
  8875. return result;
  8876. }
  8877. int sendUpdateFirmwareConfirmation(char *uuid)
  8878. {
  8879. mtrace();
  8880. int result = FAIL;
  8881. char message[4096]={0};
  8882. json_object *UpdateFirmware = json_object_new_object();
  8883. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8884. sprintf((char*)ShmOCPP20Data->UpdateFirmware.Response_status, "%s", UpdateFirmwareStatusEnumTypeStr[UpdateFirmwareStatusEnumType_Accepted]);
  8885. json_object_object_add(UpdateFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->UpdateFirmware.Response_status));
  8886. sprintf(message,"[%d,\"%s\",%s]"
  8887. ,MESSAGE_TYPE_CALLRESULT
  8888. ,uuid
  8889. ,json_object_to_json_string_ext(UpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8890. json_object_put(UpdateFirmware);
  8891. LWS_Send(message);
  8892. result = TRUE;
  8893. return result;
  8894. }
  8895. int sendUnknownConfirmation(char *uuid)
  8896. {
  8897. mtrace();
  8898. int result = FAIL;
  8899. char message[256]={0};
  8900. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8901. DEBUG_INFO("sendUnknownConfirmation...\n");
  8902. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8903. LWS_Send(message);
  8904. result = TRUE;
  8905. return result;
  8906. }
  8907. //==========================================
  8908. // send CallError routine
  8909. //==========================================
  8910. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  8911. {
  8912. mtrace();
  8913. char message[220]={0};
  8914. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  8915. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  8916. LWS_Send(message);
  8917. }
  8918. //==========================================
  8919. // Handle server request routine Start
  8920. //==========================================
  8921. int handleCancelReservationRequest(char *uuid, char *payload)
  8922. {
  8923. mtrace();
  8924. int result = FAIL;
  8925. int gunNO = 0;
  8926. int reservationIdInt = -1;
  8927. DEBUG_INFO("handleCancelReservationRequest...\n");
  8928. json_object *CancelReservation;
  8929. CancelReservation = json_tokener_parse(payload);
  8930. if(!is_error(CancelReservation))
  8931. {
  8932. // Required data
  8933. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  8934. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  8935. }
  8936. json_object_put(CancelReservation);
  8937. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  8938. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->CancelReservation);idx++)
  8939. sprintf((char*)ShmOCPP20Data->CancelReservation[idx].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Rejected]);
  8940. if(reservationIdInt != -1)
  8941. {
  8942. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  8943. //check Transaction active
  8944. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  8945. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8946. {
  8947. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  8948. {
  8949. sprintf((char*)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  8950. if(gunType[2] == GUN_TYPE_CHAdeMO)
  8951. {
  8952. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  8953. }
  8954. else
  8955. {
  8956. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  8957. }
  8958. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  8959. goto end;
  8960. }
  8961. }
  8962. for (int index = 0; index < CCS_QUANTITY; index++)
  8963. {
  8964. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  8965. {
  8966. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  8967. if(gunType[2] == GUN_TYPE_CCS)
  8968. {
  8969. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  8970. }
  8971. else
  8972. {
  8973. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  8974. }
  8975. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  8976. goto end;
  8977. }
  8978. }
  8979. for (int index = 0; index < GB_QUANTITY; index++)
  8980. {
  8981. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  8982. {
  8983. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  8984. if(gunType[2] == GUN_TYPE_GBT)
  8985. {
  8986. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  8987. }
  8988. else
  8989. {
  8990. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  8991. }
  8992. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  8993. goto end;
  8994. }
  8995. }
  8996. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8997. {
  8998. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  8999. {
  9000. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  9001. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  9002. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  9003. goto end;
  9004. }
  9005. }
  9006. for (int index = 0; index < AC_QUANTITY; index++)
  9007. {
  9008. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  9009. {
  9010. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  9011. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9012. {
  9013. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  9014. }
  9015. else
  9016. {
  9017. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  9018. }
  9019. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  9020. goto end;
  9021. }
  9022. }
  9023. }
  9024. //The reservationId does NOT match the reservationId
  9025. sendCancelReservationConfirmation(uuid, gunNO);
  9026. end:
  9027. // Fill in ocpp packet uuid
  9028. strcpy((char *)ShmOCPP20Data->CancelReservation[gunNO].guid, uuid);
  9029. return result;
  9030. }
  9031. int handleCertificateSignedRequest(char *uuid, char *payload)
  9032. {
  9033. mtrace();
  9034. int result = FAIL;
  9035. json_object *CertificateSigned;
  9036. DEBUG_INFO("handleCertificateSignedRequest...\n");
  9037. CertificateSigned = json_tokener_parse(payload);
  9038. if(!is_error(CertificateSigned))
  9039. {
  9040. memset(&ShmOCPP20Data->CertificateSigned, 0, sizeof(struct CertificateSigned_20));
  9041. memcpy(&ShmOCPP20Data->CertificateSigned.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->CertificateSigned.guid));
  9042. // Required data
  9043. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  9044. // Optional data
  9045. if(json_object_object_get(CertificateSigned, "certificateType") != NULL)
  9046. {
  9047. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateType, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateType")));
  9048. if(strcmp((char*)ShmOCPP20Data->CertificateSigned.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_ChargingStationCertificate]) == 0)
  9049. {
  9050. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  9051. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  9052. fclose(fp);
  9053. }
  9054. else if(strcmp((char*)ShmOCPP20Data->CertificateSigned.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0)
  9055. {
  9056. FILE *fp = fopen("/Storage/OCPP/certV2G.crt", "w");
  9057. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  9058. fclose(fp);
  9059. }
  9060. }
  9061. else
  9062. {
  9063. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  9064. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  9065. fclose(fp);
  9066. fp = fopen("/Storage/OCPP/certV2G.crt", "w");
  9067. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  9068. fclose(fp);
  9069. }
  9070. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9071. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Accepted]);
  9072. }
  9073. else
  9074. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Rejected]);
  9075. json_object_put(CertificateSigned);
  9076. sendCertificateSignedConfirmation(uuid);
  9077. return result;
  9078. }
  9079. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  9080. {
  9081. mtrace();
  9082. int result = FAIL;
  9083. int evseId = 0, gunIndex = 0;
  9084. char operationalStatus[16]={0};
  9085. char comfirmstr[20];
  9086. int specificId = FALSE;
  9087. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  9088. json_object *ChangeAvailability;
  9089. ChangeAvailability = json_tokener_parse(payload);
  9090. if(!is_error(ChangeAvailability))
  9091. {
  9092. // Required data
  9093. if(json_object_object_get(ChangeAvailability, "operationalStatus") != NULL)
  9094. sprintf((char*)operationalStatus, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "operationalStatus")));
  9095. if(json_object_object_get(ChangeAvailability, "evse") != NULL)
  9096. {
  9097. evseId = json_object_get_int(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "id"));
  9098. if(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "connectorId") != NULL)
  9099. gunIndex = json_object_get_int(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "connectorId"));
  9100. }
  9101. }
  9102. json_object_put(ChangeAvailability);
  9103. if((evseId != 0) && (evseId <= gunTotalNumber))
  9104. {
  9105. ShmOCPP20Data->ChangeAvailability[evseId - 1].evse.connectorId = evseId;
  9106. sprintf((char *)ShmOCPP20Data->ChangeAvailability[evseId - 1].operationalStatus, "%s", operationalStatus);
  9107. }
  9108. else if(evseId == 0)
  9109. {
  9110. for(int i=0; i < gunTotalNumber; i++)
  9111. {
  9112. ShmOCPP20Data->ChangeAvailability[i].evse.connectorId = evseId;
  9113. sprintf((char *)ShmOCPP20Data->ChangeAvailability[i].operationalStatus, "%s", operationalStatus);
  9114. }
  9115. }
  9116. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9117. {
  9118. ShmOCPP20Data->ChangeAvailability[gunIndex - 1].evse.connectorId = gunIndex;
  9119. sprintf((char *)ShmOCPP20Data->ChangeAvailability[gunIndex - 1].operationalStatus, "%s", operationalStatus);
  9120. }
  9121. else if(gunIndex == 0)
  9122. {
  9123. for(int i=0; i < gunTotalNumber; i++)
  9124. {
  9125. ShmOCPP20Data->ChangeAvailability[i].evse.connectorId = gunIndex;
  9126. sprintf((char *)ShmOCPP20Data->ChangeAvailability[i].operationalStatus, "%s", operationalStatus);
  9127. }
  9128. }
  9129. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  9130. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9131. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  9132. {
  9133. specificId = TRUE;
  9134. }
  9135. if(specificId == FALSE)
  9136. goto end;
  9137. if(strcmp((const char *)operationalStatus, OperationalStatusEnumTypeStr[OperationalStatusEnumType_Inoperative]) == 0)
  9138. {
  9139. //----------------------gunIndex is 0 ------------------------------------------------//
  9140. if(gunIndex == 0)
  9141. {
  9142. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9143. {
  9144. for(int i=0; i < gunTotalNumber; i++)
  9145. {
  9146. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9147. {
  9148. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  9149. {
  9150. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  9151. {
  9152. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9153. goto end;
  9154. }
  9155. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9156. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9157. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9158. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9159. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9160. {
  9161. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9162. goto end;
  9163. }
  9164. }
  9165. }//END FOR CHAdeMO_QUANTITY
  9166. for (int index = 0; index < CCS_QUANTITY; index++)
  9167. {
  9168. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  9169. {
  9170. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  9171. {
  9172. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9173. goto end;
  9174. }
  9175. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9176. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9177. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9178. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9179. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9180. {
  9181. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9182. goto end;
  9183. }
  9184. }
  9185. }//END FOR CCS_QUANTITY
  9186. for (int index = 0; index < GB_QUANTITY; index++)
  9187. {
  9188. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  9189. {
  9190. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  9191. {
  9192. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9193. goto end;
  9194. }
  9195. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9196. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9197. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9198. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9199. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9200. {
  9201. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9202. goto end;
  9203. }
  9204. }
  9205. }// END FOR GB_QUANTITY
  9206. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9207. {
  9208. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  9209. {
  9210. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  9211. {
  9212. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9213. goto end;
  9214. }
  9215. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  9216. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  9217. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  9218. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  9219. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9220. {
  9221. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9222. goto end;
  9223. }
  9224. }
  9225. }// END FOR DO_QUANTITY
  9226. for (int index = 0; index < AC_QUANTITY; index++)
  9227. {
  9228. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  9229. {
  9230. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  9231. {
  9232. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9233. goto end;
  9234. }
  9235. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9236. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9237. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9238. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9239. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9240. {
  9241. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9242. goto end;
  9243. }
  9244. }
  9245. }//END FOR AC_QUANTITY
  9246. }// END FOR gunTotalNumber
  9247. }
  9248. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  9249. {
  9250. for(int i=0; i < gunTotalNumber; i++)
  9251. {
  9252. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  9253. {
  9254. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9255. goto end;
  9256. }
  9257. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9258. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  9259. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  9260. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  9261. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9262. {
  9263. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9264. goto end;
  9265. }
  9266. }
  9267. }
  9268. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  9269. goto end;
  9270. }
  9271. //----------------------gunIndex is not 0 ------------------------------------------------//
  9272. //check Transaction active
  9273. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9274. {
  9275. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  9276. {
  9277. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  9278. {
  9279. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9280. goto end;
  9281. }
  9282. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9283. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9284. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9285. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9286. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9287. {
  9288. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9289. goto end;
  9290. }
  9291. else
  9292. {
  9293. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  9294. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  9295. goto end;
  9296. }
  9297. }
  9298. }//END FOR CHAdeMO_QUANTITY
  9299. for (int index = 0; index < CCS_QUANTITY; index++)
  9300. {
  9301. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  9302. {
  9303. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  9304. {
  9305. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9306. goto end;
  9307. }
  9308. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9309. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9310. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9311. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9312. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9313. {
  9314. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9315. goto end;
  9316. }
  9317. else
  9318. {
  9319. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  9320. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  9321. goto end;
  9322. }
  9323. }
  9324. }//END FOR CCS_QUANTITY
  9325. for (int index = 0; index < GB_QUANTITY; index++)
  9326. {
  9327. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  9328. {
  9329. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  9330. {
  9331. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9332. goto end;
  9333. }
  9334. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9335. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9336. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9337. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9338. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9339. {
  9340. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9341. goto end;
  9342. }
  9343. else
  9344. {
  9345. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  9346. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  9347. goto end;
  9348. }
  9349. }
  9350. }// END FOR GB_QUANTITY
  9351. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9352. {
  9353. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  9354. {
  9355. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  9356. {
  9357. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9358. goto end;
  9359. }
  9360. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  9361. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  9362. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  9363. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  9364. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9365. {
  9366. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9367. goto end;
  9368. }
  9369. else
  9370. {
  9371. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  9372. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  9373. goto end;
  9374. }
  9375. }
  9376. }// END FOR DO_QUANTITY
  9377. for (int index = 0; index < AC_QUANTITY; index++)
  9378. {
  9379. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC))
  9380. {
  9381. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  9382. {
  9383. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9384. goto end;
  9385. }
  9386. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9387. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9388. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9389. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9390. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9391. {
  9392. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9393. goto end;
  9394. }
  9395. else
  9396. {
  9397. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  9398. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  9399. goto end;
  9400. }
  9401. }
  9402. }//END FOR AC_QUANTITY
  9403. }//END FOR AvailabilityEnumTypeStr[Inoperative]
  9404. if(strcmp((const char *)operationalStatus, OperationalStatusEnumTypeStr[OperationalStatusEnumType_Operative]) == 0)
  9405. {
  9406. //----------------------gunIndex is 0 ------------------------------------------------//
  9407. if(gunIndex == 0)
  9408. {
  9409. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9410. {
  9411. for(int i=0; i < gunTotalNumber; i++)
  9412. {
  9413. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9414. {
  9415. 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
  9416. {
  9417. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9418. goto end;
  9419. }
  9420. }//END FOR CHAdeMO_QUANTITY
  9421. for (int index = 0; index < CCS_QUANTITY; index++)
  9422. {
  9423. 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
  9424. {
  9425. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9426. goto end;
  9427. }
  9428. }//END FOR CCS_QUANTITY
  9429. for (int index = 0; index < GB_QUANTITY; index++)
  9430. {
  9431. 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
  9432. {
  9433. //ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  9434. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9435. goto end;
  9436. }
  9437. }// END FOR GB_QUANTITY
  9438. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9439. {
  9440. 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
  9441. {
  9442. //ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  9443. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9444. goto end;
  9445. }
  9446. }// END FOR DO_QUANTITY
  9447. for (int index = 0; index < AC_QUANTITY; index++)
  9448. {
  9449. 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
  9450. {
  9451. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9452. goto end;
  9453. }
  9454. }//END FOR CHAdeMO_QUANTITY
  9455. }// END FOR gunTotalNumber
  9456. }
  9457. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  9458. {
  9459. for(int i=0; i < gunTotalNumber; i++)
  9460. {
  9461. for (int index = 0; index < AC_QUANTITY; index++)
  9462. {
  9463. 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
  9464. {
  9465. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9466. goto end;
  9467. }
  9468. }//END FOR CHAdeMO_QUANTITY
  9469. } // END FOR gunTotalNumber
  9470. }
  9471. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  9472. goto end;
  9473. }
  9474. //----------------------gunIndex is not 0 ------------------------------------------------//
  9475. //check Transaction active
  9476. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9477. {
  9478. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9479. {
  9480. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  9481. goto end;
  9482. }
  9483. }//END FOR CHAdeMO_QUANTITY
  9484. for (int index = 0; index < CCS_QUANTITY; index++)
  9485. {
  9486. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9487. {
  9488. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  9489. goto end;
  9490. }
  9491. }//END FOR CCS_QUANTITY
  9492. for (int index = 0; index < GB_QUANTITY; index++)
  9493. {
  9494. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9495. {
  9496. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  9497. goto end;
  9498. }
  9499. }// END FOR GB_QUANTITY
  9500. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9501. {
  9502. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9503. {
  9504. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  9505. goto end;
  9506. }
  9507. }// END FOR DO_QUANTITY
  9508. for (int index = 0; index < AC_QUANTITY; index++)
  9509. {
  9510. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9511. {
  9512. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  9513. goto end;
  9514. }
  9515. }//END FOR AC_QUANTITY
  9516. }//END FOR AvailabilityEnumTypeStr[Operative]
  9517. end:
  9518. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9519. {
  9520. sprintf((char *)ShmOCPP20Data->ChangeAvailability[gunIndex - 1].Response_status, "%s", comfirmstr );
  9521. }
  9522. else
  9523. {
  9524. sprintf((char *)ShmOCPP20Data->ChangeAvailability[0].Response_status, "%s", comfirmstr );
  9525. }
  9526. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9527. {
  9528. if(strstr(comfirmstr, ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected]) == NULL)
  9529. ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  9530. }
  9531. else if(gunIndex == 0)
  9532. {
  9533. if(strstr(comfirmstr, ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected]) == NULL)
  9534. {
  9535. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  9536. ShmOCPP20Data->CsMsg.bits[i].ChangeAvailabilityReq = ON;
  9537. }
  9538. }
  9539. sendChangeAvailabilityConfirmation(uuid, (gunIndex==0?gunIndex:gunIndex-1));
  9540. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9541. return result;
  9542. }
  9543. int handleClearCacheRequest(char *uuid, char *payload)
  9544. {
  9545. mtrace();
  9546. int result = FAIL;
  9547. char rmFileCmd[100]={0};
  9548. struct stat stats;
  9549. DEBUG_INFO("handleClearCacheRequest...\n");
  9550. stat("/Storage/OCPP", &stats);
  9551. // Check for directory existence
  9552. if (S_ISDIR(stats.st_mode) == 1)
  9553. {}
  9554. else
  9555. {
  9556. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  9557. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  9558. system(rmFileCmd);
  9559. }
  9560. /*
  9561. * TODO:
  9562. * 1. Clear cache from sqlite db
  9563. */
  9564. if(1)
  9565. {
  9566. DEBUG_INFO("open AuthorizationCache file failed\n");
  9567. sprintf((char*)ShmOCPP20Data->ClearCache.Response_status, "%s", ClearCacheStatusEnumTypeStr[ClearCacheStatusEnumType_Rejected] );
  9568. }
  9569. else
  9570. {
  9571. DEBUG_INFO("open AuthorizationCache file successful\n");
  9572. sprintf((char*)ShmOCPP20Data->ClearCache.Response_status, "%s", ClearCacheStatusEnumTypeStr[ClearCacheStatusEnumType_Accepted] );
  9573. }
  9574. sendClearCacheConfirmation(uuid);
  9575. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9576. return result;
  9577. }
  9578. int handleClearChargingProfileRequest(char *uuid, char *payload)
  9579. {
  9580. mtrace();
  9581. int result = FAIL;
  9582. int resultRename;
  9583. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  9584. char chargingProfilePurposeStr[26]={0};
  9585. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  9586. char tempchargingProfilePurposeStr[26]={0};
  9587. char sstr[160]={0};
  9588. char str[100]={0};
  9589. int c = 0;
  9590. char *loc;
  9591. char fname[200]={0};
  9592. char comfirmstr[20]={0};
  9593. char word[1600]={0};
  9594. int clearflag = FALSE;
  9595. int chargingProfileIdIsNULL = FALSE;
  9596. int connectorIsNULL = FALSE;
  9597. int chargingProfilePurposeIsNULL = FALSE;
  9598. int stackLevelIsNULL = FALSE;
  9599. //int GotoEnd = FALSE;
  9600. FILE *fptr1, *fptr2;
  9601. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  9602. int n_chargingProfile=0;
  9603. int isEmptyFile = FALSE;
  9604. char sLineWord[1600]={0};
  9605. char chargingProfiles[10][100]={0};
  9606. int ChargeProfileCount = 0;
  9607. int ch;
  9608. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  9609. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  9610. json_object *ClearChargingProfile;
  9611. ClearChargingProfile = json_tokener_parse(payload);
  9612. if(!is_error(ClearChargingProfile))
  9613. {
  9614. // Optional data
  9615. if(json_object_object_get(ClearChargingProfile, "chargingProfileId") != NULL)
  9616. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "chargingProfileId"));
  9617. else
  9618. chargingProfileIdIsNULL = TRUE;
  9619. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "evseId") != NULL)
  9620. connectorIdInt = json_object_get_int(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "evseId"));
  9621. else
  9622. connectorIsNULL = TRUE;
  9623. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "chargingProfilePurpose") != NULL)
  9624. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "chargingProfilePurpose")));
  9625. else
  9626. chargingProfilePurposeIsNULL = TRUE;
  9627. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "stackLevel") != NULL)
  9628. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "stackLevel"));
  9629. else
  9630. stackLevelIsNULL = TRUE;
  9631. }
  9632. json_object_put(ClearChargingProfile);
  9633. if(connectorIsNULL == FALSE)
  9634. {
  9635. switch(connectorIdInt)
  9636. {
  9637. case 0:
  9638. if(chargingProfilePurposeIsNULL == TRUE)
  9639. {
  9640. int l = 0;
  9641. strcpy(fname, ChargePointMaxProfile_JSON);
  9642. if((access(fname,F_OK))!=-1)
  9643. {
  9644. strcpy(chargingProfiles[l], fname);
  9645. l = l + 1;
  9646. }
  9647. strcpy(fname, TxDefaultProfile_0_JSON);
  9648. if((access(fname,F_OK))!=-1)
  9649. {
  9650. strcpy(chargingProfiles[l], fname);
  9651. l = l + 1;
  9652. }
  9653. ChargeProfileCount = l;
  9654. }
  9655. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  9656. {
  9657. strcpy(fname, ChargePointMaxProfile_JSON);
  9658. if((access(fname,F_OK))!=-1)
  9659. {
  9660. strcpy(chargingProfiles[0], fname);
  9661. ChargeProfileCount = 1;
  9662. }
  9663. }
  9664. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9665. {
  9666. strcpy(fname, TxDefaultProfile_0_JSON);
  9667. if((access(fname,F_OK))!=-1)
  9668. {
  9669. strcpy(chargingProfiles[0], fname);
  9670. ChargeProfileCount = 1;
  9671. }
  9672. }
  9673. break;
  9674. default:
  9675. if(chargingProfilePurposeIsNULL == TRUE)
  9676. {
  9677. int m = 0;
  9678. memset(fname, 0, ARRAY_SIZE(fname));
  9679. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9680. if((access(fname,F_OK))!=-1)
  9681. {
  9682. strcpy(chargingProfiles[m], fname);
  9683. m = m + 1;
  9684. }
  9685. memset(fname, 0, ARRAY_SIZE(fname));
  9686. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9687. if((access(fname,F_OK))!=-1)
  9688. {
  9689. strcpy(chargingProfiles[m], fname);
  9690. m = m + 1;
  9691. }
  9692. ChargeProfileCount = m;
  9693. }
  9694. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9695. {
  9696. //strcpy(fname, TxDefaultProfile_1_JSON);
  9697. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9698. if((access(fname,F_OK))!=-1)
  9699. {
  9700. strcpy(chargingProfiles[0], fname);
  9701. ChargeProfileCount = 1;
  9702. }
  9703. }
  9704. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  9705. {
  9706. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9707. if((access(fname,F_OK))!=-1)
  9708. {
  9709. strcpy(chargingProfiles[0], fname);
  9710. ChargeProfileCount = 1;
  9711. }
  9712. }
  9713. //strcpy(fname, ChargePointMaxProfile_JSON );
  9714. break;
  9715. }
  9716. }
  9717. else // Check all Charging Profiles
  9718. {
  9719. int i = 0;
  9720. char fnametemp[200]={0};
  9721. ChargeProfileCount = 0;
  9722. //Check ChargePointMaxProfile.json exit
  9723. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9724. {
  9725. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  9726. i = i + 1;
  9727. }
  9728. //Check TxDefaultProfile_0.json exit
  9729. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9730. {
  9731. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  9732. i = i + 1;
  9733. }
  9734. //Check TxDefaultProfile_%d.json
  9735. for(int j=1; j <= gunTotalNumber; j++)
  9736. {
  9737. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9738. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9739. if((access(fnametemp,F_OK))!=-1)
  9740. {
  9741. strcpy(chargingProfiles[i], fnametemp);
  9742. i = i + 1;
  9743. }
  9744. }
  9745. //Check TxProfile_%d.json
  9746. for(int j=1; j <= gunTotalNumber; j++)
  9747. {
  9748. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9749. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9750. if((access(fnametemp,F_OK))!=-1)
  9751. {
  9752. strcpy(chargingProfiles[i], fnametemp);
  9753. i = i + 1;
  9754. }
  9755. }
  9756. ChargeProfileCount = i;
  9757. }// End connectorIsNULL is TRUE
  9758. if(ChargeProfileCount == 0)
  9759. {
  9760. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  9761. goto end;
  9762. }
  9763. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9764. {
  9765. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  9766. goto end;
  9767. }
  9768. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9769. {
  9770. memset(str, 0, ARRAY_SIZE(str));
  9771. // clear temp file
  9772. sprintf(str,"rm -f %s",temp);
  9773. system(str);
  9774. for(int k=0; k < ChargeProfileCount; k++)
  9775. {
  9776. memset(str, 0, ARRAY_SIZE(str));
  9777. //clear file in C
  9778. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9779. system(str);
  9780. }
  9781. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  9782. goto end;
  9783. }
  9784. else if(connectorIsNULL == TRUE)
  9785. {
  9786. for(int k=0; k < ChargeProfileCount; k++)
  9787. {
  9788. fptr1 = fopen(chargingProfiles[k], "r");
  9789. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9790. //Check Charging Profile Count
  9791. while(fscanf(fptr1, "%s", word) != EOF)
  9792. {
  9793. //DEBUG_INFO("word=%s\n",word);
  9794. if(strstr(word, "chargingProfileId")!= NULL)
  9795. {
  9796. //DEBUG_INFO("test chargingProfileId \n");
  9797. n_chargingProfile = n_chargingProfile + 1;
  9798. //DEBUG_INFO("chargingProfileId Found\n");
  9799. }
  9800. }
  9801. rewind(fptr1);
  9802. //search Charging Profile Element
  9803. //int i= 0;
  9804. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9805. {
  9806. //------------------------tempconnectorIdInt------------------------//
  9807. loc = strstr(sLineWord, "connectorId");
  9808. c = 0;
  9809. memset(sstr ,0, sizeof(sstr) );
  9810. while (loc[strlen("connectorId")+2+c] != ',')
  9811. {
  9812. sstr[c] = loc[strlen("connectorId")+2+c];
  9813. c++;
  9814. }
  9815. sstr[c] = '\0';
  9816. tempconnectorIdInt = atoi(sstr);
  9817. printf("file's gun number is %d\n", tempconnectorIdInt);
  9818. //--------------------------chargingProfileId--------------------//
  9819. c = 0;
  9820. loc = strstr(sLineWord, "chargingProfileId");
  9821. memset(sstr ,0, ARRAY_SIZE(sstr));
  9822. while (loc[strlen("chargingProfileId")+2+c] != ',')
  9823. {
  9824. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  9825. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9826. c++;
  9827. }
  9828. sstr[c] = '\0';
  9829. tempchargingProfileIdInt = atoi(sstr);
  9830. //stackLevel
  9831. c = 0;
  9832. loc = strstr(sLineWord, "stackLevel");
  9833. memset(sstr ,0, ARRAY_SIZE(sstr));
  9834. while (loc[strlen("stackLevel")+2+c] != ',')
  9835. {
  9836. sstr[c] = loc[strlen("stackLevel")+2+c];
  9837. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9838. c++;
  9839. }
  9840. sstr[c] = '\0';
  9841. tempstackLevelInt = atoi(sstr);
  9842. c = 0;
  9843. loc = strstr(sLineWord, "chargingProfilePurpose");
  9844. memset(sstr ,0, ARRAY_SIZE(sstr));
  9845. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  9846. {
  9847. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  9848. c++;
  9849. }
  9850. sstr[c] = '\0';
  9851. strcpy(tempchargingProfilePurposeStr, sstr);
  9852. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9853. {
  9854. //------- not write to fptr2-------//
  9855. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  9856. //clearflag = TRUE;
  9857. }
  9858. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9859. {
  9860. //------- not write to fptr2-------//
  9861. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  9862. }
  9863. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9864. {
  9865. //------- not write to fptr2-------//
  9866. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  9867. }
  9868. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9869. {
  9870. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  9871. }
  9872. else
  9873. {
  9874. fprintf(fptr2, sLineWord);//writing data into file
  9875. }
  9876. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9877. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9878. if(clearflag == TRUE)
  9879. {
  9880. fclose(fptr1);
  9881. fclose(fptr2);
  9882. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9883. system(str);
  9884. // clear temp file
  9885. sprintf(str,"rm -f %s",temp);
  9886. system(str);
  9887. }
  9888. else
  9889. {
  9890. fclose(fptr1);
  9891. fclose(fptr2);
  9892. memset(str, 0, ARRAY_SIZE(str));
  9893. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9894. system(str);
  9895. resultRename = rename(temp, chargingProfiles[k]);
  9896. if(resultRename == 0)
  9897. {
  9898. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9899. }
  9900. else
  9901. {
  9902. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9903. }
  9904. if(comfirmstr[0]== 0)
  9905. {
  9906. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  9907. }
  9908. //Check chargingProfile is empty file
  9909. /*------ Read the file ----------------*/
  9910. fptr1=fopen(chargingProfiles[k],"r");
  9911. ch=fgetc(fptr1);
  9912. rewind(fptr1);
  9913. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9914. if(ch!=EOF)
  9915. {
  9916. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9917. {
  9918. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9919. if(sLineWord[0]=='\0')
  9920. {
  9921. isEmptyFile = TRUE;
  9922. break;
  9923. }
  9924. else
  9925. {
  9926. isEmptyFile = FALSE;
  9927. break;
  9928. }
  9929. }
  9930. }
  9931. else
  9932. isEmptyFile = TRUE;
  9933. fclose(fptr1);
  9934. if(isEmptyFile == TRUE)
  9935. {
  9936. memset(str, 0, ARRAY_SIZE(str));
  9937. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9938. system(str);
  9939. }
  9940. }
  9941. }// End of while(int k=0; k < ChargePointCount; k++)
  9942. }
  9943. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  9944. {
  9945. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  9946. for(int k=0; k < ChargeProfileCount; k++)
  9947. {
  9948. fptr1 = fopen(chargingProfiles[k], "r");
  9949. fptr2 = fopen(temp, "w+");
  9950. //Check Charging Profile Count
  9951. while(fscanf(fptr1, "%s", word) != EOF)
  9952. {
  9953. //DEBUG_INFO("word=%s\n",word);
  9954. if(strstr(word, "chargingProfileId")!= NULL)
  9955. {
  9956. n_chargingProfile = n_chargingProfile + 1;
  9957. }
  9958. }
  9959. rewind(fptr1);
  9960. //search Charging Profile Element
  9961. //int i= 0;
  9962. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9963. {
  9964. //*************************tempconnectorIdInt*********************************/
  9965. loc = strstr(sLineWord, "connectorId");
  9966. c = 0;
  9967. memset(sstr ,0, ARRAY_SIZE(sstr));
  9968. while (loc[strlen("connectorId")+2+c] != ',')
  9969. {
  9970. sstr[c] = loc[strlen("connectorId")+2+c];
  9971. c++;
  9972. }
  9973. sstr[c] = '\0';
  9974. tempconnectorIdInt = atoi(sstr);
  9975. //chargingProfileId
  9976. c = 0;
  9977. loc = strstr(sLineWord, "chargingProfileId");
  9978. memset(sstr ,0, ARRAY_SIZE(sstr));
  9979. while (loc[strlen("chargingProfileId")+2+c] != ',')
  9980. {
  9981. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  9982. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9983. c++;
  9984. }
  9985. sstr[c] = '\0';
  9986. tempchargingProfileIdInt = atoi(sstr);
  9987. //stackLevel
  9988. c = 0;
  9989. loc = strstr(sLineWord, "stackLevel");
  9990. memset(sstr ,0, ARRAY_SIZE(sstr));
  9991. while (loc[strlen("stackLevel")+2+c] != ',')
  9992. {
  9993. sstr[c] = loc[strlen("stackLevel")+2+c];
  9994. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9995. c++;
  9996. }
  9997. sstr[c] = '\0';
  9998. tempstackLevelInt = atoi(sstr);
  9999. c = 0;
  10000. loc = strstr(sLineWord, "chargingProfilePurpose");
  10001. memset(sstr ,0, ARRAY_SIZE(sstr));
  10002. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  10003. {
  10004. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  10005. c++;
  10006. }
  10007. sstr[c] = '\0';
  10008. strcpy(tempchargingProfilePurposeStr, sstr);
  10009. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  10010. {
  10011. //------- not write to fptr2-------//
  10012. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  10013. //clearflag = TRUE;
  10014. }
  10015. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  10016. {
  10017. //------- not write to fptr2-------//
  10018. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  10019. }
  10020. else if(stackLevelIsNULL == TRUE)
  10021. {
  10022. //Clear Whole File
  10023. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  10024. clearflag = TRUE;
  10025. break;
  10026. }
  10027. else
  10028. {
  10029. fprintf(fptr2, sLineWord);//writing data into file
  10030. }
  10031. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  10032. }
  10033. if(clearflag == TRUE)
  10034. {
  10035. fclose(fptr1);
  10036. fclose(fptr2);
  10037. sprintf(str,"rm -f %s",chargingProfiles[k]);
  10038. system(str);
  10039. // clear temp file
  10040. sprintf(str,"rm -f %s",temp);
  10041. system(str);
  10042. }
  10043. else
  10044. {
  10045. fclose(fptr1);
  10046. fclose(fptr2);
  10047. sprintf(str,"rm -f %s",chargingProfiles[k]);
  10048. system(str);
  10049. resultRename = rename(temp, chargingProfiles[k]);
  10050. if(resultRename == 0)
  10051. {
  10052. DEBUG_INFO("File ChargingProfile renamed successfully");
  10053. }
  10054. else
  10055. {
  10056. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  10057. }
  10058. if(comfirmstr[0]== 0)
  10059. {
  10060. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  10061. }
  10062. //Check chargingProfile is empty file
  10063. /*------ Read the file ----------------*/
  10064. fptr1=fopen(chargingProfiles[k],"r");
  10065. ch=fgetc(fptr1);
  10066. rewind(fptr1);
  10067. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  10068. if(ch!=EOF)
  10069. {
  10070. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  10071. {
  10072. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  10073. if(sLineWord[0]=='\0')
  10074. {
  10075. isEmptyFile = TRUE;
  10076. break;
  10077. }
  10078. else
  10079. {
  10080. isEmptyFile = FALSE;
  10081. break;
  10082. }
  10083. }
  10084. }
  10085. else
  10086. isEmptyFile = TRUE;
  10087. fclose(fptr1);
  10088. if(isEmptyFile == TRUE)
  10089. {
  10090. memset(str, 0, ARRAY_SIZE(str));
  10091. sprintf(str,"rm -f %s",chargingProfiles[k]);
  10092. system(str);
  10093. }
  10094. /*------- End of reading ---------------*/
  10095. }
  10096. } // while(int k=0; k < ChargeProfileCount; k++)
  10097. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  10098. end:
  10099. if(strcmp(comfirmstr, ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted]) == 0)
  10100. {
  10101. if(connectorIdInt == 0)
  10102. {
  10103. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10104. {
  10105. checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx], 0, TRUE);
  10106. }
  10107. }
  10108. else
  10109. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP20Data->SmartChargingProfile[connectorIdInt-1], 0, TRUE);
  10110. }
  10111. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  10112. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10113. return result;
  10114. }
  10115. int handleClearDisplayMessageRequest(char *uuid, char *payload)
  10116. {
  10117. mtrace();
  10118. int result = FAIL;
  10119. json_object *ClearDisplayMessage;
  10120. DEBUG_INFO("handleClearDisplayMessageRequest...\n");
  10121. sprintf((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status, ClearMessageStatusEnumTypeStr[ClearMessageStatusEnumType_Unknown]);
  10122. ClearDisplayMessage = json_tokener_parse(payload);
  10123. if(!is_error(ClearDisplayMessage))
  10124. {
  10125. // Required data
  10126. if(json_object_object_get(ClearDisplayMessage, "id") != NULL)
  10127. {
  10128. ShmOCPP20Data->ClearDisplayMessage.id = json_object_get_double(json_object_object_get(ClearDisplayMessage, "id"));
  10129. sprintf((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status, ClearMessageStatusEnumTypeStr[ClearMessageStatusEnumType_Accepted]);
  10130. }
  10131. }
  10132. json_object_put(ClearDisplayMessage);
  10133. sendCostUpdatedConfirmation(uuid);
  10134. return result;
  10135. }
  10136. int handleClearVariableMonitoringRequest(char *uuid, char *payload)
  10137. {
  10138. mtrace();
  10139. int result = FAIL;
  10140. json_object *ClearVariableMonitorin;
  10141. DEBUG_INFO("handleClearVariableMonitoringRequest...\n");
  10142. ClearVariableMonitorin = json_tokener_parse(payload);
  10143. if(!is_error(ClearVariableMonitorin))
  10144. {
  10145. // Required data
  10146. if(json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id")) <= ARRAY_SIZE(ShmOCPP20Data->ClearVariableMonitoring.id))
  10147. {
  10148. for(int idx=0;idx<json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id"));idx++)
  10149. {
  10150. ShmOCPP20Data->ClearVariableMonitoring.id[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(ClearVariableMonitorin, "id"), idx));
  10151. /*
  10152. * TODO:
  10153. * 1. Check response
  10154. */
  10155. ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].id = ShmOCPP20Data->ClearVariableMonitoring.id[idx];
  10156. strcpy((char*)ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].status, ClearMonitoringStatusEnumTypeStr[ClearMonitoringStatusEnumType_Accepted]);
  10157. }
  10158. sendClearVariableMonitoringConfirmation(uuid, json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id")));
  10159. }
  10160. }
  10161. json_object_put(ClearVariableMonitorin);
  10162. return result;
  10163. }
  10164. int handleCostUpdatedRequest(char *uuid, char *payload)
  10165. {
  10166. mtrace();
  10167. int result = FAIL;
  10168. json_object *CostUpdate;
  10169. DEBUG_INFO("handleCostUpdatedRequest...\n");
  10170. CostUpdate = json_tokener_parse(payload);
  10171. if(!is_error(CostUpdate))
  10172. {
  10173. // Required data
  10174. if(json_object_object_get(CostUpdate, "totalCost") != NULL)
  10175. {
  10176. ShmOCPP20Data->CostUpdated.totalCost = json_object_get_double(json_object_object_get(CostUpdate, "totalCost"));
  10177. }
  10178. if(json_object_object_get(CostUpdate, "transactionId") != NULL)
  10179. {
  10180. sprintf((char*)ShmOCPP20Data->CostUpdated.transactionId, "%s", json_object_get_string(json_object_object_get(CostUpdate, "transactionId")));
  10181. }
  10182. }
  10183. json_object_put(CostUpdate);
  10184. sendCostUpdatedConfirmation(uuid);
  10185. return result;
  10186. }
  10187. int handleCustomerInformationRequest(char *uuid, char *payload)
  10188. {
  10189. mtrace();
  10190. int result = FAIL;
  10191. json_object *CustomerInformation;
  10192. DEBUG_INFO("handleCustomerInformationRequest...\n");
  10193. CustomerInformation = json_tokener_parse(payload);
  10194. if(!is_error(CustomerInformation))
  10195. {
  10196. // Required data
  10197. if(json_object_object_get(CustomerInformation, "requestId") != NULL)
  10198. {
  10199. ShmOCPP20Data->CustomerInformation.requestId = json_object_get_int(json_object_object_get(CustomerInformation, "requestId"));
  10200. }
  10201. if(json_object_object_get(CustomerInformation, "report") != NULL)
  10202. {
  10203. ShmOCPP20Data->CustomerInformation.report = json_object_get_boolean(json_object_object_get(CustomerInformation, "report"));
  10204. }
  10205. if(json_object_object_get(CustomerInformation, "clear") != NULL)
  10206. {
  10207. ShmOCPP20Data->CustomerInformation.report = json_object_get_boolean(json_object_object_get(CustomerInformation, "clear"));
  10208. }
  10209. // Optional data
  10210. if(json_object_object_get(CustomerInformation, "idToken") != NULL)
  10211. {
  10212. if(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "idToken") != NULL)
  10213. {
  10214. sprintf((char*)ShmOCPP20Data->CustomerInformation.idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "idToken")));
  10215. }
  10216. if(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "type") != NULL)
  10217. {
  10218. sprintf((char*)ShmOCPP20Data->CustomerInformation.idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "type")));
  10219. }
  10220. }
  10221. if(json_object_object_get(CustomerInformation, "customerCertificate") != NULL)
  10222. {
  10223. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "hashAlgorithm") != NULL)
  10224. {
  10225. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "hashAlgorithm")));
  10226. }
  10227. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerNameHash") != NULL)
  10228. {
  10229. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerNameHash")));
  10230. }
  10231. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerKeyHash") != NULL)
  10232. {
  10233. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerKeyHash")));
  10234. }
  10235. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "serialNumber") != NULL)
  10236. {
  10237. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "serialNumber")));
  10238. }
  10239. }
  10240. strcpy((char*)ShmOCPP20Data->CustomerInformation.Response_status, CustomerInformationStatusEnumTypeStr[CustomerInformationStatusEnumType_Accepted]);
  10241. }
  10242. else
  10243. strcpy((char*)ShmOCPP20Data->CustomerInformation.Response_status, CustomerInformationStatusEnumTypeStr[CustomerInformationStatusEnumType_Rejected]);
  10244. json_object_put(CustomerInformation);
  10245. sendCustomerInformationConfirmation(uuid);
  10246. return result;
  10247. }
  10248. void createFirmwareVersionByDataTransfer(void)
  10249. {
  10250. json_object *FirmwareDataTransfer = json_object_new_object();
  10251. // AC & DC model
  10252. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  10253. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  10254. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  10255. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  10256. // DC model
  10257. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  10258. {
  10259. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  10260. {
  10261. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  10262. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  10263. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  10264. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  10265. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  10266. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  10267. }
  10268. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  10269. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  10270. {
  10271. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  10272. }
  10273. }
  10274. else
  10275. {
  10276. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  10277. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  10278. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  10279. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  10280. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  10281. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  10282. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  10283. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  10284. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  10285. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  10286. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  10287. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  10288. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  10289. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  10290. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  10291. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  10292. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  10293. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  10294. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  10295. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  10296. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  10297. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  10298. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  10299. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  10300. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  10301. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  10302. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  10303. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  10304. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  10305. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  10306. json_object_object_add(FirmwareDataTransfer, "DD1_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  10307. }
  10308. // 4G model
  10309. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  10310. {
  10311. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  10312. }
  10313. sprintf((char*)ShmOCPP20Data->DataTransfer[0].vendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  10314. sprintf((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_FirmwareVersion");
  10315. sprintf((char*)ShmOCPP20Data->DataTransfer[0].data, json_object_to_json_string(FirmwareDataTransfer));
  10316. }
  10317. int handleDataTransferRequest(char *uuid, char *payload)
  10318. {
  10319. mtrace();
  10320. int result = PASS;
  10321. DEBUG_INFO("handleDataTransferRequest...\n");
  10322. if((uuid != NULL) && (payload != NULL))
  10323. {
  10324. json_object *DataTransfer;
  10325. DataTransfer = json_tokener_parse(payload);
  10326. if(!is_error(DataTransfer))
  10327. {
  10328. // Required data
  10329. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  10330. sprintf((char*)ShmOCPP20Data->DataTransfer[0].vendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  10331. // Optional data
  10332. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  10333. sprintf((char*)ShmOCPP20Data->DataTransfer[0].messageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  10334. if(json_object_object_get(DataTransfer, "data") != NULL)
  10335. sprintf((char*)ShmOCPP20Data->DataTransfer[0].data, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  10336. result = PASS;
  10337. }
  10338. json_object_put(DataTransfer);
  10339. if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_FirmwareVersion") != NULL)
  10340. {
  10341. // Send all moudle firmware version on EVSE
  10342. createFirmwareVersionByDataTransfer();
  10343. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  10344. }
  10345. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_Tmate") != NULL)
  10346. {
  10347. system("/usr/bin/run_tmate_restart.sh &");
  10348. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  10349. }
  10350. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "SetLEDBar") != NULL)
  10351. {
  10352. json_object *data;
  10353. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  10354. if(!is_error(data))
  10355. {
  10356. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  10357. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  10358. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  10359. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  10360. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  10361. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  10362. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  10363. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  10364. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  10365. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  10366. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  10367. }
  10368. else
  10369. {
  10370. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  10371. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  10372. }
  10373. json_object_put(data);
  10374. }
  10375. else
  10376. {
  10377. // Can not find valid message id
  10378. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_UnknownMessageId]);
  10379. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data,"vendorId: %s messageId: %s data: %s"
  10380. ,ShmOCPP20Data->DataTransfer[0].vendorId
  10381. ,ShmOCPP20Data->DataTransfer[0].messageId
  10382. ,ShmOCPP20Data->DataTransfer[0].data);
  10383. }
  10384. }
  10385. else
  10386. {
  10387. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_UnknownMessageId]);
  10388. result = FAIL;
  10389. }
  10390. sendDataTransferConfirmation(uuid, 0);
  10391. return result;
  10392. }
  10393. int handleDeleteCertificateRequest(char *uuid, char *payload)
  10394. {
  10395. mtrace();
  10396. int result = FAIL;
  10397. json_object *DeleteCertificate;
  10398. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  10399. DeleteCertificate = json_tokener_parse(payload);
  10400. if(!is_error(DeleteCertificate))
  10401. {
  10402. memset(&ShmOCPP20Data->DeleteCertificate, 0, sizeof(struct DeleteCertificate_20));
  10403. memcpy(&ShmOCPP20Data->DeleteCertificate.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->DeleteCertificate.guid));
  10404. // Required data
  10405. if(json_object_object_get(DeleteCertificate, "certificateHashData") != NULL)
  10406. {
  10407. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm") != NULL)
  10408. {
  10409. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  10410. }
  10411. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash") != NULL)
  10412. {
  10413. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  10414. }
  10415. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash") != NULL)
  10416. {
  10417. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  10418. }
  10419. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber") != NULL)
  10420. {
  10421. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  10422. }
  10423. /*
  10424. * TODO:
  10425. * 1. Delete certification and response
  10426. */
  10427. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, DeleteCertificateStatusEnumTypeStr[DeleteCertificateStatusEnumType_Accepted]);
  10428. }
  10429. }
  10430. else
  10431. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, DeleteCertificateStatusEnumTypeStr[DeleteCertificateStatusEnumType_Failed]);
  10432. json_object_put(DeleteCertificate);
  10433. sendDeleteCertificateConfirmation(uuid);
  10434. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10435. return result;
  10436. }
  10437. int handleGetBaseReportRequest(char *uuid, char *payload)
  10438. {
  10439. mtrace();
  10440. int result = FAIL;
  10441. json_object *GetBaseRepor;
  10442. DEBUG_INFO("handleGetBaseReportRequest...\n");
  10443. GetBaseRepor = json_tokener_parse(payload);
  10444. if(!is_error(GetBaseRepor))
  10445. {
  10446. memset(&ShmOCPP20Data->GetBaseReport, 0, sizeof(struct GetBaseReport_20));
  10447. memcpy(&ShmOCPP20Data->GetBaseReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetBaseReport.guid));
  10448. // Required data
  10449. if(json_object_object_get(GetBaseRepor, "requestId") != NULL)
  10450. {
  10451. ShmOCPP20Data->GetBaseReport.requestId = json_object_get_int(json_object_object_get(GetBaseRepor, "requestId"));
  10452. }
  10453. if(json_object_object_get(GetBaseRepor, "reportBase") != NULL)
  10454. {
  10455. sprintf((char*)ShmOCPP20Data->GetBaseReport.reportBase, "%s", json_object_get_string(json_object_object_get(GetBaseRepor, "reportBase")));
  10456. }
  10457. if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_SummaryInventory]) == 0)
  10458. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  10459. else
  10460. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  10461. }
  10462. else
  10463. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  10464. json_object_put(GetBaseRepor);
  10465. sendGetBaseReportConfirmation(uuid);
  10466. return result;
  10467. }
  10468. int handleGetChargingProfilesRequest(char *uuid, char *payload)
  10469. {
  10470. mtrace();
  10471. int result = FAIL;
  10472. int gun_index = -1;
  10473. json_object *GetChargingProfiles;
  10474. DEBUG_INFO("handleGetChargingProfilesRequest...\n");
  10475. GetChargingProfiles = json_tokener_parse(payload);
  10476. if(!is_error(GetChargingProfiles))
  10477. {
  10478. if(json_object_object_get(GetChargingProfiles, "evseId") != NULL)
  10479. {
  10480. 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;
  10481. }
  10482. if(gun_index >-1)
  10483. {
  10484. memset(&ShmOCPP20Data->GetChargingProfiles[gun_index], 0, sizeof(struct GetChargingProfiles_20));
  10485. memcpy(&ShmOCPP20Data->GetChargingProfiles[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetChargingProfiles[gun_index].guid));
  10486. // Required data
  10487. if(json_object_object_get(GetChargingProfiles, "requestId") != NULL)
  10488. {
  10489. ShmOCPP20Data->GetChargingProfiles[gun_index].requestId = json_object_get_int(json_object_object_get(GetChargingProfiles, "requestId"));
  10490. }
  10491. if(json_object_object_get(GetChargingProfiles, "chargingProfile") != NULL)
  10492. {
  10493. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfilePurpose") != NULL)
  10494. {
  10495. sprintf((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.chargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfilePurpose")));
  10496. }
  10497. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "stackLevel") != NULL)
  10498. {
  10499. ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "stackLevel"));
  10500. }
  10501. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingLimitSource") != NULL)
  10502. {
  10503. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingLimitSource"));idx++)
  10504. {
  10505. 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)));
  10506. }
  10507. }
  10508. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfileId") != NULL)
  10509. {
  10510. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfileId"));idx++)
  10511. {
  10512. 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));
  10513. }
  10514. }
  10515. }
  10516. strcpy((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status, GetChargingProfileStatusEnumTypeStr[GetChargingProfileStatusEnumType_Accepted]);
  10517. }
  10518. else
  10519. strcpy((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status, GetChargingProfileStatusEnumTypeStr[GetChargingProfileStatusEnumType_NoProfiles]);
  10520. }
  10521. json_object_put(GetChargingProfiles);
  10522. sendGetChargingProfilesConfirmation(uuid, gun_index);
  10523. return result;
  10524. }
  10525. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  10526. {
  10527. mtrace();
  10528. int result = FAIL;
  10529. int connectorIdInt, durationInt;
  10530. char chargingRateUnitStr[4]={0};
  10531. char comfirmstr[20];
  10532. int confirmPeriods = 0;
  10533. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  10534. json_object *GetCompositeSchedule;
  10535. GetCompositeSchedule = json_tokener_parse(payload);
  10536. if(!is_error(GetCompositeSchedule))
  10537. {
  10538. // Required data
  10539. if(json_object_object_get(GetCompositeSchedule, "evseId") != NULL)
  10540. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "evseId"));
  10541. else
  10542. connectorIdInt = -1;
  10543. if(json_object_object_get(GetCompositeSchedule, "duration"))
  10544. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  10545. else
  10546. durationInt = 86400;
  10547. // Optional data
  10548. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  10549. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  10550. }
  10551. json_object_put(GetCompositeSchedule);
  10552. memset(ShmOCPP20Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  10553. if((connectorIdInt == 0) ||
  10554. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  10555. {
  10556. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  10557. struct ChargingProfileType tmpProfile[1];
  10558. memset(&ShmOCPP20Data->GetCompositeSchedule[gun_index], 0, sizeof(struct GetCompositeSchedule_20));
  10559. memcpy(&ShmOCPP20Data->GetCompositeSchedule[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].guid));
  10560. if(strstr(chargingRateUnitStr, "W") != NULL)
  10561. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], 0, FALSE);
  10562. else
  10563. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], 0, TRUE);
  10564. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod);idx++)
  10565. {
  10566. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].chargingSchedule[0].chargingSchedulePeriod[idx].startPeriod);
  10567. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].chargingSchedule[0].chargingSchedulePeriod[idx].limit);
  10568. }
  10569. memcpy(&ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule, &tmpProfile[0].chargingSchedule[0], sizeof(struct CompositeScheduleType));
  10570. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod);idx++)
  10571. {
  10572. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].startPeriod);
  10573. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit);
  10574. if((ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].startPeriod==0) &&
  10575. (ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit==0) &&
  10576. (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))
  10577. {
  10578. confirmPeriods = idx;
  10579. break;
  10580. }
  10581. }
  10582. if((confirmPeriods == 0) && (tmpProfile[0].id > 0))
  10583. {
  10584. confirmPeriods += 1;
  10585. }
  10586. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  10587. }
  10588. else
  10589. {
  10590. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusEnumTypeStr[GenericStatusEnumType_Rejected]);
  10591. }
  10592. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10593. return result;
  10594. }
  10595. int handleGetDisplayMessagesRequest(char *uuid, char *payload)
  10596. {
  10597. mtrace();
  10598. int result = FAIL;
  10599. json_object *GetDisplayMessages;
  10600. DEBUG_INFO("handleGetDisplayMessagesRequest...\n");
  10601. GetDisplayMessages = json_tokener_parse(payload);
  10602. if(!is_error(GetDisplayMessages))
  10603. {
  10604. memset(&ShmOCPP20Data->GetDisplayMessages, 0, sizeof(struct GetDisplayMessages_20));
  10605. memcpy(&ShmOCPP20Data->GetDisplayMessages.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetDisplayMessages.guid));
  10606. // Required data
  10607. if(json_object_object_get(GetDisplayMessages, "requestId") != NULL)
  10608. {
  10609. ShmOCPP20Data->GetDisplayMessages.requestId = json_object_get_int(json_object_object_get(GetDisplayMessages, "requestId"));
  10610. }
  10611. // Optional data
  10612. if(json_object_object_get(GetDisplayMessages, "priority") != NULL)
  10613. {
  10614. sprintf((char*)ShmOCPP20Data->GetDisplayMessages.priority, "%s", json_object_get_string(json_object_object_get(GetDisplayMessages, "priority")));
  10615. }
  10616. if(json_object_object_get(GetDisplayMessages, "state") != NULL)
  10617. {
  10618. sprintf((char*)ShmOCPP20Data->GetDisplayMessages.state, "%s", json_object_get_string(json_object_object_get(GetDisplayMessages, "state")));
  10619. }
  10620. if(json_object_array_length(json_object_object_get(GetDisplayMessages, "id")) <= ARRAY_SIZE(ShmOCPP20Data->GetDisplayMessages.id))
  10621. {
  10622. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetDisplayMessages, "id"));idx++)
  10623. {
  10624. ShmOCPP20Data->GetDisplayMessages.id[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(GetDisplayMessages, "id"), idx));
  10625. }
  10626. strcpy((char*)ShmOCPP20Data->GetDisplayMessages.Response_status, GetDisplayMessagesStatusEnumTypeStr[GetDisplayMessagesStatusEnumType_Accepted]);
  10627. ShmOCPP20Data->MsMsg.bits.GetDisplayMessagesReq = ON;
  10628. }
  10629. else
  10630. strcpy((char*)ShmOCPP20Data->GetDisplayMessages.Response_status, GetDisplayMessagesStatusEnumTypeStr[GetDisplayMessagesStatusEnumType_Unknown]);
  10631. }
  10632. json_object_put(GetDisplayMessages);
  10633. return result;
  10634. }
  10635. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  10636. {
  10637. mtrace();
  10638. int result = FAIL;
  10639. json_object *GetInstalledCertificateIds;
  10640. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  10641. GetInstalledCertificateIds = json_tokener_parse(payload);
  10642. if(!is_error(GetInstalledCertificateIds))
  10643. {
  10644. memset(&ShmOCPP20Data->GetInstalledCertificateIds, 0, sizeof(struct GetInstalledCertificateIds_20));
  10645. memcpy(&ShmOCPP20Data->GetInstalledCertificateIds.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetInstalledCertificateIds.guid));
  10646. // Optional data
  10647. if(json_object_array_length(json_object_object_get(GetInstalledCertificateIds, "certificateType")) <= ARRAY_SIZE(ShmOCPP20Data->GetInstalledCertificateIds.certificateType))
  10648. {
  10649. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetInstalledCertificateIds, "certificateType"));idx++)
  10650. {
  10651. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetInstalledCertificateIds, "certificateType"), idx)));
  10652. /*
  10653. * TODO:
  10654. * 1. Get installed certificate info for response
  10655. */
  10656. }
  10657. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  10658. }
  10659. else
  10660. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_NotFound]);
  10661. }
  10662. json_object_put(GetInstalledCertificateIds);
  10663. sendInstallCertificateConfirmation(uuid);
  10664. return result;
  10665. }
  10666. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10667. {
  10668. mtrace();
  10669. int result = FAIL;
  10670. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10671. if(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "FALSE") == 0)
  10672. {
  10673. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10674. localversion = -1;
  10675. }
  10676. else
  10677. {
  10678. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10679. DB_getListVerion();
  10680. }
  10681. ShmOCPP20Data->GetLocalListVersion.Response_versionNumber = localversion;
  10682. sendGetLocalListVersionConfirmation(uuid);
  10683. return result;
  10684. }
  10685. static char fnamePlusPath[100]={0};
  10686. static char fnamePWithNoPath[60]={0};
  10687. void checkUploadLog(void)
  10688. {
  10689. FILE *fp;
  10690. /* Open the command for reading. */
  10691. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10692. if (fp == NULL) {
  10693. printf("Failed to run command\n" );
  10694. exit(1);
  10695. }
  10696. int ftppathlen = 0;
  10697. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10698. int i = 0;
  10699. /* Read the output a line at a time - output it. */
  10700. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10701. if(i==0)
  10702. {
  10703. ftppathlen = strlen(fnamePlusPath);
  10704. printf("%s\n", fnamePlusPath);
  10705. fnamePlusPath[ftppathlen]='\0';
  10706. break;
  10707. }
  10708. i= i+1;
  10709. }
  10710. /* close */
  10711. pclose(fp);
  10712. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10713. {
  10714. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  10715. {
  10716. fnamePlusPath[k]='\0';
  10717. }
  10718. }
  10719. i=1;
  10720. //char fname[60]={0};
  10721. while(i < ftppathlen)
  10722. {
  10723. int len=ftppathlen-i;
  10724. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10725. {
  10726. printf("compare '/' all right\n");
  10727. break;
  10728. }
  10729. i=i+1;
  10730. }
  10731. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10732. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10733. fnamePWithNoPath[i+1] = '\0';
  10734. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10735. {
  10736. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10737. {
  10738. fnamePWithNoPath[j]='\0';
  10739. }
  10740. }
  10741. FILE* fp1 = fopen(fnamePlusPath, "r");
  10742. if (fp1)
  10743. {
  10744. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10745. // file exists
  10746. fclose(fp1);
  10747. }
  10748. else
  10749. {
  10750. // file doesn't exist
  10751. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10752. }
  10753. }
  10754. void* GetLogProcess(void* data)
  10755. {
  10756. pthread_detach(pthread_self());
  10757. mtrace();
  10758. int requestId, retriesInt=0, retryIntervalInt=0;
  10759. char logType[32], remoteLocation[1024]={0}, oldestTimestamp[30]={0}, latestTimestamp[30]={0};
  10760. 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};
  10761. int port=0;
  10762. int isSuccess = FALSE;
  10763. char ftpbuf[1024]={0};
  10764. char cmdBuf[2048];
  10765. struct tm *tmNow;
  10766. time_t CurrentTime;
  10767. struct tm tmStart;
  10768. struct tm tmStop;
  10769. CurrentTime = time(NULL);
  10770. tmNow=localtime(&CurrentTime);
  10771. uint16_t targetYear, targetMonth;
  10772. json_object *GetLog;
  10773. DEBUG_INFO("GetGetProcess...\n");
  10774. GetLog = json_tokener_parse(data);
  10775. if(!is_error(GetLog))
  10776. {
  10777. // Required data
  10778. if(json_object_object_get(GetLog, "requestId") != NULL)
  10779. requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  10780. if(json_object_object_get(GetLog, "logType") != NULL)
  10781. sprintf(logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  10782. if(json_object_object_get(GetLog, "log") != NULL)
  10783. {
  10784. if(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation") != NULL)
  10785. sprintf(remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  10786. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  10787. sprintf(oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  10788. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  10789. sprintf(latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  10790. }
  10791. // Optional data
  10792. if(json_object_object_get(GetLog, "retries") != NULL)
  10793. retriesInt = json_object_get_int(json_object_object_get(GetLog, "retries"));
  10794. else
  10795. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  10796. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  10797. retryIntervalInt = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  10798. else
  10799. retryIntervalInt = 30;
  10800. }
  10801. json_object_put(GetLog);
  10802. ShmOCPP20Data->GetLog.requestId = requestId;
  10803. // Pack log to compress file
  10804. 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) &&
  10805. (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))
  10806. {
  10807. // Pack system log
  10808. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10809. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  10810. targetYear = tmStart.tm_year;
  10811. targetMonth = tmStart.tm_mon;
  10812. do
  10813. {
  10814. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10815. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10816. if(targetMonth+1>=13)
  10817. {
  10818. targetYear += 1;
  10819. targetMonth = 1;
  10820. }
  10821. else
  10822. {
  10823. targetMonth += 1;
  10824. }
  10825. }while((targetYear < (tmNow->tm_year+1900)) ||
  10826. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10827. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  10828. system(cmdBuf);
  10829. // Pack charging & event log
  10830. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  10831. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  10832. targetYear = tmStart.tm_year;
  10833. targetMonth = tmStart.tm_mon;
  10834. do
  10835. {
  10836. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  10837. if(targetMonth+1>=13)
  10838. {
  10839. targetYear += 1;
  10840. targetMonth = 1;
  10841. }
  10842. else
  10843. {
  10844. targetMonth += 1;
  10845. }
  10846. }while((targetYear < (tmNow->tm_year+1900)) ||
  10847. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  10848. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  10849. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  10850. system(cmdBuf);
  10851. // Combine log file
  10852. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  10853. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  10854. }
  10855. else
  10856. {
  10857. system("exec /root/logPackTools 'log' 6");
  10858. }
  10859. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP20Data->GetLog.Response_filename);
  10860. system(cmdBuf);
  10861. checkUploadLog();
  10862. //****************location*******************/
  10863. if(strcmp(remoteLocation,"")==0)
  10864. {
  10865. DEBUG_INFO("remoteLocation is <Empty>!\n");
  10866. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  10867. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  10868. goto end;
  10869. }
  10870. memset(protocol, 0, ARRAY_SIZE(protocol));
  10871. memset(user, 0, ARRAY_SIZE(user) );
  10872. memset(password, 0, ARRAY_SIZE(password));
  10873. memset(host, 0, ARRAY_SIZE(host));
  10874. memset(path, 0, ARRAY_SIZE(path));
  10875. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  10876. memset(host1, 0, ARRAY_SIZE(host1));
  10877. memset(path1, 0, ARRAY_SIZE(path1));
  10878. /*location: ftp://user:password@host:port/path*/
  10879. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  10880. if((access(fnamePlusPath,F_OK))!=-1)
  10881. {
  10882. DEBUG_INFO("fnamePlusPath exist.\n");
  10883. }
  10884. else
  10885. {
  10886. DEBUG_INFO("fnamePlusPath not exist!\n");
  10887. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  10888. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  10889. goto end;
  10890. }
  10891. if(strchr(remoteLocation,'@')==NULL)
  10892. {
  10893. sscanf(remoteLocation,
  10894. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  10895. protocol, host, &port, path);
  10896. strcpy(user,"anonymous");
  10897. strcpy(password,"");
  10898. }
  10899. else
  10900. {
  10901. //DEBUG_INFO("pch=%s\n", pch);
  10902. sscanf(remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  10903. protocol, user, password, host, &port, path);
  10904. }
  10905. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  10906. {
  10907. DEBUG_INFO("protocol is not ftp/http ! \n");
  10908. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  10909. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  10910. goto end;
  10911. }
  10912. if(strncmp(remoteLocation,"http", 4) == 0)
  10913. {
  10914. sscanf(remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  10915. sprintf(ftppath,"/%s", path);
  10916. do
  10917. {
  10918. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploading]);
  10919. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  10920. sleep(3);
  10921. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, remoteLocation);
  10922. if(!isSuccess)
  10923. {
  10924. DEBUG_INFO("sendLogStatusNotificationRequest fail...retries: %d\n", retriesInt);
  10925. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  10926. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  10927. sleep(retryIntervalInt);
  10928. }
  10929. else
  10930. {
  10931. DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
  10932. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
  10933. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  10934. }
  10935. retriesInt--;
  10936. }while((isSuccess == 0)&&(retriesInt >= 0));
  10937. }
  10938. else
  10939. {
  10940. sscanf(host,"%[^/]%s",host1, path1);
  10941. if(strlen(path) > 0)
  10942. sprintf(ftppath,"/%s", path);
  10943. else
  10944. sprintf(ftppath,"/%s", path1);
  10945. int ftppathlen=strlen(ftppath);
  10946. int i=1;
  10947. char filenametemp[50];
  10948. while(i < ftppathlen)
  10949. {
  10950. int len=ftppathlen-i;
  10951. if(ftppath[len]== 47) // '/' ascll code: 47
  10952. {
  10953. DEBUG_INFO("find '/' all right\n");
  10954. break;
  10955. }
  10956. i=i+1;
  10957. }
  10958. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  10959. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  10960. filenametemp[i+1] = 0;
  10961. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  10962. if(port == 0)
  10963. port = 21;
  10964. do
  10965. {
  10966. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploading]);
  10967. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  10968. sleep(3);
  10969. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  10970. if(!isSuccess)
  10971. {
  10972. DEBUG_INFO("sendLogStatusNotificationRequest fail...retries: %d\n", retriesInt);
  10973. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  10974. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  10975. sleep(retryIntervalInt);
  10976. }
  10977. else
  10978. {
  10979. DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
  10980. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
  10981. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  10982. }
  10983. retriesInt--;
  10984. }while((!isSuccess)&&(retriesInt >= 0));
  10985. }
  10986. end:
  10987. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle;
  10988. pthread_exit(NULL);
  10989. }
  10990. int handleGetLogRequest(char *uuid, char *payload)
  10991. {
  10992. mtrace();
  10993. int result = FAIL;
  10994. char fName[258];
  10995. time_t CurrentTime;
  10996. struct tm *tm;
  10997. pthread_t th_Status;
  10998. CurrentTime = time(NULL);
  10999. tm = localtime(&CurrentTime);
  11000. 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);
  11001. sprintf((char*)ShmOCPP20Data->GetLog.Response_filename, "%s", fName);
  11002. sprintf((char*)ShmOCPP20Data->GetLog.Response_status, "%s", LogStatusEnumTypeStr[LogStatusEnumType_Accepted]);
  11003. sendGetLogConfirmation(uuid);
  11004. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  11005. return result;
  11006. }
  11007. int handleGetMonitoringReportRequest(char *uuid, char *payload)
  11008. {
  11009. mtrace();
  11010. int result = FAIL;
  11011. json_object *GetMonitoringReport;
  11012. DEBUG_INFO("handleGetMonitoringReportRequest...\n");
  11013. GetMonitoringReport = json_tokener_parse(payload);
  11014. if(!is_error(GetMonitoringReport))
  11015. {
  11016. memset(&ShmOCPP20Data->GetMonitoringReport, 0, sizeof(struct GetMonitoringReport_20));
  11017. memcpy(&ShmOCPP20Data->GetMonitoringReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.guid));
  11018. // Required data
  11019. if(json_object_object_get(GetMonitoringReport, "requestId") != NULL)
  11020. {
  11021. ShmOCPP20Data->GetMonitoringReport.requestId = json_object_get_int(json_object_object_get(GetMonitoringReport, "requestId"));
  11022. }
  11023. // Optional data
  11024. if(json_object_object_get(GetMonitoringReport, "monitoringCriteria") != NULL)
  11025. {
  11026. sprintf((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria, "%s", json_object_get_string(json_object_object_get(GetMonitoringReport, "monitoringCriteria")));
  11027. }
  11028. if(json_object_object_get(GetMonitoringReport, "componentVariable") != NULL)
  11029. {
  11030. if(json_object_array_length(json_object_object_get(GetMonitoringReport, "componentVariable")) <= ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.componentVariable))
  11031. {
  11032. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetMonitoringReport, "componentVariable"));idx++)
  11033. {
  11034. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component") != NULL)
  11035. {
  11036. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "name") != NULL)
  11037. {
  11038. 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")));
  11039. }
  11040. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "instance") != NULL)
  11041. {
  11042. 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")));
  11043. }
  11044. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "evse") != NULL)
  11045. {
  11046. 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)
  11047. {
  11048. 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"));
  11049. }
  11050. 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)
  11051. {
  11052. 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"));
  11053. }
  11054. }
  11055. }
  11056. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable") != NULL)
  11057. {
  11058. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "name") != NULL)
  11059. {
  11060. 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")));
  11061. }
  11062. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "instance") != NULL)
  11063. {
  11064. 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")));
  11065. }
  11066. }
  11067. }
  11068. }
  11069. }
  11070. }
  11071. json_object_put(GetMonitoringReport);
  11072. /*
  11073. * TODO:
  11074. * 1. Response result
  11075. */
  11076. strcpy((char*)ShmOCPP20Data->GetReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  11077. sendGetMonitoringReportConfirmation(uuid);
  11078. return result;
  11079. }
  11080. int handleGetReportRequest(char *uuid, char *payload)
  11081. {
  11082. mtrace();
  11083. int result = FAIL;
  11084. json_object *GetReport;
  11085. DEBUG_INFO("handleGetReportRequest...\n");
  11086. GetReport = json_tokener_parse(payload);
  11087. if(!is_error(GetReport))
  11088. {
  11089. memset(&ShmOCPP20Data->GetReport, 0, sizeof(struct GetReport_20));
  11090. memcpy(&ShmOCPP20Data->GetReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetReport.guid));
  11091. // Required data
  11092. if(json_object_object_get(GetReport, "requestId") != NULL)
  11093. {
  11094. ShmOCPP20Data->GetReport.requestId = json_object_get_int(json_object_object_get(GetReport, "requestId"));
  11095. }
  11096. // Optional data
  11097. if(json_object_object_get(GetReport, "componentCriteria") != NULL)
  11098. {
  11099. sprintf((char*)ShmOCPP20Data->GetReport.componentCriteria, "%s", json_object_get_string(json_object_object_get(GetReport, "componentCriteria")));
  11100. }
  11101. if(json_object_object_get(GetReport, "componentVariable") != NULL)
  11102. {
  11103. if(json_object_array_length(json_object_object_get(GetReport, "componentVariable")) <= ARRAY_SIZE(ShmOCPP20Data->GetReport.componentVariable))
  11104. {
  11105. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetReport, "componentVariable"));idx++)
  11106. {
  11107. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component") != NULL)
  11108. {
  11109. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "name") != NULL)
  11110. {
  11111. 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")));
  11112. }
  11113. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "instance") != NULL)
  11114. {
  11115. 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")));
  11116. }
  11117. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "evse") != NULL)
  11118. {
  11119. 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)
  11120. {
  11121. 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"));
  11122. }
  11123. 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)
  11124. {
  11125. 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"));
  11126. }
  11127. }
  11128. }
  11129. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable") != NULL)
  11130. {
  11131. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "name") != NULL)
  11132. {
  11133. 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")));
  11134. }
  11135. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "instance") != NULL)
  11136. {
  11137. 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")));
  11138. }
  11139. }
  11140. }
  11141. }
  11142. }
  11143. }
  11144. json_object_put(GetReport);
  11145. /*
  11146. * TODO:
  11147. * 1. Response result
  11148. */
  11149. strcpy((char*)ShmOCPP20Data->GetReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  11150. sendGetReportConfirmation(uuid);
  11151. return result;
  11152. }
  11153. int handleGetTransactionStatusRequest(char *uuid, char *payload)
  11154. {
  11155. mtrace();
  11156. int result = FAIL;
  11157. int8_t gun_index = -1;
  11158. json_object *GetTransactionStatus;
  11159. DEBUG_INFO("handleGetTransactionStatusRequest...\n");
  11160. GetTransactionStatus = json_tokener_parse(payload);
  11161. if(!is_error(GetTransactionStatus))
  11162. {
  11163. /*
  11164. * TODO:
  11165. * 1. Check transaction locate which connector
  11166. */
  11167. memset(&ShmOCPP20Data->GetTransactionStatus[gun_index], 0, sizeof(struct GetTransactionStatus_20));
  11168. memcpy(&ShmOCPP20Data->GetTransactionStatus[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetTransactionStatus[gun_index].guid));
  11169. if(json_object_object_get(GetTransactionStatus, "transactionId") != NULL)
  11170. {
  11171. sprintf((char*)ShmOCPP20Data->GetTransactionStatus[gun_index].transactionId, "%s", json_object_get_string(json_object_object_get(GetTransactionStatus, "transactionId")));
  11172. }
  11173. ShmOCPP20Data->GetTransactionStatus[gun_index].Response_messagesInQueue = FALSE;
  11174. ShmOCPP20Data->GetTransactionStatus[gun_index].Response_ongoingIndicator = FALSE;
  11175. }
  11176. json_object_put(GetTransactionStatus);
  11177. sendGetTransactionStatusConfirmation(uuid, gun_index);
  11178. return result;
  11179. }
  11180. int handleGetVariablesRequest(char *uuid, char *payload)
  11181. {
  11182. mtrace();
  11183. int result = FAIL;
  11184. json_object *GetVariables;
  11185. DEBUG_INFO("handleGetVariablesRequest...\n");
  11186. GetVariables = json_tokener_parse(payload);
  11187. if(!is_error(GetVariables))
  11188. {
  11189. memset(&ShmOCPP20Data->GetVariables, 0, sizeof(struct SetVariables_20));
  11190. memcpy(&ShmOCPP20Data->GetVariables.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetVariables.guid));
  11191. // Required data
  11192. if(json_object_array_length(json_object_object_get(GetVariables, "getVariableData")) <= ARRAY_SIZE(ShmOCPP20Data->GetVariables.getVariableData))
  11193. {
  11194. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetVariables, "getVariableData"));idx++)
  11195. {
  11196. if(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx) != NULL)
  11197. {
  11198. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "attributeType") != NULL)
  11199. {
  11200. 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")));
  11201. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, (char*)ShmOCPP20Data->GetVariables.getVariableData[idx].attributeType);
  11202. }
  11203. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component") != NULL)
  11204. {
  11205. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "name") != NULL)
  11206. {
  11207. 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")));
  11208. }
  11209. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "instance") != NULL)
  11210. {
  11211. 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")));
  11212. }
  11213. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "evse") != NULL)
  11214. {
  11215. 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)
  11216. {
  11217. 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"));
  11218. }
  11219. 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)
  11220. {
  11221. 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"));
  11222. }
  11223. }
  11224. memcpy(&ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component, &ShmOCPP20Data->GetVariables.getVariableData[idx].component, sizeof(struct ComponentType));
  11225. }
  11226. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable") != NULL)
  11227. {
  11228. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "name") != NULL)
  11229. {
  11230. 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")));
  11231. }
  11232. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "instance") != NULL)
  11233. {
  11234. 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")));
  11235. }
  11236. memcpy(&ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable , &ShmOCPP20Data->GetVariables.getVariableData[idx].variable, sizeof(struct VariableType));
  11237. }
  11238. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  11239. {
  11240. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name) == 0) &&
  11241. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.instance, (char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.instance) == 0) &&
  11242. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name) == 0) &&
  11243. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.instance, (char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.instance) == 0))
  11244. {
  11245. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_Accepted]);
  11246. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value);
  11247. break;
  11248. }
  11249. else
  11250. {
  11251. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_UnknownComponent]);
  11252. memset(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, 0x00, ARRAY_SIZE(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue));
  11253. }
  11254. }
  11255. }
  11256. }
  11257. }
  11258. sendGetVariablesConfirmation(uuid, json_object_array_length(json_object_object_get(GetVariables, "getVariableData")));
  11259. }
  11260. json_object_put(GetVariables);
  11261. return result;
  11262. }
  11263. int handleInstallCertificateRequest(char *uuid, char *payload)
  11264. {
  11265. mtrace();
  11266. int result = FAIL;
  11267. json_object *InstallCertificate;
  11268. DEBUG_INFO("handleInstallCertificateRequest...\n");
  11269. InstallCertificate = json_tokener_parse(payload);
  11270. if(!is_error(InstallCertificate))
  11271. {
  11272. memset(&ShmOCPP20Data->InstallCertificate, 0, sizeof(struct InstallCertificate_20));
  11273. memcpy(&ShmOCPP20Data->InstallCertificate.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->InstallCertificate.guid));
  11274. // Required data
  11275. if(json_object_object_get(InstallCertificate, "certificateType") != NULL)
  11276. {
  11277. sprintf((char*)ShmOCPP20Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  11278. }
  11279. if(json_object_object_get(InstallCertificate, "certificate") != NULL)
  11280. {
  11281. sprintf((char*)ShmOCPP20Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  11282. }
  11283. }
  11284. json_object_put(InstallCertificate);
  11285. /*
  11286. * TODO:
  11287. * 1. Install certification preocess and response
  11288. */
  11289. strcpy((char*)ShmOCPP20Data->InstallCertificate.Response_status, InstallCertificateStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  11290. sendInstallCertificateConfirmation(uuid);
  11291. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11292. return result;
  11293. }
  11294. int handlePublishFirmwareRequest(char *uuid, char *payload)
  11295. {
  11296. mtrace();
  11297. int result = FAIL;
  11298. json_object *PublishFirmware;
  11299. DEBUG_INFO("handlePublishFirmwareRequest...\n");
  11300. PublishFirmware = json_tokener_parse(payload);
  11301. if(!is_error(PublishFirmware))
  11302. {
  11303. memset(&ShmOCPP20Data->PublishFirmware, 0, sizeof(struct PublishFirmware_20));
  11304. memcpy(&ShmOCPP20Data->PublishFirmware.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->PublishFirmware.guid));
  11305. // Required data
  11306. if(json_object_object_get(PublishFirmware, "requestId") != NULL)
  11307. {
  11308. ShmOCPP20Data->PublishFirmware.requestId = json_object_get_int(json_object_object_get(PublishFirmware, "requestId"));
  11309. }
  11310. if(json_object_object_get(PublishFirmware, "checksum") != NULL)
  11311. {
  11312. sprintf((char*)ShmOCPP20Data->PublishFirmware.requestId, "%s", json_object_get_string(json_object_object_get(PublishFirmware, "checksum")));
  11313. }
  11314. // Optional data
  11315. if(json_object_object_get(PublishFirmware, "location") != NULL)
  11316. {
  11317. sprintf((char*)ShmOCPP20Data->PublishFirmware.location, "%s", json_object_get_string(json_object_object_get(PublishFirmware, "location")));
  11318. }
  11319. if(json_object_object_get(PublishFirmware, "retries") != NULL)
  11320. {
  11321. ShmOCPP20Data->PublishFirmware.retries = json_object_get_int(json_object_object_get(PublishFirmware, "retries"));
  11322. }
  11323. if(json_object_object_get(PublishFirmware, "retryInterval") != NULL)
  11324. {
  11325. ShmOCPP20Data->PublishFirmware.retryInterval = json_object_get_int(json_object_object_get(PublishFirmware, "retryInterval"));
  11326. }
  11327. }
  11328. json_object_put(PublishFirmware);
  11329. /*
  11330. * TODO:
  11331. * 1. Publish firmware preocess and response
  11332. */
  11333. strcpy((char*)ShmOCPP20Data->PublishFirmware.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  11334. sendPublishFirmwareConfirmation(uuid);
  11335. return result;
  11336. }
  11337. int handleRemoteStartTransactionRequest(char *uuid, char *payload)
  11338. {
  11339. mtrace();
  11340. int result = FAIL;
  11341. int8_t gun_index = -1;
  11342. uint8_t isPeriodOverMax = FALSE;
  11343. uint8_t isProfileOverMax = FALSE;
  11344. uint8_t isConnectorMismatch = FALSE;
  11345. uint8_t isTxProfile = FALSE;
  11346. uint8_t existProfileQuantity = 0;
  11347. uint8_t filename[128]={0};
  11348. uint8_t word[2048]={0};
  11349. FILE *filePtr;
  11350. json_object *RemoteStartTransaction;
  11351. DEBUG_INFO("handleRemoteStartTransactionRequest...\n");
  11352. RemoteStartTransaction = json_tokener_parse(payload);
  11353. if(!is_error(RemoteStartTransaction))
  11354. {
  11355. if(json_object_object_get(RemoteStartTransaction, "evseId") != NULL)
  11356. {
  11357. gun_index = json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"));
  11358. }
  11359. else
  11360. {
  11361. /*
  11362. * TODO:
  11363. * 1. Selected connector process
  11364. */
  11365. gun_index = 0;
  11366. }
  11367. memset(&ShmOCPP20Data->RequestStartTransaction[gun_index], 0, sizeof(struct RequestStartTransaction_20));
  11368. memcpy(&ShmOCPP20Data->RequestStartTransaction[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->RequestStartTransaction[gun_index].guid));
  11369. // Required data
  11370. if(json_object_object_get(RemoteStartTransaction, "remoteStartId") != NULL)
  11371. {
  11372. ShmOCPP20Data->RequestStartTransaction[gun_index].remoteStartId = json_object_get_int(json_object_object_get(RemoteStartTransaction, "remoteStartId"));
  11373. }
  11374. if(json_object_object_get(RemoteStartTransaction, "idToken") != NULL)
  11375. {
  11376. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken") != NULL)
  11377. {
  11378. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken")));
  11379. }
  11380. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type") != NULL)
  11381. {
  11382. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type")));
  11383. }
  11384. }
  11385. // Optional data
  11386. if(json_object_object_get(RemoteStartTransaction, "groupIdToken") != NULL)
  11387. {
  11388. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken") != NULL)
  11389. {
  11390. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken")));
  11391. }
  11392. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type") != NULL)
  11393. {
  11394. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type")));
  11395. }
  11396. }
  11397. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11398. {
  11399. // Check periods is over max configuration
  11400. if(json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod")) > 10)
  11401. {
  11402. isPeriodOverMax = TRUE;
  11403. }
  11404. // Check periods is over max configuration
  11405. if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  11406. {
  11407. if(gun_index > 0)
  11408. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", gun_index);
  11409. else
  11410. isConnectorMismatch = TRUE;
  11411. if(!isConnectorMismatch)
  11412. {
  11413. filePtr = fopen((char*)filename, "r");
  11414. if (!filePtr)
  11415. {
  11416. DEBUG_INFO("%s not exist, create it.\n", filename);
  11417. filePtr = fopen((char*)filename, "w+");
  11418. }
  11419. else
  11420. {
  11421. //Check Charging Profile Count
  11422. while(fscanf(filePtr, "%s", word) != EOF)
  11423. {
  11424. //DEBUG_INFO("word=%s\n",word);
  11425. if(strstr((char*)word, "chargingProfileId")!= NULL)
  11426. {
  11427. existProfileQuantity += 1;
  11428. }
  11429. }
  11430. }
  11431. fclose(filePtr);
  11432. }
  11433. }
  11434. else
  11435. {
  11436. }
  11437. if(existProfileQuantity > 3)
  11438. isProfileOverMax = TRUE;
  11439. }
  11440. // Profile replace or add info
  11441. if((gun_index > 0) && !isPeriodOverMax && !isProfileOverMax && !isConnectorMismatch && !isTxProfile)
  11442. {
  11443. FILE *infile;
  11444. FILE *outfile;
  11445. char tmpProfileName[32];
  11446. char rmFileCmd[128];
  11447. char tempchargingProfilePurposeStr[30]={0};
  11448. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  11449. sprintf((char*)tmpProfileName, "/Storage/OCPP/tmpProfileRemote");
  11450. infile = fopen ((char*)filename, "r");
  11451. outfile = fopen ((char*)tmpProfileName, "w");
  11452. int d = fgetc(infile);
  11453. rewind(infile);
  11454. if(d == EOF)
  11455. {
  11456. // Profile is empty
  11457. fprintf(outfile,"%s\n", payload);
  11458. fclose(infile);
  11459. fclose(outfile);
  11460. sprintf(rmFileCmd,"rm -f %s",filename);
  11461. system(rmFileCmd);
  11462. rename((char*)tmpProfileName, (char*)filename);
  11463. }
  11464. else
  11465. {
  11466. // Profile is not empty
  11467. char buf[2048]={0};
  11468. int ChargingProfileAdded = FALSE;
  11469. while (fgets(buf, sizeof(buf), infile) != NULL)
  11470. {
  11471. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  11472. json_object *tmpChargingProfile;
  11473. tmpChargingProfile = json_tokener_parse(buf);
  11474. if(!is_error(tmpChargingProfile))
  11475. {
  11476. if(json_object_object_get(tmpChargingProfile, "evseId") != NULL)
  11477. {
  11478. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "evseId") );
  11479. }
  11480. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  11481. {
  11482. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11483. {
  11484. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11485. }
  11486. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11487. {
  11488. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  11489. }
  11490. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11491. {
  11492. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11493. }
  11494. }
  11495. }
  11496. json_object_put(tmpChargingProfile);
  11497. if((tempconnectorIdInt == gun_index) &&
  11498. (tempchargingProfileIdInt == json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "csChargingProfiles"), "chargingProfileId"))))
  11499. {
  11500. if((tempstackLevelInt == json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "csChargingProfiles"), "stackLevel"))) &&
  11501. (strcmp(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "csChargingProfiles"), "chargingProfilePurpose"))) == 0))
  11502. {
  11503. if(ChargingProfileAdded == FALSE)
  11504. {
  11505. fprintf(outfile,"%s\n",payload);
  11506. ChargingProfileAdded = TRUE;
  11507. }
  11508. }
  11509. else
  11510. {
  11511. if(tempstackLevelInt < json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "csChargingProfiles"), "stackLevel")))
  11512. {
  11513. if(ChargingProfileAdded == FALSE)
  11514. {
  11515. fprintf(outfile,"%s\n",buf);
  11516. fprintf(outfile,"%s\n",payload);
  11517. ChargingProfileAdded = TRUE;
  11518. }
  11519. else
  11520. {
  11521. fprintf(outfile,"%s\n",buf);
  11522. }
  11523. }
  11524. else
  11525. {
  11526. if(ChargingProfileAdded == FALSE)
  11527. {
  11528. fprintf(outfile,"%s\n",buf);
  11529. fprintf(outfile,"%s\n",payload);
  11530. ChargingProfileAdded = TRUE;
  11531. }
  11532. else
  11533. {
  11534. fprintf(outfile,"%s\n",buf);
  11535. }
  11536. }
  11537. }
  11538. }
  11539. else
  11540. {
  11541. if(tempchargingProfileIdInt < json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "csChargingProfiles"), "chargingProfileId")))
  11542. {
  11543. if(ChargingProfileAdded == FALSE)
  11544. {
  11545. fprintf(outfile,"%s\n",buf);
  11546. fprintf(outfile,"%s\n",payload);
  11547. ChargingProfileAdded = TRUE;
  11548. }
  11549. else
  11550. {
  11551. fprintf(outfile,"%s\n",buf);
  11552. }
  11553. }
  11554. else if(tempstackLevelInt < json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "csChargingProfiles"), "stackLevel")))
  11555. {
  11556. if(ChargingProfileAdded == FALSE)
  11557. {
  11558. fprintf(outfile,"%s\n",buf);
  11559. fprintf(outfile,"%s\n",payload);
  11560. ChargingProfileAdded = TRUE;
  11561. }
  11562. else
  11563. {
  11564. fprintf(outfile,"%s\n",buf);
  11565. }
  11566. }
  11567. else
  11568. {
  11569. if(ChargingProfileAdded == FALSE)
  11570. {
  11571. fprintf(outfile,"%s\n",buf);
  11572. fprintf(outfile,"%s\n",payload);
  11573. ChargingProfileAdded = TRUE;
  11574. }
  11575. else
  11576. {
  11577. fprintf(outfile,"%s\n",buf);
  11578. }
  11579. }
  11580. }
  11581. } // end of while loop
  11582. fclose(infile);
  11583. fclose(outfile);
  11584. sprintf(rmFileCmd,"rm -f %s",filename);
  11585. system(rmFileCmd);
  11586. rename((char*)tmpProfileName, (char*)filename);
  11587. }
  11588. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[(gun_index==0?gun_index:gun_index-1)].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted] );
  11589. random_uuid((char*)ShmOCPP20Data->RequestStartTransaction[(gun_index==0?gun_index:gun_index-1)].Response_transactionId);
  11590. result = PASS;
  11591. }
  11592. else
  11593. {
  11594. if(gun_index <= 0)
  11595. DEBUG_WARN("Connector id is wrong.\n");
  11596. if(isConnectorMismatch)
  11597. DEBUG_WARN("Connector id is mismatch.\n");
  11598. if(isPeriodOverMax)
  11599. DEBUG_WARN("Profile periods quantity is over spec.\n");
  11600. if(isProfileOverMax)
  11601. DEBUG_WARN("Profile quantity is over spec.\n");
  11602. if(!isTxProfile)
  11603. DEBUG_WARN("Profile purpose is not TxProfile.\n");
  11604. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[(gun_index==0?gun_index:gun_index-1)].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected] );
  11605. }
  11606. }
  11607. json_object_put(RemoteStartTransaction);
  11608. sendRemoteStartTransactionConfirmation(uuid, gun_index);
  11609. return result;
  11610. }
  11611. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11612. {
  11613. mtrace();
  11614. int result = FAIL;
  11615. int match = FALSE;
  11616. int GunNO = 0;
  11617. int tempIndex = 0;
  11618. char transactionIdStr[37];
  11619. int transactionIdIsNULL= TRUE;
  11620. json_object *RemoteStopTransaction;
  11621. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11622. if(server_pending == TRUE)
  11623. {
  11624. return 0;
  11625. }
  11626. RemoteStopTransaction = json_tokener_parse(payload);
  11627. if(!is_error(RemoteStopTransaction))
  11628. {
  11629. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11630. {
  11631. sprintf(transactionIdStr, "%s", json_object_get_string(json_object_object_get(RemoteStopTransaction, "transactionId")));
  11632. transactionIdIsNULL = FALSE;
  11633. }
  11634. }
  11635. json_object_put(RemoteStopTransaction);
  11636. if(transactionIdIsNULL == FALSE)
  11637. {
  11638. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11639. {
  11640. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, transactionIdStr) != NULL)
  11641. {
  11642. //check Transaction active
  11643. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11644. {
  11645. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11646. {
  11647. tempIndex = ((gun_index==2) ? 1: 0);
  11648. }
  11649. else
  11650. {
  11651. tempIndex = gun_index;
  11652. }
  11653. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11654. {
  11655. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11656. {
  11657. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11658. {
  11659. match = TRUE;
  11660. GunNO = gun_index;
  11661. }
  11662. }
  11663. }// END FOR CHAdeMO_QUANTITY
  11664. }
  11665. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11666. {
  11667. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11668. {
  11669. tempIndex = ((gun_index==2) ? 1: 0);
  11670. }
  11671. else
  11672. {
  11673. tempIndex = gun_index;
  11674. }
  11675. for (int index = 0; index < CCS_QUANTITY; index++)
  11676. {
  11677. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11678. {
  11679. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11680. {
  11681. match = TRUE;
  11682. GunNO = gun_index;
  11683. }
  11684. }
  11685. }// END FOR CCS_QUANTITY
  11686. }
  11687. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11688. {
  11689. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11690. {
  11691. tempIndex = ((gun_index==2) ? 1: 0);
  11692. }
  11693. else
  11694. {
  11695. tempIndex = gun_index;
  11696. }
  11697. for (int index = 0; index < GB_QUANTITY; index++)
  11698. {
  11699. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11700. {
  11701. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11702. {
  11703. match = TRUE;
  11704. GunNO = gun_index;
  11705. }
  11706. }
  11707. }// END FOR GB_QUANTITY
  11708. }
  11709. else if(gunType[gun_index] == GUN_TYPE_DO)
  11710. {
  11711. tempIndex = gun_index;
  11712. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11713. {
  11714. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11715. {
  11716. 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
  11717. {
  11718. match = TRUE;
  11719. GunNO = gun_index;
  11720. }
  11721. }
  11722. }// END FOR GB_QUANTITY
  11723. }
  11724. else
  11725. {
  11726. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11727. {
  11728. tempIndex = 2;
  11729. }
  11730. else
  11731. {
  11732. tempIndex = gun_index;
  11733. }
  11734. for (int index = 0; index < AC_QUANTITY; index++)
  11735. {
  11736. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11737. {
  11738. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11739. {
  11740. match = TRUE;
  11741. GunNO = gun_index;
  11742. }
  11743. }
  11744. }// END FOR CHAdeMO_QUANTITY
  11745. } // END FOR AC ELSE
  11746. }// CHECK IF ResponseTransactionId == transactionIdInt
  11747. }//END FOR
  11748. if( match == TRUE)
  11749. {
  11750. ShmOCPP20Data->CsMsg.bits[GunNO].RequestStopTransactionReq = ON; // inform csu of StopTransaction
  11751. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  11752. }
  11753. else
  11754. {
  11755. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  11756. }
  11757. }
  11758. else
  11759. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  11760. sendRemoteStopTransactionConfirmation(uuid, GunNO);
  11761. return result;
  11762. }
  11763. int handleReserveNowRequest(char *uuid, char *payload)
  11764. {
  11765. mtrace();
  11766. int result = FAIL;
  11767. int connectorIdInt=0, reservationIdInt=0;
  11768. int tempIndex = 0;
  11769. json_object *ReserveNow;
  11770. DEBUG_INFO("handleReserveNowRequest ...\n");
  11771. ReserveNow = json_tokener_parse(payload);
  11772. if(!is_error(ReserveNow))
  11773. {
  11774. if(json_object_object_get(ReserveNow, "evseId") != NULL)
  11775. {
  11776. connectorIdInt = json_object_get_int(json_object_object_get(ReserveNow, "evseId"));
  11777. connectorIdInt = (connectorIdInt==0)?1:connectorIdInt;
  11778. memset(&ShmOCPP20Data->ReserveNow[connectorIdInt-1], 0x00, sizeof(struct ReserveNow_20));
  11779. ShmOCPP20Data->ReserveNow[connectorIdInt-1].evseId = json_object_get_int(json_object_object_get(ReserveNow, "evseId"));
  11780. }
  11781. // Required data
  11782. if(json_object_object_get(ReserveNow, "reservationId") != NULL)
  11783. ShmOCPP20Data->ReserveNow[connectorIdInt-1].id = json_object_get_int(json_object_object_get(ReserveNow, "reservationId"));
  11784. if(json_object_object_get(ReserveNow, "expiryDateTime") != NULL)
  11785. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].expiryDateTime, "%s", json_object_get_string(json_object_object_get(ReserveNow, "expiryDateTime")));
  11786. if(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "idToken") != NULL)
  11787. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "idToken")));
  11788. if(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "type") != NULL)
  11789. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "type")));
  11790. // Optional data
  11791. if(json_object_object_get(ReserveNow, "connectorType") != NULL)
  11792. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].connectorType, "%s", json_object_get_string(json_object_object_get(ReserveNow, "connectorType")));
  11793. if(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "idToken") != NULL)
  11794. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "idToken")));
  11795. if(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "type") != NULL)
  11796. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "type")));
  11797. result = PASS;
  11798. }
  11799. json_object_put(ReserveNow);
  11800. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  11801. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  11802. {
  11803. //check Transaction active
  11804. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  11805. {
  11806. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11807. {
  11808. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11809. }
  11810. else
  11811. {
  11812. tempIndex = connectorIdInt -1;
  11813. }
  11814. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11815. {
  11816. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11817. {
  11818. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  11819. {
  11820. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11821. {
  11822. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11823. {
  11824. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  11825. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  11826. }
  11827. 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'))
  11828. {
  11829. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  11830. }
  11831. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11832. {
  11833. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  11834. }
  11835. else
  11836. {
  11837. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  11838. }
  11839. }
  11840. 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
  11841. {
  11842. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  11843. }
  11844. }
  11845. else
  11846. {
  11847. //replace reservation
  11848. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  11849. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  11850. }
  11851. }
  11852. } // END FOR CHAdeMO_QUANTITY
  11853. }
  11854. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  11855. {
  11856. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11857. {
  11858. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11859. }
  11860. else
  11861. {
  11862. tempIndex = connectorIdInt -1;
  11863. }
  11864. for (int index = 0; index < CCS_QUANTITY; index++)
  11865. {
  11866. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11867. {
  11868. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  11869. {
  11870. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11871. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  11872. {
  11873. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11874. {
  11875. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  11876. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  11877. }
  11878. 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'))
  11879. {
  11880. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  11881. }
  11882. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  11883. {
  11884. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  11885. }
  11886. else
  11887. {
  11888. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  11889. }
  11890. }
  11891. 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
  11892. {
  11893. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  11894. }
  11895. }
  11896. else
  11897. {
  11898. //replace reservation
  11899. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  11900. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  11901. }
  11902. }
  11903. } // END FOR CCS_QUANTITY
  11904. }
  11905. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  11906. {
  11907. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11908. {
  11909. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  11910. }
  11911. else
  11912. {
  11913. tempIndex = connectorIdInt -1;
  11914. }
  11915. for (int index = 0; index < GB_QUANTITY; index++)
  11916. {
  11917. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11918. {
  11919. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  11920. {
  11921. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11922. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  11923. {
  11924. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11925. {
  11926. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  11927. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  11928. }
  11929. 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'))
  11930. {
  11931. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  11932. }
  11933. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11934. {
  11935. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  11936. }
  11937. else
  11938. {
  11939. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  11940. }
  11941. }
  11942. 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
  11943. {
  11944. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  11945. }
  11946. }
  11947. else
  11948. {
  11949. //replace reservation
  11950. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  11951. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  11952. }
  11953. }
  11954. }// END FOR GB_QUANTITY
  11955. }
  11956. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  11957. {
  11958. tempIndex = connectorIdInt -1;
  11959. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11960. {
  11961. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11962. {
  11963. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  11964. {
  11965. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  11966. 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
  11967. {
  11968. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  11969. {
  11970. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  11971. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  11972. }
  11973. 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'))
  11974. {
  11975. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  11976. }
  11977. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  11978. {
  11979. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  11980. }
  11981. else
  11982. {
  11983. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  11984. }
  11985. }
  11986. 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
  11987. {
  11988. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  11989. }
  11990. }
  11991. else
  11992. {
  11993. //replace reservation
  11994. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  11995. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  11996. }
  11997. }
  11998. }// END FOR DO_QUANTITY
  11999. }
  12000. else
  12001. {
  12002. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12003. {
  12004. tempIndex = 2;
  12005. }
  12006. else
  12007. {
  12008. tempIndex = (connectorIdInt -1);
  12009. }
  12010. for (int index = 0; index < AC_QUANTITY; index++)
  12011. {
  12012. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12013. {
  12014. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12015. {
  12016. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12017. {
  12018. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12019. {
  12020. 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))
  12021. {
  12022. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  12023. }
  12024. else
  12025. {
  12026. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  12027. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  12028. }
  12029. }
  12030. 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'))
  12031. {
  12032. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  12033. }
  12034. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12035. {
  12036. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  12037. }
  12038. else
  12039. {
  12040. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  12041. }
  12042. }
  12043. 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
  12044. {
  12045. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  12046. }
  12047. }
  12048. else
  12049. {
  12050. //replace reservation
  12051. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  12052. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  12053. }
  12054. }
  12055. } // END FOR AC_QUANTITY
  12056. }
  12057. }
  12058. else if(connectorIdInt == 0)
  12059. {
  12060. //check Transaction active
  12061. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12062. {
  12063. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12064. {
  12065. 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'))
  12066. {
  12067. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  12068. goto end;
  12069. }
  12070. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12071. {
  12072. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  12073. goto end;
  12074. }
  12075. 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
  12076. {
  12077. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  12078. goto end;
  12079. }
  12080. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12081. {
  12082. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  12083. goto end;
  12084. }
  12085. }
  12086. }// END FOR CHAdeMO_QUANTITY
  12087. for (int index = 0; index < CCS_QUANTITY; index++)
  12088. {
  12089. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12090. {
  12091. 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'))
  12092. {
  12093. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  12094. goto end;
  12095. }
  12096. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  12097. {
  12098. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  12099. goto end;
  12100. }
  12101. 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
  12102. {
  12103. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  12104. goto end;
  12105. }
  12106. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12107. {
  12108. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  12109. goto end;
  12110. }
  12111. }
  12112. } // END FOR CCS_QUANTITY
  12113. for (int index = 0; index < GB_QUANTITY; index++)
  12114. {
  12115. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12116. {
  12117. 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'))
  12118. {
  12119. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  12120. goto end;
  12121. }
  12122. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12123. {
  12124. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  12125. goto end;
  12126. }
  12127. 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
  12128. {
  12129. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  12130. goto end;
  12131. }
  12132. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12133. {
  12134. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  12135. goto end;
  12136. }
  12137. }
  12138. } // END FOR GB_QUANTITY
  12139. for (int index = 0; index < AC_QUANTITY; index++)
  12140. {
  12141. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12142. {
  12143. 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'))
  12144. {
  12145. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  12146. goto end;
  12147. }
  12148. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12149. {
  12150. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  12151. goto end;
  12152. }
  12153. 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
  12154. {
  12155. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  12156. goto end;
  12157. }
  12158. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12159. {
  12160. 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))
  12161. {
  12162. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  12163. goto end;
  12164. }
  12165. }
  12166. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12167. {
  12168. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  12169. goto end;
  12170. }
  12171. }
  12172. }// END FOR AC_QUANTITY
  12173. //The connectorId is 0
  12174. ShmOCPP20Data->CsMsg.bits[0].ReserveNowReq = ON;
  12175. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  12176. strcpy((char *)ShmOCPP20Data->ReserveNow[0].guid, uuid);
  12177. result = TRUE;
  12178. return result;
  12179. }
  12180. else
  12181. {
  12182. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  12183. }
  12184. if(strcmp((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status,ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]) == 0)
  12185. {
  12186. strcpy((char *)ShmOCPP20Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12187. result = TRUE;
  12188. return result;
  12189. }
  12190. end:
  12191. sendReserveNowConfirmation(uuid, (connectorIdInt==0?connectorIdInt:connectorIdInt-1));
  12192. return result;
  12193. }
  12194. int handleResetRequest(char *uuid, char *payload)
  12195. {
  12196. mtrace();
  12197. int result = FAIL;
  12198. json_object *Reset = json_object_new_object();
  12199. DEBUG_INFO("handleResetRequest...\n");
  12200. Reset = json_tokener_parse(payload);
  12201. if(!is_error(Reset))
  12202. {
  12203. // Required data
  12204. if(json_object_object_get(Reset, "type") != NULL)
  12205. {
  12206. sprintf((char*)ShmOCPP20Data->Reset.type, "%s", json_object_get_string(json_object_object_get(Reset, "type")));
  12207. }
  12208. if(json_object_object_get(Reset, "evseId") != NULL)
  12209. {
  12210. ShmOCPP20Data->Reset.evseId = json_object_get_int(json_object_object_get(Reset, "evseId"));
  12211. }
  12212. }
  12213. json_object_put(Reset);
  12214. if((strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_Immediate])==0) || (strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_OnIdle])==0))
  12215. {
  12216. strcpy((char *)ShmOCPP20Data->Reset.guid, uuid);
  12217. strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]);
  12218. ShmOCPP20Data->MsMsg.bits.ResetReq = ON;
  12219. result = PASS;
  12220. }
  12221. else
  12222. {
  12223. strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Rejected]);
  12224. }
  12225. if(strlen((char*)ShmOCPP20Data->Reset.Response_status) > 0)
  12226. sendResetConfirmation(uuid);
  12227. return result;
  12228. }
  12229. int handleSendLocalListRequest(char *uuid, char *payload)
  12230. {
  12231. mtrace();
  12232. int result = FAIL;
  12233. char updateTypestr[15]={0};
  12234. int checkState_Faulted = FALSE;
  12235. json_object *SendLocalList;
  12236. DEBUG_INFO("handleSendLocalListRequest...\n");
  12237. if(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "FALSE") == 0)
  12238. {
  12239. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  12240. goto end;
  12241. }
  12242. SendLocalList = json_tokener_parse(payload);
  12243. if(!is_error(SendLocalList))
  12244. {
  12245. memset(&ShmOCPP20Data->SendLocalList, 0x00, sizeof(struct SendLocalList_20));
  12246. // Required data
  12247. if(json_object_object_get(SendLocalList, "versionNumber") != NULL)
  12248. {
  12249. ShmOCPP20Data->SendLocalList.versionNumber = json_object_get_int(json_object_object_get(SendLocalList, "versionNumber"));
  12250. }
  12251. if(json_object_object_get(SendLocalList, "updateType") != NULL)
  12252. sprintf((char*)ShmOCPP20Data->SendLocalList.updateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12253. // Optional data
  12254. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12255. {
  12256. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12257. {
  12258. // Required data
  12259. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idToken") != NULL)
  12260. {
  12261. 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")));
  12262. 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")));
  12263. }
  12264. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12265. {
  12266. 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")));
  12267. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "cacheExpiryDateTime") != NULL)
  12268. 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")));
  12269. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "chargingPriority") != NULL)
  12270. 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"));
  12271. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "groupIdToken") != NULL)
  12272. {
  12273. 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")));
  12274. 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")));
  12275. }
  12276. }
  12277. }
  12278. }
  12279. }
  12280. json_object_put(SendLocalList);
  12281. //check Charge Point state
  12282. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12283. {
  12284. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12285. {
  12286. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12287. }
  12288. }
  12289. for (int index = 0; index < CCS_QUANTITY; index++)
  12290. {
  12291. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12292. {
  12293. checkState_Faulted = TRUE; //OCPP Status
  12294. }
  12295. }
  12296. for (int index = 0; index < GB_QUANTITY; index++)
  12297. {
  12298. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12299. {
  12300. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12301. }
  12302. }
  12303. for (int index = 0; index < AC_QUANTITY; index++)
  12304. {
  12305. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12306. {
  12307. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12308. }
  12309. }
  12310. if(checkState_Faulted == TRUE)
  12311. {
  12312. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  12313. goto end;
  12314. }
  12315. // Check update type
  12316. if(strcmp(updateTypestr, UpdateEnumTypeStr[UpdateEnumType_Full]) == 0)
  12317. {
  12318. //Local list full update
  12319. DEBUG_INFO("Local list full update.\n");
  12320. DB_getListVerion();
  12321. if(ShmOCPP20Data->SendLocalList.versionNumber < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  12322. {
  12323. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  12324. goto end;
  12325. }
  12326. DB_cleanLocalList();
  12327. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->SendLocalList.localAuthorizationList);idx++)
  12328. DB_addLocalList(ShmOCPP20Data->SendLocalList.versionNumber, &ShmOCPP20Data->SendLocalList.localAuthorizationList[idx]);
  12329. }
  12330. else if(strcmp(updateTypestr, UpdateEnumTypeStr[UpdateEnumType_Differential]) == 0)
  12331. {
  12332. //Local list different update
  12333. DEBUG_INFO("Local list different update.\n");
  12334. DB_getListVerion();
  12335. if(ShmOCPP20Data->SendLocalList.versionNumber < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  12336. {
  12337. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_VersionMismatch]);
  12338. goto end;
  12339. }
  12340. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->SendLocalList.localAuthorizationList);idx++)
  12341. DB_addLocalList(ShmOCPP20Data->SendLocalList.versionNumber, &ShmOCPP20Data->SendLocalList.localAuthorizationList[idx]);
  12342. }
  12343. else
  12344. {
  12345. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  12346. goto end;
  12347. }
  12348. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Accepted]);
  12349. end:
  12350. sendSendLocalListConfirmation(uuid);
  12351. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12352. return result;
  12353. }
  12354. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12355. {
  12356. mtrace();
  12357. int result = FAIL;
  12358. int8_t gun_index = -1;
  12359. uint8_t isPeriodOverMax = FALSE;
  12360. uint8_t isProfileOverMax = FALSE;
  12361. uint8_t isConnectorMismatch = FALSE;
  12362. uint8_t existProfileQuantity = 0;
  12363. uint8_t filename[128]={0};
  12364. uint8_t word[2048]={0};
  12365. FILE *filePtr;
  12366. json_object *SetChargingProfile;
  12367. DEBUG_INFO("handleSetChargingProfileRequest...\n");
  12368. SetChargingProfile = json_tokener_parse(payload);
  12369. if(!is_error(SetChargingProfile))
  12370. {
  12371. // Required data
  12372. if(json_object_object_get(SetChargingProfile, "evseId") != NULL)
  12373. {
  12374. gun_index = json_object_get_int(json_object_object_get(SetChargingProfile, "evseId"));
  12375. }
  12376. if(json_object_object_get(SetChargingProfile, "chargingProfile") != NULL)
  12377. {
  12378. // Check periods is over max configuration
  12379. if(json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod")) > 10)
  12380. {
  12381. isPeriodOverMax = TRUE;
  12382. }
  12383. // Check periods is over max configuration
  12384. if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL)
  12385. {
  12386. if(gun_index == 0)
  12387. {
  12388. sprintf((char*)filename, ChargePointMaxProfile_JSON);
  12389. filePtr = fopen((char*)filename, "r");
  12390. if (!filePtr)
  12391. {
  12392. DEBUG_INFO("%s not exist, create it.\n", ChargePointMaxProfile_JSON);
  12393. filePtr = fopen((char*)filename, "w+");
  12394. }
  12395. else
  12396. {
  12397. //Check Charging Profile Count
  12398. while(fscanf(filePtr, "%s", word) != EOF)
  12399. {
  12400. //DEBUG_INFO("word=%s\n",word);
  12401. if(strstr((char*)word, "chargingProfileId")!= NULL)
  12402. {
  12403. existProfileQuantity += 1;
  12404. }
  12405. }
  12406. }
  12407. fclose(filePtr);
  12408. }
  12409. else
  12410. isConnectorMismatch = TRUE;
  12411. }
  12412. else if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) != NULL)
  12413. {
  12414. if(gun_index < 5)
  12415. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", gun_index);
  12416. else
  12417. isConnectorMismatch = TRUE;
  12418. if(!isConnectorMismatch)
  12419. {
  12420. filePtr = fopen((char*)filename, "r");
  12421. if (!filePtr)
  12422. {
  12423. DEBUG_INFO("%s not exist, create it.\n", filename);
  12424. filePtr = fopen((char*)filename, "w+");
  12425. }
  12426. else
  12427. {
  12428. //Check Charging Profile Count
  12429. while(fscanf(filePtr, "%s", word) != EOF)
  12430. {
  12431. //DEBUG_INFO("word=%s\n",word);
  12432. if(strstr((char*)word, "chargingProfileId")!= NULL)
  12433. {
  12434. existProfileQuantity += 1;
  12435. }
  12436. }
  12437. }
  12438. fclose(filePtr);
  12439. }
  12440. }
  12441. else if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  12442. {
  12443. if(gun_index>0)
  12444. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", gun_index);
  12445. else
  12446. isConnectorMismatch = TRUE;
  12447. if(!isConnectorMismatch)
  12448. {
  12449. filePtr = fopen((char*)filename, "r");
  12450. if (!filePtr)
  12451. {
  12452. DEBUG_INFO("%s not exist, create it.\n", filename);
  12453. filePtr = fopen((char*)filename, "w+");
  12454. }
  12455. else
  12456. {
  12457. //Check Charging Profile Count
  12458. while(fscanf(filePtr, "%s", word) != EOF)
  12459. {
  12460. //DEBUG_INFO("word=%s\n",word);
  12461. if(strstr((char*)word, "chargingProfileId")!= NULL)
  12462. {
  12463. existProfileQuantity += 1;
  12464. }
  12465. }
  12466. }
  12467. fclose(filePtr);
  12468. }
  12469. }
  12470. else if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationExternalConstraints]) != NULL)
  12471. {
  12472. }
  12473. else
  12474. {
  12475. }
  12476. if(existProfileQuantity > 3)
  12477. isProfileOverMax = TRUE;
  12478. }
  12479. // Profile replace or add info
  12480. if((gun_index > -1) && !isPeriodOverMax && !isProfileOverMax && !isConnectorMismatch)
  12481. {
  12482. FILE *infile;
  12483. FILE *outfile;
  12484. char tmpProfileName[32];
  12485. char rmFileCmd[128];
  12486. char tempchargingProfilePurposeStr[30]={0};
  12487. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  12488. sprintf((char*)tmpProfileName, "/Storage/OCPP/tmpProfile");
  12489. infile = fopen ((char*)filename, "r");
  12490. outfile = fopen ((char*)tmpProfileName, "w");
  12491. int d = fgetc(infile);
  12492. rewind(infile);
  12493. if(d == EOF)
  12494. {
  12495. // Profile is empty
  12496. fprintf(outfile,"%s\n", payload);
  12497. fclose(infile);
  12498. fclose(outfile);
  12499. sprintf(rmFileCmd,"rm -f %s",filename);
  12500. system(rmFileCmd);
  12501. rename((char*)tmpProfileName, (char*)filename);
  12502. }
  12503. else
  12504. {
  12505. // Profile is not empty
  12506. char buf[2048]={0};
  12507. int ChargingProfileAdded = FALSE;
  12508. while (fgets(buf, sizeof(buf), infile) != NULL)
  12509. {
  12510. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  12511. json_object *tmpChargingProfile;
  12512. tmpChargingProfile = json_tokener_parse(buf);
  12513. if(!is_error(tmpChargingProfile))
  12514. {
  12515. if(json_object_object_get(tmpChargingProfile, "evseId") != NULL)
  12516. {
  12517. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "evseId") );
  12518. }
  12519. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12520. {
  12521. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12522. {
  12523. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12524. }
  12525. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12526. {
  12527. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12528. }
  12529. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12530. {
  12531. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12532. }
  12533. }
  12534. }
  12535. json_object_put(tmpChargingProfile);
  12536. if((tempconnectorIdInt == gun_index) &&
  12537. (tempchargingProfileIdInt == json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"))))
  12538. {
  12539. if((tempstackLevelInt == json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"))) &&
  12540. (strcmp(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose"))) == 0))
  12541. {
  12542. //DEBUG_INFO("update set chargingProfile to file -0\n");
  12543. if(ChargingProfileAdded == FALSE)
  12544. {
  12545. fprintf(outfile,"%s\n",payload);
  12546. ChargingProfileAdded = TRUE;
  12547. }
  12548. }
  12549. else
  12550. {
  12551. if(tempstackLevelInt < json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel")))
  12552. {
  12553. if(ChargingProfileAdded == FALSE)
  12554. {
  12555. fprintf(outfile,"%s\n",buf);
  12556. fprintf(outfile,"%s\n",payload);
  12557. ChargingProfileAdded = TRUE;
  12558. }
  12559. else
  12560. {
  12561. fprintf(outfile,"%s\n",buf);
  12562. }
  12563. }
  12564. else
  12565. {
  12566. if(ChargingProfileAdded == FALSE)
  12567. {
  12568. fprintf(outfile,"%s\n",buf);
  12569. fprintf(outfile,"%s\n",payload);
  12570. ChargingProfileAdded = TRUE;
  12571. }
  12572. else
  12573. {
  12574. fprintf(outfile,"%s\n",buf);
  12575. }
  12576. }
  12577. }
  12578. }
  12579. else
  12580. {
  12581. if(tempchargingProfileIdInt < json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId")))
  12582. {
  12583. if(ChargingProfileAdded == FALSE)
  12584. {
  12585. fprintf(outfile,"%s\n",buf);
  12586. fprintf(outfile,"%s\n",payload);
  12587. ChargingProfileAdded = TRUE;
  12588. }
  12589. else
  12590. {
  12591. fprintf(outfile,"%s\n",buf);
  12592. }
  12593. }
  12594. else if(tempstackLevelInt < json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel")))
  12595. {
  12596. if(ChargingProfileAdded == FALSE)
  12597. {
  12598. fprintf(outfile,"%s\n",buf);
  12599. fprintf(outfile,"%s\n",payload);
  12600. ChargingProfileAdded = TRUE;
  12601. }
  12602. else
  12603. {
  12604. fprintf(outfile,"%s\n",buf);
  12605. }
  12606. }
  12607. else
  12608. {
  12609. if(ChargingProfileAdded == FALSE)
  12610. {
  12611. fprintf(outfile,"%s\n",buf);
  12612. fprintf(outfile,"%s\n",payload);
  12613. ChargingProfileAdded = TRUE;
  12614. }
  12615. else
  12616. {
  12617. fprintf(outfile,"%s\n",buf);
  12618. }
  12619. }
  12620. }
  12621. } // end of while loop
  12622. fclose(infile);
  12623. fclose(outfile);
  12624. sprintf(rmFileCmd,"rm -f %s",filename);
  12625. system(rmFileCmd);
  12626. rename((char*)tmpProfileName, (char*)filename);
  12627. }
  12628. sprintf((char*)ShmOCPP20Data->SetChargingProfile[(gun_index==0?gun_index:gun_index-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted] );
  12629. result = PASS;
  12630. }
  12631. else
  12632. {
  12633. if(gun_index == -1)
  12634. DEBUG_WARN("Connector id is wrong.\n");
  12635. if(isConnectorMismatch)
  12636. DEBUG_WARN("Connector id is mismatch.\n");
  12637. if(isPeriodOverMax)
  12638. DEBUG_WARN("Profile periods quantity is over spec.\n");
  12639. if(isProfileOverMax)
  12640. DEBUG_WARN("Profile quantity is over spec.\n");
  12641. sprintf((char*)ShmOCPP20Data->SetChargingProfile[(gun_index==0?gun_index:gun_index-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Rejected] );
  12642. }
  12643. }
  12644. json_object_put(SetChargingProfile);
  12645. if(strcmp((char*)ShmOCPP20Data->SetChargingProfile[(gun_index==0?gun_index:gun_index-1)].Response_status, ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted]) == 0)
  12646. {
  12647. if(gun_index == 0)
  12648. {
  12649. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12650. {
  12651. checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx], 0, TRUE);
  12652. }
  12653. }
  12654. else
  12655. checkCompositeSchedule(gun_index, 86400, &ShmOCPP20Data->SmartChargingProfile[gun_index-1], 0, TRUE);
  12656. }
  12657. sendSetChargingProfileConfirmation(uuid, (gun_index==0?gun_index:gun_index-1));
  12658. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12659. return result;
  12660. }
  12661. int handleSetDisplayMessagesRequest(char *uuid, char *payload)
  12662. {
  12663. mtrace();
  12664. int result = FAIL;
  12665. json_object *SetDisplayMessage;
  12666. DEBUG_INFO("handleSetDisplayMessageRequest...\n");
  12667. SetDisplayMessage = json_tokener_parse(payload);
  12668. if(!is_error(SetDisplayMessage))
  12669. {
  12670. memset(&ShmOCPP20Data->SetDisplayMessage, 0, sizeof(struct SetDisplayMessage_20));
  12671. memcpy(&ShmOCPP20Data->SetDisplayMessage.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetDisplayMessage.guid));
  12672. // Required data
  12673. if(json_object_object_get(SetDisplayMessage, "message") != NULL)
  12674. {
  12675. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "id") != NULL)
  12676. ShmOCPP20Data->SetDisplayMessage.message.id = json_object_get_int(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "id"));
  12677. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "priority") != NULL)
  12678. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.priority, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "priority")));
  12679. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "state") != NULL)
  12680. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.state, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "state")));
  12681. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "startDateTime") != NULL)
  12682. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.startDateTime, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "startDateTime")));
  12683. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "endDateTime") != NULL)
  12684. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.endDateTime, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "endDateTime")));
  12685. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "transactionId") != NULL)
  12686. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.transactionId, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "transactionId")));
  12687. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message") != NULL)
  12688. {
  12689. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "format") != NULL)
  12690. 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")));
  12691. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "language") != NULL)
  12692. 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")));
  12693. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "content") != NULL)
  12694. 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")));
  12695. }
  12696. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display") != NULL)
  12697. {
  12698. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "name") != NULL)
  12699. 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")));
  12700. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "instance") != NULL)
  12701. 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")));
  12702. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse") != NULL)
  12703. {
  12704. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "id") != NULL)
  12705. 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"));
  12706. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "connectorId") != NULL)
  12707. 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"));
  12708. }
  12709. }
  12710. }
  12711. }
  12712. json_object_put(SetDisplayMessage);
  12713. strcpy((char*)ShmOCPP20Data->SetDisplayMessage.Response_status, DisplayMessageStatusEnumTypeStr[DisplayMessageStatusEnumType_Accepted]);
  12714. sendSetDisplayMessagesConfirmation(uuid);
  12715. // Announce CSU there is display request come from server
  12716. ShmOCPP20Data->MsMsg.bits.SetDisplayMessageReq = ON;
  12717. return result;
  12718. }
  12719. int handleSetMonitoringBaseRequest(char *uuid, char *payload)
  12720. {
  12721. mtrace();
  12722. int result = FAIL;
  12723. json_object *SetMonitoringBase;
  12724. DEBUG_INFO("handleSetMonitoringBaseRequest...\n");
  12725. SetMonitoringBase = json_tokener_parse(payload);
  12726. if(!is_error(SetMonitoringBase))
  12727. {
  12728. memset(&ShmOCPP20Data->SetMonitoringBase, 0, sizeof(struct SetMonitoringBase_20));
  12729. memcpy(&ShmOCPP20Data->SetMonitoringBase.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetMonitoringBase.guid));
  12730. // Required data
  12731. if(json_object_object_get(SetMonitoringBase, "monitoringBase") != NULL)
  12732. sprintf((char*)ShmOCPP20Data->SetMonitoringBase.monitoringBase, "%s",json_object_get_string(json_object_object_get(SetMonitoringBase, "monitoringBase")));
  12733. }
  12734. json_object_put(SetMonitoringBase);
  12735. /*
  12736. * TODO:
  12737. * 1. Configure monitor base and response
  12738. */
  12739. strcpy((char*)ShmOCPP20Data->SetMonitoringBase.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  12740. sendSetMonitoringBaseConfirmation(uuid);
  12741. return result;
  12742. }
  12743. int handleSetMonitoringLevelRequest(char *uuid, char *payload)
  12744. {
  12745. mtrace();
  12746. int result = FAIL;
  12747. json_object *SetMonitoringLevel;
  12748. DEBUG_INFO("handleSetMonitoringLevelRequest...\n");
  12749. SetMonitoringLevel = json_tokener_parse(payload);
  12750. if(!is_error(SetMonitoringLevel))
  12751. {
  12752. memset(&ShmOCPP20Data->SetMonitoringLevel, 0, sizeof(struct SetMonitoringLevel_20));
  12753. memcpy(&ShmOCPP20Data->SetMonitoringLevel.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetMonitoringLevel.guid));
  12754. // Required data
  12755. if(json_object_object_get(SetMonitoringLevel, "severity") != NULL)
  12756. ShmOCPP20Data->SetMonitoringLevel.severity = json_object_get_int(json_object_object_get(SetMonitoringLevel, "severity"));
  12757. }
  12758. json_object_put(SetMonitoringLevel);
  12759. /*
  12760. * TODO:
  12761. * Configure monitor status and response
  12762. */
  12763. strcpy((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  12764. sendSetMonitoringLevelConfirmation(uuid);
  12765. return result;
  12766. }
  12767. int handleSetNetworkProfileRequest(char *uuid, char *payload)
  12768. {
  12769. mtrace();
  12770. int result = FAIL;
  12771. json_object *SetNetworkProfile;
  12772. DEBUG_INFO("handleSetNetworkProfileRequest...\n");
  12773. SetNetworkProfile = json_tokener_parse(payload);
  12774. if(!is_error(SetNetworkProfile))
  12775. {
  12776. memset(&ShmOCPP20Data->SetNetworkProfile, 0, sizeof(struct SetNetworkProfile_20));
  12777. memcpy(&ShmOCPP20Data->SetNetworkProfile.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.guid));
  12778. // Required data
  12779. if(json_object_object_get(SetNetworkProfile, "configurationSlot") != NULL)
  12780. ShmOCPP20Data->SetNetworkProfile.configurationSlot = json_object_get_int(json_object_object_get(SetNetworkProfile, "configurationSlot"));
  12781. if(json_object_object_get(SetNetworkProfile, "connectionData") != NULL)
  12782. {
  12783. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppVersion") != NULL)
  12784. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppVersion")));
  12785. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport") != NULL)
  12786. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport")));
  12787. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl") != NULL)
  12788. {
  12789. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl")));
  12790. memcpy((char*)ShmOCPP20Data->OcppServerURL, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl));
  12791. }
  12792. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout") != NULL)
  12793. ShmOCPP20Data->SetNetworkProfile.connectionData.messageTimeout = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout"));
  12794. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppInterface") != NULL)
  12795. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppInterface, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppInterface")));
  12796. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn") != NULL)
  12797. {
  12798. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "server") != NULL)
  12799. 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")));
  12800. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "user") != NULL)
  12801. 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")));
  12802. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "group") != NULL)
  12803. 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")));
  12804. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "password") != NULL)
  12805. 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")));
  12806. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "key") != NULL)
  12807. 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")));
  12808. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "type") != NULL)
  12809. 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")));
  12810. }
  12811. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn") != NULL)
  12812. {
  12813. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apn") != NULL)
  12814. {
  12815. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn));
  12816. 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")));
  12817. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn);
  12818. }
  12819. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnUserName") != NULL)
  12820. {
  12821. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName));
  12822. 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")));
  12823. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName);
  12824. }
  12825. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnPassword") != NULL)
  12826. {
  12827. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword));
  12828. 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")));
  12829. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword);
  12830. }
  12831. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "simPin") != NULL)
  12832. 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"));
  12833. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "preferredNetwork") != NULL)
  12834. 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")));
  12835. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "useOnlyPreferredNetwork") != NULL)
  12836. 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"));
  12837. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnAuthentication") != NULL)
  12838. 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")));
  12839. }
  12840. DB_addNetworkProfile(ShmOCPP20Data->SetNetworkProfile.configurationSlot, (char*)json_object_get_string(json_object_object_get(SetNetworkProfile, "connectionData")));
  12841. }
  12842. }
  12843. json_object_put(SetNetworkProfile);
  12844. /*
  12845. * TODO:
  12846. * 1. Process network configuration and response
  12847. */
  12848. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP12]) == 0)
  12849. {
  12850. }
  12851. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP15]) == 0)
  12852. {
  12853. }
  12854. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP16]) == 0)
  12855. {
  12856. }
  12857. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP20]) == 0)
  12858. {
  12859. }
  12860. else
  12861. {
  12862. }
  12863. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, OCPPTransportEnumTypeStr[OCPPTransportEnumType_JSON]) == 0)
  12864. {
  12865. }
  12866. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, OCPPTransportEnumTypeStr[OCPPTransportEnumType_SOAP]) == 0)
  12867. {
  12868. }
  12869. else
  12870. {
  12871. }
  12872. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired0]) == 0)
  12873. {
  12874. }
  12875. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired1]) == 0)
  12876. {
  12877. }
  12878. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired2]) == 0)
  12879. {
  12880. }
  12881. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired3]) == 0)
  12882. {
  12883. }
  12884. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless0]) == 0)
  12885. {
  12886. }
  12887. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless1]) == 0)
  12888. {
  12889. }
  12890. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless2]) == 0)
  12891. {
  12892. }
  12893. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless3]) == 0)
  12894. {
  12895. }
  12896. else
  12897. {
  12898. }
  12899. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_IKEv2]) == 0)
  12900. {
  12901. }
  12902. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_IPSec]) == 0)
  12903. {
  12904. }
  12905. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_L2TP]) == 0)
  12906. {
  12907. }
  12908. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_PPTP]) == 0)
  12909. {
  12910. }
  12911. else
  12912. {
  12913. }
  12914. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_CHAP]) == 0)
  12915. {
  12916. }
  12917. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_NONE]) == 0)
  12918. {
  12919. }
  12920. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_PAP]) == 0)
  12921. {
  12922. }
  12923. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_AUTO]) == 0)
  12924. {
  12925. }
  12926. else
  12927. {
  12928. }
  12929. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Accepted]);
  12930. sendSetNetworkProfileConfirmation(uuid);
  12931. return result;
  12932. }
  12933. int handleSetVariableMonitoringRequest(char *uuid, char *payload)
  12934. {
  12935. mtrace();
  12936. int result = FAIL;
  12937. json_object *SetVariableMonitoring;
  12938. uint8_t variableQuantity = 0;
  12939. DEBUG_INFO("handleSetVariableMonitoringRequest...\n");
  12940. SetVariableMonitoring = json_tokener_parse(payload);
  12941. if(!is_error(SetVariableMonitoring))
  12942. {
  12943. memset(&ShmOCPP20Data->SetVariableMonitoring, 0, sizeof(struct SetVariableMonitoring_20));
  12944. memcpy(&ShmOCPP20Data->SetVariableMonitoring.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetVariableMonitoring.guid));
  12945. // Required data
  12946. for(int idx=0;idx<json_object_array_length(json_object_object_get(SetVariableMonitoring, "setMonitoringData"));idx++)
  12947. {
  12948. variableQuantity++;
  12949. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "id") != NULL)
  12950. {
  12951. 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"));
  12952. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].id = ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].id;
  12953. }
  12954. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "value") != NULL)
  12955. {
  12956. 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"));
  12957. }
  12958. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "type") != NULL)
  12959. {
  12960. 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")));
  12961. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type, (char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type);
  12962. }
  12963. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "severity") != NULL)
  12964. {
  12965. 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"));
  12966. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].severity = ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].severity;
  12967. }
  12968. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "transaction") != NULL)
  12969. {
  12970. 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"));
  12971. }
  12972. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "component") != NULL)
  12973. {
  12974. 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)
  12975. {
  12976. 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")));
  12977. }
  12978. 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)
  12979. {
  12980. 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")));
  12981. }
  12982. 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)
  12983. {
  12984. 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)
  12985. {
  12986. 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"));
  12987. }
  12988. 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)
  12989. {
  12990. 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"));
  12991. }
  12992. }
  12993. memcpy(&ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component, &ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].component, sizeof(struct ComponentType));
  12994. }
  12995. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "variable") != NULL)
  12996. {
  12997. 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)
  12998. {
  12999. 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")));
  13000. }
  13001. 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)
  13002. {
  13003. 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")));
  13004. }
  13005. memcpy(&ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable , &ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].variable, sizeof(struct VariableType));
  13006. }
  13007. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status, SetMonitoringStatusEnumTypeStr[SetMonitoringStatusEnumType_Accepted]);
  13008. }
  13009. }
  13010. json_object_put(SetVariableMonitoring);
  13011. sendSetVariableMonitoringConfirmation(uuid, variableQuantity);
  13012. return result;
  13013. }
  13014. int handleSetVariablesRequest(char *uuid, char *payload)
  13015. {
  13016. mtrace();
  13017. int result = FAIL;
  13018. json_object *SetVariables;
  13019. DEBUG_INFO("handleSetVariablesRequest...\n");
  13020. SetVariables = json_tokener_parse(payload);
  13021. if(!is_error(SetVariables))
  13022. {
  13023. memset(&ShmOCPP20Data->SetVariables, 0, sizeof(struct SetVariables_20));
  13024. memcpy(&ShmOCPP20Data->SetVariables.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetVariables.guid));
  13025. // Required data
  13026. for(int idx=0;idx<json_object_array_length(json_object_object_get(SetVariables, "setVariableData"));idx++)
  13027. {
  13028. if(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx) != NULL)
  13029. {
  13030. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component") != NULL)
  13031. {
  13032. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "name") != NULL)
  13033. {
  13034. 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")));
  13035. }
  13036. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "instance") != NULL)
  13037. {
  13038. 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")));
  13039. }
  13040. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "evse") != NULL)
  13041. {
  13042. 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)
  13043. {
  13044. 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"));
  13045. }
  13046. 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)
  13047. {
  13048. 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"));
  13049. }
  13050. }
  13051. memcpy(&ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component, &ShmOCPP20Data->SetVariables.setVariableData[idx].component, sizeof(struct ComponentType));
  13052. }
  13053. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable") != NULL)
  13054. {
  13055. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "name") != NULL)
  13056. {
  13057. 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")));
  13058. }
  13059. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "instance") != NULL)
  13060. {
  13061. 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")));
  13062. }
  13063. memcpy(&ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable , &ShmOCPP20Data->SetVariables.setVariableData[idx].variable, sizeof(struct VariableType));
  13064. }
  13065. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeType") != NULL)
  13066. {
  13067. 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")));
  13068. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeType);
  13069. }
  13070. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeValue") != NULL)
  13071. {
  13072. 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")));
  13073. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownComponent]);
  13074. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  13075. {
  13076. if((strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name) != NULL) &&
  13077. (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) &&
  13078. (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name) != NULL) &&
  13079. (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))
  13080. {
  13081. strcpy((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  13082. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[idx_var]);
  13083. if(((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL)) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "NetworkConfigurationPriority") != NULL))
  13084. {
  13085. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_RebootRequired]);
  13086. }
  13087. else
  13088. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  13089. }
  13090. }
  13091. }
  13092. }
  13093. }
  13094. sendSetVariableConfirmation(uuid, json_object_array_length(json_object_object_get(SetVariables, "setVariableData")));
  13095. }
  13096. json_object_put(SetVariables);
  13097. return result;
  13098. }
  13099. int handleTriggerMessageRequest(char *uuid, char *payload)
  13100. {
  13101. mtrace();
  13102. int result = FAIL;
  13103. int connectorIdIsNULL = FALSE;
  13104. int connectorIdInt =0;
  13105. json_object *TriggerMessage;
  13106. DEBUG_INFO("handleTriggerMessageRequest\n");
  13107. TriggerMessage = json_tokener_parse(payload);
  13108. if(!is_error(TriggerMessage))
  13109. {
  13110. memset(&ShmOCPP20Data->TriggerMessage, 0, sizeof(struct TriggerMessage_20));
  13111. memcpy(&ShmOCPP20Data->TriggerMessage.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->TriggerMessage.guid));
  13112. // Required data
  13113. if(json_object_object_get(TriggerMessage, "requestedMessage") != NULL)
  13114. sprintf((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(TriggerMessage, "requestedMessage")));
  13115. // Optional data
  13116. if(json_object_object_get(TriggerMessage, "evse") != NULL)
  13117. {
  13118. // Required data
  13119. if(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "id") != NULL)
  13120. ShmOCPP20Data->TriggerMessage.evse.id = json_object_get_int(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "id"));
  13121. // Optional data
  13122. if(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "connectorId") != NULL)
  13123. {
  13124. ShmOCPP20Data->TriggerMessage.evse.connectorId = json_object_get_int(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "connectorId"));
  13125. connectorIdInt = ShmOCPP20Data->TriggerMessage.evse.connectorId;
  13126. }
  13127. else
  13128. connectorIdIsNULL = TRUE;
  13129. }
  13130. }
  13131. json_object_put(TriggerMessage);
  13132. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  13133. {
  13134. if((strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_BootNotification]) != 0) &&
  13135. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_LogStatusNotification]) != 0) &&
  13136. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_FirmwareStatusNotification]) != 0 ) &&
  13137. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_Heartbeat]) != 0) &&
  13138. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_MeterValues]) != 0) &&
  13139. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) != 0 ) &&
  13140. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignV2GCertificate]) != 0 ) &&
  13141. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_StatusNotification]) != 0 ) &&
  13142. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_TransactionEvent]) != 0 ) &&
  13143. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignCombinedCertificate]) != 0 ) &&
  13144. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_PublishFirmwareStatusNotification]) != 0 ))
  13145. {
  13146. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_NotImplemented] );
  13147. sendTriggerMessageConfirmation(uuid);
  13148. return TRUE;
  13149. }
  13150. else
  13151. {
  13152. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Accepted] );
  13153. sendTriggerMessageConfirmation(uuid);
  13154. }
  13155. }
  13156. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  13157. {
  13158. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Rejected] );
  13159. sendTriggerMessageConfirmation(uuid);
  13160. return TRUE;
  13161. }
  13162. //==========================
  13163. // Trigger message
  13164. //==========================
  13165. if( strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_FirmwareStatusNotification]) == 0)
  13166. {
  13167. if((strlen((char*)ShmOCPP20Data->FirmwareStatusNotification.status) == 0) ||
  13168. ((FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Downloading) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Downloaded) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Idle) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Installing)))
  13169. {
  13170. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle;
  13171. }
  13172. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  13173. }
  13174. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_LogStatusNotification]) == 0 )
  13175. {
  13176. if(strlen((char*)ShmOCPP20Data->LogStatusNotification.status) == 0)
  13177. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Idle]);
  13178. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13179. }
  13180. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_BootNotification]) == 0 )
  13181. {
  13182. if(DB_updateBootType(BootReasonEnumType_Triggered))
  13183. server_sign = FALSE;
  13184. }
  13185. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_Heartbeat]) == 0 )
  13186. {
  13187. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP20Data->BootNotification.Response_interval);
  13188. }
  13189. else if (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_MeterValues]) == 0 )
  13190. {
  13191. if(connectorIdIsNULL == FALSE)
  13192. {
  13193. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13194. {
  13195. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  13196. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValueReq = ON;
  13197. }
  13198. }
  13199. else
  13200. {
  13201. for(int idx=0;idx< gunTotalNumber;idx++)
  13202. {
  13203. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  13204. cpinitateMsg.bits[idx].TriggerMeterValueReq = ON;
  13205. }
  13206. }
  13207. }
  13208. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_StatusNotification]) == 0 )
  13209. {
  13210. if(connectorIdIsNULL == FALSE)
  13211. {
  13212. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13213. {
  13214. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = ON;
  13215. }
  13216. }
  13217. else
  13218. {
  13219. for(int idx=0;idx< gunTotalNumber;idx++)
  13220. cpinitateMsg.bits[idx].StatusNotificationReq = ON;
  13221. }
  13222. }
  13223. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) == 0 )
  13224. {
  13225. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  13226. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13227. {
  13228. 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\" &");
  13229. }
  13230. }
  13231. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignV2GCertificate]) == 0 )
  13232. {
  13233. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  13234. if(access("/Storage/OCPP/certV2G.csr",F_OK) == -1)
  13235. {
  13236. 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\" &");
  13237. }
  13238. }
  13239. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_TransactionEvent]) == 0 )
  13240. {
  13241. if(connectorIdIsNULL == FALSE)
  13242. {
  13243. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13244. {
  13245. cpinitateMsg.bits[connectorIdInt -1].TransactionEventReq = ON;
  13246. }
  13247. }
  13248. else
  13249. {
  13250. for(int idx=0;idx< gunTotalNumber;idx++)
  13251. cpinitateMsg.bits[idx].TransactionEventReq = ON;
  13252. }
  13253. }
  13254. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignCombinedCertificate]) == 0 )
  13255. {
  13256. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  13257. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13258. {
  13259. 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\" &");
  13260. }
  13261. if(access("/Storage/OCPP/certV2G.csr",F_OK) == -1)
  13262. {
  13263. 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\" &");
  13264. }
  13265. }
  13266. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_PublishFirmwareStatusNotification]) == 0 )
  13267. {
  13268. ShmOCPP20Data->MsMsg.bits.PublishFirmwareReq = ON;
  13269. }
  13270. return result;
  13271. }
  13272. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13273. {
  13274. mtrace();
  13275. int result = FAIL;
  13276. int connectorIdInt =0;
  13277. int tempIndex = 0;
  13278. json_object *UnlockConnector;
  13279. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13280. UnlockConnector = json_tokener_parse(payload);
  13281. if(!is_error(UnlockConnector))
  13282. {
  13283. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13284. {
  13285. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13286. }
  13287. if(json_object_object_get(UnlockConnector, "evseId") != NULL)
  13288. {
  13289. ShmOCPP20Data->UnlockConnector[(connectorIdInt>0?connectorIdInt-1:0)].evseId = json_object_get_int(json_object_object_get(UnlockConnector, "evseId"));
  13290. }
  13291. }
  13292. json_object_put(UnlockConnector);
  13293. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13294. if(gunTotalNumber == 0)
  13295. {
  13296. sprintf((char*)ShmOCPP20Data->UnlockConnector[connectorIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  13297. goto end;
  13298. }
  13299. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13300. {
  13301. sprintf((char*)ShmOCPP20Data->UnlockConnector[connectorIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  13302. goto end;
  13303. }
  13304. else
  13305. {
  13306. memset(&ShmOCPP20Data->UnlockConnector[connectorIdInt-1], 0, sizeof(struct UnlockConnector_20));
  13307. memcpy(&ShmOCPP20Data->UnlockConnector[connectorIdInt-1].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->UnlockConnector[connectorIdInt-1].guid));
  13308. //check Transaction active
  13309. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13310. {
  13311. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13312. {
  13313. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13314. }
  13315. else
  13316. {
  13317. tempIndex = connectorIdInt -1;
  13318. }
  13319. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13320. {
  13321. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  13322. {
  13323. //stop Transaction
  13324. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  13325. }
  13326. }
  13327. }
  13328. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13329. {
  13330. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13331. {
  13332. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13333. }
  13334. else
  13335. {
  13336. tempIndex = connectorIdInt -1;
  13337. }
  13338. for (int index = 0; index < CCS_QUANTITY; index++)
  13339. {
  13340. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  13341. {
  13342. //stop Transaction
  13343. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  13344. }
  13345. }
  13346. }
  13347. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13348. {
  13349. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13350. {
  13351. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13352. }
  13353. else
  13354. {
  13355. tempIndex = connectorIdInt -1;
  13356. }
  13357. for (int index = 0; index < GB_QUANTITY; index++)
  13358. {
  13359. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  13360. {
  13361. //stop Transaction
  13362. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  13363. }
  13364. }
  13365. }
  13366. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13367. {
  13368. tempIndex = connectorIdInt -1;
  13369. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13370. {
  13371. 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)))
  13372. {
  13373. //stop Transaction
  13374. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  13375. }
  13376. }
  13377. }
  13378. else
  13379. {
  13380. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13381. {
  13382. tempIndex = 2;
  13383. }
  13384. else
  13385. {
  13386. tempIndex = connectorIdInt-1;
  13387. }
  13388. for (int index = 0; index < AC_QUANTITY; index++)
  13389. {
  13390. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  13391. {
  13392. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  13393. }
  13394. }
  13395. }
  13396. ShmOCPP20Data->UnlockConnector[connectorIdInt-1].connectorId = connectorIdInt;
  13397. strcpy((char *)ShmOCPP20Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13398. result = TRUE;
  13399. return result;
  13400. }
  13401. end:
  13402. //json_object_put(obj); --- remove temporally
  13403. sendUnlockConnectorConfirmation(uuid, connectorIdInt-1);
  13404. return result;
  13405. }
  13406. int handleUnpublishFirmwareRequest(char *uuid, char *payload)
  13407. {
  13408. mtrace();
  13409. int result = FAIL;
  13410. json_object *UnpublishFirmware;
  13411. DEBUG_INFO("handleUnpublishFirmwareRequest...\n");
  13412. UnpublishFirmware = json_tokener_parse(payload);
  13413. if(!is_error(UnpublishFirmware))
  13414. {
  13415. memset(&ShmOCPP20Data->UnpublishFirmware, 0, sizeof(struct UnpublishFirmware_20));
  13416. memcpy(&ShmOCPP20Data->UnpublishFirmware.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->UnpublishFirmware.guid));
  13417. // Required data
  13418. if(json_object_object_get(UnpublishFirmware, "checksum") != NULL)
  13419. sprintf((char*)ShmOCPP20Data->UnpublishFirmware.checksum, json_object_get_string(json_object_object_get(UnpublishFirmware, "checksum")));
  13420. }
  13421. json_object_put(UnpublishFirmware);
  13422. ShmOCPP20Data->MsMsg.bits.UnpublishFirmwareReq = ON;
  13423. /*
  13424. * TODO:
  13425. * 1. Check unpublished status
  13426. */
  13427. sprintf((char*)ShmOCPP20Data->UnpublishFirmware.Response_status, UnpublishFirmwareStatusEnumTypeStr[Unpublished_NoFirmware]);
  13428. sendUnpublishFirmwareConfirmation(uuid);
  13429. return result;
  13430. }
  13431. static char UpdateFirmwarepayloadData[512]={0};
  13432. void *UpdateFirmwareProcess(void *data)
  13433. {
  13434. pthread_detach(pthread_self());
  13435. mtrace();
  13436. int retriesInt =0, retryIntervalInt=0;
  13437. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  13438. int port=0;
  13439. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  13440. int isSuccess = 0;
  13441. char ftpbuf[1024];
  13442. char temp[1024];
  13443. char * pch;
  13444. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13445. json_object *UpdateFirmware;
  13446. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  13447. if(!is_error(UpdateFirmware))
  13448. {
  13449. // Required data
  13450. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13451. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13452. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13453. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13454. // Optional data
  13455. if(json_object_object_get(UpdateFirmware, "retries"))
  13456. {
  13457. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13458. }
  13459. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13460. {
  13461. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13462. }
  13463. }
  13464. json_object_put(UpdateFirmware);
  13465. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13466. memset(path, 0, ARRAY_SIZE(path));
  13467. // Wait retrieveData
  13468. if(strlen(retrieveDatestr) > 10)
  13469. {
  13470. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadScheduled]);
  13471. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  13472. do
  13473. {
  13474. sleep(1);
  13475. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13476. }
  13477. system("rm -f /mnt/*");
  13478. if(strncmp(locationstr,"http", 4) == 0)
  13479. {
  13480. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13481. sprintf(ftppath,"/%s", path);
  13482. DEBUG_INFO("locationstr: %s\n", locationstr);
  13483. DEBUG_INFO("protocol: %s\n",protocol);
  13484. DEBUG_INFO("host: %s\n",host);
  13485. DEBUG_INFO("path: %s\n",path);
  13486. DEBUG_INFO("ftppath: %s\n",ftppath);
  13487. int ftppathlen=strlen(ftppath);
  13488. int i=1;
  13489. char filenametemp[50];
  13490. while(i < ftppathlen)
  13491. {
  13492. int len=ftppathlen-i;
  13493. if(ftppath[len]== 47) // '/' ascll code: 47
  13494. {
  13495. DEBUG_INFO("compare '/' all right\n");
  13496. break;
  13497. }
  13498. i=i+1;
  13499. }
  13500. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13501. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13502. filenametemp[i+1] = 0;
  13503. do
  13504. {
  13505. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading]);
  13506. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  13507. sleep(3);
  13508. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13509. if(!isSuccess)
  13510. {
  13511. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  13512. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  13513. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13514. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  13515. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  13516. }
  13517. else
  13518. {
  13519. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]);
  13520. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  13521. }
  13522. retriesInt--;
  13523. }while((isSuccess == 0)&&(retriesInt >= 0));
  13524. }
  13525. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13526. {
  13527. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13528. memset(temp, 0, ARRAY_SIZE(temp));
  13529. strcpy(ftpbuf, locationstr);
  13530. int ftppathlen=strlen(ftpbuf);
  13531. int i=1;
  13532. char filenametemp[50];
  13533. while(i < ftppathlen)
  13534. {
  13535. int len=ftppathlen-i;
  13536. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13537. {
  13538. DEBUG_INFO(" compare '/' all right\n");
  13539. break;
  13540. }
  13541. i=i+1;
  13542. }
  13543. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13544. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13545. filenametemp[i+1] = 0;
  13546. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13547. pch=strchr(temp,'@');
  13548. if(pch==NULL)
  13549. {
  13550. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13551. protocol, host, &port, path);
  13552. strcpy(user,"anonymous");
  13553. strcpy(password,"");
  13554. }
  13555. else
  13556. {
  13557. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13558. protocol, user, password, host, &port, path);
  13559. }
  13560. sscanf(host,"%[^/]%s",host1, path1);
  13561. sprintf(ftppath,"%s", path1);
  13562. if(port == 0)
  13563. {
  13564. port = 21;
  13565. }
  13566. do
  13567. {
  13568. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading]);
  13569. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  13570. sleep(3);
  13571. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13572. if(!isSuccess)
  13573. {
  13574. //BulldogUtil.sleepMs(interval*1000);
  13575. DEBUG_INFO("Update firmware request and download file fail.\n");
  13576. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  13577. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  13578. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13579. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  13580. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  13581. }
  13582. else
  13583. {
  13584. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]);
  13585. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  13586. }
  13587. retriesInt--;
  13588. }while((!isSuccess)&&(retriesInt >= 0));
  13589. }
  13590. else
  13591. {
  13592. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  13593. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  13594. sleep(1);
  13595. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  13596. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  13597. }
  13598. if(strstr((char*)ShmOCPP20Data->FirmwareStatusNotification.status, FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]) != NULL)ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq = ON;
  13599. pthread_exit(NULL);
  13600. }
  13601. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13602. {
  13603. mtrace();
  13604. int result = FAIL;
  13605. pthread_t t;
  13606. sendUpdateFirmwareConfirmation(uuid);
  13607. memset(UpdateFirmwarepayloadData, 0, ARRAY_SIZE(UpdateFirmwarepayloadData));
  13608. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  13609. memset(&ShmOCPP20Data->UpdateFirmware, 0, sizeof(struct UpdateFirmware_20));
  13610. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  13611. ////pthread_join(t, NULL); //
  13612. //pthread_detach(t);
  13613. //sendUpdateFirmwareConfirmation(uuid);
  13614. ShmOCPP20Data->MsMsg.bits.UpdateFirmwareConf = ON;
  13615. return result;
  13616. }
  13617. int handleUnknownRequest(char *uuid, char *payload)
  13618. {
  13619. mtrace();
  13620. int result = FAIL;
  13621. DEBUG_INFO("handleUnknownRequest...\n");
  13622. sendUnknownConfirmation(uuid);
  13623. result = PASS;
  13624. return result;
  13625. }
  13626. //==========================================
  13627. // Handle server response routine
  13628. //==========================================
  13629. void handleAuthorizeResponse(char *payload, int gun_index)
  13630. {
  13631. mtrace();
  13632. DEBUG_INFO("handleAuthorizeResponse...\n");
  13633. json_object *Authorize;
  13634. Authorize = json_tokener_parse(payload);
  13635. if(!is_error(Authorize))
  13636. {
  13637. if(json_object_object_get(Authorize, "idTokenInfo") != NULL)
  13638. {
  13639. // Required data
  13640. sprintf((char *)(char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "status")));
  13641. // Optional data
  13642. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "cacheExpiryDateTime") != NULL)
  13643. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "cacheExpiryDateTime")));
  13644. else
  13645. memset(ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime));
  13646. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "chargingPriority") != NULL)
  13647. ShmOCPP20Data->Authorize.Response_idTokenInfo.chargingPriority = json_object_get_int(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "chargingPriority"));
  13648. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "language1") != NULL)
  13649. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.language1, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language1")));
  13650. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "evseId") != NULL)
  13651. {
  13652. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(Authorize, "idTagInfo"), "evseId"));idx++)
  13653. {
  13654. 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));
  13655. }
  13656. }
  13657. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "language2") != NULL)
  13658. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.language2, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language2")));
  13659. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "groupIdToken") != NULL)
  13660. {
  13661. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "idToken") != NULL)
  13662. 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")));
  13663. else
  13664. memset(ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken));
  13665. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "type") != NULL)
  13666. 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")));
  13667. }
  13668. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "personalMessage") != NULL)
  13669. {
  13670. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "format") != NULL)
  13671. 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")));
  13672. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "language") != NULL)
  13673. 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")));
  13674. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "content") != NULL)
  13675. 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")));
  13676. }
  13677. }
  13678. if(json_object_object_get(Authorize, "certificateStatus") != NULL)
  13679. {
  13680. strcpy((char *)ShmOCPP20Data->Authorize.Response_certificateStatus, json_object_get_string(json_object_object_get(Authorize, "certificateStatus")));
  13681. }
  13682. }
  13683. json_object_put(Authorize);
  13684. //Update idTag information to authorization cache if supported
  13685. if((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].value, "TRUE") == 0) &&
  13686. (strlen((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken) > 0) &&
  13687. (strlen((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime) >0) &&
  13688. strstr((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != NULL)
  13689. {
  13690. DB_addLocalCache(&ShmOCPP20Data->Authorize.idToken, &ShmOCPP20Data->Authorize.Response_idTokenInfo);
  13691. }
  13692. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  13693. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  13694. authorizeRetryTimes = 0;
  13695. }
  13696. void handleBootNotificationResponse(char *payload, int gun_index)
  13697. {
  13698. mtrace();
  13699. char statusStr[12]={0};
  13700. char currentTimeStr[30]={0};
  13701. int intervalInt = 0;
  13702. DEBUG_INFO("handleBootNotificationResponse...\n");
  13703. json_object *BootNotification;
  13704. BootNotification = json_tokener_parse(payload);
  13705. if(!is_error(BootNotification))
  13706. {
  13707. // Required data
  13708. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13709. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13710. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13711. }
  13712. json_object_put(BootNotification);
  13713. DEBUG_INFO("statusStr: %s\n", statusStr);
  13714. ShmOCPP20Data->BootNotification.Response_interval = intervalInt;
  13715. BootNotificationInterval = intervalInt;
  13716. HeartBeatWaitTime = intervalInt;
  13717. //write back to ShmOCPP20Data->BootNotification
  13718. strcpy((char *)ShmOCPP20Data->BootNotification.Response_currentTime, currentTimeStr);
  13719. strcpy((char *)ShmOCPP20Data->BootNotification.Response_status, statusStr);
  13720. if((strcmp(statusStr, RegistrationStatusEnumTypeStr[RegistrationStatusEnumType_Accepted]) == 0 ))
  13721. {
  13722. server_sign = TRUE;
  13723. server_pending =FALSE;
  13724. DB_updateBootType(BootReasonEnumType_PowerUp);
  13725. }
  13726. else if(strcmp(statusStr, RegistrationStatusEnumTypeStr[RegistrationStatusEnumType_Pending]) == 0)
  13727. {
  13728. server_pending = TRUE;
  13729. }
  13730. syncDateTimeRTC(ShmOCPP20Data->BootNotification.Response_currentTime);
  13731. srand(time(NULL));
  13732. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP20Data->BootNotification.Response_interval-((rand()%8)+3));
  13733. SetOcppConnStatus(TRUE);
  13734. ShmOCPP20Data->SpMsg.bits.BootNotificationConf = ON;
  13735. }
  13736. void handleClearedChargingLimitResponse(char *payload, int gun_index)
  13737. {
  13738. mtrace();
  13739. json_object *ClearedChargingLimit;
  13740. DEBUG_INFO("handleClearedChargingLimitResponse...\n");
  13741. ClearedChargingLimit = json_tokener_parse(payload);
  13742. if(!is_error(ClearedChargingLimit))
  13743. {
  13744. // Required data
  13745. if(json_object_object_get(ClearedChargingLimit,"status") != NULL)
  13746. sprintf((char*)ShmOCPP20Data->ClearChargingProfile[gun_index].Response_status, json_object_get_string(json_object_object_get(ClearedChargingLimit,"status")));
  13747. }
  13748. json_object_put(ClearedChargingLimit);
  13749. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq = OFF;
  13750. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitConf = ON;
  13751. }
  13752. void handleDataTransferResponse(char *payload, int gun_index)
  13753. {
  13754. mtrace();
  13755. json_object *DataTrans;
  13756. DEBUG_INFO("handleDataTransferResponse...\n");
  13757. DataTrans = json_tokener_parse(payload);
  13758. if(!is_error(DataTrans))
  13759. {
  13760. // Required data
  13761. if(json_object_object_get(DataTrans,"status") != NULL)
  13762. sprintf((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_status, json_object_get_string(json_object_object_get(DataTrans,"status")));
  13763. // Optional data
  13764. if(json_object_object_get(DataTrans,"data") != NULL)
  13765. sprintf((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_data, json_object_get_string(json_object_object_get(DataTrans,"data")));
  13766. }
  13767. json_object_put(DataTrans);
  13768. ShmOCPP20Data->CpMsg.bits[gun_index].DataTransferReq = OFF;
  13769. ShmOCPP20Data->CpMsg.bits[gun_index].DataTransferConf = ON;
  13770. }
  13771. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13772. {
  13773. mtrace();
  13774. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13775. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = OFF;
  13776. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationConf = ON;
  13777. }
  13778. void handleGet15118EVCertificateResponse(char *payload, int gun_index)
  13779. {
  13780. mtrace();
  13781. json_object *Get15118EVCertificate;
  13782. DEBUG_INFO("handleGet15118EVCertificateResponse...\n");
  13783. Get15118EVCertificate = json_tokener_parse(payload);
  13784. if(!is_error(Get15118EVCertificate))
  13785. {
  13786. // Required data
  13787. if(json_object_object_get(Get15118EVCertificate,"status") != NULL)
  13788. sprintf((char*)ShmOCPP20Data->Get15118EVCertificate.Response_status, json_object_get_string(json_object_object_get(Get15118EVCertificate,"status")));
  13789. // Optional data
  13790. if(json_object_object_get(Get15118EVCertificate,"exiResponse") != NULL)
  13791. sprintf((char*)ShmOCPP20Data->Get15118EVCertificate.Response_exiResponse, json_object_get_string(json_object_object_get(Get15118EVCertificate,"exiResponse")));
  13792. }
  13793. json_object_put(Get15118EVCertificate);
  13794. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq = OFF;
  13795. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateConf = ON;
  13796. }
  13797. void hanldeGetCertificateStatusResponse(char *payload, int gun_index)
  13798. {
  13799. mtrace();
  13800. json_object *GetCertificateStatus;
  13801. DEBUG_INFO("hanldeGetCertificateStatusResponse...\n");
  13802. GetCertificateStatus = json_tokener_parse(payload);
  13803. if(!is_error(GetCertificateStatus))
  13804. {
  13805. // Required data
  13806. if(json_object_object_get(GetCertificateStatus,"status") != NULL)
  13807. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_status, json_object_get_string(json_object_object_get(GetCertificateStatus,"status")));
  13808. // Optional data
  13809. if(json_object_object_get(GetCertificateStatus,"ocspResult") != NULL)
  13810. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_ocspResult, json_object_get_string(json_object_object_get(GetCertificateStatus,"ocspResult")));
  13811. }
  13812. json_object_put(GetCertificateStatus);
  13813. ShmOCPP20Data->SpMsg.bits.GetCertificateStatusReq = OFF;
  13814. ShmOCPP20Data->SpMsg.bits.GetCertificateStatusConf = ON;
  13815. }
  13816. void handleHeartbeatResponse(char *payload, int gun_index)
  13817. {
  13818. mtrace();
  13819. DEBUG_INFO("handleHeartbeatResponse...\n");
  13820. json_object *Heartbeat;
  13821. Heartbeat = json_tokener_parse(payload);
  13822. if(!is_error(Heartbeat))
  13823. {
  13824. // Required data
  13825. if(json_object_object_get(Heartbeat,"currentTime") != NULL)
  13826. sprintf((char *)ShmOCPP20Data->Heartbeat.Response_currentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  13827. }
  13828. json_object_put(Heartbeat);
  13829. if(FirstHeartBeat == OFF)
  13830. {
  13831. FirstHeartBeat = ON;
  13832. DEBUG_INFO("FirstHeartBeat \n");
  13833. }
  13834. HeartBeatWithNOResponse = 0;
  13835. clientTime.Heartbeat=time((time_t*)NULL);
  13836. syncDateTimeRTC(ShmOCPP20Data->Heartbeat.Response_currentTime);
  13837. }
  13838. void hanldeLogStatusNotificationResponse(char *payload, int gun_index)
  13839. {
  13840. mtrace();
  13841. DEBUG_INFO("hanldeLogStatusNotificationResponse...\n");
  13842. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  13843. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationConf = ON;
  13844. }
  13845. void handleMeterValuesResponse(char *payload, int gun_index)
  13846. {
  13847. mtrace();
  13848. DEBUG_INFO("handleMeterValuesResponse...\n");
  13849. }
  13850. void handleNotifyChargingLimitResponse(char *payload, int gun_index)
  13851. {
  13852. mtrace();
  13853. DEBUG_INFO("handleNotifyChargingLimitResponse...\n");
  13854. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitReq = OFF;
  13855. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitConf = ON;
  13856. }
  13857. void hanldeNotifyCustomerInformationResponse(char *payload, int gun_index)
  13858. {
  13859. mtrace();
  13860. DEBUG_INFO("hanldeNotifyCustomerInformationResponse...\n");
  13861. }
  13862. void hanldeNotifyDisplayMessagesResponse(char *payload, int gun_index)
  13863. {
  13864. mtrace();
  13865. DEBUG_INFO("hanldeNotifyDisplayMessagesResponse...\n");
  13866. ShmOCPP20Data->SpMsg.bits.NotifyDisplayMessagesReq = OFF;
  13867. ShmOCPP20Data->SpMsg.bits.NotifyDisplayMessagesConf = ON;
  13868. }
  13869. void hanldeNotifyEVChargingNeedsResponse(char *payload, int gun_index)
  13870. {
  13871. mtrace();
  13872. json_object *NotifyEVChargingNeeds;
  13873. DEBUG_INFO("hanldeNotifyEVChargingNeedsResponse...\n");
  13874. NotifyEVChargingNeeds = json_tokener_parse(payload);
  13875. if(!is_error(NotifyEVChargingNeeds))
  13876. {
  13877. // Required data
  13878. if(json_object_object_get(NotifyEVChargingNeeds,"status") != NULL)
  13879. sprintf((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].Response_status, json_object_get_string(json_object_object_get(NotifyEVChargingNeeds,"status")));
  13880. }
  13881. json_object_put(NotifyEVChargingNeeds);
  13882. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitReq = OFF;
  13883. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitConf = ON;
  13884. }
  13885. void hanldeNotifyEVChargingScheduleResponse(char *payload, int gun_index)
  13886. {
  13887. mtrace();
  13888. json_object *NotifyEVChargingSchedule;
  13889. DEBUG_INFO("hanldeNotifyEVChargingScheduleResponse...\n");
  13890. NotifyEVChargingSchedule = json_tokener_parse(payload);
  13891. if(!is_error(NotifyEVChargingSchedule))
  13892. {
  13893. // Required data
  13894. if(json_object_object_get(NotifyEVChargingSchedule,"status") != NULL)
  13895. sprintf((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].Response_status, json_object_get_string(json_object_object_get(NotifyEVChargingSchedule,"status")));
  13896. }
  13897. json_object_put(NotifyEVChargingSchedule);
  13898. ShmOCPP20Data->SpMsg.bits.NotifyEVChargingScheduleReq = OFF;
  13899. ShmOCPP20Data->SpMsg.bits.NotifyEVChargingScheduleConf = ON;
  13900. }
  13901. void hanldeNotifyEventResponse(char *payload, int gun_index)
  13902. {
  13903. mtrace();
  13904. DEBUG_INFO("hanldeNotifyEventResponse...\n");
  13905. ShmOCPP20Data->SpMsg.bits.NotifyEventReq = OFF;
  13906. ShmOCPP20Data->SpMsg.bits.NotifyEventConf = ON;
  13907. }
  13908. void hanldeNotifyMonitoringReportResponse(char *payload, int gun_index)
  13909. {
  13910. mtrace();
  13911. DEBUG_INFO("hanldeNotifyMonitoringReportResponse...\n");
  13912. ShmOCPP20Data->SpMsg.bits.NotifyMonitoringReportReq = OFF;
  13913. ShmOCPP20Data->SpMsg.bits.NotifyMonitoringReportConf = ON;
  13914. }
  13915. void hanldeNotifyReportResponse(char *payload, int gun_index)
  13916. {
  13917. mtrace();
  13918. DEBUG_INFO("hanldeNotifyReportResponse...\n");
  13919. ShmOCPP20Data->SpMsg.bits.NotifyReportReq = OFF;
  13920. ShmOCPP20Data->SpMsg.bits.NotifyReportConf = ON;
  13921. }
  13922. void hanldePublishFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13923. {
  13924. mtrace();
  13925. DEBUG_INFO("hanldePublishFirmwareStatusNotificationResponse...\n");
  13926. ShmOCPP20Data->CsMsg.bits[gun_index].PublishFirmwareStatusNotificationReq = OFF;
  13927. ShmOCPP20Data->CsMsg.bits[gun_index].PublishFirmwareStatusNotificationConf = ON;
  13928. }
  13929. void hanldeReportChargingProfilesResponse(char *payload, int gun_index)
  13930. {
  13931. mtrace();
  13932. DEBUG_INFO("hanldeReportChargingProfilesResponse...gun_index: %d\n", gun_index);
  13933. ShmOCPP20Data->SpMsg.bits.ReportChargingProfilesReq = OFF;
  13934. ShmOCPP20Data->SpMsg.bits.ReportChargingProfilesConf = ON;
  13935. }
  13936. void hanldeReservationStatusUpdateResponse(char *payload, int gun_index)
  13937. {
  13938. mtrace();
  13939. DEBUG_INFO("hanldeReservationStatusUpdateResponse...gun_index: %d\n", gun_index);
  13940. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = OFF;
  13941. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateConf = ON;
  13942. }
  13943. void hanldeSecurityEventNotificationResponse(char *payload, int gun_index)
  13944. {
  13945. mtrace();
  13946. DEBUG_INFO("hanldeSecurityEventNotificationResponse...\n");
  13947. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = OFF;
  13948. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationConf = ON;
  13949. }
  13950. void hanldeSignCertificateResponse(char *payload, int gun_index)
  13951. {
  13952. mtrace();
  13953. json_object *SignCertificate;
  13954. DEBUG_INFO("hanldeSignCertificateResponse...\n");
  13955. SignCertificate = json_tokener_parse(payload);
  13956. if(!is_error(SignCertificate))
  13957. {
  13958. // Required data
  13959. if(json_object_object_get(SignCertificate,"status") != NULL)
  13960. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_status, json_object_get_string(json_object_object_get(SignCertificate,"status")));
  13961. // Optional data
  13962. if(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "reasonCode") != NULL)
  13963. {
  13964. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_statusInfo.reasonCode, json_object_get_string(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "reasonCode")));
  13965. if(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "additionalInfo") != NULL)
  13966. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_statusInfo.additionalInfo, json_object_get_string(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "additionalInfo")));
  13967. }
  13968. }
  13969. json_object_put(SignCertificate);
  13970. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = OFF;
  13971. ShmOCPP20Data->SpMsg.bits.SignCertificateConf = ON;
  13972. }
  13973. void handleStatusNotificationResponse(char *payload, int gun_index)
  13974. {
  13975. mtrace();
  13976. DEBUG_INFO("handleStatusNotificationResponse...gun_index: %d\n", gun_index);
  13977. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  13978. cpinitateMsg.bits[gun_index].StatusNotificationConf = ON;
  13979. }
  13980. void hanldeTransactionEvenResponse(char *payload, int gun_index)
  13981. {
  13982. mtrace();
  13983. json_object *TransactionEven;
  13984. DEBUG_INFO("hanldeTransactionEvenResponse...\n");
  13985. TransactionEven = json_tokener_parse(payload);
  13986. if(!is_error(TransactionEven))
  13987. {
  13988. // Required data
  13989. // Optional data
  13990. if(json_object_object_get(TransactionEven,"totalCost") != NULL)
  13991. ShmOCPP20Data->TransactionEvent[gun_index].Response_totalCost = json_object_get_double(json_object_object_get(TransactionEven,"totalCost"));
  13992. if(json_object_object_get(TransactionEven,"chargingPriority") != NULL)
  13993. ShmOCPP20Data->TransactionEvent[gun_index].Response_chargingPriority = json_object_get_int(json_object_object_get(TransactionEven,"chargingPriority"));
  13994. if(json_object_object_get(TransactionEven,"idTokenInfo") != NULL)
  13995. {
  13996. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "status") != NULL)
  13997. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "status")));
  13998. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "cacheExpiryDateTime") != NULL)
  13999. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.cacheExpiryDateTime, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "cacheExpiryDateTime")));
  14000. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "chargingPriority") != NULL)
  14001. ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.chargingPriority = json_object_get_int(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "chargingPriority"));
  14002. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "language1") != NULL)
  14003. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.language1, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "language1")));
  14004. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken") != NULL)
  14005. {
  14006. if(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "idToken") != NULL)
  14007. 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")));
  14008. if(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "type") != NULL)
  14009. 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")));
  14010. }
  14011. }
  14012. }
  14013. json_object_put(TransactionEven);
  14014. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = OFF;
  14015. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf = ON;
  14016. }
  14017. //==========================================
  14018. // Handle Error routine
  14019. //==========================================
  14020. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  14021. {
  14022. mtrace();
  14023. #ifdef SystemLogMessage
  14024. DEBUG_INFO("errorCode: %s\n", errorCode);
  14025. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  14026. DEBUG_INFO("errorDetails: %s\n", payload);
  14027. #endif
  14028. }
  14029. //===============================================
  14030. // Common routine
  14031. //===============================================
  14032. int initialConfigurationTable(void)
  14033. {
  14034. DEBUG_INFO("initialConfigurationTable...\n");
  14035. memset(&ShmOCPP20Data->ControllerComponentVariable[0], 0, ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable));
  14036. DB_variableIsCreate();
  14037. DB_variableLoadFromDb();
  14038. DB_getNetworkProfileFromDb();
  14039. return 0;
  14040. }
  14041. int TransactionMessageAttemptsGet(void)
  14042. {
  14043. return TransactionMessageAttemptsValue;
  14044. }
  14045. int FirstHeartBeatResponse(void)
  14046. {
  14047. return FirstHeartBeat;
  14048. }
  14049. int TransactionMessageRetryIntervalGet(void)
  14050. {
  14051. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP20Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14052. }
  14053. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  14054. {
  14055. int result = TRUE;
  14056. char rmFileCmd[100]={0};
  14057. char FilePath[100]={0};
  14058. char ftpbuf[200];
  14059. int systemresult;
  14060. //DEBUG_INFO("filename=%s\n",filename);
  14061. //DEBUG_INFO("url=%s\n",url);
  14062. sprintf(FilePath,"/mnt/%s",filename);
  14063. system("ping 8.8.8.8 &");
  14064. if((access(FilePath,F_OK))!=-1)
  14065. {
  14066. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14067. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14068. system(rmFileCmd);
  14069. }
  14070. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14071. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14072. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14073. systemresult = system(ftpbuf);
  14074. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14075. if(systemresult != 0)
  14076. {
  14077. DEBUG_INFO("http DownLoad error!\n");
  14078. result = FALSE;
  14079. }
  14080. system("pkill ping");
  14081. return result;
  14082. }
  14083. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  14084. {
  14085. int result = TRUE;
  14086. char rmFileCmd[100]={0};
  14087. char FilePath[100]={0};
  14088. char ftpbuf[200];
  14089. int systemresult;
  14090. //char temp[100];
  14091. sprintf(FilePath,"/mnt/%s",filename);
  14092. system("ping 8.8.8.8 &");
  14093. if((access(FilePath,F_OK))!=-1)
  14094. {
  14095. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14096. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14097. system(rmFileCmd);
  14098. }
  14099. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14100. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14101. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  14102. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14103. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14104. systemresult = system(ftpbuf);
  14105. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14106. if(systemresult != 0)
  14107. {
  14108. printf("wget error!\n");
  14109. result = FALSE;
  14110. }
  14111. system("pkill ping");
  14112. return result;
  14113. }
  14114. int httpUploadFile(char *location, char *path, char *filename,char *url)
  14115. {
  14116. char rmFileCmd[100]={0};
  14117. char FilePath[100]={0};
  14118. char buf[512];
  14119. int systemresult = 0;
  14120. //DEBUG_INFO("filename=%s\n",filename);
  14121. //DEBUG_INFO("url=%s\n",url);
  14122. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  14123. if((access(FilePath,F_OK))!=-1)
  14124. {
  14125. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14126. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14127. system(rmFileCmd);
  14128. }
  14129. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  14130. if(fp == NULL)
  14131. {
  14132. DEBUG_INFO("log is NULL\n");
  14133. return FALSE;
  14134. }
  14135. else
  14136. {
  14137. fprintf(fp, "%s\n", url);
  14138. fprintf(fp, "%s\n", filename);
  14139. fclose(fp);
  14140. }
  14141. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  14142. if(phpFP == NULL)
  14143. {
  14144. DEBUG_INFO("PHP upload fail.\n");
  14145. return FALSE;
  14146. }
  14147. else
  14148. {
  14149. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  14150. {
  14151. if(strstr(buf, "result") != NULL)
  14152. {
  14153. sscanf(buf, "result: %d", &systemresult);
  14154. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  14155. }
  14156. }
  14157. pclose(phpFP);
  14158. }
  14159. if(systemresult != 1)
  14160. {
  14161. DEBUG_INFO("HTTP upload error!\n");
  14162. return FALSE;
  14163. }
  14164. return TRUE;
  14165. }
  14166. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  14167. {
  14168. struct hostent* server;
  14169. char *IPbuffer;
  14170. char ftpbuf[200];
  14171. int systemresult;
  14172. // To retrieve host information
  14173. server = gethostbyname(location);
  14174. // To convert an Internet network
  14175. // address into ASCII string
  14176. IPbuffer = inet_ntoa(*((struct in_addr*)
  14177. server->h_addr_list[0]));
  14178. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14179. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  14180. /* format : ftpput -u username -p passwd IP target source*/
  14181. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  14182. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14183. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14184. systemresult = system(ftpbuf);
  14185. DEBUG_INFO("systemresult=%d\n",systemresult);
  14186. if(systemresult != 0)
  14187. {
  14188. DEBUG_INFO("ftpput error!\n");
  14189. return FALSE;
  14190. }
  14191. return TRUE;
  14192. }
  14193. //=========================================
  14194. // Routine
  14195. //=========================================
  14196. int GetOcppServerURL()
  14197. {
  14198. int result = FALSE;
  14199. struct yuarel url;
  14200. char urlStr[512];
  14201. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  14202. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  14203. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  14204. if((ShmOCPP20Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP20Data->OcppServerURL,"") != 0))
  14205. {
  14206. memcpy(urlStr, ShmOCPP20Data->OcppServerURL, ARRAY_SIZE(ShmOCPP20Data->OcppServerURL));
  14207. if(yuarel_parse(&url, urlStr) != -1)
  14208. {
  14209. sprintf(OcppProtocol, "%s", url.scheme);
  14210. sprintf(OcppHost, "%s", url.host);
  14211. if(url.path == NULL)
  14212. OcppTempPath[0] = '\0';
  14213. else
  14214. sprintf(OcppTempPath, "%s", url.path);
  14215. if(url.port == 0)
  14216. {
  14217. if(strcmp(OcppProtocol, "wss") == 0)
  14218. OcppPort = 443;
  14219. else
  14220. OcppPort = 80;
  14221. }
  14222. else
  14223. OcppPort = url.port;
  14224. result = TRUE;
  14225. }
  14226. }
  14227. else
  14228. {
  14229. strcpy(OcppHost,"");
  14230. }
  14231. return result;
  14232. }
  14233. int GetOcppPath()
  14234. {
  14235. int result = FALSE;
  14236. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  14237. {
  14238. if(OcppTempPath == NULL)
  14239. {
  14240. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14241. }
  14242. else
  14243. {
  14244. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14245. }
  14246. result = TRUE;
  14247. }
  14248. else if((ShmOCPP20Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP20Data->ChargeBoxId,"") != 0))
  14249. {
  14250. if(OcppTempPath == NULL)
  14251. {
  14252. sprintf(OcppPath,"/%s",ShmOCPP20Data->ChargeBoxId);
  14253. }
  14254. else
  14255. {
  14256. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP20Data->ChargeBoxId);
  14257. }
  14258. result = TRUE;
  14259. }
  14260. else
  14261. {
  14262. strcpy(OcppPath,"");
  14263. }
  14264. return result;
  14265. }
  14266. int GetOcppPort()
  14267. {
  14268. return OcppPort;
  14269. }
  14270. int GetOcppConnStatus(void)
  14271. {
  14272. return ShmOCPP20Data->OcppConnStatus;
  14273. }
  14274. void SetOcppConnStatus(uint8_t status)
  14275. {
  14276. ShmOCPP20Data->OcppConnStatus = status;
  14277. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  14278. }
  14279. int GetHeartBeatWithNOResponse(void)
  14280. {
  14281. return HeartBeatWithNOResponse;
  14282. }
  14283. void SetHeartBeatWithNOResponse(void)
  14284. {
  14285. HeartBeatWithNOResponse = 0;
  14286. }
  14287. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  14288. void storeTempStopTransaction(int gun_index)
  14289. {
  14290. char TempStopTransaction[256];
  14291. char message[1024*20]={0};
  14292. char guid[37]={0};
  14293. uint8_t tempIndex;
  14294. json_object *TransactionEvent = json_object_new_object();
  14295. json_object *transactionInfo = json_object_new_object();
  14296. json_object *idToken = json_object_new_object();
  14297. json_object *evse = json_object_new_object();
  14298. json_object *meterValues = json_object_new_array();
  14299. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14300. DEBUG_INFO("storeTempStopTransaction...\n");
  14301. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14302. {
  14303. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14304. {
  14305. tempIndex = ((gun_index==2) ? 1: 0);
  14306. }
  14307. else
  14308. {
  14309. tempIndex = gun_index;
  14310. }
  14311. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14312. {
  14313. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  14314. {
  14315. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  14316. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  14317. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  14318. else
  14319. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  14320. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  14321. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  14322. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  14323. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  14324. {
  14325. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  14326. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  14327. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  14328. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  14329. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  14330. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  14331. {
  14332. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  14333. }
  14334. else
  14335. {
  14336. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  14337. }
  14338. }
  14339. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  14340. {
  14341. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  14342. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  14343. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  14344. }
  14345. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  14346. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  14347. ) //S_PRECHARGE
  14348. {
  14349. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  14350. {
  14351. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  14352. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartUserId);
  14353. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", ShmOCPP20Data->Authorize.idToken.type);
  14354. }
  14355. if(ShmOCPP20Data->TransactionEvent[gun_index].eventType[0] == '\0')
  14356. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  14357. else
  14358. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  14359. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  14360. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  14361. }
  14362. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  14363. {
  14364. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  14365. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  14366. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  14367. }
  14368. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  14369. {
  14370. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  14371. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  14372. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  14373. }
  14374. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  14375. {
  14376. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  14377. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  14378. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  14379. }
  14380. 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
  14381. {
  14382. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  14383. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  14384. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  14385. }
  14386. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  14387. {
  14388. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  14389. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  14390. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  14391. }
  14392. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  14393. {
  14394. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  14395. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  14396. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  14397. }
  14398. } //end of the same index
  14399. }//end of for CHAdeMO_QUANTITY
  14400. }
  14401. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14402. {
  14403. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14404. {
  14405. tempIndex = ((gun_index==2) ? 1: 0);
  14406. }
  14407. else
  14408. {
  14409. tempIndex = gun_index;
  14410. }
  14411. for (int index = 0; index < CCS_QUANTITY; index++)
  14412. {
  14413. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14414. {
  14415. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  14416. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  14417. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  14418. else
  14419. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  14420. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  14421. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  14422. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  14423. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  14424. {
  14425. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  14426. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  14427. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  14428. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  14429. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  14430. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  14431. {
  14432. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  14433. }
  14434. else
  14435. {
  14436. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  14437. }
  14438. }
  14439. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  14440. {
  14441. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  14442. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  14443. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  14444. }
  14445. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  14446. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  14447. ) //S_PRECHARGE
  14448. {
  14449. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  14450. {
  14451. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  14452. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartUserId);
  14453. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", ShmOCPP20Data->Authorize.idToken.type);
  14454. }
  14455. if(ShmOCPP20Data->TransactionEvent[gun_index].eventType[0] == '\0')
  14456. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  14457. else
  14458. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  14459. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  14460. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  14461. }
  14462. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  14463. {
  14464. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  14465. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  14466. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  14467. }
  14468. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  14469. {
  14470. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  14471. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  14472. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  14473. }
  14474. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  14475. {
  14476. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  14477. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  14478. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  14479. }
  14480. 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
  14481. {
  14482. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  14483. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  14484. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  14485. }
  14486. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  14487. {
  14488. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  14489. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  14490. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  14491. }
  14492. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  14493. {
  14494. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  14495. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  14496. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  14497. }
  14498. } //end of the same index
  14499. } // end of for CCS_QUANTITY
  14500. }
  14501. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14502. {
  14503. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14504. {
  14505. tempIndex = ((gun_index==2) ? 1: 0);
  14506. }
  14507. else
  14508. {
  14509. tempIndex = gun_index;
  14510. }
  14511. for (int index = 0; index < GB_QUANTITY; index++)
  14512. {
  14513. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14514. {
  14515. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  14516. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  14517. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  14518. else
  14519. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  14520. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  14521. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  14522. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  14523. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  14524. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  14525. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  14526. } //end of the same index
  14527. } // end of for GB_QUANTITY
  14528. }
  14529. else if(gunType[gun_index] == GUN_TYPE_DO)
  14530. {
  14531. tempIndex = gun_index;
  14532. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14533. {
  14534. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14535. {
  14536. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  14537. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  14538. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  14539. else
  14540. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  14541. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  14542. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  14543. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  14544. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  14545. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  14546. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  14547. } //end of the same index
  14548. }
  14549. }
  14550. else
  14551. {
  14552. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14553. {
  14554. tempIndex = 2;
  14555. }
  14556. else
  14557. {
  14558. tempIndex = gun_index;
  14559. }
  14560. for (int index = 0; index < AC_QUANTITY; index++)
  14561. {
  14562. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14563. {
  14564. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  14565. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  14566. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  14567. else
  14568. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  14569. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  14570. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  14571. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  14572. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  14573. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  14574. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  14575. }//end of the same index
  14576. }//end of for AC_QUANTITY
  14577. }
  14578. // Message
  14579. json_object_object_add(TransactionEvent, "eventType", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  14580. json_object_object_add(TransactionEvent, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].timestamp));
  14581. json_object_object_add(TransactionEvent, "triggerReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason));
  14582. json_object_object_add(TransactionEvent, "seqNo", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].seqNo));
  14583. json_object_object_add(TransactionEvent, "offline", json_object_new_boolean(ShmOCPP20Data->TransactionEvent[gun_index].offline));
  14584. if(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed > 0)
  14585. json_object_object_add(TransactionEvent, "numberOfPhasesUsed", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed));
  14586. if(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent > 0)
  14587. json_object_object_add(TransactionEvent, "cableMaxCurrent", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent));
  14588. if(ShmOCPP20Data->TransactionEvent[gun_index].reservationId > 0)
  14589. json_object_object_add(TransactionEvent, "reservationId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].reservationId));
  14590. json_object_object_add(transactionInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId));
  14591. json_object_object_add(transactionInfo, "chargingState", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState));
  14592. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging > 0)
  14593. json_object_object_add(transactionInfo, "timeSpentCharging", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging));
  14594. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason) > 0)
  14595. json_object_object_add(transactionInfo, "stoppedReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason));
  14596. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId > 0)
  14597. json_object_object_add(transactionInfo, "remoteStartId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId));
  14598. json_object_object_add(TransactionEvent, "transactionInfo", transactionInfo);
  14599. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken) > 0)
  14600. {
  14601. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
  14602. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type));
  14603. json_object_object_add(TransactionEvent, "idToken", idToken);
  14604. }
  14605. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.id));
  14606. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId));
  14607. json_object_object_add(TransactionEvent, "evse", evse);
  14608. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0].timestamp) > 0)
  14609. {
  14610. for(int idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue);idxMeter++)
  14611. {
  14612. json_object *meterValue = json_object_new_object();
  14613. json_object *sampledValues = json_object_new_array();
  14614. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].timestamp));
  14615. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  14616. {
  14617. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0) &&
  14618. ((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)))
  14619. {
  14620. json_object *sampledValue = json_object_new_object();
  14621. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  14622. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  14623. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  14624. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  14625. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  14626. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  14627. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  14628. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  14629. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  14630. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  14631. {
  14632. json_object *unitOfMeasure = json_object_new_object();
  14633. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  14634. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  14635. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  14636. }
  14637. json_object_array_add(sampledValues, sampledValue);
  14638. }
  14639. }
  14640. json_object_object_add(meterValue, "sampledValue", sampledValues);
  14641. json_object_array_add(meterValues, meterValue);
  14642. }
  14643. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  14644. }
  14645. random_uuid(guid);
  14646. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL
  14647. , guid
  14648. , "TransactionEvent"
  14649. , json_object_to_json_string_ext(TransactionEvent, JSON_C_TO_STRING_PLAIN));
  14650. json_object_put(TransactionEvent);
  14651. // open file for writing
  14652. FILE *outfile;
  14653. outfile = fopen (TempStopTransaction, "w+");
  14654. //DEBUG_INFO("data = %s\n", queuedata);
  14655. fputs(message, outfile);
  14656. fputs("\n", outfile);
  14657. fclose (outfile);
  14658. }
  14659. void checkTempStopTransaction(int gun_index)
  14660. {
  14661. FILE *fptr1;
  14662. char ch;
  14663. char str[QUEUE_MESSAGE_LENGTH]={0};
  14664. char guid[37]={0};
  14665. char tempdata[65]={0};
  14666. char TempStopTransaction[256];
  14667. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14668. fptr1 = fopen(TempStopTransaction, "r");
  14669. if (!fptr1)
  14670. {
  14671. //DEBUG_INFO("TempStopTransaction_%d not found or unable to open the input file!\n", (gun_index+1));
  14672. return ;
  14673. }
  14674. ch=fgetc(fptr1);
  14675. rewind(fptr1);
  14676. if(ch!=EOF)
  14677. {
  14678. // copy all contents to the temporary file except the specific line
  14679. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  14680. {
  14681. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14682. if(str[0]=='\0')
  14683. {
  14684. break;
  14685. }
  14686. strncpy(guid, str+4, 36); //copy guid
  14687. sprintf(tempdata, "TransactionEvent,%d", (gun_index));
  14688. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14689. {
  14690. //DEBUG_INFO("StopTransaction mapitem pass\n");
  14691. }
  14692. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14693. memset(str,0,ARRAY_SIZE(str));
  14694. }
  14695. }
  14696. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14697. fclose(fptr1);
  14698. remove(TempStopTransaction); // remove the original file
  14699. }
  14700. int GetWebSocketPingInterval(void)
  14701. {
  14702. return atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].value);
  14703. }
  14704. int GetServerSign(void)
  14705. {
  14706. return server_sign;
  14707. }
  14708. uint8_t GetOcppSecurityProfile()
  14709. {
  14710. return atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].value);
  14711. }
  14712. void GetOcppChargerBoxId(uint8_t *data)
  14713. {
  14714. sprintf((char*)data, "%s", ShmOCPP20Data->ChargeBoxId);
  14715. }
  14716. void GetOcppSecurityPassword(uint8_t *data)
  14717. {
  14718. sprintf((char*)data, "%s", ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].value);
  14719. }
  14720. void SetServerSign(int value)
  14721. {
  14722. server_sign = value;
  14723. }
  14724. int GetBootNotificationInterval(void)
  14725. {
  14726. return BootNotificationInterval;
  14727. }
  14728. int GetInternetConn(void)
  14729. {
  14730. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14731. }
  14732. int GetBackendConnectionTimeout(void)
  14733. {
  14734. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  14735. }
  14736. int isConnectorInitMode(int gun_index)
  14737. {
  14738. int tempIndex = 0;
  14739. int result = TRUE;
  14740. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14741. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14742. {
  14743. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14744. {
  14745. tempIndex = ((gun_index==2) ? 1: 0);
  14746. }
  14747. else
  14748. {
  14749. tempIndex = gun_index;
  14750. }
  14751. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14752. {
  14753. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  14754. {
  14755. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14756. } //end of the same index
  14757. }//end of for CHAdeMO_QUANTITY
  14758. }
  14759. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14760. {
  14761. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14762. {
  14763. tempIndex = ((gun_index==2) ? 1: 0);
  14764. }
  14765. else
  14766. {
  14767. tempIndex = gun_index;
  14768. }
  14769. for (int index = 0; index < CCS_QUANTITY; index++)
  14770. {
  14771. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14772. {
  14773. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14774. } //end of the same index
  14775. } // end of for CCS_QUANTITY
  14776. }
  14777. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14778. {
  14779. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14780. {
  14781. tempIndex = ((gun_index==2) ? 1: 0);
  14782. }
  14783. else
  14784. {
  14785. tempIndex = gun_index;
  14786. }
  14787. for (int index = 0; index < GB_QUANTITY; index++)
  14788. {
  14789. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14790. {
  14791. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14792. } //end of the same index
  14793. } // end of for GB_QUANTITY
  14794. }
  14795. else if(gunType[gun_index] == GUN_TYPE_DO)
  14796. {
  14797. tempIndex = gun_index;
  14798. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14799. {
  14800. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14801. {
  14802. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14803. } //end of the same index
  14804. }
  14805. }
  14806. else
  14807. {
  14808. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14809. {
  14810. tempIndex = 2;
  14811. }
  14812. else
  14813. {
  14814. tempIndex = gun_index;
  14815. }
  14816. for (int index = 0; index < AC_QUANTITY; index++)
  14817. {
  14818. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14819. {
  14820. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14821. }//end of the same index
  14822. }//end of for AC_QUANTITY
  14823. }
  14824. return result;
  14825. }
  14826. void refreshProcDogTimer()
  14827. {
  14828. ShmOCPP20Data->procDogTime = time((time_t*)NULL);
  14829. }
  14830. void InitialSystemValue(void)
  14831. {
  14832. int connectorIndex = 0;
  14833. gunTotalNumber=0;
  14834. SystemInitial = 0;
  14835. localversion=0;
  14836. BootNotificationInterval = 10;
  14837. authorizeRetryTimes = 0;
  14838. GunStatusInterval = 10;
  14839. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].value);
  14840. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].value);
  14841. //Hear Beat
  14842. HeartBeatWithNOResponse = 0;
  14843. HeartBeatCountPerHour = 0;
  14844. HeartBeatWaitTime = atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value);;
  14845. FirstHeartBeat = 0;
  14846. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle; // Idle
  14847. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle; // Idle
  14848. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14849. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14850. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14851. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14852. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14853. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14854. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14855. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14856. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14857. memset(gunType, 0, ARRAY_SIZE(gunType));
  14858. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14859. {
  14860. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  14861. {
  14862. // DO series
  14863. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  14864. {
  14865. SystemInitial = SystemInitial + 1;
  14866. gunTotalNumber = gunTotalNumber + 1;
  14867. gunType[connectorIndex] = GUN_TYPE_DO;
  14868. connectorIndex = connectorIndex + 1;
  14869. }
  14870. }
  14871. else
  14872. {
  14873. // DM, DW, DS series
  14874. //check connector / socket type (index: 8, 9, 10)
  14875. for(int index=7; index <10 ; index++)
  14876. {
  14877. if(index != 8)
  14878. {
  14879. // DC Connector
  14880. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  14881. {
  14882. SystemInitial = SystemInitial + 1;
  14883. gunTotalNumber = gunTotalNumber + 1;
  14884. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  14885. connectorIndex = connectorIndex + 1;
  14886. }
  14887. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  14888. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  14889. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  14890. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  14891. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  14892. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  14893. {
  14894. SystemInitial = SystemInitial + 1;
  14895. gunTotalNumber = gunTotalNumber + 1;
  14896. gunType[connectorIndex] = GUN_TYPE_CCS;
  14897. connectorIndex = connectorIndex + 1;
  14898. }
  14899. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  14900. {
  14901. SystemInitial = SystemInitial + 1;
  14902. gunTotalNumber = gunTotalNumber + 1;
  14903. gunType[connectorIndex] = GUN_TYPE_GBT;
  14904. connectorIndex = connectorIndex + 1;
  14905. }
  14906. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  14907. {
  14908. SystemInitial = SystemInitial + 1;
  14909. gunTotalNumber = gunTotalNumber + 1;
  14910. gunType[connectorIndex] = GUN_TYPE_DO;
  14911. connectorIndex = connectorIndex + 1;
  14912. }
  14913. }
  14914. else
  14915. {
  14916. // AC Connector
  14917. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14918. {
  14919. SystemInitial = SystemInitial + 1;
  14920. gunTotalNumber = gunTotalNumber + 1;
  14921. gunType[connectorIndex] = GUN_TYPE_AC;
  14922. connectorIndex = connectorIndex + 1;
  14923. }
  14924. }
  14925. }
  14926. }
  14927. //DEBUG_INFO("DC ...\n");
  14928. }
  14929. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14930. {
  14931. //check connector / socket type (index: 8, 9, 10)
  14932. for(int index=7; index <10 ; index++)
  14933. {
  14934. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14935. {
  14936. SystemInitial = SystemInitial + 1;
  14937. gunTotalNumber = gunTotalNumber + 1;
  14938. gunType[connectorIndex] = GUN_TYPE_AC;
  14939. connectorIndex = connectorIndex + 1;
  14940. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14941. }
  14942. }
  14943. }
  14944. //Status && ConnectorPlugIn Setting
  14945. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14946. {
  14947. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14948. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14949. }
  14950. for (int index = 0; index < CCS_QUANTITY; index++)
  14951. {
  14952. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14953. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14954. }
  14955. for (int index = 0; index < GB_QUANTITY; index++)
  14956. {
  14957. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14958. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14959. }
  14960. for (int index = 0; index < AC_QUANTITY; index++)
  14961. {
  14962. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14963. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14964. }
  14965. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14966. {
  14967. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  14968. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  14969. }
  14970. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14971. {
  14972. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  14973. cpinitateMsg.bits[gun_index].StatusNotificationConf = OFF;
  14974. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14975. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14976. }
  14977. clientTime.Heartbeat=time((time_t*)NULL);
  14978. sleep(1);
  14979. }
  14980. void LWS_Send(char *str)
  14981. {
  14982. //=====================================================
  14983. // Check InternetConn 0: disconnected, 1: connected
  14984. //====================================================
  14985. if(GetOcppConnStatus() == 0)
  14986. {
  14987. DEBUG_INFO("offline now !!!\n");
  14988. return;
  14989. }
  14990. // Only disable isWebsocketSendable operation initiated by charger
  14991. if((strstr((char*)str, "\"Authorize\"") != NULL)
  14992. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  14993. || (strstr((char*)str, "\"ClearedChargingLimit\"") != NULL)
  14994. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  14995. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  14996. || (strstr((char*)str, "\"Get15118EVCertificate\"") != NULL)
  14997. || (strstr((char*)str, "\"GetCertificateStatus\"") != NULL)
  14998. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  14999. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15000. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15001. || (strstr((char*)str, "\"NotifyChargingLimit\"") != NULL)
  15002. || (strstr((char*)str, "\"NotifyCustomerInformation\"") != NULL)
  15003. || (strstr((char*)str, "\"NotifyDisplayMessages\"") != NULL)
  15004. || (strstr((char*)str, "\"NotifyEVChargingNeeds\"") != NULL)
  15005. || (strstr((char*)str, "\"NotifyEVChargingSchedule\"") != NULL)
  15006. || (strstr((char*)str, "\"NotifyEvent\"") != NULL)
  15007. || (strstr((char*)str, "\"NotifyMonitoringReport\"") != NULL)
  15008. || (strstr((char*)str, "\"NotifyReport\"") != NULL)
  15009. || (strstr((char*)str, "\"PublishFirmwareStatusNotification\"") != NULL)
  15010. || (strstr((char*)str, "\"ReportChargingProfiles\"") != NULL)
  15011. || (strstr((char*)str, "\"ReservationStatusUpdate\"") != NULL)
  15012. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15013. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15014. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15015. || (strstr((char*)str, "\"TransactionEven\"") != NULL))
  15016. {
  15017. isWebsocketSendable = OFF;
  15018. }
  15019. pthread_mutex_lock(&lock_send);
  15020. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15021. sprintf((char *)SendBuffer, "%s", str);
  15022. SendBufLen = strlen(str);
  15023. pthread_mutex_unlock(&lock_send);
  15024. lws_callback_on_writable(wsi_client);
  15025. //lws_service(context, 0);
  15026. //sleep(1);
  15027. }
  15028. void LWS_SendNow(char *str)
  15029. {
  15030. //=====================================================
  15031. // Check InternetConn 0: disconnected, 1: connected
  15032. //====================================================
  15033. if(GetOcppConnStatus() == 0)
  15034. {
  15035. DEBUG_INFO("offline now !!!\n");
  15036. return;
  15037. }
  15038. // Only disable isWebsocketSendable operation initiated by charger
  15039. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15040. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15041. || (strstr((char*)str, "\"ClearedChargingLimit\"") != NULL)
  15042. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15043. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15044. || (strstr((char*)str, "\"Get15118EVCertificate\"") != NULL)
  15045. || (strstr((char*)str, "\"GetCertificateStatus\"") != NULL)
  15046. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15047. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15048. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15049. || (strstr((char*)str, "\"NotifyChargingLimit\"") != NULL)
  15050. || (strstr((char*)str, "\"NotifyCustomerInformation\"") != NULL)
  15051. || (strstr((char*)str, "\"NotifyDisplayMessages\"") != NULL)
  15052. || (strstr((char*)str, "\"NotifyEVChargingNeeds\"") != NULL)
  15053. || (strstr((char*)str, "\"NotifyEVChargingSchedule\"") != NULL)
  15054. || (strstr((char*)str, "\"NotifyEvent\"") != NULL)
  15055. || (strstr((char*)str, "\"NotifyMonitoringReport\"") != NULL)
  15056. || (strstr((char*)str, "\"NotifyReport\"") != NULL)
  15057. || (strstr((char*)str, "\"PublishFirmwareStatusNotification\"") != NULL)
  15058. || (strstr((char*)str, "\"ReportChargingProfiles\"") != NULL)
  15059. || (strstr((char*)str, "\"ReservationStatusUpdate\"") != NULL)
  15060. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15061. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15062. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15063. || (strstr((char*)str, "\"TransactionEven\"") != NULL))
  15064. {
  15065. isWebsocketSendable = OFF;
  15066. }
  15067. pthread_mutex_lock(&lock_send);
  15068. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15069. sprintf((char *)SendBuffer, "%s", str);
  15070. SendBufLen = strlen(str);
  15071. pthread_mutex_unlock(&lock_send);
  15072. lws_callback_on_writable(wsi_client);
  15073. lws_service(context, 0);
  15074. //sleep(1);
  15075. }