MessageHandler.c 906 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708
  1. #include "Module_OcppBackend20.h"
  2. #include "define.h"
  3. static char *APNAuthenticationEnumTypeStr[] = {
  4. MACROSTR(CHAP),
  5. MACROSTR(NONE),
  6. MACROSTR(PAP),
  7. MACROSTR(AUTO)
  8. };
  9. static char *AttributeEnumTypeStr[] = {
  10. MACROSTR(Actual),
  11. MACROSTR(Target),
  12. MACROSTR(MinSet),
  13. MACROSTR(MaxSet)
  14. };
  15. static char *AuthorizationStatusEnumTypeStr[] = {
  16. MACROSTR(Accepted),
  17. MACROSTR(Blocked),
  18. MACROSTR(ConcurrentTx),
  19. MACROSTR(Expired),
  20. MACROSTR(Invalid),
  21. MACROSTR(NoCredit),
  22. MACROSTR(NotAllowedTypeEVSE),
  23. MACROSTR(NotAtThisLocation),
  24. MACROSTR(NotAtThisTime),
  25. MACROSTR(Unknown)
  26. };
  27. #if 0
  28. static char *AuthorizeCertificateStatusEnumTypeStr[] = {
  29. MACROSTR(Accepted),
  30. MACROSTR(SignatureError),
  31. MACROSTR(CertificateExpired),
  32. MACROSTR(CertificateRevoked),
  33. MACROSTR(NoCertificateAvailable),
  34. MACROSTR(CertChainError),
  35. MACROSTR(ContractCancelled)
  36. };
  37. #endif
  38. static char *BootReasonEnumTypeStr[] = {
  39. MACROSTR(ApplicationReset),
  40. MACROSTR(FirmwareUpdate),
  41. MACROSTR(LocalReset),
  42. MACROSTR(PowerUp),
  43. MACROSTR(RemoteReset),
  44. MACROSTR(ScheduledReset),
  45. MACROSTR(Triggered),
  46. MACROSTR(Unknown),
  47. MACROSTR(Watchdog)
  48. };
  49. static char *CancelReservationStatusEnumTypeStr[] = {
  50. MACROSTR(Accepted),
  51. MACROSTR(Rejected)
  52. };
  53. static char *CertificateActionEnumTypeStr[] = {
  54. MACROSTR(Install),
  55. MACROSTR(Update)
  56. };
  57. static char *CertificateSignedStatusEnumTypeStr[] = {
  58. MACROSTR(Accepted),
  59. MACROSTR(Rejected)
  60. };
  61. static char *CertificateSigningUseEnumTypeStr[] = {
  62. MACROSTR(ChargingStationCertificate),
  63. MACROSTR(V2GCertificate)
  64. };
  65. static char *ChangeAvailabilityStatusEnumTypeStr[] = {
  66. MACROSTR(Accepted),
  67. MACROSTR(Rejected),
  68. MACROSTR(Scheduled)
  69. };
  70. #if 0
  71. static char *ChargingLimitSourceEnumTypeStr[] = {
  72. MACROSTR(EMS),
  73. MACROSTR(Other),
  74. MACROSTR(SO),
  75. MACROSTR(CSO)
  76. };
  77. #endif
  78. static char *ChargingProfileKindEnumTypeStr[] = {
  79. MACROSTR(Absolute),
  80. MACROSTR(Recurring),
  81. MACROSTR(Relative)
  82. };
  83. static char *ChargingProfilePurposeEnumTypeStr[] = {
  84. MACROSTR(ChargingStationExternalConstraints),
  85. MACROSTR(ChargingStationMaxProfile),
  86. MACROSTR(TxDefaultProfile),
  87. MACROSTR(TxProfile)
  88. };
  89. static char *ChargingProfileStatusEnumTypeStr[] = {
  90. MACROSTR(Accepted),
  91. MACROSTR(Rejected)
  92. };
  93. static char *ChargingRateUnitEnumTypeStr[] = {
  94. MACROSTR(W),
  95. MACROSTR(A)
  96. };
  97. static char *ChargingStateEnumTypeStr[] = {
  98. MACROSTR(Charging),
  99. MACROSTR(EVConnected),
  100. MACROSTR(SuspendedEV),
  101. MACROSTR(SuspendedEVSE),
  102. MACROSTR(Idle)
  103. };
  104. static char *ClearCacheStatusEnumTypeStr[] = {
  105. MACROSTR(Accepted),
  106. MACROSTR(Rejected)
  107. };
  108. static char *ClearChargingProfileStatusEnumTypeStr[] = {
  109. MACROSTR(Accepted),
  110. MACROSTR(Unknown)
  111. };
  112. static char *ClearMessageStatusEnumTypeStr[] = {
  113. MACROSTR(Accepted),
  114. MACROSTR(Unknown)
  115. };
  116. static char *ClearMonitoringStatusEnumTypeStr[] = {
  117. MACROSTR(Accepted),
  118. MACROSTR(Rejected),
  119. MACROSTR(NotFound)
  120. };
  121. static char *ComponentCriterionEnumTypeStr[] = {
  122. MACROSTR(Active),
  123. MACROSTR(Available),
  124. MACROSTR(Enabled),
  125. MACROSTR(Problem)
  126. };
  127. #if 0
  128. static char *ConnectorEnumTypeStr[] = {
  129. MACROSTR(cCCS1),
  130. MACROSTR(cCCS2),
  131. MACROSTR(cG105),
  132. MACROSTR(cTesla),
  133. MACROSTR(cType1),
  134. MACROSTR(cType2),
  135. MACROSTR(s309-1P-16A),
  136. MACROSTR(s309-1P-32A),
  137. MACROSTR(s309-3P-16A),
  138. MACROSTR(s309-3P-32A),
  139. MACROSTR(sBS1361),
  140. MACROSTR(sCEE-7-7),
  141. MACROSTR(sType2),
  142. MACROSTR(sType3),
  143. MACROSTR(Other1PhMax16A),
  144. MACROSTR(Other1PhOver16A),
  145. MACROSTR(Other3Ph),
  146. MACROSTR(Pan),
  147. MACROSTR(wInductive),
  148. MACROSTR(wResonant),
  149. MACROSTR(Undetermined),
  150. MACROSTR(Unknown)
  151. };
  152. #endif
  153. static char *ConnectorStatusEnumTypeStr[] = {
  154. MACROSTR(Available),
  155. MACROSTR(Occupied),
  156. MACROSTR(Reserved),
  157. MACROSTR(Unavailable),
  158. MACROSTR(Faulted)
  159. };
  160. #if 0
  161. static char *CostKindEnumTypeStr[] = {
  162. MACROSTR(CarbonDioxideEmission),
  163. MACROSTR(RelativePricePercentage),
  164. MACROSTR(RenewableGenerationPercentage)
  165. };
  166. #endif
  167. static char *CustomerInformationStatusEnumTypeStr[] = {
  168. MACROSTR(Accepted),
  169. MACROSTR(Rejected),
  170. MACROSTR(Invalid)
  171. };
  172. static char *DataEnumTypeStr[] = {
  173. MACROSTR(string),
  174. MACROSTR(decimal),
  175. MACROSTR(integer),
  176. MACROSTR(dateTime),
  177. MACROSTR(boolean),
  178. MACROSTR(OptionList),
  179. MACROSTR(SequenceList),
  180. MACROSTR(MemberList)
  181. };
  182. static char *DataTransferStatusEnumTypeStr[] = {
  183. MACROSTR(Accepted),
  184. MACROSTR(Rejected),
  185. MACROSTR(UnknownMessageId),
  186. MACROSTR(UnknownVendorId)
  187. };
  188. static char *DeleteCertificateStatusEnumTypeStr[] = {
  189. MACROSTR(Accepted),
  190. MACROSTR(Failed),
  191. MACROSTR(NotFound)
  192. };
  193. static char *DisplayMessageStatusEnumTypeStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(NotSupportedMessageFormat),
  196. MACROSTR(Rejected),
  197. MACROSTR(NotSupportedPriority),
  198. MACROSTR(NotSupportedState),
  199. MACROSTR(UnknownTransaction)
  200. };
  201. #if 0
  202. static char *EnergyTransferModeEnumTypeStr[] = {
  203. MACROSTR(DC),
  204. MACROSTR(AC_single_phase),
  205. MACROSTR(AC_two_phase),
  206. MACROSTR(AC_three_phase)
  207. };
  208. #endif
  209. static char *EventNotificationEnumTypeStr[] = {
  210. MACROSTR(HardWiredNotification),
  211. MACROSTR(HardWiredMonitor),
  212. MACROSTR(PreconfiguredMonitor),
  213. MACROSTR(CustomMonitor)
  214. };
  215. static char *EventTriggerEnumTypeStr[] = {
  216. MACROSTR(Alerting),
  217. MACROSTR(Delta),
  218. MACROSTR(Periodic)
  219. };
  220. static char *FirmwareStatusEnumTypeStr[] = {
  221. MACROSTR(Downloaded),
  222. MACROSTR(DownloadFailed),
  223. MACROSTR(Downloading),
  224. MACROSTR(DownloadScheduled),
  225. MACROSTR(DownloadPaused),
  226. MACROSTR(Idle),
  227. MACROSTR(InstallationFailed),
  228. MACROSTR(Installing),
  229. MACROSTR(Installed),
  230. MACROSTR(InstallRebooting),
  231. MACROSTR(InstallScheduled),
  232. MACROSTR(InstallVerificationFailed),
  233. MACROSTR(InvalidSignature),
  234. MACROSTR(SignatureVerified)
  235. };
  236. static char *GenericDeviceModelStatusEnumTypeStr[] = {
  237. MACROSTR(Accepted),
  238. MACROSTR(Rejected),
  239. MACROSTR(NotSupported),
  240. MACROSTR(EmptyResultSet)
  241. };
  242. static char *GenericStatusEnumTypeStr[] = {
  243. MACROSTR(Accepted),
  244. MACROSTR(Rejected)
  245. };
  246. static char *GetCertificateIdUseEnumTypeStr[] = {
  247. MACROSTR(V2GRootCertificate),
  248. MACROSTR(MORootCertificate),
  249. MACROSTR(CSMSRootCertificate),
  250. MACROSTR(V2GCertificateChain),
  251. MACROSTR(ManufacturerRootCertificate)
  252. };
  253. static char *GetCertificateStatusEnumTypeStr[] = {
  254. MACROSTR(Accepted),
  255. MACROSTR(Failed)
  256. };
  257. static char *GetChargingProfileStatusEnumTypeStr[] = {
  258. MACROSTR(Accepted),
  259. MACROSTR(NoProfiles)
  260. };
  261. static char *GetDisplayMessagesStatusEnumTypeStr[] = {
  262. MACROSTR(Accepted),
  263. MACROSTR(Unknown)
  264. };
  265. static char *GetInstalledCertificateStatusEnumTypeStr[] = {
  266. MACROSTR(Accepted),
  267. MACROSTR(NotFound)
  268. };
  269. static char *GetVariableStatusEnumTypeStr[] = {
  270. MACROSTR(Accepted),
  271. MACROSTR(Rejected),
  272. MACROSTR(UnknownComponent),
  273. MACROSTR(UnknownVariable),
  274. MACROSTR(NotSupportedAttributeType)
  275. };
  276. static char *HashAlgorithmEnumTypeStr[] = {
  277. MACROSTR(SHA256),
  278. MACROSTR(SHA384),
  279. MACROSTR(SHA512)
  280. };
  281. static char *IdTokenEnumTypeStr[] = {
  282. MACROSTR(Central),
  283. MACROSTR(eMAID),
  284. MACROSTR(ISO14443),
  285. MACROSTR(KeyCode),
  286. MACROSTR(Local),
  287. MACROSTR(NoAuthorization),
  288. MACROSTR(ISO15693)
  289. };
  290. static char *InstallCertificateUseEnumTypeStr[] = {
  291. MACROSTR(V2GRootCertificate),
  292. MACROSTR(MORootCertificate),
  293. MACROSTR(CSMSRootCertificate),
  294. MACROSTR(ManufacturerRootCertificate)
  295. };
  296. static char *InstallCertificateStatusEnumTypeStr[]={
  297. MACROSTR(Accepted),
  298. MACROSTR(Failed),
  299. MACROSTR(Rejected)
  300. };
  301. static char *Iso15118EVCertificateStatusEnumTypeStr[] = {
  302. MACROSTR(Accepted),
  303. MACROSTR(Failed)
  304. };
  305. static char *LocationEnumTypeStr[] = {
  306. MACROSTR(Body),
  307. MACROSTR(Cable),
  308. MACROSTR(EV),
  309. MACROSTR(Inlet),
  310. MACROSTR(Outlet)
  311. };
  312. static char *LogEnumTypeStr[] = {
  313. MACROSTR(DiagnosticsLog),
  314. MACROSTR(SecurityLog)
  315. };
  316. static char *LogStatusEnumTypeStr[] = {
  317. MACROSTR(Accepted),
  318. MACROSTR(Rejected),
  319. MACROSTR(AcceptedCanceled)
  320. };
  321. static char *MeasurandEnumTypeStr[] = {
  322. MACROSTR(Current.Export),
  323. MACROSTR(Current.Import),
  324. MACROSTR(Current.Offered),
  325. MACROSTR(Energy.Active.Export.Register),
  326. MACROSTR(Energy.Active.Import.Register),
  327. MACROSTR(Energy.Reactive.Export.Register),
  328. MACROSTR(Energy.Reactive.Import.Register),
  329. MACROSTR(Energy.Active.Export.Interval),
  330. MACROSTR(Energy.Active.Import.Interval),
  331. MACROSTR(Energy.Active.Net),
  332. MACROSTR(Energy.Reactive.Export.Interval),
  333. MACROSTR(Energy.Reactive.Import.Interval),
  334. MACROSTR(Energy.Reactive.Net),
  335. MACROSTR(Energy.Apparent.Net),
  336. MACROSTR(Energy.Apparent.Import),
  337. MACROSTR(Energy.Apparent.Export),
  338. MACROSTR(Frequency),
  339. MACROSTR(Power.Active.Export),
  340. MACROSTR(Power.Active.Import),
  341. MACROSTR(Power.Factor),
  342. MACROSTR(Power.Offered),
  343. MACROSTR(Power.Reactive.Export),
  344. MACROSTR(Power.Reactive.Import),
  345. MACROSTR(SoC),
  346. MACROSTR(Voltage)
  347. };
  348. static char *MessageFormatEnumTypeStr[] = {
  349. MACROSTR(ASCII),
  350. MACROSTR(HTML),
  351. MACROSTR(URI),
  352. MACROSTR(UTF8)
  353. };
  354. static char *MessagePriorityEnumTypeStr[] = {
  355. MACROSTR(AlwaysFront),
  356. MACROSTR(InFront),
  357. MACROSTR(NormalCycle)
  358. };
  359. static char *MessageStateEnumTypeStr[] = {
  360. MACROSTR(Charging),
  361. MACROSTR(Faulted),
  362. MACROSTR(Idle),
  363. MACROSTR(Unavailable)
  364. };
  365. static char *MessageTriggerEnumTypeStr[] = {
  366. MACROSTR(BootNotification),
  367. MACROSTR(LogStatusNotification),
  368. MACROSTR(FirmwareStatusNotification),
  369. MACROSTR(Heartbeat),
  370. MACROSTR(MeterValues),
  371. MACROSTR(SignChargingStationCertificate),
  372. MACROSTR(SignV2GCertificate),
  373. MACROSTR(StatusNotification),
  374. MACROSTR(TransactionEvent),
  375. MACROSTR(SignCombinedCertificate),
  376. MACROSTR(PublishFirmwareStatusNotification)
  377. };
  378. static char *MonitorEnumTypeStr[] = {
  379. MACROSTR(UpperThreshold),
  380. MACROSTR(LowerThreshold),
  381. MACROSTR(Delta),
  382. MACROSTR(Periodic),
  383. MACROSTR(PeriodicClockAligned)
  384. };
  385. static char *MonitoringBaseEnumTypeStr[] = {
  386. MACROSTR(All),
  387. MACROSTR(FactoryDefault),
  388. MACROSTR(HardWiredOnly)
  389. };
  390. static char *MonitoringCriterionEnumTypeStr[] = {
  391. MACROSTR(ThresholdMonitoring),
  392. MACROSTR(DeltaMonitoring),
  393. MACROSTR(PeriodicMonitoring)
  394. };
  395. static char *MutabilityEnumTypeStr[] = {
  396. MACROSTR(ReadOnly),
  397. MACROSTR(WriteOnly),
  398. MACROSTR(ReadWrite)
  399. };
  400. static char *NotifyEVChargingNeedsStatusEnumTypeStr[] = {
  401. MACROSTR(Accepted),
  402. MACROSTR(Rejected),
  403. MACROSTR(Processing)
  404. };
  405. static char *OCPPInterfaceEnumTypeStr[] = {
  406. MACROSTR(Wired0),
  407. MACROSTR(Wired1),
  408. MACROSTR(Wired2),
  409. MACROSTR(Wired3),
  410. MACROSTR(Wireless0),
  411. MACROSTR(Wireless1),
  412. MACROSTR(Wireless2),
  413. MACROSTR(Wireless3)
  414. };
  415. static char *OCPPTransportEnumTypeStr[] = {
  416. MACROSTR(JSON),
  417. MACROSTR(SOAP)
  418. };
  419. static char *OCPPVersionEnumTypeStr[] = {
  420. MACROSTR(OCPP12),
  421. MACROSTR(OCPP15),
  422. MACROSTR(OCPP16),
  423. MACROSTR(OCPP20)
  424. };
  425. static char *OperationalStatusEnumTypeStr[] = {
  426. MACROSTR(Inoperative),
  427. MACROSTR(Operative)
  428. };
  429. static char *PhaseEnumTypeStr[] = {
  430. MACROSTR(L1),
  431. MACROSTR(L2),
  432. MACROSTR(L3),
  433. MACROSTR(N),
  434. MACROSTR(L1-N),
  435. MACROSTR(L2-N),
  436. MACROSTR(L3-N),
  437. MACROSTR(L1-L2),
  438. MACROSTR(L2-L3),
  439. MACROSTR(L3-L1)
  440. };
  441. static char *PublishFirmwareStatusEnumTypeStr[] = {
  442. MACROSTR(Downloaded),
  443. MACROSTR(DownloadFailed),
  444. MACROSTR(Downloading),
  445. MACROSTR(DownloadScheduled),
  446. MACROSTR(DownloadPaused),
  447. MACROSTR(PublishFailed),
  448. MACROSTR(Published),
  449. MACROSTR(InvalidChecksum),
  450. MACROSTR(ChecksumVerified)
  451. };
  452. static char *ReadingContextEnumTypeStr[] = {
  453. MACROSTR(Interruption.Begin),
  454. MACROSTR(Interruption.End),
  455. MACROSTR(Other),
  456. MACROSTR(Sample.Clock),
  457. MACROSTR(Sample.Periodic),
  458. MACROSTR(Transaction.Begin),
  459. MACROSTR(Transaction.End),
  460. MACROSTR(Trigger)
  461. };
  462. #if 0
  463. static char *ReasonEnumTypeStr[] = {
  464. MACROSTR(DeAuthorized),
  465. MACROSTR(EmergencyStop),
  466. MACROSTR(EnergyLimitReached),
  467. MACROSTR(EVDisconnected),
  468. MACROSTR(GroundFault),
  469. MACROSTR(ImmediateReset),
  470. MACROSTR(Local),
  471. MACROSTR(LocalOutOfCredit),
  472. MACROSTR(MasterPass),
  473. MACROSTR(Other),
  474. MACROSTR(OvercurrentFault),
  475. MACROSTR(PowerLoss),
  476. MACROSTR(PowerQuality),
  477. MACROSTR(Reboot),
  478. MACROSTR(Remote),
  479. MACROSTR(SOCLimitReached),
  480. MACROSTR(StoppedByEV),
  481. MACROSTR(TimeLimitReached),
  482. MACROSTR(TimeLimitReached)
  483. };
  484. #endif
  485. static char *RecurrencyKindEnumTypeStr[] = {
  486. MACROSTR(Daily),
  487. MACROSTR(Weekly)
  488. };
  489. static char *RegistrationStatusEnumTypeStr[] = {
  490. MACROSTR(Accepted),
  491. MACROSTR(Pending),
  492. MACROSTR(Rejected)
  493. };
  494. static char *ReportBaseEnumTypeStr[] = {
  495. MACROSTR(ConfigurationInventory),
  496. MACROSTR(FullInventory),
  497. MACROSTR(SummaryInventory)
  498. };
  499. static char *RequestStartStopStatusEnumTypeStr[] = {
  500. MACROSTR(Accepted),
  501. MACROSTR(Rejected)
  502. };
  503. static char *ReservationUpdateStatusEnumTypeStr[] = {
  504. MACROSTR(Expired),
  505. MACROSTR(Removed)
  506. };
  507. static char *ReserveNowStatusEnumTypeStr[] = {
  508. MACROSTR(Accepted),
  509. MACROSTR(Faulted),
  510. MACROSTR(Occupied),
  511. MACROSTR(Rejected),
  512. MACROSTR(Unavailable)
  513. };
  514. static char *ResetEnumTypeStr[] = {
  515. MACROSTR(Immediate),
  516. MACROSTR(OnIdle)
  517. };
  518. static char *ResetStatusEnumTypeStr[] = {
  519. MACROSTR(Accepted),
  520. MACROSTR(Rejected),
  521. MACROSTR(Scheduled)
  522. };
  523. static char *SetMonitoringStatusEnumTypeStr[] = {
  524. MACROSTR(Accepted),
  525. MACROSTR(UnknownComponent),
  526. MACROSTR(UnknownVariable),
  527. MACROSTR(UnsupportedMonitorType),
  528. MACROSTR(Rejected),
  529. MACROSTR(OutOfRange),
  530. MACROSTR(Duplicate)
  531. };
  532. static char *SetNetworkProfileStatusEnumTypeStr[] = {
  533. MACROSTR(Accepted),
  534. MACROSTR(Rejected),
  535. MACROSTR(Failed)
  536. };
  537. static char *SetVariableStatusEnumTypeStr[] = {
  538. MACROSTR(Accepted),
  539. MACROSTR(Rejected),
  540. MACROSTR(InvalidValue),
  541. MACROSTR(UnknownComponent),
  542. MACROSTR(UnknownVariable),
  543. MACROSTR(NotSupportedAttributeType),
  544. MACROSTR(OutOfRange),
  545. MACROSTR(RebootRequired)
  546. };
  547. static char *TransactionEventEnumTypeStr[] = {
  548. MACROSTR(Ended),
  549. MACROSTR(Started),
  550. MACROSTR(Updated)
  551. };
  552. static char *TriggerMessageStatusEnumTypeStr[] = {
  553. MACROSTR(Accepted),
  554. MACROSTR(Rejected),
  555. MACROSTR(NotImplemented)
  556. };
  557. static char *TriggerReasonEnumTypeStr[] = {
  558. MACROSTR(Authorized),
  559. MACROSTR(CablePluggedIn),
  560. MACROSTR(ChargingRateChanged),
  561. MACROSTR(ChargingStateChanged),
  562. MACROSTR(Deauthorized),
  563. MACROSTR(EnergyLimitReached),
  564. MACROSTR(EVCommunicationLost),
  565. MACROSTR(EVConnectTimeout),
  566. MACROSTR(MeterValueClock),
  567. MACROSTR(MeterValuePeriodic),
  568. MACROSTR(TimeLimitReached),
  569. MACROSTR(Trigger),
  570. MACROSTR(UnlockCommand),
  571. MACROSTR(StopAuthorized),
  572. MACROSTR(EVDeparted),
  573. MACROSTR(EVDetected),
  574. MACROSTR(RemoteStop),
  575. MACROSTR(RemoteStart),
  576. MACROSTR(AbnormalCondition),
  577. MACROSTR(SignedDataReceived),
  578. MACROSTR(ResetCommand)
  579. };
  580. static char *UnlockStatusEnumTypeStr[] = {
  581. MACROSTR(Unlocked),
  582. MACROSTR(UnlockFailed),
  583. MACROSTR(OngoingAuthorizedTransaction),
  584. MACROSTR(UnknownConnector)
  585. };
  586. static char *UnpublishFirmwareStatusEnumTypeStr[] = {
  587. MACROSTR(DownloadOngoing),
  588. MACROSTR(NoFirmware),
  589. MACROSTR(Unpublished)
  590. };
  591. static char *UpdateEnumTypeStr[] = {
  592. MACROSTR(Differential),
  593. MACROSTR(Full)
  594. };
  595. static char *UpdateFirmwareStatusEnumTypeStr[] = {
  596. MACROSTR(Accepted),
  597. MACROSTR(Rejected),
  598. MACROSTR(AcceptedCanceled),
  599. MACROSTR(InvalidCertificate),
  600. MACROSTR(RevokedCertificate)
  601. };
  602. static char *UpdateStatusEnumTypeStr[] = {
  603. MACROSTR(Accepted),
  604. MACROSTR(Failed),
  605. MACROSTR(VersionMismatch)
  606. };
  607. static char *UploadLogStatusEnumTypeStr[] = {
  608. MACROSTR(BadMessage),
  609. MACROSTR(Idle),
  610. MACROSTR(NotSupportedOperation),
  611. MACROSTR(PermissionDenied),
  612. MACROSTR(Uploaded),
  613. MACROSTR(UploadFailure),
  614. MACROSTR(Uploading)
  615. };
  616. static char *VPNEnumTypeStr[] = {
  617. MACROSTR(IKEv2),
  618. MACROSTR(IPSec),
  619. MACROSTR(L2TP),
  620. MACROSTR(PPTP)
  621. };
  622. #if 0
  623. static char *ChargePointErrorCodeEnumTypeStr[] = {
  624. MACROSTR(ConnectorLockFailure),
  625. MACROSTR(EVCommunicationError),
  626. MACROSTR(GroundFailure),
  627. MACROSTR(HighTemperature),
  628. MACROSTR(InternalError),
  629. MACROSTR(LocalListConflict),
  630. MACROSTR(NoError),
  631. MACROSTR(OtherError),
  632. MACROSTR(OverCurrentFailure),
  633. MACROSTR(OverVoltage),
  634. MACROSTR(PowerMeterFailure),
  635. MACROSTR(PowerSwitchFailure),
  636. MACROSTR(ReaderFailure),
  637. MACROSTR(ResetFailure),
  638. MACROSTR(UnderVoltage),
  639. MACROSTR(WeakSignal)
  640. };
  641. #endif
  642. static char *GetCompositeScheduleStatusEnumTypeStr[] = {
  643. MACROSTR(Accepted),
  644. MACROSTR(Rejected)
  645. };
  646. static char *RemoteStartStopStatusEnumTypeStr[] = {
  647. MACROSTR(Accepted),
  648. MACROSTR(Rejected)
  649. };
  650. #if 0
  651. static char * StopTransactionReasonEnumTypeStr[] = {
  652. MACROSTR(EmergencyStop),
  653. MACROSTR(EVDisconnected),
  654. MACROSTR(HardReset),
  655. MACROSTR(Local),
  656. MACROSTR(Other),
  657. MACROSTR(PowerLoss),
  658. MACROSTR(Reboot),
  659. MACROSTR(Remote),
  660. MACROSTR(SoftReset),
  661. MACROSTR(UnlockCommand),
  662. MACROSTR(DeAuthorized)
  663. };
  664. #endif
  665. //ChargePointMaxProfile
  666. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile_OCPP20.json"
  667. //TxDefaultProfile
  668. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0_OCPP20.json"
  669. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  670. struct StatusCodeData *ShmStatusCodeData;
  671. struct PsuData *ShmPsuData ;
  672. struct OCPP20Data *ShmOCPP20Data;
  673. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  674. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  675. //===============================
  676. // Gun Total Numbers
  677. //===============================
  678. static int gunTotalNumber = 0;
  679. static uint8_t gunType[4] = {0};
  680. //===============================
  681. // Local List Version
  682. //===============================
  683. static int localversion=0;
  684. //===============================
  685. // OCPP sign variable
  686. //===============================
  687. static int server_sign = FALSE;
  688. int server_pending = FALSE;
  689. static int BootNotificationInterval = 10;
  690. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  691. //===============================
  692. // OCPP auth variable
  693. //===============================
  694. static int authorizeRetryTimes = 0; //number of Retry times
  695. //===============================
  696. // OCPP other variables
  697. //===============================
  698. static int HeartBeatWaitTime = 10;
  699. static int FirstHeartBeat = 0;
  700. static int FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle; // Idle
  701. static int LogStatusNotificationStatus = UploadLogStatusEnumType_Idle; // Idle
  702. static char CurrentChargingProfileScheduleStr[30] = {0};
  703. //========================================
  704. // OCPP status/previous related variables
  705. //========================================
  706. static int GunStatusInterval = 10;
  707. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  708. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  709. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  710. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  711. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  712. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  713. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  714. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  715. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  716. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  717. static int TransactionMessageAttemptsValue = 0;
  718. static int TransactionMessageRetryIntervalValue = 0;
  719. static struct AuthorizationData idTagQuery;
  720. //=============================================
  721. // OCPP HeartBeat Response Not Receive Counts
  722. //============================================
  723. static int HeartBeatWithNOResponse = 0;
  724. static int HeartBeatCountPerHour = 0;
  725. sqlite3 *db;
  726. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  727. int TransactionMessageAttemptsGet(void);
  728. int TransactionMessageRetryIntervalGet(void);
  729. int GetOcppConnStatus(void);
  730. void SetOcppConnStatus(uint8_t status);
  731. int setKeyValue(char *key, char *value);
  732. void OCPP_get_TableAuthlocalAllData(void);
  733. void processUnkownKey(void);
  734. struct StructOCPPMeterValue
  735. {
  736. unsigned char TimeStamp[28];
  737. struct StructSampledValue SampledValue[10];
  738. };
  739. struct ClientTime
  740. {
  741. unsigned int Heartbeat;
  742. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  743. unsigned int StartTransaction;
  744. unsigned int StopTransaction;
  745. unsigned int MeterValues[CONNECTOR_QUANTITY];
  746. }clientTime;
  747. typedef union
  748. {
  749. //Operations Initiated by Central System
  750. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  751. struct
  752. {
  753. //CsMsgValue[0]
  754. unsigned char StatusNotificationReq:1; //bit 0,
  755. unsigned char StatusNotificationConf:1; //bit 1,
  756. unsigned char TriggerMeterValueReq:1; //bit 2,
  757. unsigned char TransactionEventReq:1; //bit 3,
  758. unsigned char SampleMeterReq:1; //bit 4,
  759. unsigned char ClockAlignMeterReq:1; //bit 5,
  760. unsigned char TriggerStatusNotificationReq:1; //bit 6,
  761. unsigned char isOnCharging:1; //bit7
  762. }bits[CONNECTOR_QUANTITY];
  763. }CpinitiateMsg;
  764. CpinitiateMsg cpinitateMsg;
  765. //=========================================
  766. // Save configuration
  767. //=========================================
  768. int runShellCmd(const char*cmd)
  769. {
  770. int result = FAIL;
  771. char buf[256];
  772. FILE *fp;
  773. fp = popen(cmd, "r");
  774. if(fp != NULL)
  775. {
  776. while(fgets(buf, sizeof(buf), fp) != NULL)
  777. {
  778. DEBUG_INFO("%s\n", buf);
  779. }
  780. result = PASS;
  781. }
  782. pclose(fp);
  783. return result;
  784. }
  785. int StoreUsrConfigData(struct SysConfigData *UsrData)
  786. {
  787. int result = PASS;
  788. int fd,wrd;
  789. unsigned int i,Chk;
  790. unsigned char *ptr, *BufTmp;
  791. int MtdBlockSize = 0x300000;
  792. Chk=0;
  793. ptr=(unsigned char *)UsrData;
  794. if((BufTmp=malloc(MtdBlockSize))!=NULL)
  795. {
  796. memset(BufTmp,0,MtdBlockSize);
  797. memcpy(BufTmp,ptr,sizeof(struct SysConfigData));
  798. for(i=ARRAY_SIZE(UsrData->CsuBootLoadFwRev);i<MtdBlockSize-4;i++)
  799. Chk+=*(BufTmp+i);
  800. memcpy(BufTmp+MtdBlockSize-4, &Chk, 4);
  801. // Output configuration to file.
  802. fd = open("/mnt/EvseConfig.bin", O_RDWR|O_CREAT);
  803. if (fd < 0)
  804. {
  805. DEBUG_ERROR("open /mnt/EvseConfig.bin NG\n");
  806. free(BufTmp);
  807. return 0;
  808. }
  809. wrd=write(fd, BufTmp, MtdBlockSize);
  810. close(fd);
  811. if(wrd<MtdBlockSize)
  812. {
  813. DEBUG_ERROR("write /mnt/EvseConfig.bin NG\n");
  814. free(BufTmp);
  815. return 0;
  816. }
  817. DEBUG_INFO("EvseConfig write to file in /mnt OK.\n");
  818. DEBUG_INFO("Erase /dev/mtd10.\n");
  819. runShellCmd("flash_erase /dev/mtd10 0 0");
  820. DEBUG_INFO("Write /dev/mtd10.\n");
  821. runShellCmd("nandwrite -p /dev/mtd10 /mnt/EvseConfig.bin");
  822. DEBUG_INFO("Erase /dev/mtd11.\n");
  823. runShellCmd("flash_erase /dev/mtd11 0 0");
  824. DEBUG_INFO("Write /dev/mtd11.\n");
  825. runShellCmd("nandwrite -p /dev/mtd11 /mnt/EvseConfig.bin");
  826. system("rm -f /mnt/EvseConfig.bin");
  827. DEBUG_INFO("EvseConfig write to flash OK\n");
  828. }
  829. else
  830. {
  831. DEBUG_ERROR("alloc BlockSize NG\r\n");
  832. result = FAIL;
  833. }
  834. if(BufTmp!=NULL)
  835. free(BufTmp);
  836. return result;
  837. }
  838. //=========================================
  839. // Date time related function
  840. //=========================================
  841. void getNowDatetime(uint8_t *data)
  842. {
  843. time_t t = time(NULL);
  844. struct tm tm = *localtime(&t);
  845. sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  846. }
  847. //=========================================
  848. // Sqlite3 related function
  849. //=========================================
  850. int DB_Initial()
  851. {
  852. int result = PASS;
  853. char* errMsg = NULL;
  854. char *sqlOcppAuthCache = "create table if not exists ocpp20_auth_cache (idx integer primary key,"
  855. "idToken text UNIQUE,"
  856. "type text,"
  857. "status text,"
  858. "cacheExpiryDateTime text,"
  859. "chargingPriority integer,"
  860. "language1 text,"
  861. "evseId text,"
  862. "language2 text,"
  863. "groupIdToken_idToken text,"
  864. "groupIdToken_type text,"
  865. "personalMessage text);";
  866. char *sqlOcppAuthLocal = "create table if not exists ocpp20_auth_local (idx integer primary key,"
  867. "idToken text UNIQUE,"
  868. "type text,"
  869. "status text,"
  870. "cacheExpiryDateTime text,"
  871. "chargingPriority integer,"
  872. "language1 text,"
  873. "evseId text,"
  874. "language2 text,"
  875. "groupIdToken_idToken text,"
  876. "groupIdToken_type text,"
  877. "personalMessage text,"
  878. "version text);";
  879. char *sqlOcppVariable = "create table if not exists ocpp20_variable (idx integer primary key,"
  880. "componentName text NOT NULL ,"
  881. "componentInstance text, "
  882. "variableName text NOT NULL, "
  883. "variableInstance text, "
  884. "variableCharacteristicsDataType integer, "
  885. "variableCharacteristicsUnit text, "
  886. "variableCharacteristicsMaxLimit real,"
  887. "variableAttributesType text, "
  888. "variableAttributesTypeMutability text, "
  889. "variableAttributesTypeValue text, "
  890. "unique(componentName, componentInstance,variableName, variableInstance) on conflict replace);";
  891. char *sqlBootType = "create table if not exists ocpp20_boot_type (idx integer primary key,"
  892. "type text);";
  893. char *sqlNetworkProfile = "create table if not exists ocpp20_networkprofile (idx integer primary key,"
  894. "slot integer UNIQUE, connectionData text);";
  895. char *sqlTransaction = "create table if not exists ocpp20_transaction_record (idx integer primary key,"
  896. "occurDatetime text,"
  897. "message_type text,"
  898. "message_content text)";
  899. //sqlite3_config(SQLITE_CONFIG_URI, 1);
  900. if(sqlite3_open(OCPP_LOCAL_DB_FILE, &db))
  901. {
  902. result = FAIL;
  903. DEBUG_ERROR( "Can't open database: %s\n", sqlite3_errmsg(db));
  904. sqlite3_close(db);
  905. }
  906. else
  907. {
  908. DEBUG_INFO( "OCPP local database open successfully.\n");
  909. if (sqlite3_exec(db, sqlOcppAuthCache, 0, 0, &errMsg) != SQLITE_OK)
  910. {
  911. result = FAIL;
  912. DEBUG_ERROR( "Create OCPP 2.0 auth cache table error message: %s\n", errMsg);
  913. }
  914. else
  915. {
  916. DEBUG_INFO( "Create OCPP 2.0 auth cache table table successfully\n");
  917. }
  918. if (sqlite3_exec(db, sqlOcppAuthLocal, 0, 0, &errMsg) != SQLITE_OK)
  919. {
  920. result = FAIL;
  921. DEBUG_ERROR( "Create OCPP 2.0 auth list table error message: %s\n", errMsg);
  922. }
  923. else
  924. {
  925. DEBUG_INFO( "Create OCPP 2.0 auth list table successfully\n");
  926. }
  927. if (sqlite3_exec(db, sqlOcppVariable, 0, 0, &errMsg) != SQLITE_OK)
  928. {
  929. result = FAIL;
  930. DEBUG_ERROR( "Create OCPP 2.0 variable table error message: %s\n", errMsg);
  931. }
  932. else
  933. {
  934. DEBUG_INFO( "Create OCPP 2.0 variable table successfully\n");
  935. }
  936. if (sqlite3_exec(db, sqlBootType, 0, 0, &errMsg) != SQLITE_OK)
  937. {
  938. result = FAIL;
  939. DEBUG_ERROR( "Create OCPP 2.0 boot_type table error message: %s\n", errMsg);
  940. }
  941. else
  942. {
  943. DEBUG_INFO( "Create OCPP 2.0 boot_type table successfully\n");
  944. }
  945. if (sqlite3_exec(db, sqlNetworkProfile, 0, 0, &errMsg) != SQLITE_OK)
  946. {
  947. result = FAIL;
  948. DEBUG_ERROR( "Create OCPP 2.0 ocpp20_networkprofile table error message: %s\n", errMsg);
  949. }
  950. else
  951. {
  952. DEBUG_INFO( "Create OCPP 2.0 ocpp20_networkprofile table successfully\n");
  953. }
  954. if (sqlite3_exec(db, sqlTransaction, 0, 0, &errMsg) != SQLITE_OK)
  955. {
  956. result = FAIL;
  957. DEBUG_ERROR( "Create OCPP 2.0 ocpp20_transaction_record table error message: %s\n", errMsg);
  958. }
  959. else
  960. {
  961. DEBUG_INFO( "Create OCPP 2.0 ocpp20_transaction_record table successfully\n");
  962. }
  963. //sqlite3_close(db);
  964. }
  965. return result;
  966. }
  967. int DB_cbGetVersion(void *para, int columnCount, char **columnValue, char **columnName)
  968. {
  969. localversion = columnValue[12] ? atoi(columnValue[12]) : 0;
  970. return 0;
  971. }
  972. void DB_getListVerion()
  973. {
  974. char sql[256];
  975. char* errMsg = NULL;
  976. strcpy(sql, "select * from ocpp20_auth_local order by version desc, idx desc limit 1");
  977. /* Execute SQL statement */
  978. if( sqlite3_exec(db, sql, DB_cbGetVersion, 0, &errMsg) != SQLITE_OK )
  979. {
  980. DEBUG_INFO("SQL error: %s", errMsg);
  981. }
  982. }
  983. int DB_cbGetIdTag(void *para, int columnCount, char **columnValue, char **columnName)
  984. {
  985. sprintf((char*)idTagQuery.idToken.idToken,"%s", columnValue[1] ? columnValue[1] : "NULL");
  986. sprintf((char*)idTagQuery.idToken.type,"%s", columnValue[2] ? columnValue[2] : "NULL");
  987. sprintf((char*)idTagQuery.idTokenInfo.status,"%s", columnValue[3] ? columnValue[3] : "NULL");
  988. sprintf((char*)idTagQuery.idTokenInfo.cacheExpiryDateTime,"%s", columnValue[4] ? columnValue[4] : "NULL");
  989. idTagQuery.idTokenInfo.chargingPriority = columnValue[5] ? atoi(columnValue[5]) : -1;
  990. sprintf((char*)idTagQuery.idTokenInfo.language1,"%s", columnValue[6] ? columnValue[6] : "NULL");
  991. sprintf((char*)idTagQuery.idTokenInfo.language2,"%s", columnValue[8] ? columnValue[8] : "NULL");
  992. sprintf((char*)idTagQuery.idTokenInfo.groupIdToken.idToken,"%s", columnValue[9] ? columnValue[9] : "NULL");
  993. sprintf((char*)idTagQuery.idTokenInfo.groupIdToken.type,"%s", columnValue[10] ? columnValue[10] : "NULL");
  994. return 0;
  995. }
  996. void DB_getIdTag(char idTag[], uint8_t isQueryFromCache)
  997. {
  998. char sql[256];
  999. char* errMsg = NULL;
  1000. memset(&idTagQuery, 0, sizeof(idTagQuery));
  1001. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  1002. if(isQueryFromCache)
  1003. sprintf(sql,"select * from ocpp20_auth_cache where idToken='%s'", idTag);
  1004. else
  1005. sprintf(sql,"select * from ocpp20_auth_local where idToken='%s'", idTag);
  1006. /* Execute SQL statement */
  1007. if(sqlite3_exec(db, sql, DB_cbGetIdTag, 0, &errMsg) != SQLITE_OK )
  1008. {
  1009. DEBUG_INFO("SQL error: %s", errMsg);
  1010. }
  1011. }
  1012. int DB_cbTableAuthlocalAllData(void *para, int columnCount, char **columnValue, char **columnName)
  1013. {
  1014. for (int i = 0; i < columnCount; i++)
  1015. {
  1016. DEBUG_INFO("%s = %s, ", columnName[i], columnValue[i]);
  1017. }
  1018. return 0;
  1019. }
  1020. void DB_get_TableAuthlocalAllData(void)
  1021. {
  1022. char sql[256];
  1023. char* errMsg = NULL;
  1024. sprintf(sql,"select * from ocpp20_auth_local;");
  1025. /* Execute SQL statement */
  1026. if(sqlite3_exec(db, sql, DB_cbTableAuthlocalAllData, 0,&errMsg) != SQLITE_OK)
  1027. {
  1028. DEBUG_INFO("SQL error: %s", errMsg);
  1029. }
  1030. }
  1031. int DB_cbAddLocalListCache(void *para, int columnCount, char **columnValue, char **columnName)
  1032. {
  1033. for(int i = 0; i<columnCount; i++)
  1034. {
  1035. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1036. }
  1037. return 0;
  1038. }
  1039. int DB_addLocalList(int listVersion, struct AuthorizationData *data)
  1040. {
  1041. int result = PASS;
  1042. char sql[512];
  1043. char* errMsg = NULL;
  1044. sprintf(sql,"insert or replace into ocpp20_auth_local (idToken, type, status, cacheExpiryDateTime, chargingPriority, language1, language2, groupIdToken_idToken, groupIdToken_type, version) VALUES('%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', %d ); SELECT * from ocpp20_auth_local;",
  1045. data->idToken.idToken,
  1046. data->idToken.type,
  1047. data->idTokenInfo.status,
  1048. data->idTokenInfo.cacheExpiryDateTime,
  1049. data->idTokenInfo.chargingPriority,
  1050. data->idTokenInfo.language1,
  1051. data->idTokenInfo.language2,
  1052. data->idTokenInfo.groupIdToken.idToken,
  1053. data->idTokenInfo.groupIdToken.type,
  1054. listVersion);
  1055. //* Execute SQL statement */
  1056. if(sqlite3_exec(db, sql, DB_cbAddLocalListCache, 0, &errMsg) != SQLITE_OK)
  1057. {
  1058. DEBUG_INFO("SQL error: %s\n", errMsg);
  1059. result = FAIL;
  1060. }
  1061. else
  1062. {
  1063. memset(sql, 0, ARRAY_SIZE(sql));
  1064. sprintf(sql, "UPDATE ocpp20_auth_local SET version=%d",listVersion);
  1065. if( sqlite3_exec(db, sql, NULL, NULL, &errMsg) != SQLITE_OK )
  1066. {
  1067. DEBUG_INFO("SQL error: %s\n", errMsg);
  1068. result = FAIL;
  1069. }
  1070. }
  1071. return result;
  1072. }
  1073. int DB_addLocalCache(struct IdTokenType *idToken, struct IdTokenInfoType *idTokenInfo)
  1074. {
  1075. int result = PASS;
  1076. char sql[512];
  1077. char* errMsg = NULL;
  1078. sprintf(sql,"insert or replace into ocpp20_auth_cache (idToken, type, status, cacheExpiryDateTime, chargingPriority, language1, language2, groupIdToken_idToken, groupIdToken_type) VALUES('%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s'); SELECT * from ocpp20_auth_cache;",
  1079. idToken->idToken,
  1080. idToken->type,
  1081. idTokenInfo->status,
  1082. idTokenInfo->cacheExpiryDateTime,
  1083. idTokenInfo->chargingPriority,
  1084. idTokenInfo->language1,
  1085. idTokenInfo->language2,
  1086. idTokenInfo->groupIdToken.idToken,
  1087. idTokenInfo->groupIdToken.type);
  1088. //* Execute SQL statement */
  1089. if(sqlite3_exec(db, sql, DB_cbAddLocalListCache, 0, &errMsg) != SQLITE_OK)
  1090. {
  1091. DEBUG_INFO("SQL error: %s\n", errMsg);
  1092. result = FAIL;
  1093. }
  1094. return result;
  1095. }
  1096. int deleteIdTagcallback(void *para, int columnCount, char **columnValue, char **columnName)
  1097. {
  1098. // localversion = argv[5] ? atoi(columnValue[5]) : 0;
  1099. // printf("localversion=%d\n", localversion);
  1100. return 0;
  1101. }
  1102. void DB_deleteIdTag(char idTag[])
  1103. {
  1104. char sql[512];
  1105. char* errMsg = NULL;
  1106. sprintf(sql,"DELETE from ocpp20_auth_local where idToken='%s'; SELECT * from ocpp20_auth_local;", idTag);
  1107. //* Execute SQL statement */
  1108. if( sqlite3_exec(db, sql, deleteIdTagcallback, 0, &errMsg) != SQLITE_OK )
  1109. {
  1110. DEBUG_INFO("SQL error: %s", errMsg);
  1111. }
  1112. }
  1113. int DB_cleanLocalList()
  1114. {
  1115. int result = PASS;
  1116. char * sqlcleanLocalList = "delete from ocpp20_auth_cache";
  1117. char *errMsg = 0;
  1118. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1119. {
  1120. DEBUG_INFO("%s\n", errMsg);
  1121. result = FAIL;
  1122. }
  1123. return result;
  1124. }
  1125. int DB_cleanLocalCache()
  1126. {
  1127. int result = PASS;
  1128. char * sqlcleanLocalList = "delete from ocpp20_auth_local";
  1129. char *errMsg = 0;
  1130. if (sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg) != SQLITE_OK)
  1131. {
  1132. DEBUG_INFO("%s\n", errMsg);
  1133. result = FAIL;
  1134. }
  1135. return result;
  1136. }
  1137. int BootTypecallback(void *para, int columnCount, char **columnValue, char **columnName)
  1138. {
  1139. sprintf((char*)ShmOCPP20Data->BootNotification.reason,"%s", columnValue[1] ? columnValue[1] : BootReasonEnumTypeStr[BootReasonEnumType_PowerUp]);
  1140. return 0;
  1141. }
  1142. void DB_getBooType()
  1143. {
  1144. char sql[256];
  1145. char* errMsg = NULL;
  1146. sprintf(sql,"select * from ocpp20_boot_type;");
  1147. /* Execute SQL statement */
  1148. if(sqlite3_exec(db, sql, BootTypecallback, 0, &errMsg) != SQLITE_OK )
  1149. {
  1150. DEBUG_INFO("SQL error: %s\n", errMsg);
  1151. }
  1152. }
  1153. int DB_cbUpdateBootType(void *para, int columnCount, char **columnValue, char **columnName)
  1154. {
  1155. for(int i = 0; i<columnCount; i++)
  1156. {
  1157. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1158. }
  1159. return 0;
  1160. }
  1161. int DB_updateBootType(BootReasonEnumType reason)
  1162. {
  1163. int result = PASS;
  1164. char sql[512];
  1165. char* errMsg = NULL;
  1166. sprintf(sql,"insert or replace into ocpp20_boot_type (idx, type) VALUES(1, '%s');", BootReasonEnumTypeStr[reason>BootReasonEnumType_Watchdog?BootReasonEnumType_PowerUp:reason]);
  1167. //* Execute SQL statement */
  1168. if(sqlite3_exec(db, sql, DB_cbUpdateBootType, 0, &errMsg) != SQLITE_OK)
  1169. {
  1170. DEBUG_INFO("SQL error: %s\n", errMsg);
  1171. result = FAIL;
  1172. }
  1173. return result;
  1174. }
  1175. int DB_cbVariableSaveToDb(void *para, int columnCount, char **columnValue, char **columnName)
  1176. {
  1177. for(int i = 0; i<columnCount; i++)
  1178. {
  1179. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  1180. }
  1181. return 0;
  1182. }
  1183. int DB_variableSaveToDb(struct ReportDataType *variable)
  1184. {
  1185. int result = FAIL;
  1186. char sql[4096];
  1187. char* errMsg = NULL;
  1188. sprintf(sql,"insert or replace into ocpp20_variable (componentName, componentInstance, variableName, variableInstance, variableCharacteristicsDataType, variableCharacteristicsUnit, variableCharacteristicsMaxLimit, variableAttributesType, variableAttributesTypeMutability, variableAttributesTypeValue) VALUES('%s', '%s', '%s', '%s', '%s', '%s', %f, '%s', '%s', '%s'); SELECT * from ocpp20_variable;",
  1189. variable->component.name,
  1190. variable->component.instance,
  1191. variable->variable.name,
  1192. variable->variable.instance,
  1193. variable->variableCharacteristics.dataType,
  1194. variable->variableCharacteristics.unit,
  1195. variable->variableCharacteristics.maxLimit,
  1196. variable->variableAttribute[0].type,
  1197. variable->variableAttribute[0].mutability,
  1198. variable->variableAttribute[0].value);
  1199. //* Execute SQL statement */
  1200. if(sqlite3_exec(db, sql, DB_cbVariableSaveToDb, 0, &errMsg) != SQLITE_OK)
  1201. {
  1202. DEBUG_INFO("SQL error: %s\n", errMsg);
  1203. result = FAIL;
  1204. }
  1205. return result;
  1206. }
  1207. int DB_cbVariableIsCreate(void *para, int columnCount, char **columnValue, char **columnName)
  1208. {
  1209. memset(&ShmOCPP20Data->ControllerComponentVariable[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable));
  1210. if(atoi(columnValue[0]) == 0)
  1211. {
  1212. DB_updateBootType(BootReasonEnumType_PowerUp);
  1213. // Create variable table content
  1214. /* AlignedDataCtrlr Required item */
  1215. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].component.name, "AlignedDataCtrlr");
  1216. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variable.name, "Enabled");
  1217. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1218. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1219. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1220. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1221. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled]);
  1222. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].component.name, "AlignedDataCtrlr");
  1223. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variable.name, "Available");
  1224. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1225. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1226. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1227. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variableAttribute[0].value, "TRUE");
  1228. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available]);
  1229. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].component.name, "AlignedDataCtrlr");
  1230. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variable.name, "Measurands");
  1231. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1232. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableCharacteristics.maxLimit = 10;
  1233. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1234. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1235. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1236. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC");
  1237. else
  1238. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage");
  1239. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands]);
  1240. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].component.name, "AlignedDataCtrlr");
  1241. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variable.name, "Interval");
  1242. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.unit, "Seconds");
  1243. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1244. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableCharacteristics.minLimit = 10;
  1245. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1246. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1247. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value, "0");
  1248. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval]);
  1249. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].component.name, "AlignedDataCtrlr");
  1250. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variable.name, "SendDuringIdle");
  1251. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1252. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1253. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1254. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variableAttribute[0].value, "TRUE");
  1255. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle]);
  1256. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].component.name, "AlignedDataCtrlr");
  1257. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variable.name, "SignReadings");
  1258. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1259. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1260. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1261. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variableAttribute[0].value, "FALSE");
  1262. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings]);
  1263. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].component.name, "AlignedDataCtrlr");
  1264. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  1265. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1266. ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableCharacteristics.maxLimit = 10;
  1267. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1268. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1269. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1270. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC");
  1271. else
  1272. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage");
  1273. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands]);
  1274. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].component.name, "AlignedDataCtrlr");
  1275. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  1276. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableCharacteristics.unit, "Seconds");
  1277. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1278. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1279. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1280. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variableAttribute[0].value, "0");
  1281. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval]);
  1282. /* AuthCtrlrVariable Required item */
  1283. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].component.name, "AuthCtrlr");
  1284. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variable.name, "Enabled");
  1285. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1286. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1287. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1288. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1289. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled]);
  1290. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].component.name, "AlignedDataCtrlr");
  1291. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variable.name, "AdditionalInfoItemsPerMessage");
  1292. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1293. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1294. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1295. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variableAttribute[0].value, "0");
  1296. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage]);
  1297. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].component.name, "AuthCtrlr");
  1298. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variable.name, "OfflineTxForUnknownIdEnabled");
  1299. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1300. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1301. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1302. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].value, "FALSE");
  1303. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled]);
  1304. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].component.name, "AuthCtrlr");
  1305. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variable.name, "AuthorizeRemoteStart");
  1306. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1307. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1308. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1309. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variableAttribute[0].value, "FALSE");
  1310. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart]);
  1311. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].component.name, "AuthCtrlr");
  1312. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variable.name, "LocalAuthorizeOffline");
  1313. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1314. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1315. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1316. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "TRUE");
  1317. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline]);
  1318. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].component.name, "AuthCtrlr");
  1319. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variable.name, "LocalPreAuthorize");
  1320. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1321. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1322. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1323. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].value, "TRUE");
  1324. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize]);
  1325. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].component.name, "AuthCtrlr");
  1326. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variable.name, "MasterPassGroupId");
  1327. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1328. ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableCharacteristics.maxLimit = 36;
  1329. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1330. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1331. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variableAttribute[0].value, " ");
  1332. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId]);
  1333. /* AuthCacheCtrlr Variable Required item*/
  1334. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].component.name, "AuthCacheCtrlr");
  1335. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variable.name, "Enabled");
  1336. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1337. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1338. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1339. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1340. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled]);
  1341. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].component.name, "AuthCacheCtrlr");
  1342. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variable.name, "Available");
  1343. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1344. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1345. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1346. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variableAttribute[0].value, "TRUE");
  1347. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available]);
  1348. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].component.name, "AuthCacheCtrlr");
  1349. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variable.name, "LifeTime");
  1350. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableCharacteristics.unit, "Seconds");
  1351. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1352. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1353. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1354. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variableAttribute[0].value, "TRUE");
  1355. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime]);
  1356. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].component.name, "AuthCacheCtrlr");
  1357. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variable.name, "Storage");
  1358. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1359. ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableCharacteristics.maxLimit = (1024*10);
  1360. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1361. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1362. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variableAttribute[0].value, "TRUE");
  1363. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage]);
  1364. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].component.name, "AuthCacheCtrlr");
  1365. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variable.name, "Policy");
  1366. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1367. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1368. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1369. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variableAttribute[0].value, "LRU,LFU");
  1370. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy]);
  1371. /* ClockCtrlr Variable Required item */
  1372. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].component.name, "ClockCtrlr");
  1373. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variable.name, "DateTime");
  1374. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_dateTime]);
  1375. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1376. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1377. getNowDatetime(ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variableAttribute[0].value);
  1378. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime]);
  1379. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].component.name, "ClockCtrlr");
  1380. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variable.name, "NtpSource");
  1381. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1382. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1383. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1384. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variableAttribute[0].value, "DHCP, manual");
  1385. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource]);
  1386. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].component.name, "ClockCtrlr");
  1387. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.name, "NtpServerUri");
  1388. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.instance, "1");
  1389. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1390. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1391. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1392. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variableAttribute[0].value, " ");
  1393. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri]);
  1394. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].component.name, "ClockCtrlr");
  1395. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variable.name, "TimeOffset");
  1396. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1397. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1398. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1399. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variableAttribute[0].value, "+00:00");
  1400. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset]);
  1401. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].component.name, "ClockCtrlr");
  1402. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variable.name, "NextTimeOffsetTransitionDateTime");
  1403. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_dateTime]);
  1404. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1405. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1406. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variableAttribute[0].value, " ");
  1407. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime]);
  1408. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].component.name, "ClockCtrlr");
  1409. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.name, "TimeOffset");
  1410. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.instance, "NextTransition");
  1411. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1412. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1413. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1414. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variableAttribute[0].value, "+00:00");
  1415. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset]);
  1416. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].component.name, "ClockCtrlr");
  1417. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variable.name, "TimeSource");
  1418. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_SequenceList]);
  1419. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1420. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1421. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variableAttribute[0].value, "Heartbeat,RealTimeClock");
  1422. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource]);
  1423. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].component.name, "ClockCtrlr");
  1424. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variable.name, "TimeZone");
  1425. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1426. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1427. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1428. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variableAttribute[0].value, "UTC");
  1429. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone]);
  1430. /* ChargingStation Required item */
  1431. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].component.name, "ChargingStation");
  1432. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variable.name, "Available");
  1433. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1434. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1435. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1436. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variableAttribute[0].value, "FALSE");
  1437. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available]);
  1438. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].component.name, "ChargingStation");
  1439. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variable.name, "AvailabilityState");
  1440. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1441. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1442. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1443. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variableAttribute[0].value, "Available,Occupied,Reserved,Unavailable,Faulted");
  1444. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState]);
  1445. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].component.name, "ChargingStation");
  1446. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variable.name, "SupplyPhases");
  1447. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1448. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1449. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1450. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variableAttribute[0].value, "3");
  1451. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases]);
  1452. /* Connector Required item */
  1453. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].component.name, "Connector");
  1454. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variable.name, "Available");
  1455. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1456. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1457. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1458. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variableAttribute[0].value, "FALSE");
  1459. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_Available]);
  1460. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].component.name, "Connector");
  1461. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variable.name, "ConnectorType");
  1462. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1463. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1464. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1465. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variableAttribute[0].value, " ");
  1466. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType]);
  1467. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].component.name, "Connector");
  1468. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variable.name, "SupplyPhases");
  1469. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1470. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1471. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1472. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variableAttribute[0].value, "3");
  1473. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases]);
  1474. /* CustomizationCtrlr Required item */
  1475. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].component.name, "CustomizationCtrlr");
  1476. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variable.name, "CustomImplementationEnabled");
  1477. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1478. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1479. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1480. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variableAttribute[0].value, "FALSE");
  1481. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled]);
  1482. /* DeviceDataCtrlr Required item */
  1483. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  1484. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.instance, "GetReport");
  1485. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1486. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1487. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1488. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1489. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variableAttribute[0].value, "10");
  1490. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage]);
  1491. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  1492. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.instance, "GetVariables");
  1493. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1494. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1495. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1496. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1497. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variableAttribute[0].value, "10");
  1498. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage]);
  1499. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].component.name, "DeviceDataCtrlr");
  1500. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.instance, "GetReport");
  1501. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.name, "BytesPerMessage");
  1502. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1503. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1504. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1505. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variableAttribute[0].value, "2048");
  1506. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage]);
  1507. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  1508. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.instance, "GetVariables");
  1509. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  1510. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1511. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1512. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1513. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variableAttribute[0].value, "2048");
  1514. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage]);
  1515. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].component.name, "DeviceDataCtrlr");
  1516. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variable.name, "ConfigurationValueSize");
  1517. ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableCharacteristics.maxLimit = 1000;
  1518. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1519. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1520. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1521. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variableAttribute[0].value, "10");
  1522. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize]);
  1523. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].component.name, "DeviceDataCtrlr");
  1524. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variable.name, "ReportingValueSize");
  1525. ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableCharacteristics.maxLimit = 2500;
  1526. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1527. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1528. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1529. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variableAttribute[0].value, "10");
  1530. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize]);
  1531. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  1532. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.instance, "SetVariables");
  1533. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1534. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1535. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1536. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1537. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variableAttribute[0].value, "10");
  1538. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage]);
  1539. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  1540. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.instance, "SetVariables");
  1541. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  1542. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1543. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1544. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1545. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variableAttribute[0].value, "2048");
  1546. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage]);
  1547. /* DisplayMessageCtrlr Required item */
  1548. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].component.name, "DisplayMessageCtrlr");
  1549. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variable.name, "Enabled");
  1550. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1551. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1552. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1553. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1554. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled]);
  1555. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].component.name, "DisplayMessageCtrlr");
  1556. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variable.name, "Available");
  1557. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1558. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1559. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1560. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variableAttribute[0].value, "FALSE");
  1561. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available]);
  1562. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].component.name, "DisplayMessageCtrlr");
  1563. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variable.name, "DisplayMessages");
  1564. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1565. ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableCharacteristics.maxLimit = 1;
  1566. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1567. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1568. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variableAttribute[0].value, "%s", "1");
  1569. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages]);
  1570. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].component.name, "DisplayMessageCtrlr");
  1571. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variable.name, "SupportedFormats");
  1572. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1573. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1574. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1575. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variableAttribute[0].value, " ");
  1576. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats]);
  1577. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].component.name, "DisplayMessageCtrlr");
  1578. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variable.name, "SupportedPriorities");
  1579. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1580. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1581. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1582. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variableAttribute[0].value, " ");
  1583. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities]);
  1584. /* EVSE Required item */
  1585. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].component.name, "EVSE");
  1586. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variable.name, "Available");
  1587. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1588. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1589. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1590. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variableAttribute[0].value, "FALSE");
  1591. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_Available]);
  1592. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].component.name, "EVSE");
  1593. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variable.name, "AvailabilityState");
  1594. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1595. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1596. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1597. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variableAttribute[0].value, "Available,Occupied,Reserved,Unavailable,Faulted");
  1598. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState]);
  1599. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].component.name, "EVSE");
  1600. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variable.name, "SupplyPhases");
  1601. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1602. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1603. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1604. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variableAttribute[0].value, "3");
  1605. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases]);
  1606. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].component.name, "EVSE");
  1607. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variable.name, "Power");
  1608. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_decimal]);
  1609. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1610. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1611. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variableAttribute[0].value, "7700");
  1612. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[EVSE_Power]);
  1613. /* LocalAuthListCtrlr Required item */
  1614. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].component.name, "LocalAuthListCtrlr");
  1615. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variable.name, "Enabled");
  1616. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1617. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1618. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1619. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  1620. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled]);
  1621. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].component.name, "LocalAuthListCtrlr");
  1622. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variable.name, "Entries");
  1623. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1624. ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableCharacteristics.maxLimit = 5000;
  1625. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1626. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1627. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variableAttribute[0].value, "5000");
  1628. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries]);
  1629. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].component.name, "LocalAuthListCtrlr");
  1630. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variable.name, "Available");
  1631. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1632. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1633. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1634. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variableAttribute[0].value, "TRUE");
  1635. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available]);
  1636. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].component.name, "LocalAuthListCtrlr");
  1637. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1638. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.instance, "SendLocalList");
  1639. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1640. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1641. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1642. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variableAttribute[0].value, "50");
  1643. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage]);
  1644. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].component.name, "LocalAuthListCtrlr");
  1645. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.name, "BytesPerMessage");
  1646. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.instance, "SendLocalList");
  1647. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1648. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1649. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1650. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variableAttribute[0].value, "2048");
  1651. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage]);
  1652. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].component.name, "LocalAuthListCtrlr");
  1653. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variable.name, "Storage");
  1654. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1655. ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableCharacteristics.maxLimit = (1024*10);
  1656. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1657. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1658. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variableAttribute[0].value, "5000");
  1659. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage]);
  1660. /* MonitoringCtrlr Required item */
  1661. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].component.name, "MonitoringCtrlr");
  1662. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variable.instance, "Enabled");
  1663. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1664. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1665. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1666. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variableAttribute[0].value, "FALSE");
  1667. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled]);
  1668. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].component.name, "MonitoringCtrlr");
  1669. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variable.instance, "Available");
  1670. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1671. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1672. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1673. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variableAttribute[0].value, "FALSE");
  1674. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available]);
  1675. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  1676. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.instance, "ClearVariableMonitoring");
  1677. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1678. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1679. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1680. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1681. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variableAttribute[0].value, "1");
  1682. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage]);
  1683. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  1684. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.instance, "SetVariableMonitoring");
  1685. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  1686. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1687. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1688. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1689. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variableAttribute[0].value, "1");
  1690. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage]);
  1691. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  1692. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.instance, "ClearVariableMonitoring");
  1693. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  1694. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1695. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1696. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1697. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variableAttribute[0].value, "2048");
  1698. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage]);
  1699. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  1700. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.instance, "SetVariableMonitoring");
  1701. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  1702. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1703. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1704. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1705. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variableAttribute[0].value, "2048");
  1706. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage]);
  1707. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].component.name, "MonitoringCtrlr");
  1708. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variable.name, "OfflineQueuingSeverity");
  1709. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1710. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1711. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1712. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variableAttribute[0].value, "2048");
  1713. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity]);
  1714. /* OCPPCommCtrlr Required item */
  1715. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].component.name, "OCPPCommCtrlr");
  1716. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variable.name, "ActiveNetworkProfile");
  1717. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1718. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1719. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1720. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variableAttribute[0].value, "1");
  1721. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile]);
  1722. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].component.name, "OCPPCommCtrlr");
  1723. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.instance, "Default");
  1724. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.name, "MessageTimeout");
  1725. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableCharacteristics.unit, "Seconds");
  1726. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1727. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1728. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1729. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variableAttribute[0].value, "30");
  1730. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout]);
  1731. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].component.name, "OCPPCommCtrlr");
  1732. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variable.name, "FileTransferProtocols");
  1733. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1734. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1735. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1736. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variableAttribute[0].value, "FTP,FTPS,HTTP,HTTPS");
  1737. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols]);
  1738. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].component.name, "OCPPCommCtrlr");
  1739. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variable.name, "HeartbeatInterval");
  1740. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.unit, "Seconds");
  1741. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1742. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1743. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1744. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value, "30");
  1745. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval]);
  1746. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].component.name, "OCPPCommCtrlr");
  1747. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variable.name, "NetworkConfigurationPriority");
  1748. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_SequenceList]);
  1749. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1750. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1751. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value, "[0]");
  1752. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority]);
  1753. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].component.name, "OCPPCommCtrlr");
  1754. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variable.name, "NetworkProfileConnectionAttempts");
  1755. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1756. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1757. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1758. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variableAttribute[0].value, "3");
  1759. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts]);
  1760. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].component.name, "OCPPCommCtrlr");
  1761. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variable.name, "OfflineThreshold");
  1762. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableCharacteristics.unit, "Seconds");
  1763. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1764. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1765. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1766. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variableAttribute[0].value, "30");
  1767. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold]);
  1768. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].component.name, "OCPPCommCtrlr");
  1769. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variable.name, "QueueAllMessages");
  1770. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1771. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1772. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1773. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variableAttribute[0].value, "FALSE");
  1774. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages]);
  1775. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].component.name, "OCPPCommCtrlr");
  1776. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.instance, "TransactionEvent");
  1777. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.name, "MessageAttempts");
  1778. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableCharacteristics.unit, "Seconds");
  1779. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1780. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1781. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1782. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].value, "3");
  1783. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts]);
  1784. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].component.name, "OCPPCommCtrlr");
  1785. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.instance, "TransactionEvent");
  1786. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.name, "MessageAttemptInterval");
  1787. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableCharacteristics.unit, "Seconds");
  1788. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1789. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1790. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1791. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].value, "3");
  1792. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval]);
  1793. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].component.name, "OCPPCommCtrlr");
  1794. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variable.name, "UnlockOnEVSideDisconnect");
  1795. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1796. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1797. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1798. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variableAttribute[0].value, "TRUE");
  1799. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect]);
  1800. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].component.name, "OCPPCommCtrlr");
  1801. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variable.name, "WebSocketPingInterval");
  1802. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.unit, "Seconds");
  1803. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1804. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1805. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1806. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].value, "30");
  1807. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval]);
  1808. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].component.name, "OCPPCommCtrlr");
  1809. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variable.name, "ResetRetries");
  1810. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1811. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1812. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1813. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variableAttribute[0].value, "3");
  1814. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries]);
  1815. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].component.name, "OCPPCommCtrlr");
  1816. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variable.name, "PublicKeyWithSignedMeterValue");
  1817. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  1818. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1819. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1820. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variableAttribute[0].value, "Never,OncePerTransaction,EveryMeterValue");
  1821. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue]);
  1822. /* ReservationCtrlr Required item */
  1823. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].component.name, "ReservationCtrlr");
  1824. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variable.name, "Enabled");
  1825. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1826. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1827. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1828. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  1829. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled]);
  1830. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].component.name, "ReservationCtrlr");
  1831. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variable.name, "Available");
  1832. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1833. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1834. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1835. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variableAttribute[0].value, "TRUE");
  1836. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available]);
  1837. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].component.name, "ReservationCtrlr");
  1838. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variable.name, "NonEvseSpecific");
  1839. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1840. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1841. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1842. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variableAttribute[0].value, "FALSE");
  1843. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific]);
  1844. /* SampledDataCtrlr Required item */
  1845. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].component.name, "SampledDataCtrlr");
  1846. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variable.name, "Enabled");
  1847. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1848. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1849. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1850. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  1851. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled]);
  1852. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].component.name, "SampledDataCtrlr");
  1853. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variable.name, "Available");
  1854. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1855. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1856. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1857. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variableAttribute[0].value, "TRUE");
  1858. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available]);
  1859. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].component.name, "SampledDataCtrlr");
  1860. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variable.name, "SignReadings");
  1861. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1862. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1863. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1864. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variableAttribute[0].value, "FALSE");
  1865. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings]);
  1866. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].component.name, "SampledDataCtrlr");
  1867. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  1868. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1869. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableCharacteristics.maxLimit = 10;
  1870. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1871. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1872. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1873. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC");
  1874. else
  1875. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage");
  1876. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands]);
  1877. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].component.name, "SampledDataCtrlr");
  1878. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  1879. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableCharacteristics.unit, "Seconds");
  1880. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1881. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1882. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1883. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variableAttribute[0].value, "0");
  1884. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval]);
  1885. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].component.name, "SampledDataCtrlr");
  1886. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variable.name, "TxStartedMeasurands");
  1887. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1888. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableCharacteristics.maxLimit = 10;
  1889. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1890. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1891. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variableAttribute[0].value, " ");
  1892. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands]);
  1893. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].component.name, "SampledDataCtrlr");
  1894. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variable.name, "TxUpdatedMeasurands");
  1895. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1896. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableCharacteristics.maxLimit = 10;
  1897. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1898. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1899. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  1900. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC");
  1901. else
  1902. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variableAttribute[0].value, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage");
  1903. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands]);
  1904. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].component.name, "SampledDataCtrlr");
  1905. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variable.name, "TxUpdatedInterval");
  1906. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.unit, "Seconds");
  1907. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1908. ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableCharacteristics.minLimit = 10;
  1909. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1910. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1911. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value, "30");
  1912. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval]);
  1913. /* SecurityCtrlr Required item */
  1914. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].component.name, "SecurityCtrlr");
  1915. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variable.name, "BasicAuthPassword");
  1916. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1917. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableCharacteristics.maxLimit = 40;
  1918. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1919. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_WriteOnly]);
  1920. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].value, "%s", ShmSysConfigAndInfo->SysConfig.OcppSecurityPassword);
  1921. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword]);
  1922. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].component.name, "SecurityCtrlr");
  1923. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variable.name, "Identity");
  1924. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1925. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableCharacteristics.maxLimit = 48;
  1926. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1927. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1928. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variableAttribute[0].value, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  1929. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity]);
  1930. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].component.name, "SecurityCtrlr");
  1931. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variable.name, "OrganizationName");
  1932. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  1933. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1934. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1935. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variableAttribute[0].value, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  1936. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName]);
  1937. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].component.name, "SecurityCtrlr");
  1938. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variable.name, "CertificateEntries");
  1939. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1940. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableCharacteristics.maxLimit = 1;
  1941. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1942. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1943. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variableAttribute[0].value, "1");
  1944. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries]);
  1945. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].component.name, "SecurityCtrlr");
  1946. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variable.name, "SecurityProfile");
  1947. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1948. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1949. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1950. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].value, "%d", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  1951. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile]);
  1952. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].component.name, "SecurityCtrlr");
  1953. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variable.name, "AdditionalRootCertificateCheck");
  1954. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1955. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1956. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1957. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variableAttribute[0].value, "FALSE");
  1958. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck]);
  1959. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].component.name, "SecurityCtrlr");
  1960. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variable.name, "MaxCertificateChainSize");
  1961. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1962. ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableCharacteristics.maxLimit = 10000;
  1963. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1964. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1965. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variableAttribute[0].value, "10000");
  1966. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize]);
  1967. /* SmartChargingCtrlr Required item */
  1968. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].component.name, "SmartChargingCtrlr");
  1969. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variable.name, "Enabled");
  1970. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1971. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1972. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  1973. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variableAttribute[0].value, "TRUE");
  1974. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled]);
  1975. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].component.name, "SmartChargingCtrlr");
  1976. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variable.name, "Available");
  1977. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1978. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1979. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1980. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variableAttribute[0].value, "TRUE");
  1981. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available]);
  1982. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].component.name, "SmartChargingCtrlr");
  1983. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variable.name, "ACPhaseSwitchingSupported");
  1984. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  1985. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1986. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1987. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variableAttribute[0].value, "FALSE");
  1988. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported]);
  1989. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].component.name, "SmartChargingCtrlr");
  1990. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variable.name, "ProfileStackLevel");
  1991. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  1992. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  1993. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  1994. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variableAttribute[0].value, "0");
  1995. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel]);
  1996. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].component.name, "SmartChargingCtrlr");
  1997. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variable.name, "RateUnit");
  1998. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_MemberList]);
  1999. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2000. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2001. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variableAttribute[0].value, "A,W");
  2002. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit]);
  2003. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].component.name, "SmartChargingCtrlr");
  2004. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variable.name, "PeriodsPerSchedule");
  2005. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2006. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2007. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2008. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variableAttribute[0].value, "10");
  2009. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule]);
  2010. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].component.name, "SmartChargingCtrlr");
  2011. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variable.name, "ExternalControlSignalsEnabled");
  2012. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2013. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2014. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2015. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variableAttribute[0].value, "FALSE");
  2016. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled]);
  2017. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].component.name, "SmartChargingCtrlr");
  2018. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variable.name, "NotifyChargingLimitWithSchedules");
  2019. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2020. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2021. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2022. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variableAttribute[0].value, "FALSE");
  2023. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules]);
  2024. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].component.name, "SmartChargingCtrlr");
  2025. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variable.name, "Phases3to1");
  2026. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2027. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2028. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2029. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variableAttribute[0].value, "FALSE");
  2030. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1]);
  2031. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].component.name, "SmartChargingCtrlr");
  2032. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variable.name, "Entries");
  2033. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2034. ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableCharacteristics.maxLimit = 10;
  2035. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2036. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2037. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variableAttribute[0].value, "10");
  2038. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries]);
  2039. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].component.name, "SmartChargingCtrlr");
  2040. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variable.name, "LimitChangeSignificance");
  2041. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_decimal]);
  2042. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2043. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2044. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variableAttribute[0].value, "1");
  2045. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance]);
  2046. /* TariffCostCtrlr Required item */
  2047. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].component.name, "TariffCostCtrlr");
  2048. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.instance, "Tariff");
  2049. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.name, "Enabled");
  2050. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2051. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2052. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2053. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variableAttribute[0].value, "FALSE");
  2054. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled]);
  2055. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].component.name, "TariffCostCtrlr");
  2056. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.instance, "Tariff");
  2057. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.name, "Available");
  2058. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2059. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2060. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2061. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variableAttribute[0].value, "FALSE");
  2062. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_Available]);
  2063. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].component.name, "TariffCostCtrlr");
  2064. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variable.name, "TariffFallbackMessage");
  2065. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2066. ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableCharacteristics.maxLimit = 255;
  2067. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2068. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2069. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variableAttribute[0].value, " ");
  2070. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage]);
  2071. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].component.name, "TariffCostCtrlr");
  2072. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.instance, "Cost");
  2073. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.name, "Enabled");
  2074. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2075. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2076. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2077. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variableAttribute[0].value, "FALSE");
  2078. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled]);
  2079. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].component.name, "TariffCostCtrlr");
  2080. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.instance, "Cost");
  2081. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.name, "Available");
  2082. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2083. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2084. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2085. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variableAttribute[0].value, "FALSE");
  2086. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Available]);
  2087. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].component.name, "TariffCostCtrlr");
  2088. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variable.name, "TotalCostFallbackMessage");
  2089. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2090. ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableCharacteristics.maxLimit = 255;
  2091. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2092. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2093. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variableAttribute[0].value, " ");
  2094. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage]);
  2095. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].component.name, "TariffCostCtrlr");
  2096. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variable.name, "Currency");
  2097. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_string]);
  2098. ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableCharacteristics.maxLimit = 3;
  2099. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2100. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2101. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variableAttribute[0].value, "NTD");
  2102. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[Cost_Currency]);
  2103. /* TxCtrlr Required item */
  2104. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2105. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variable.name, "ChargingBeforeAcceptedEnabled");
  2106. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2107. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2108. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2109. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variableAttribute[0].value, "FALSE");
  2110. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled]);
  2111. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].component.name, "TxCtrlr");
  2112. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variable.name, "EVConnectionTimeOut");
  2113. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableCharacteristics.unit, "Seconds");
  2114. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2115. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2116. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2117. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variableAttribute[0].value, "180");
  2118. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut]);
  2119. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].component.name, "TxCtrlr");
  2120. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variable.name, "StopTxOnEVSideDisconnect");
  2121. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2122. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2123. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2124. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variableAttribute[0].value, "TRUE");
  2125. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect]);
  2126. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2127. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variable.name, "TxBeforeAcceptedEnabled");
  2128. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2129. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2130. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2131. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variableAttribute[0].value, "FALSE");
  2132. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled]);
  2133. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].component.name, "TxCtrlr");
  2134. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variable.name, "TxStartPoint");
  2135. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2136. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2137. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2138. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variableAttribute[0].value, "PowerPathClosed");
  2139. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint]);
  2140. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].component.name, "TxCtrlr");
  2141. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variable.name, "TxStopPoint");
  2142. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_OptionList]);
  2143. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2144. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadOnly]);
  2145. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variableAttribute[0].value, "PowerPathClosed");
  2146. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint]);
  2147. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].component.name, "TxCtrlr");
  2148. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variable.name, "MaxEnergyOnInvalidId");
  2149. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_integer]);
  2150. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableCharacteristics.unit, "Wh");
  2151. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2152. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2153. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variableAttribute[0].value, "0");
  2154. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId]);
  2155. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].component.name, "TxCtrlr");
  2156. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variable.name, "StopTxOnInvalidId");
  2157. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableCharacteristics.dataType, "%s", DataEnumTypeStr[DataEnumType_boolean]);
  2158. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].type, "%s", AttributeEnumTypeStr[AttributeEnumType_Target]);
  2159. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].mutability, "%s", MutabilityEnumTypeStr[MutabilityEnumType_ReadWrite]);
  2160. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variableAttribute[0].value, "FALSE");
  2161. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId]);
  2162. }
  2163. else
  2164. {
  2165. // Variable name init
  2166. /* AlignedDataCtrlr Required item */
  2167. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].component.name, "AlignedDataCtrlr");
  2168. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Enabled].variable.name, "Enabled");
  2169. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].component.name, "AlignedDataCtrlr");
  2170. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Available].variable.name, "Available");
  2171. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].component.name, "AlignedDataCtrlr");
  2172. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Measurands].variable.name, "Measurands");
  2173. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].component.name, "AlignedDataCtrlr");
  2174. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variable.name, "Interval");
  2175. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].component.name, "AlignedDataCtrlr");
  2176. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SendDuringIdle].variable.name, "SendDuringIdle");
  2177. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].component.name, "AlignedDataCtrlr");
  2178. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_SignReadings].variable.name, "SignReadings");
  2179. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].component.name, "AlignedDataCtrlr");
  2180. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2181. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].component.name, "AlignedDataCtrlr");
  2182. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2183. /* AuthCtrlrVariable Required item */
  2184. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].component.name, "AuthCtrlr");
  2185. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variable.name, "Enabled");
  2186. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].component.name, "AlignedDataCtrlr");
  2187. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AdditionalInfoItemsPerMessage].variable.name, "AdditionalInfoItemsPerMessage");
  2188. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].component.name, "AuthCtrlr");
  2189. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variable.name, "OfflineTxForUnknownIdEnabled");
  2190. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].component.name, "AuthCtrlr");
  2191. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_AuthorizeRemoteStart].variable.name, "AuthorizeRemoteStart");
  2192. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].component.name, "AuthCtrlr");
  2193. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variable.name, "LocalAuthorizeOffline");
  2194. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].component.name, "AuthCtrlr");
  2195. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variable.name, "LocalPreAuthorize");
  2196. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].component.name, "AuthCtrlr");
  2197. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_MasterPassGroupId].variable.name, "MasterPassGroupId");
  2198. /* AuthCacheCtrlr Variable Required item */
  2199. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].component.name, "AuthCacheCtrlr");
  2200. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variable.name, "Enabled");
  2201. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].component.name, "AuthCacheCtrlr");
  2202. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Available].variable.name, "Available");
  2203. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].component.name, "AuthCacheCtrlr");
  2204. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_LifeTime].variable.name, "LifeTime");
  2205. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].component.name, "AuthCacheCtrlr");
  2206. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Storage].variable.name, "Storage");
  2207. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].component.name, "AuthCacheCtrlr");
  2208. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Policy].variable.name, "Policy");
  2209. /* ClockCtrlr Variable Required item */
  2210. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].component.name, "ClockCtrlr");
  2211. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_DateTime].variable.name, "DateTime");
  2212. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].component.name, "ClockCtrlr");
  2213. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpSource].variable.name, "NtpSource");
  2214. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].component.name, "ClockCtrlr");
  2215. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.name, "NtpServerUri");
  2216. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NtpServerUri].variable.instance, "1");
  2217. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].component.name, "ClockCtrlr");
  2218. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeOffset].variable.name, "TimeOffset");
  2219. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].component.name, "ClockCtrlr");
  2220. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTimeOffsetTransitionDateTime].variable.name, "NextTimeOffsetTransitionDateTime");
  2221. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].component.name, "ClockCtrlr");
  2222. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.name, "TimeOffset");
  2223. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_NextTransition_TimeOffset].variable.instance, "NextTransition");
  2224. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].component.name, "ClockCtrlr");
  2225. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeSource].variable.name, "TimeSource");
  2226. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].component.name, "ClockCtrlr");
  2227. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ClockCtrlr_TimeZone].variable.name, "TimeZone");
  2228. /* ChargingStation Required item */
  2229. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].component.name, "ChargingStation");
  2230. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_Available].variable.name, "Available");
  2231. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].component.name, "ChargingStation");
  2232. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_AvailabilityState].variable.name, "AvailabilityState");
  2233. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].component.name, "ChargingStation");
  2234. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ChargingStation_SupplyPhases].variable.name, "SupplyPhases");
  2235. /* Connector Required item */
  2236. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].component.name, "Connector");
  2237. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_Available].variable.name, "Available");
  2238. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].component.name, "Connector");
  2239. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_ConnectorType].variable.name, "ConnectorType");
  2240. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].component.name, "Connector");
  2241. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Connector_SupplyPhases].variable.name, "SupplyPhases");
  2242. /* CustomizationCtrlr Required item */
  2243. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].component.name, "CustomizationCtrlr");
  2244. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[CustomizationCtrlr_CustomImplementationEnabled].variable.name, "CustomImplementationEnabled");
  2245. /* DeviceDataCtrlr Required item */
  2246. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2247. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.instance, "GetReport");
  2248. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2249. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2250. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.instance, "GetVariables");
  2251. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2252. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2253. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.instance, "GetReport");
  2254. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetReport_BytesPerMessage].variable.name, "BytesPerMessage");
  2255. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2256. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.instance, "GetVariables");
  2257. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_GetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2258. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].component.name, "DeviceDataCtrlr");
  2259. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ConfigurationValueSize].variable.name, "ConfigurationValueSize");
  2260. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].component.name, "DeviceDataCtrlr");
  2261. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_ReportingValueSize].variable.name, "ReportingValueSize");
  2262. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].component.name, "DeviceDataCtrlr");
  2263. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.instance, "SetVariables");
  2264. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2265. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].component.name, "DeviceDataCtrlr");
  2266. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.instance, "SetVariables");
  2267. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DeviceDataCtrlr_SetVariables_BytesPerMessage].variable.name, "BytesPerMessage");
  2268. /* DisplayMessageCtrlr Required item */
  2269. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].component.name, "DisplayMessageCtrlr");
  2270. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Enabled].variable.name, "Enabled");
  2271. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].component.name, "DisplayMessageCtrlr");
  2272. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_Available].variable.name, "Available");
  2273. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].component.name, "DisplayMessageCtrlr");
  2274. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_DisplayMessages].variable.name, "DisplayMessages");
  2275. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].component.name, "DisplayMessageCtrlr");
  2276. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedFormats].variable.name, "SupportedFormats");
  2277. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].component.name, "DisplayMessageCtrlr");
  2278. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[DisplayMessageCtrlr_SupportedPriorities].variable.name, "SupportedPriorities");
  2279. /* EVSE Required item */
  2280. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].component.name, "EVSE");
  2281. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Available].variable.name, "Available");
  2282. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].component.name, "EVSE");
  2283. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_AvailabilityState].variable.name, "AvailabilityState");
  2284. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].component.name, "EVSE");
  2285. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_SupplyPhases].variable.name, "SupplyPhases");
  2286. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].component.name, "EVSE");
  2287. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[EVSE_Power].variable.name, "Power");
  2288. /* LocalAuthListCtrlr Required item */
  2289. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].component.name, "LocalAuthListCtrlr");
  2290. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variable.name, "Enabled");
  2291. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].component.name, "LocalAuthListCtrlr");
  2292. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Entries].variable.name, "Entries");
  2293. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].component.name, "LocalAuthListCtrlr");
  2294. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Available].variable.name, "Available");
  2295. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].component.name, "LocalAuthListCtrlr");
  2296. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2297. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_ItemsPerMessage].variable.instance, "SendLocalList");
  2298. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].component.name, "LocalAuthListCtrlr");
  2299. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.name, "BytesPerMessage");
  2300. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_BytesPerMessage].variable.instance, "SendLocalList");
  2301. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].component.name, "LocalAuthListCtrlr");
  2302. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Storage].variable.name, "Storage");
  2303. /* MonitoringCtrlr Required item */
  2304. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].component.name, "MonitoringCtrlr");
  2305. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Enabled].variable.instance, "Enabled");
  2306. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].component.name, "MonitoringCtrlr");
  2307. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_Available].variable.instance, "Available");
  2308. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2309. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.instance, "ClearVariableMonitoring");
  2310. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2311. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].component.name, "MonitoringCtrlr");
  2312. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.instance, "SetVariableMonitoring");
  2313. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_ItemsPerMessage].variable.name, "ItemsPerMessage");
  2314. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2315. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.instance, "ClearVariableMonitoring");
  2316. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_ClearVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2317. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].component.name, "MonitoringCtrlr");
  2318. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.instance, "SetVariableMonitoring");
  2319. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_SetVariableMonitoring_BytesPerMessage].variable.name, "BytesPerMessage");
  2320. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].component.name, "MonitoringCtrlr");
  2321. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[MonitoringCtrlr_OfflineQueuingSeverity].variable.name, "OfflineQueuingSeverity");
  2322. /* OCPPCommCtrlr Required item */
  2323. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].component.name, "OCPPCommCtrlr");
  2324. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ActiveNetworkProfile].variable.name, "ActiveNetworkProfile");
  2325. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].component.name, "OCPPCommCtrlr");
  2326. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.instance, "Default");
  2327. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageTimeout].variable.name, "MessageTimeout");
  2328. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].component.name, "OCPPCommCtrlr");
  2329. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_FileTransferProtocols].variable.name, "FileTransferProtocols");
  2330. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].component.name, "OCPPCommCtrlr");
  2331. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variable.name, "HeartbeatInterval");
  2332. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].component.name, "OCPPCommCtrlr");
  2333. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variable.name, "NetworkConfigurationPriority");
  2334. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].component.name, "OCPPCommCtrlr");
  2335. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkProfileConnectionAttempts].variable.name, "NetworkProfileConnectionAttempts");
  2336. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].component.name, "OCPPCommCtrlr");
  2337. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_OfflineThreshold].variable.name, "OfflineThreshold");
  2338. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].component.name, "OCPPCommCtrlr");
  2339. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_QueueAllMessages].variable.name, "QueueAllMessages");
  2340. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].component.name, "OCPPCommCtrlr");
  2341. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.instance, "TransactionEvent");
  2342. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variable.name, "MessageAttempts");
  2343. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].component.name, "OCPPCommCtrlr");
  2344. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.instance, "TransactionEvent");
  2345. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variable.name, "MessageAttemptInterval");
  2346. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].component.name, "OCPPCommCtrlr");
  2347. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_UnlockOnEVSideDisconnect].variable.name, "UnlockOnEVSideDisconnect");
  2348. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].component.name, "OCPPCommCtrlr");
  2349. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variable.name, "WebSocketPingInterval");
  2350. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].component.name, "OCPPCommCtrlr");
  2351. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_ResetRetries].variable.name, "ResetRetries");
  2352. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].component.name, "OCPPCommCtrlr");
  2353. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_PublicKeyWithSignedMeterValue].variable.name, "PublicKeyWithSignedMeterValue");
  2354. /* ReservationCtrlr Required item */
  2355. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].component.name, "ReservationCtrlr");
  2356. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Enabled].variable.name, "Enabled");
  2357. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].component.name, "ReservationCtrlr");
  2358. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_Available].variable.name, "Available");
  2359. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].component.name, "ReservationCtrlr");
  2360. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[ReservationCtrlr_NonEvseSpecific].variable.name, "NonEvseSpecific");
  2361. /* SampledDataCtrlr Required item */
  2362. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].component.name, "SampledDataCtrlr");
  2363. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Enabled].variable.name, "Enabled");
  2364. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].component.name, "SampledDataCtrlr");
  2365. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_Available].variable.name, "Available");
  2366. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].component.name, "SampledDataCtrlr");
  2367. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_SignReadings].variable.name, "SignReadings");
  2368. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].component.name, "SampledDataCtrlr");
  2369. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedMeasurands].variable.name, "TxEndedMeasurands");
  2370. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].component.name, "SampledDataCtrlr");
  2371. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxEndedInterval].variable.name, "TxEndedInterval");
  2372. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].component.name, "SampledDataCtrlr");
  2373. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxStartedMeasurands].variable.name, "TxStartedMeasurands");
  2374. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].component.name, "SampledDataCtrlr");
  2375. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedMeasurands].variable.name, "TxUpdatedMeasurands");
  2376. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].component.name, "SampledDataCtrlr");
  2377. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variable.name, "TxUpdatedInterval");
  2378. /* SecurityCtrlr Required item */
  2379. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].component.name, "SecurityCtrlr");
  2380. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variable.name, "BasicAuthPassword");
  2381. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].component.name, "SecurityCtrlr");
  2382. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_Identity].variable.name, "Identity");
  2383. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].component.name, "SecurityCtrlr");
  2384. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_OrganizationName].variable.name, "OrganizationName");
  2385. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].component.name, "SecurityCtrlr");
  2386. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_CertificateEntries].variable.name, "CertificateEntries");
  2387. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].component.name, "SecurityCtrlr");
  2388. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variable.name, "SecurityProfile");
  2389. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].component.name, "SecurityCtrlr");
  2390. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_AdditionalRootCertificateCheck].variable.name, "AdditionalRootCertificateCheck");
  2391. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].component.name, "SecurityCtrlr");
  2392. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_MaxCertificateChainSize].variable.name, "MaxCertificateChainSize");
  2393. /* SmartChargingCtrlr Required item */
  2394. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].component.name, "SmartChargingCtrlr");
  2395. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Enabled].variable.name, "Enabled");
  2396. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].component.name, "SmartChargingCtrlr");
  2397. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Available].variable.name, "Available");
  2398. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].component.name, "SmartChargingCtrlr");
  2399. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ACPhaseSwitchingSupported].variable.name, "ACPhaseSwitchingSupported");
  2400. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].component.name, "SmartChargingCtrlr");
  2401. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ProfileStackLevel].variable.name, "ProfileStackLevel");
  2402. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].component.name, "SmartChargingCtrlr");
  2403. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_RateUnit].variable.name, "RateUnit");
  2404. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].component.name, "SmartChargingCtrlr");
  2405. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_PeriodsPerSchedule].variable.name, "PeriodsPerSchedule");
  2406. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].component.name, "SmartChargingCtrlr");
  2407. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_ExternalControlSignalsEnabled].variable.name, "ExternalControlSignalsEnabled");
  2408. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].component.name, "SmartChargingCtrlr");
  2409. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_NotifyChargingLimitWithSchedules].variable.name, "NotifyChargingLimitWithSchedules");
  2410. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].component.name, "SmartChargingCtrlr");
  2411. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Phases3to1].variable.name, "Phases3to1");
  2412. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].component.name, "SmartChargingCtrlr");
  2413. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_Entries].variable.name, "Entries");
  2414. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].component.name, "SmartChargingCtrlr");
  2415. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[SmartChargingCtrlr_LimitChangeSignificance].variable.name, "LimitChangeSignificance");
  2416. /* TariffCostCtrlr Required item */
  2417. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].component.name, "TariffCostCtrlr");
  2418. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.instance, "Tariff");
  2419. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Enabled].variable.name, "Enabled");
  2420. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].component.name, "TariffCostCtrlr");
  2421. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.instance, "Tariff");
  2422. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_Available].variable.name, "Available");
  2423. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].component.name, "TariffCostCtrlr");
  2424. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Tariff_TariffFallbackMessage].variable.name, "TariffFallbackMessage");
  2425. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].component.name, "TariffCostCtrlr");
  2426. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.instance, "Cost");
  2427. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Enabled].variable.name, "Enabled");
  2428. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].component.name, "TariffCostCtrlr");
  2429. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.instance, "Cost");
  2430. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Available].variable.name, "Available");
  2431. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].component.name, "TariffCostCtrlr");
  2432. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_TotalCostFallbackMessage].variable.name, "TotalCostFallbackMessage");
  2433. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].component.name, "TariffCostCtrlr");
  2434. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[Cost_Currency].variable.name, "Currency");
  2435. /* TxCtrlr Required item */
  2436. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2437. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_ChargingBeforeAcceptedEnabled].variable.name, "ChargingBeforeAcceptedEnabled");
  2438. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].component.name, "TxCtrlr");
  2439. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_EVConnectionTimeOut].variable.name, "EVConnectionTimeOut");
  2440. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].component.name, "TxCtrlr");
  2441. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnEVSideDisconnect].variable.name, "StopTxOnEVSideDisconnect");
  2442. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].component.name, "TxCtrlr");
  2443. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxBeforeAcceptedEnabled].variable.name, "TxBeforeAcceptedEnabled");
  2444. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].component.name, "TxCtrlr");
  2445. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStartPoint].variable.name, "TxStartPoint");
  2446. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].component.name, "TxCtrlr");
  2447. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_TxStopPoint].variable.name, "TxStopPoint");
  2448. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].component.name, "TxCtrlr");
  2449. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_MaxEnergyOnInvalidId].variable.name, "MaxEnergyOnInvalidId");
  2450. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].component.name, "TxCtrlr");
  2451. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[TxCtrlr_StopTxOnInvalidId].variable.name, "StopTxOnInvalidId");
  2452. }
  2453. return 0;
  2454. }
  2455. void DB_variableIsCreate()
  2456. {
  2457. char sql[512];
  2458. char* errMsg = NULL;
  2459. sprintf(sql,"select count(idx) as quantity from ocpp20_variable;");
  2460. /* Execute SQL statement */
  2461. if(sqlite3_exec(db, sql, DB_cbVariableIsCreate, 0, &errMsg) != SQLITE_OK )
  2462. {
  2463. DEBUG_INFO("SQL error: %s\n", errMsg);
  2464. }
  2465. }
  2466. int DB_cbVariableLoadFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  2467. {
  2468. for(int idx=0;idx<CtrlrVariable_CNT;idx++)
  2469. {
  2470. if((strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].component.name, columnValue[1]) == 0) &&
  2471. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].component.instance, columnValue[2]) == 0) &&
  2472. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variable.name, columnValue[3]) == 0) &&
  2473. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variable.instance, columnValue[4]) == 0))
  2474. {
  2475. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.dataType, "%s", columnValue[5]);
  2476. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.unit, "%s", columnValue[6]);
  2477. ShmOCPP20Data->ControllerComponentVariable[idx].variableCharacteristics.maxLimit = strlen(columnValue[7])>0?atoi(columnValue[7]):255;
  2478. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].type, "%s", columnValue[8]);
  2479. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].mutability, "%s", columnValue[9]);
  2480. sprintf((char*)ShmOCPP20Data->ControllerComponentVariable[idx].variableAttribute[0].value, "%s", columnValue[10]);
  2481. }
  2482. }
  2483. return 0;
  2484. }
  2485. void DB_variableLoadFromDb()
  2486. {
  2487. char sql[512];
  2488. char* errMsg = NULL;
  2489. sprintf(sql,"select * from ocpp20_variable order by idx;");
  2490. /* Execute SQL statement */
  2491. if(sqlite3_exec(db, sql, DB_cbVariableLoadFromDb, 0, &errMsg) != SQLITE_OK )
  2492. {
  2493. DEBUG_INFO("SQL error: %s\n", errMsg);
  2494. }
  2495. }
  2496. int DB_cbGetNetworkProfileFromDb(void *para, int columnCount, char **columnValue, char **columnName)
  2497. {
  2498. memset(&ShmOCPP20Data->NetworkConnectionProfile[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile));
  2499. if(columnCount > 0)
  2500. {
  2501. for(int idx=0;idx<columnCount;idx++)
  2502. {
  2503. json_object *SetNetworkProfile;
  2504. SetNetworkProfile = json_tokener_parse(columnValue[2]);
  2505. if(!is_error(SetNetworkProfile))
  2506. {
  2507. // Required data
  2508. if(json_object_object_get(SetNetworkProfile, "ocppVersion") != NULL)
  2509. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppVersion, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppVersion")));
  2510. if(json_object_object_get(SetNetworkProfile, "ocppTransport") != NULL)
  2511. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppTransport")));
  2512. if(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl") != NULL)
  2513. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppCsmsUrl")));
  2514. if(json_object_object_get(SetNetworkProfile, "messageTimeout") != NULL)
  2515. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.messageTimeout = json_object_get_int(json_object_object_get(SetNetworkProfile, "messageTimeout"));
  2516. if(json_object_object_get(SetNetworkProfile, "ocppInterface") != NULL)
  2517. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppInterface, "%s", json_object_get_string(json_object_object_get(SetNetworkProfile, "ocppInterface")));
  2518. if(json_object_object_get(SetNetworkProfile, "vpn") != NULL)
  2519. {
  2520. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server") != NULL)
  2521. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.server, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "server")));
  2522. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user") != NULL)
  2523. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.user, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "user")));
  2524. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group") != NULL)
  2525. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.group, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "group")));
  2526. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password") != NULL)
  2527. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.password, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "password")));
  2528. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key") != NULL)
  2529. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.key, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "key")));
  2530. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type") != NULL)
  2531. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.vpn.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "vpn"), "type")));
  2532. }
  2533. if(json_object_object_get(SetNetworkProfile, "apn") != NULL)
  2534. {
  2535. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn") != NULL)
  2536. {
  2537. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn));
  2538. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apn, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apn")));
  2539. }
  2540. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName") != NULL)
  2541. {
  2542. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName));
  2543. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnUserName, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnUserName")));
  2544. }
  2545. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword") != NULL)
  2546. {
  2547. memset(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, 0x00, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword));
  2548. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnPassword, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnPassword")));
  2549. }
  2550. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin") != NULL)
  2551. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.simPin = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "simPin"));
  2552. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork") != NULL)
  2553. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.preferredNetwork, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "preferredNetwork")));
  2554. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork") != NULL)
  2555. ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.useOnlyPreferredNetwork = json_object_get_boolean(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "useOnlyPreferredNetwork"));
  2556. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication") != NULL)
  2557. sprintf((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.apn.apnAuthentication, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "apn"), "apnAuthentication")));
  2558. }
  2559. }
  2560. json_object_put(SetNetworkProfile);
  2561. ShmOCPP20Data->NetworkConnectionProfile[idx].slot = atoi(columnValue[1]);
  2562. }
  2563. }
  2564. return 0;
  2565. }
  2566. void DB_getNetworkProfileFromDb()
  2567. {
  2568. char sql[512];
  2569. char* errMsg = NULL;
  2570. sprintf(sql,"select * from ocpp20_networkprofile order by slot;");
  2571. /* Execute SQL statement */
  2572. if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
  2573. {
  2574. DEBUG_INFO("SQL error: %s\n", errMsg);
  2575. }
  2576. }
  2577. int DB_addNetworkProfile(int slot, char *data)
  2578. {
  2579. int result = PASS;
  2580. char sql[512];
  2581. char* errMsg = NULL;
  2582. sprintf(sql,"insert or replace into ocpp20_networkprofile (slot, connectionData) VALUES('%d', '%s'); SELECT * from ocpp20_networkprofile order by slot;",
  2583. slot,
  2584. data);
  2585. //* Execute SQL statement */
  2586. if(sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK)
  2587. {
  2588. DEBUG_INFO("SQL error: %s\n", errMsg);
  2589. result = FAIL;
  2590. }
  2591. return result;
  2592. }
  2593. int DB_deleteNetworkProfile(int slot)
  2594. {
  2595. int result = PASS;
  2596. char sql[512];
  2597. char* errMsg = NULL;
  2598. sprintf(sql,"DELETE from ocpp20_networkprofile where slot=%d; SELECT * from ocpp20_networkprofile order by slot;", slot);
  2599. //* Execute SQL statement */
  2600. if( sqlite3_exec(db, sql, DB_cbGetNetworkProfileFromDb, 0, &errMsg) != SQLITE_OK )
  2601. {
  2602. DEBUG_INFO("SQL error: %s", errMsg);
  2603. result = FAIL;
  2604. }
  2605. return result;
  2606. }
  2607. int getCurrentYear()
  2608. {
  2609. int result = 0;
  2610. time_t CurrentTime;
  2611. struct tm *tm;
  2612. CurrentTime = time(NULL);
  2613. tm=localtime(&CurrentTime);
  2614. result = (tm->tm_year + 1900);
  2615. return result;
  2616. }
  2617. int OCPP_insert_transaction_msg(uint8_t isStartTransaction, char *transactionMsg)
  2618. {
  2619. int result = PASS;
  2620. char* errMsg = NULL;
  2621. char sqlStr[8192];
  2622. sprintf(sqlStr, "insert into ocpp20_transaction_record(occurDatetime, message_type, message_content) values(CURRENT_TIMESTAMP, '%s', '%s');", (isStartTransaction?"startTransaction":"stopTransaction"), transactionMsg);
  2623. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  2624. {
  2625. result = FAIL;
  2626. DEBUG_INFO( "Insert local transaction record error message: %s\n", errMsg);
  2627. }
  2628. sprintf(sqlStr, "delete from ocpp20_transaction_record where (idx < (select idx from ocpp_transaction_record order by idx desc limit 1)-2000) and (occurDatetime < '%04d-01-01 00:00:00');", (getCurrentYear()-3));
  2629. if (sqlite3_exec(db, sqlStr, 0, 0, &errMsg) != SQLITE_OK)
  2630. {
  2631. result = FAIL;
  2632. DEBUG_INFO( "delete local transaction record error message: %s\n", errMsg);
  2633. }
  2634. return result;
  2635. }
  2636. //==========================================
  2637. // Check time passed since today
  2638. //==========================================
  2639. long long DiffTimebWithNow(struct timeb ST)
  2640. {
  2641. //return milli-second
  2642. struct timeb ET;
  2643. long long StartTime,StopTime;
  2644. ftime(&ET);
  2645. StartTime=(long long)ST.time;
  2646. StopTime=(long long)ET.time;
  2647. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  2648. }
  2649. int getTimePassSinceToday(uint8_t gun_index)
  2650. {
  2651. int result = -1;
  2652. static time_t lastTime[4];
  2653. time_t t;
  2654. struct tm *tmStartToday;
  2655. struct timeb tbStartToday;
  2656. t=time(NULL);
  2657. if(difftime(t, lastTime[gun_index])>0)
  2658. {
  2659. tmStartToday=localtime(&t);
  2660. tmStartToday->tm_hour = 0;
  2661. tmStartToday->tm_min = 0;
  2662. tmStartToday->tm_sec = 0;
  2663. tbStartToday.time = mktime(tmStartToday);
  2664. tbStartToday.millitm = 0;
  2665. result = DiffTimebWithNow(tbStartToday)/1000;
  2666. lastTime[gun_index] = t;
  2667. }
  2668. return result;
  2669. }
  2670. int syncDateTimeRTC(uint8_t *data)
  2671. {
  2672. struct ParsingResult
  2673. {
  2674. int result;
  2675. int scanedElement;
  2676. int year;
  2677. int month;
  2678. int mday;
  2679. int hour;
  2680. int min;
  2681. int sec;
  2682. int tz_hour;
  2683. int tz_min;
  2684. float minSec;
  2685. }result;
  2686. struct tm tmOrg;
  2687. struct tm *tmTarget;
  2688. struct timeb tbTarget;
  2689. char buf[128];
  2690. memset(&result, 0x00, sizeof(struct ParsingResult));
  2691. result.result = PASS;
  2692. if(strstr((char*)data, ".") != NULL)
  2693. {
  2694. // Original data with mini second
  2695. if(strstr((char*)data, "Z") != NULL)
  2696. {
  2697. // Original data with Z
  2698. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
  2699. &result.year,
  2700. &result.month,
  2701. &result.mday,
  2702. &result.hour,
  2703. &result.min,
  2704. &result.sec,
  2705. &result.minSec);
  2706. }
  2707. else
  2708. {
  2709. // Original data without Z
  2710. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
  2711. &result.year,
  2712. &result.month,
  2713. &result.mday,
  2714. &result.hour,
  2715. &result.min,
  2716. &result.sec,
  2717. &result.minSec,
  2718. &result.tz_hour,
  2719. &result.tz_min);
  2720. }
  2721. }
  2722. else
  2723. {
  2724. // Original data without mini second
  2725. if(strstr((char*)data, "Z") != NULL)
  2726. {
  2727. // Original data with Z
  2728. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
  2729. &result.year,
  2730. &result.month,
  2731. &result.mday,
  2732. &result.hour,
  2733. &result.min,
  2734. &result.sec);
  2735. }
  2736. else
  2737. {
  2738. // Original data without Z
  2739. result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
  2740. &result.year,
  2741. &result.month,
  2742. &result.mday,
  2743. &result.hour,
  2744. &result.min,
  2745. &result.sec,
  2746. &result.tz_hour,
  2747. &result.tz_min);
  2748. }
  2749. }
  2750. tmOrg.tm_year = result.year - 1900;
  2751. tmOrg.tm_mon = result.month - 1;
  2752. tmOrg.tm_mday = result.mday;
  2753. tmOrg.tm_hour = result.hour;
  2754. tmOrg.tm_min = result.min;
  2755. tmOrg.tm_sec = result.sec;
  2756. tmOrg.tm_gmtoff = 0;
  2757. tbTarget.time = mktime(&tmOrg);
  2758. tbTarget.timezone = 0;
  2759. tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
  2760. tmTarget = gmtime(&tbTarget.time);
  2761. sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
  2762. //DEBUG_INFO(" org date time: %s\n", data);
  2763. //DEBUG_INFO("parse date time: %s\n", buf);
  2764. system(buf);
  2765. system("/sbin/hwclock -w --systohc");
  2766. if(result.scanedElement < 6)
  2767. result.result = FAIL;
  2768. return result.result;
  2769. }
  2770. //==========================================
  2771. // GetCompositeSchedule logic related function
  2772. //==========================================
  2773. int DiffTimebSec(struct timeb ST, struct timeb ET)
  2774. {
  2775. //return milli-second
  2776. unsigned int StartTime,StopTime;
  2777. StartTime=(unsigned int)ST.time;
  2778. StopTime=(unsigned int)ET.time;
  2779. return (StopTime-StartTime);
  2780. }
  2781. int DiffTimebWithNowSec(struct timeb ST)
  2782. {
  2783. //return milli-second
  2784. struct timeb ET;
  2785. unsigned int StartTime,StopTime;
  2786. ftime(&ET);
  2787. StartTime=(unsigned int)ST.time;
  2788. StopTime=(unsigned int)ET.time;
  2789. return (StopTime-StartTime);
  2790. }
  2791. int getStartStop(uint8_t *start, uint8_t *stop)
  2792. {
  2793. int result = -1;
  2794. struct tm tmStart;
  2795. struct timeb tbStart;
  2796. struct tm tmStop;
  2797. struct timeb tbStop;
  2798. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  2799. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  2800. {
  2801. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  2802. //DEBUG_INFO("Stop: %d-%d-%d %d:%d:%d\n", tmStop.tm_year, tmStop.tm_mon, tmStop.tm_mday, tmStop.tm_hour, tmStop.tm_min, tmStop.tm_sec);
  2803. tmStart.tm_year -= 1900;
  2804. tmStart.tm_mon -= 1;
  2805. tbStart.time = mktime(&tmStart);
  2806. tbStart.millitm = 0;
  2807. tmStop.tm_year -= 1900;
  2808. tmStop.tm_mon -= 1;
  2809. tbStop.time = mktime(&tmStop);
  2810. tbStop.millitm = 0;
  2811. result = DiffTimebSec(tbStart, tbStop);
  2812. //DEBUG_INFO("getStartStop(): %d\n", result);
  2813. }
  2814. else
  2815. {
  2816. DEBUG_WARN("Start or stop date parsing error.\r\n");
  2817. }
  2818. return result;
  2819. }
  2820. int isOvertNow(uint8_t *start)
  2821. {
  2822. int result = NO;
  2823. struct tm tmStart;
  2824. struct timeb tbStart;
  2825. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6))
  2826. {
  2827. //DEBUG_INFO("Start: %d-%d-%d %d:%d:%d\n", tmStart.tm_year, tmStart.tm_mon, tmStart.tm_mday, tmStart.tm_hour, tmStart.tm_min, tmStart.tm_sec);
  2828. tmStart.tm_year -= 1900;
  2829. tmStart.tm_mon -= 1;
  2830. tbStart.time = mktime(&tmStart);
  2831. tbStart.millitm = 0;
  2832. if(DiffTimebWithNowSec(tbStart) <= 0)
  2833. result = NO;
  2834. else
  2835. result = YES;
  2836. }
  2837. else
  2838. {
  2839. DEBUG_WARN("Start date parsing error.\n");
  2840. }
  2841. return result;
  2842. }
  2843. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  2844. {
  2845. int result = -1;
  2846. struct tm tmStart;
  2847. struct timeb tbStart;
  2848. struct tm tmStop;
  2849. struct timeb tbStop;
  2850. if((sscanf((char*)start, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStart.tm_year, &tmStart.tm_mon, &tmStart.tm_mday, &tmStart.tm_hour, &tmStart.tm_min, &tmStart.tm_sec) == 6) &&
  2851. (sscanf((char*)stop, "%4d-%2d-%2dT%2d:%2d:%2d", &tmStop.tm_year, &tmStop.tm_mon, &tmStop.tm_mday, &tmStop.tm_hour, &tmStop.tm_min, &tmStop.tm_sec) == 6))
  2852. {
  2853. tmStart.tm_year -= 1900;
  2854. tmStart.tm_mon -= 1;
  2855. tbStart.time = mktime(&tmStart);
  2856. tbStart.millitm = 0;
  2857. tmStop.tm_year -= 1900;
  2858. tmStop.tm_mon -= 1;
  2859. tbStop.time = mktime(&tmStop);
  2860. tbStop.millitm = 0;
  2861. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  2862. }
  2863. return result;
  2864. }
  2865. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct ChargingProfileType *compositeProfile, uint8_t idxSchedule, uint8_t isUnitA)
  2866. {
  2867. FILE *fp;
  2868. char profileFileName[128];
  2869. char *line = NULL;
  2870. size_t len = 0;
  2871. time_t CurrentTime;
  2872. struct tm *tmComposite;
  2873. struct ChargingProfileType maxProfile;
  2874. struct ChargingProfileType defaultTxProfile;
  2875. struct ChargingProfileType txProfile;
  2876. struct ChargingSchedulePeriodType tmpPeriod;
  2877. uint8_t limitMax=0;
  2878. uint8_t limitDef=0;
  2879. uint8_t limitTx=0;
  2880. int compositePeriodIdx = 0;
  2881. CurrentTime = time(NULL);
  2882. tmComposite=localtime(&CurrentTime);
  2883. 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);
  2884. if(isUnitA)
  2885. sprintf((char*)compositeProfile->chargingSchedule[idxSchedule].chargingRateUnit, "A");
  2886. else
  2887. sprintf((char*)compositeProfile->chargingSchedule[idxSchedule].chargingRateUnit, "W");
  2888. compositeProfile->chargingSchedule[idxSchedule].duration = durationReq;
  2889. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  2890. {
  2891. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  2892. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  2893. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  2894. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 0;
  2895. }
  2896. compositeProfile->id = 0;
  2897. compositeProfile->stackLevel = 99 ;
  2898. sprintf((char*)compositeProfile->chargingProfileKind ,ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]);
  2899. maxProfile.id = -1;
  2900. defaultTxProfile.id = -1;
  2901. txProfile.id = -1;
  2902. maxProfile.chargingSchedule[idxSchedule].duration = -1;
  2903. defaultTxProfile.chargingSchedule[idxSchedule].duration = -1;
  2904. txProfile.chargingSchedule[idxSchedule].duration = -1;
  2905. system("rm -f /tmp/*.json");
  2906. system("cp /Storage/OCPP/*.json /tmp 2>/dev/null");
  2907. /*
  2908. * Search valid charging profile
  2909. */
  2910. //DEBUG_INFO("====================================\n");
  2911. // Search tx profile
  2912. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  2913. if((access(profileFileName, F_OK))!=-1)
  2914. {
  2915. fp = fopen(profileFileName, "r");
  2916. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  2917. {
  2918. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  2919. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  2920. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  2921. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  2922. }
  2923. txProfile.id = -1;
  2924. txProfile.stackLevel = -1;
  2925. while(getline(&line, &len, fp) != -1)
  2926. {
  2927. json_object *obj = NULL;
  2928. obj = json_tokener_parse(line);
  2929. if(is_error(obj))
  2930. {
  2931. DEBUG_ERROR("Parse txProfile from file error.\n");
  2932. }
  2933. else
  2934. {
  2935. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.id) &&
  2936. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.stackLevel)
  2937. )
  2938. {
  2939. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  2940. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2941. )
  2942. {
  2943. struct tm tmFrom, tmTo;
  2944. struct timeb tbFrom, tbTo;
  2945. 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) &&
  2946. (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))
  2947. {
  2948. tmFrom.tm_year -= 1900;
  2949. tmFrom.tm_mon -= 1;
  2950. tbFrom.time = mktime(&tmFrom);
  2951. tmTo.tm_year -= 1900;
  2952. tmTo.tm_mon -= 1;
  2953. tbTo.time = mktime(&tmTo);
  2954. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  2955. {
  2956. if(txProfile.id == -1)
  2957. DEBUG_INFO("TxProfile found.\n");
  2958. else
  2959. DEBUG_INFO("TxProfile updated.\n");
  2960. // Required item
  2961. txProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  2962. txProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  2963. sprintf((char*)txProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  2964. if(isUnitA)
  2965. {
  2966. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  2967. 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++)
  2968. {
  2969. 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"));
  2970. 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?
  2971. 3:
  2972. 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")));
  2973. 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")));
  2974. }
  2975. }
  2976. else
  2977. {
  2978. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  2979. 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++)
  2980. {
  2981. 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"));
  2982. 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?
  2983. 3:
  2984. 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")));
  2985. 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));
  2986. }
  2987. }
  2988. // Optional item
  2989. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  2990. {
  2991. sprintf((char*)txProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  2992. }
  2993. else
  2994. {
  2995. sprintf((char*)txProfile.validFrom, " ");
  2996. }
  2997. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  2998. {
  2999. sprintf((char*)txProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3000. }
  3001. else
  3002. {
  3003. sprintf((char*)txProfile.validTo, " ");
  3004. }
  3005. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  3006. {
  3007. sprintf((char*)txProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  3008. }
  3009. else
  3010. {
  3011. sprintf((char*)txProfile.recurrencyKind, " ");
  3012. }
  3013. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3014. {
  3015. sprintf((char*)txProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  3016. }
  3017. else
  3018. {
  3019. sprintf((char*)txProfile.transactionId, " ");
  3020. }
  3021. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3022. {
  3023. txProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3024. }
  3025. else
  3026. {
  3027. txProfile.chargingSchedule[idxSchedule].duration = 86400;
  3028. }
  3029. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3030. {
  3031. 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")));
  3032. }
  3033. else
  3034. {
  3035. 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));
  3036. }
  3037. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3038. {
  3039. txProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3040. }
  3041. else
  3042. {
  3043. txProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3044. }
  3045. }
  3046. }
  3047. }
  3048. else
  3049. {
  3050. if(txProfile.id == -1)
  3051. DEBUG_INFO("TxProfile found.\n");
  3052. else
  3053. DEBUG_INFO("TxProfile updated.\n");
  3054. // Required item
  3055. txProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3056. txProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3057. sprintf((char*)txProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3058. if(isUnitA)
  3059. {
  3060. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3061. 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++)
  3062. {
  3063. 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"));
  3064. 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?
  3065. 3:
  3066. 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")));
  3067. 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")));
  3068. }
  3069. }
  3070. else
  3071. {
  3072. sprintf((char*)txProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3073. 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++)
  3074. {
  3075. 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"));
  3076. 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?
  3077. 3:
  3078. 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")));
  3079. 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));
  3080. }
  3081. }
  3082. // Optional item
  3083. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3084. {
  3085. sprintf((char*)txProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3086. }
  3087. else
  3088. {
  3089. sprintf((char*)txProfile.validFrom, " ");
  3090. }
  3091. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3092. {
  3093. sprintf((char*)txProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3094. }
  3095. else
  3096. {
  3097. sprintf((char*)txProfile.validTo, " ");
  3098. }
  3099. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  3100. {
  3101. sprintf((char*)txProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  3102. }
  3103. else
  3104. {
  3105. sprintf((char*)txProfile.recurrencyKind, " ");
  3106. }
  3107. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3108. {
  3109. sprintf((char*)txProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  3110. }
  3111. else
  3112. {
  3113. sprintf((char*)txProfile.transactionId, " ");
  3114. }
  3115. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3116. {
  3117. txProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3118. }
  3119. else
  3120. {
  3121. txProfile.chargingSchedule[idxSchedule].duration = 86400;
  3122. }
  3123. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3124. {
  3125. 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")));
  3126. }
  3127. else
  3128. {
  3129. 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));
  3130. }
  3131. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3132. {
  3133. txProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3134. }
  3135. else
  3136. {
  3137. txProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3138. }
  3139. }
  3140. }
  3141. }
  3142. json_object_put(obj);
  3143. }
  3144. fclose(fp);
  3145. /*
  3146. if(txProfile.ChargingProfileId != -1)
  3147. {
  3148. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3149. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3150. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3151. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3152. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3153. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3154. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  3155. DEBUG_INFO("Profile start schedule: %s\n", txProfile.chargingSchedule[idxSchedule].StartSchedule);
  3156. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.chargingSchedule[idxSchedule].Duration);
  3157. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  3158. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.chargingSchedule[idxSchedule].MinChargingRate);
  3159. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  3160. {
  3161. if(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3162. {
  3163. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3164. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  3165. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3166. }
  3167. }
  3168. }
  3169. else
  3170. DEBUG_INFO("TxProfile not found.\n");*/
  3171. }
  3172. // Search default tx profile
  3173. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  3174. if((access(profileFileName, F_OK))==-1)
  3175. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  3176. if((access(profileFileName, F_OK))!=-1)
  3177. {
  3178. fp = fopen(profileFileName, "r");
  3179. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3180. {
  3181. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3182. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3183. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3184. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse = 0;
  3185. }
  3186. defaultTxProfile.id = -1;
  3187. defaultTxProfile.stackLevel = -1;
  3188. while(getline(&line, &len, fp) != -1)
  3189. {
  3190. json_object *obj = NULL;
  3191. obj = json_tokener_parse(line);
  3192. if(is_error(obj))
  3193. {
  3194. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  3195. }
  3196. else
  3197. {
  3198. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.id) &&
  3199. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.stackLevel)
  3200. )
  3201. {
  3202. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  3203. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3204. )
  3205. {
  3206. struct tm tmFrom, tmTo;
  3207. struct timeb tbFrom, tbTo;
  3208. 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) &&
  3209. (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))
  3210. {
  3211. tmFrom.tm_year -= 1900;
  3212. tmFrom.tm_mon -= 1;
  3213. tbFrom.time = mktime(&tmFrom);
  3214. tmTo.tm_year -= 1900;
  3215. tmTo.tm_mon -= 1;
  3216. tbTo.time = mktime(&tmTo);
  3217. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3218. {
  3219. if(defaultTxProfile.id == -1)
  3220. DEBUG_INFO("TxDefaultProfile found.\n");
  3221. else
  3222. DEBUG_INFO("TxDefaultProfile updated.\n");
  3223. // Required item
  3224. defaultTxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3225. defaultTxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3226. sprintf((char*)defaultTxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3227. if(isUnitA)
  3228. {
  3229. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3230. 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++)
  3231. {
  3232. 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"));
  3233. 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?
  3234. 3:
  3235. 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")));
  3236. 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")));
  3237. }
  3238. }
  3239. else
  3240. {
  3241. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3242. 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++)
  3243. {
  3244. 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"));
  3245. 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?
  3246. 3:
  3247. 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")));
  3248. 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));
  3249. }
  3250. }
  3251. // Optional item
  3252. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3253. {
  3254. sprintf((char*)defaultTxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3255. }
  3256. else
  3257. {
  3258. sprintf((char*)defaultTxProfile.validFrom, " ");
  3259. }
  3260. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3261. {
  3262. sprintf((char*)defaultTxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3263. }
  3264. else
  3265. {
  3266. sprintf((char*)defaultTxProfile.validTo, " ");
  3267. }
  3268. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  3269. {
  3270. sprintf((char*)defaultTxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  3271. }
  3272. else
  3273. {
  3274. sprintf((char*)defaultTxProfile.recurrencyKind, " ");
  3275. }
  3276. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3277. {
  3278. sprintf((char*)defaultTxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  3279. }
  3280. else
  3281. {
  3282. sprintf((char*)defaultTxProfile.transactionId, " ");
  3283. }
  3284. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3285. {
  3286. defaultTxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3287. }
  3288. else
  3289. {
  3290. defaultTxProfile.chargingSchedule[idxSchedule].duration = 86400;
  3291. }
  3292. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3293. {
  3294. 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")));
  3295. }
  3296. else
  3297. {
  3298. 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));
  3299. }
  3300. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3301. {
  3302. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3303. }
  3304. else
  3305. {
  3306. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3307. }
  3308. }
  3309. }
  3310. }
  3311. else
  3312. {
  3313. if(defaultTxProfile.id == -1)
  3314. DEBUG_INFO("TxDefaultProfile found.\n");
  3315. else
  3316. DEBUG_INFO("TxDefaultProfile updated.\n");
  3317. // Required item
  3318. defaultTxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3319. defaultTxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3320. sprintf((char*)defaultTxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3321. if(isUnitA)
  3322. {
  3323. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3324. 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++)
  3325. {
  3326. 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"));
  3327. 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?
  3328. 3:
  3329. 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")));
  3330. 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")));
  3331. }
  3332. }
  3333. else
  3334. {
  3335. sprintf((char*)defaultTxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3336. 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++)
  3337. {
  3338. 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"));
  3339. 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?
  3340. 3:
  3341. 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")));
  3342. 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));
  3343. }
  3344. }
  3345. // Optional item
  3346. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3347. {
  3348. sprintf((char*)defaultTxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3349. }
  3350. else
  3351. {
  3352. sprintf((char*)defaultTxProfile.validFrom, " ");
  3353. }
  3354. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3355. {
  3356. sprintf((char*)defaultTxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3357. }
  3358. else
  3359. {
  3360. sprintf((char*)defaultTxProfile.validTo, " ");
  3361. }
  3362. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  3363. {
  3364. sprintf((char*)defaultTxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  3365. }
  3366. else
  3367. {
  3368. sprintf((char*)defaultTxProfile.recurrencyKind, " ");
  3369. }
  3370. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3371. {
  3372. sprintf((char*)defaultTxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  3373. }
  3374. else
  3375. {
  3376. sprintf((char*)defaultTxProfile.transactionId, " ");
  3377. }
  3378. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3379. {
  3380. defaultTxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3381. }
  3382. else
  3383. {
  3384. defaultTxProfile.chargingSchedule[idxSchedule].duration = 86400;
  3385. }
  3386. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3387. {
  3388. 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")));
  3389. }
  3390. else
  3391. {
  3392. 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));
  3393. }
  3394. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3395. {
  3396. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3397. }
  3398. else
  3399. {
  3400. defaultTxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3401. }
  3402. }
  3403. }
  3404. }
  3405. json_object_put(obj);
  3406. }
  3407. fclose(fp);
  3408. /*
  3409. if(defaultTxProfile.ChargingProfileId != -1)
  3410. {
  3411. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3412. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3413. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3414. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3415. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3416. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3417. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3418. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].StartSchedule);
  3419. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.chargingSchedule[idxSchedule].Duration);
  3420. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  3421. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  3422. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  3423. {
  3424. if(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3425. {
  3426. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3427. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  3428. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3429. }
  3430. }
  3431. }
  3432. else
  3433. DEBUG_INFO("TxDefaultProfile not found.\n");
  3434. DEBUG_INFO("------------------------------------\n");*/
  3435. }
  3436. // Search max profile
  3437. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  3438. if((access(profileFileName, F_OK))!=-1)
  3439. {
  3440. fp = fopen(profileFileName, "r");
  3441. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3442. {
  3443. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = -1;
  3444. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit = -1;
  3445. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases = 3;
  3446. }
  3447. maxProfile.id = -1;
  3448. maxProfile.stackLevel = -1;
  3449. while(getline(&line, &len, fp) != -1)
  3450. {
  3451. json_object *obj = NULL;
  3452. obj = json_tokener_parse(line);
  3453. if(is_error(obj))
  3454. {
  3455. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  3456. }
  3457. else
  3458. {
  3459. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.id) &&
  3460. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.stackLevel)
  3461. )
  3462. {
  3463. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  3464. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3465. )
  3466. {
  3467. struct tm tmFrom, tmTo;
  3468. struct timeb tbFrom, tbTo;
  3469. 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) &&
  3470. (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))
  3471. {
  3472. tmFrom.tm_year -= 1900;
  3473. tmFrom.tm_mon -= 1;
  3474. tbFrom.time = mktime(&tmFrom);
  3475. tmTo.tm_year -= 1900;
  3476. tmTo.tm_mon -= 1;
  3477. tbTo.time = mktime(&tmTo);
  3478. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  3479. {
  3480. if(maxProfile.id == -1)
  3481. DEBUG_INFO("MaxProfile found.\n");
  3482. else
  3483. DEBUG_INFO("MaxProfile updated.\n");
  3484. // Required item
  3485. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3486. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3487. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3488. if(isUnitA)
  3489. {
  3490. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3491. 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++)
  3492. {
  3493. 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"));
  3494. 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?
  3495. 3:
  3496. 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")));
  3497. 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")));
  3498. }
  3499. }
  3500. else
  3501. {
  3502. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3503. 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++)
  3504. {
  3505. 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"));
  3506. 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?
  3507. 3:
  3508. 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")));
  3509. 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));
  3510. }
  3511. }
  3512. // Optional item
  3513. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3514. {
  3515. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3516. }
  3517. else
  3518. {
  3519. sprintf((char*)maxProfile.validFrom, " ");
  3520. }
  3521. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3522. {
  3523. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3524. }
  3525. else
  3526. {
  3527. sprintf((char*)maxProfile.validTo, " ");
  3528. }
  3529. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  3530. {
  3531. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  3532. }
  3533. else
  3534. {
  3535. sprintf((char*)maxProfile.recurrencyKind, " ");
  3536. }
  3537. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3538. {
  3539. sprintf((char*)maxProfile.transactionId, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  3540. }
  3541. else
  3542. {
  3543. sprintf((char*)maxProfile.transactionId, " ");
  3544. }
  3545. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3546. {
  3547. maxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3548. }
  3549. else
  3550. {
  3551. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  3552. }
  3553. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3554. {
  3555. 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")));
  3556. }
  3557. else
  3558. {
  3559. 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));
  3560. }
  3561. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3562. {
  3563. maxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3564. }
  3565. else
  3566. {
  3567. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3568. }
  3569. }
  3570. }
  3571. }
  3572. else
  3573. {
  3574. if(maxProfile.id == -1)
  3575. DEBUG_INFO("MaxProfile found.\n");
  3576. else
  3577. DEBUG_INFO("MaxProfile updated.\n");
  3578. // Required item
  3579. maxProfile.id = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  3580. maxProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  3581. sprintf((char*)maxProfile.chargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  3582. if(isUnitA)
  3583. {
  3584. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "A");
  3585. 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++)
  3586. {
  3587. 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"));
  3588. 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?
  3589. 3:
  3590. 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")));
  3591. 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")));
  3592. }
  3593. }
  3594. else
  3595. {
  3596. sprintf((char*)maxProfile.chargingSchedule[idxSchedule].chargingRateUnit, "W");
  3597. 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++)
  3598. {
  3599. 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"));
  3600. 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?
  3601. 3:
  3602. 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")));
  3603. 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));
  3604. }
  3605. }
  3606. // Optional item
  3607. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  3608. {
  3609. sprintf((char*)maxProfile.validFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  3610. }
  3611. else
  3612. {
  3613. sprintf((char*)maxProfile.validFrom, " ");
  3614. }
  3615. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  3616. {
  3617. sprintf((char*)maxProfile.validTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  3618. }
  3619. else
  3620. {
  3621. sprintf((char*)maxProfile.validTo, " ");
  3622. }
  3623. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  3624. {
  3625. sprintf((char*)maxProfile.recurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  3626. }
  3627. else
  3628. {
  3629. sprintf((char*)maxProfile.recurrencyKind, " ");
  3630. }
  3631. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  3632. {
  3633. sprintf((char*)maxProfile.transactionId,"%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId")));
  3634. }
  3635. else
  3636. {
  3637. sprintf((char*)maxProfile.transactionId, " ");
  3638. }
  3639. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  3640. {
  3641. maxProfile.chargingSchedule[idxSchedule].duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  3642. }
  3643. else
  3644. {
  3645. maxProfile.chargingSchedule[idxSchedule].duration = 86400;
  3646. }
  3647. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  3648. {
  3649. 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")));
  3650. }
  3651. else
  3652. {
  3653. 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));
  3654. }
  3655. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  3656. {
  3657. maxProfile.chargingSchedule[idxSchedule].minChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  3658. }
  3659. else
  3660. {
  3661. maxProfile.chargingSchedule[idxSchedule].minChargingRate = -1;
  3662. }
  3663. }
  3664. }
  3665. }
  3666. json_object_put(obj);
  3667. }
  3668. fclose(fp);
  3669. /*
  3670. if(maxProfile.ChargingProfileId !=-1)
  3671. {
  3672. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  3673. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  3674. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  3675. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  3676. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  3677. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  3678. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  3679. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.chargingSchedule[idxSchedule].StartSchedule);
  3680. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  3681. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  3682. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  3683. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  3684. {
  3685. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3686. {
  3687. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3688. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  3689. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3690. }
  3691. }
  3692. }
  3693. else
  3694. DEBUG_INFO("MaxProfile not found.\n");
  3695. DEBUG_INFO("------------------------------------\n");*/
  3696. }
  3697. /*
  3698. * Align found profile start schedule & periods
  3699. */
  3700. //DEBUG_INFO("====================================\n");
  3701. /*
  3702. // For local test usage, force modify found profile start schedule info
  3703. 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);
  3704. 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);
  3705. 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);
  3706. */
  3707. if(txProfile.id != -1)
  3708. {
  3709. if(strstr((char*)txProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  3710. {
  3711. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  3712. {
  3713. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  3714. 0:
  3715. (txProfile.chargingSchedule[idxSchedule].duration-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  3716. }
  3717. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3718. {
  3719. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3720. {
  3721. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  3722. 0:
  3723. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  3724. if(idxPeriod > 0)
  3725. {
  3726. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3727. {
  3728. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3729. }
  3730. }
  3731. }
  3732. }
  3733. }
  3734. else if(strstr((char*)txProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  3735. {
  3736. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  3737. {
  3738. txProfile.chargingSchedule[idxSchedule].duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.chargingSchedule[idxSchedule].duration:((txProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  3739. 0:
  3740. (txProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  3741. }
  3742. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3743. {
  3744. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3745. {
  3746. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod:((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  3747. 0:
  3748. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  3749. if(idxPeriod > 0)
  3750. {
  3751. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3752. {
  3753. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3754. }
  3755. }
  3756. }
  3757. }
  3758. }
  3759. else
  3760. {
  3761. if(strstr((char*)txProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  3762. {
  3763. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  3764. {
  3765. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  3766. 0:
  3767. (txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  3768. }
  3769. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3770. {
  3771. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3772. {
  3773. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  3774. 0:
  3775. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  3776. if(idxPeriod > 0)
  3777. {
  3778. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3779. {
  3780. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3781. }
  3782. }
  3783. }
  3784. }
  3785. }
  3786. else
  3787. {
  3788. if(txProfile.chargingSchedule[idxSchedule].duration != -1)
  3789. {
  3790. txProfile.chargingSchedule[idxSchedule].duration = ((txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  3791. 0:
  3792. (txProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  3793. }
  3794. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3795. {
  3796. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3797. {
  3798. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  3799. 0:
  3800. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(txProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  3801. if(idxPeriod > 0)
  3802. {
  3803. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3804. {
  3805. txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3806. }
  3807. }
  3808. }
  3809. }
  3810. }
  3811. }
  3812. /*
  3813. DEBUG_INFO("txProfile after align.\n");
  3814. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  3815. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  3816. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  3817. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  3818. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  3819. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  3820. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  3821. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3822. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.chargingSchedule[idxSchedule].Duration);
  3823. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  3824. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.chargingSchedule[idxSchedule].MinChargingRate);
  3825. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  3826. {
  3827. if(txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3828. {
  3829. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3830. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  3831. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3832. }
  3833. }*/
  3834. }
  3835. if(defaultTxProfile.id != -1)
  3836. {
  3837. if(strstr((char*)defaultTxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  3838. {
  3839. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  3840. {
  3841. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  3842. 0:
  3843. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  3844. }
  3845. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3846. {
  3847. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3848. {
  3849. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  3850. 0:
  3851. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  3852. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod < txProfile.chargingSchedule[idxSchedule].duration)
  3853. {
  3854. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod += (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  3855. }
  3856. if(idxPeriod > 0)
  3857. {
  3858. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3859. {
  3860. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3861. }
  3862. }
  3863. }
  3864. }
  3865. }
  3866. else if(strstr((char*)defaultTxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  3867. {
  3868. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  3869. {
  3870. defaultTxProfile.chargingSchedule[idxSchedule].duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.chargingSchedule[idxSchedule].duration:((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  3871. 0:
  3872. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  3873. }
  3874. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3875. {
  3876. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3877. {
  3878. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod:((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  3879. 0:
  3880. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  3881. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod < txProfile.chargingSchedule[idxSchedule].duration)
  3882. {
  3883. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod += (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  3884. }
  3885. if(idxPeriod > 0)
  3886. {
  3887. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3888. {
  3889. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3890. }
  3891. }
  3892. }
  3893. }
  3894. }
  3895. else
  3896. {
  3897. if(strstr((char*)defaultTxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  3898. {
  3899. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  3900. {
  3901. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  3902. 0:
  3903. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  3904. }
  3905. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3906. {
  3907. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3908. {
  3909. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  3910. 0:
  3911. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  3912. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod < txProfile.chargingSchedule[idxSchedule].duration)
  3913. {
  3914. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod += (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  3915. }
  3916. if(idxPeriod > 0)
  3917. {
  3918. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3919. {
  3920. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3921. }
  3922. }
  3923. }
  3924. }
  3925. }
  3926. else
  3927. {
  3928. if(defaultTxProfile.chargingSchedule[idxSchedule].duration != -1)
  3929. {
  3930. defaultTxProfile.chargingSchedule[idxSchedule].duration = ((defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  3931. 0:
  3932. (defaultTxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  3933. }
  3934. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3935. {
  3936. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3937. {
  3938. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  3939. 0:
  3940. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(defaultTxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  3941. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod < txProfile.chargingSchedule[idxSchedule].duration)
  3942. {
  3943. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod += (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  3944. }
  3945. if(idxPeriod > 0)
  3946. {
  3947. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  3948. {
  3949. defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  3950. }
  3951. }
  3952. }
  3953. }
  3954. }
  3955. }
  3956. /*
  3957. DEBUG_INFO("defaultTxProfile after align.\n");
  3958. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  3959. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  3960. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  3961. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  3962. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  3963. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  3964. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  3965. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  3966. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.chargingSchedule[idxSchedule].Duration);
  3967. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  3968. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  3969. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  3970. {
  3971. if(defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  3972. {
  3973. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  3974. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  3975. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  3976. }
  3977. }
  3978. DEBUG_INFO("------------------------------------\n");*/
  3979. }
  3980. if(maxProfile.id != -1)
  3981. {
  3982. if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Absolute]) != NULL)
  3983. {
  3984. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  3985. {
  3986. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  3987. 0:
  3988. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  3989. }
  3990. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  3991. {
  3992. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  3993. {
  3994. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  3995. 0:
  3996. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  3997. if(idxPeriod > 0)
  3998. {
  3999. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4000. {
  4001. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4002. }
  4003. }
  4004. }
  4005. }
  4006. }
  4007. else if(strstr((char*)maxProfile.chargingProfileKind, ChargingProfileKindEnumTypeStr[ChargingProfileKindEnumType_Relative]) != NULL)
  4008. {
  4009. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4010. {
  4011. maxProfile.chargingSchedule[idxSchedule].duration = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.chargingSchedule[idxSchedule].duration:((maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4012. 0:
  4013. (maxProfile.chargingSchedule[idxSchedule].duration-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[9].startSchedule)));
  4014. }
  4015. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4016. {
  4017. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4018. {
  4019. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = !cpinitateMsg.bits[(connectorId==0?0:connectorId-1)].isOnCharging?maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod:((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule))<0?
  4020. 0:
  4021. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartStop(ShmOCPP20Data->TransactionEvent[(connectorId==0?0:connectorId-1)].timestamp, compositeProfile->chargingSchedule[idxSchedule].startSchedule)));
  4022. if(idxPeriod > 0)
  4023. {
  4024. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4025. {
  4026. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4027. }
  4028. }
  4029. }
  4030. }
  4031. }
  4032. else
  4033. {
  4034. if(strstr((char*)maxProfile.recurrencyKind, RecurrencyKindEnumTypeStr[RecurrencyKindEnumType_Weekly]) != NULL)
  4035. {
  4036. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4037. {
  4038. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4039. 0:
  4040. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4041. }
  4042. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4043. {
  4044. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4045. {
  4046. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE))<0?
  4047. 0:
  4048. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, FALSE)));
  4049. if(idxPeriod > 0)
  4050. {
  4051. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4052. {
  4053. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4054. }
  4055. }
  4056. }
  4057. }
  4058. }
  4059. else
  4060. {
  4061. if(maxProfile.chargingSchedule[idxSchedule].duration != -1)
  4062. {
  4063. maxProfile.chargingSchedule[idxSchedule].duration = ((maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4064. 0:
  4065. (maxProfile.chargingSchedule[idxSchedule].duration-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4066. }
  4067. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4068. {
  4069. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod != -1)
  4070. {
  4071. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod = ((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE))<0?
  4072. 0:
  4073. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod-getStartSinceRecurring(maxProfile.chargingSchedule[idxSchedule].startSchedule, compositeProfile->chargingSchedule[idxSchedule].startSchedule, TRUE)));
  4074. if(idxPeriod > 0)
  4075. {
  4076. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].startPeriod == maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod)
  4077. {
  4078. maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod-1].limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit;
  4079. }
  4080. }
  4081. }
  4082. }
  4083. }
  4084. }
  4085. /*
  4086. DEBUG_INFO("MaxProfile after align.\n");
  4087. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  4088. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  4089. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  4090. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  4091. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  4092. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  4093. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  4094. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  4095. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.chargingSchedule[idxSchedule].Duration);
  4096. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.chargingSchedule[idxSchedule].ChargingRateUnit);
  4097. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.chargingSchedule[idxSchedule].MinChargingRate);
  4098. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod);idxPeriod++)
  4099. {
  4100. if(maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  4101. {
  4102. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].StartPeriod);
  4103. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].Limit);
  4104. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.chargingSchedule[idxSchedule].ChargingSchedulePeriod[idxPeriod].NumberPhases);
  4105. }
  4106. }
  4107. DEBUG_INFO("------------------------------------\n");*/
  4108. }
  4109. /*
  4110. * Merge to conposite schedule
  4111. */
  4112. //DEBUG_INFO("====================================\n");
  4113. // Find each profile period quantity
  4114. for(int idx=0;idx<ARRAY_SIZE(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  4115. {
  4116. if(maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  4117. limitMax = idx+1;
  4118. }
  4119. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  4120. {
  4121. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  4122. limitDef = idx+1;
  4123. }
  4124. for(int idx=0;idx<ARRAY_SIZE(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod);idx++)
  4125. {
  4126. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idx].limit != -1)
  4127. limitTx = idx+1;
  4128. }
  4129. // TxProfile found, composite schedule based on it
  4130. if(txProfile.id != -1)
  4131. {
  4132. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  4133. {
  4134. if((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit != -1) &&
  4135. (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod < durationReq) &&
  4136. (txProfile.chargingSchedule[idxSchedule].duration > 0))
  4137. {
  4138. if(maxProfile.id != -1)
  4139. {
  4140. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4141. {
  4142. if((txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod))
  4143. {
  4144. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  4145. {
  4146. tmpPeriod.startPeriod = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod;
  4147. tmpPeriod.numberPhases = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].numberPhases;
  4148. 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);
  4149. }
  4150. else
  4151. {
  4152. tmpPeriod.startPeriod = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod;
  4153. tmpPeriod.numberPhases = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].numberPhases;
  4154. tmpPeriod.limit = txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].limit;
  4155. }
  4156. }
  4157. if(idxMaxPeriod == (limitMax-1))
  4158. {
  4159. if(tmpPeriod.limit != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  4160. {
  4161. if(tmpPeriod.startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4162. {
  4163. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4164. compositePeriodIdx++;
  4165. }
  4166. else
  4167. {
  4168. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4169. }
  4170. }
  4171. }
  4172. }
  4173. }
  4174. else
  4175. {
  4176. if(txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4177. {
  4178. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod],sizeof(struct ChargingSchedulePeriodType));
  4179. compositePeriodIdx++;
  4180. }
  4181. else
  4182. {
  4183. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod],sizeof(struct ChargingSchedulePeriodType));
  4184. }
  4185. }
  4186. }
  4187. if(idxTxPeriod == (limitTx-1))
  4188. {
  4189. if(defaultTxProfile.id != -1)
  4190. {
  4191. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  4192. {
  4193. if((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= (txProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxTxPeriod].startPeriod + (txProfile.chargingSchedule[idxSchedule].duration-defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod))) &&
  4194. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod < durationReq) &&
  4195. (defaultTxProfile.chargingSchedule[idxSchedule].duration>0))
  4196. {
  4197. if(maxProfile.id != -1)
  4198. {
  4199. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4200. {
  4201. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod)
  4202. {
  4203. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  4204. {
  4205. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  4206. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  4207. 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);
  4208. }
  4209. else
  4210. {
  4211. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  4212. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  4213. tmpPeriod.limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit;
  4214. }
  4215. if(tmpPeriod.limit != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  4216. {
  4217. if(tmpPeriod.startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4218. {
  4219. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4220. compositePeriodIdx++;
  4221. }
  4222. else
  4223. {
  4224. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4225. }
  4226. }
  4227. // Delete duplicate period
  4228. if(compositePeriodIdx > 1)
  4229. {
  4230. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  4231. {
  4232. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  4233. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  4234. compositePeriodIdx -= 1;
  4235. }
  4236. }
  4237. }
  4238. else
  4239. break;
  4240. }
  4241. }
  4242. else
  4243. {
  4244. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4245. {
  4246. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  4247. compositePeriodIdx++;
  4248. }
  4249. else
  4250. {
  4251. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  4252. }
  4253. }
  4254. }
  4255. }
  4256. }
  4257. }
  4258. }
  4259. }
  4260. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  4261. else if(defaultTxProfile.id != -1)
  4262. {
  4263. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  4264. {
  4265. if((defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit != -1) &&
  4266. (defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod < durationReq) &&
  4267. (defaultTxProfile.chargingSchedule[idxSchedule].duration > 0))
  4268. {
  4269. if(maxProfile.id != -1)
  4270. {
  4271. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4272. {
  4273. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod >= maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod)
  4274. {
  4275. if((maxProfile.chargingSchedule[idxSchedule].duration > 0))
  4276. {
  4277. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  4278. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  4279. 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);
  4280. }
  4281. else
  4282. {
  4283. tmpPeriod.startPeriod = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod;
  4284. tmpPeriod.numberPhases = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].numberPhases;
  4285. tmpPeriod.limit = defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].limit;
  4286. }
  4287. if(tmpPeriod.limit != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  4288. {
  4289. if(tmpPeriod.startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4290. {
  4291. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4292. compositePeriodIdx++;
  4293. }
  4294. else
  4295. {
  4296. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4297. }
  4298. }
  4299. // Delete duplicate period
  4300. if(compositePeriodIdx > 1)
  4301. {
  4302. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  4303. {
  4304. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  4305. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  4306. compositePeriodIdx -= 1;
  4307. }
  4308. }
  4309. }
  4310. else
  4311. break;
  4312. }
  4313. }
  4314. else
  4315. {
  4316. if(defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod].startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4317. {
  4318. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  4319. compositePeriodIdx++;
  4320. }
  4321. else
  4322. {
  4323. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxDefPeriod],sizeof(struct ChargingSchedulePeriodType));
  4324. }
  4325. }
  4326. }
  4327. }
  4328. }
  4329. // Fill other period by MaxProfile
  4330. if(maxProfile.id != -1)
  4331. {
  4332. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  4333. {
  4334. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit != -1) &&
  4335. (maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod < durationReq) &&
  4336. (maxProfile.chargingSchedule[idxSchedule].duration > 0))
  4337. {
  4338. if((maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].startPeriod >= compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].startPeriod) &&
  4339. (maxProfile.chargingSchedule[idxSchedule].duration > compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].startPeriod))
  4340. {
  4341. tmpPeriod.startPeriod = (compositePeriodIdx==0)?0:compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].startPeriod;
  4342. tmpPeriod.numberPhases = compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].numberPhases;
  4343. tmpPeriod.limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit;
  4344. }
  4345. if((compositePeriodIdx > 0) && (maxProfile.chargingSchedule[idxSchedule].duration > compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].startPeriod))
  4346. {
  4347. 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;
  4348. tmpPeriod.numberPhases = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].numberPhases;
  4349. tmpPeriod.limit = maxProfile.chargingSchedule[idxSchedule].chargingSchedulePeriod[idxMaxPeriod].limit;
  4350. }
  4351. if(tmpPeriod.limit != -1)
  4352. {
  4353. if(tmpPeriod.limit != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].limit)
  4354. {
  4355. if(tmpPeriod.startPeriod != compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].startPeriod)
  4356. {
  4357. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4358. compositePeriodIdx++;
  4359. }
  4360. else
  4361. {
  4362. memcpy(&compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct ChargingSchedulePeriodType));
  4363. }
  4364. }
  4365. // Delete duplicate period
  4366. if(compositePeriodIdx > 1)
  4367. {
  4368. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit == compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-2].limit)
  4369. {
  4370. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].startPeriod = -1;
  4371. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[compositePeriodIdx-1].limit = -1;
  4372. compositePeriodIdx -= 1;
  4373. }
  4374. }
  4375. }
  4376. }
  4377. }
  4378. }
  4379. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  4380. DEBUG_INFO("Schedule start: %s\n", compositeProfile->chargingSchedule[idxSchedule].startSchedule);
  4381. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->chargingSchedule[idxSchedule].duration);
  4382. DEBUG_INFO("Rate unit: %s\n", compositeProfile->chargingSchedule[idxSchedule].chargingRateUnit);
  4383. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  4384. {
  4385. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod >= 0)
  4386. {
  4387. compositeProfile->id = 1;
  4388. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod);
  4389. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit);
  4390. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases);
  4391. }
  4392. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit == -1)
  4393. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit =0;
  4394. if(compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod == -1)
  4395. compositeProfile->chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod =0;
  4396. }
  4397. if(line)
  4398. free(line);
  4399. ShmOCPP20Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = ON;
  4400. }
  4401. //==========================================
  4402. // Init all share memory
  4403. //==========================================
  4404. int InitShareMemory()
  4405. {
  4406. int result = PASS;
  4407. int MeterSMId;
  4408. //creat ShmSysConfigAndInfo
  4409. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  4410. {
  4411. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  4412. result = FAIL;
  4413. }
  4414. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4415. {
  4416. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  4417. result = FAIL;
  4418. }
  4419. else
  4420. {}
  4421. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  4422. {
  4423. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  4424. result = FAIL;
  4425. }
  4426. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4427. {
  4428. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  4429. result = FAIL;
  4430. }
  4431. else
  4432. {}
  4433. //creat ShmPsuData
  4434. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  4435. {
  4436. DEBUG_ERROR("shmget ShmPsuData NG\n");
  4437. result = FAIL;
  4438. }
  4439. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4440. {
  4441. DEBUG_ERROR("shmat ShmPsuData NG\n");
  4442. result = FAIL;
  4443. }
  4444. else
  4445. {}
  4446. //creat ShmOCPP20Data
  4447. if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), 0777)) < 0)
  4448. {
  4449. DEBUG_ERROR("shmget ShmOCPP20Data NG\n");
  4450. result = FAIL;
  4451. }
  4452. else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  4453. {
  4454. DEBUG_ERROR("shmat ShmOCPP20Data NG\n");
  4455. result = FAIL;
  4456. }
  4457. else
  4458. {}
  4459. /****************************** For Initial Settings************************************************/
  4460. /*
  4461. DEBUG_INFO("Authorize_20 size: %d\n", sizeof(struct Authorize_20));
  4462. DEBUG_INFO("BootNotification_20 size: %d\n", sizeof(struct BootNotification_20));
  4463. DEBUG_INFO("CancelReservation_20 size: %d\n", sizeof(struct CancelReservation_20));
  4464. DEBUG_INFO("CertificateSigned_20 size: %d\n", sizeof(struct CertificateSigned_20));
  4465. DEBUG_INFO("ChangeAvailability_20 size: %d\n", sizeof(struct ChangeAvailability_20));
  4466. DEBUG_INFO("ClearCache_20 size: %d\n", sizeof(struct ClearCache_20));
  4467. DEBUG_INFO("ClearChargingProfile_20 size: %d\n", sizeof(struct ClearChargingProfile_20));
  4468. DEBUG_INFO("ClearDisplayMessage_20 size: %d\n", sizeof(struct ClearDisplayMessage_20));
  4469. DEBUG_INFO("ClearedChargingLimit_20 size: %d\n", sizeof(struct ClearedChargingLimit_20));
  4470. DEBUG_INFO("ClearVariableMonitoring_20 size: %d\n", sizeof(struct ClearVariableMonitoring_20));
  4471. DEBUG_INFO("CostUpdated_20 size: %d\n", sizeof(struct CostUpdated_20));
  4472. DEBUG_INFO("CustomerInformation_20 size: %d\n", sizeof(struct CustomerInformation_20));
  4473. DEBUG_INFO("DeleteCertificate_20 size: %d\n", sizeof(struct DeleteCertificate_20));
  4474. DEBUG_INFO("FirmwareStatusNotification_20 size: %d\n", sizeof(struct FirmwareStatusNotification_20));
  4475. DEBUG_INFO("Get15118EVCertificate_20 size: %d\n", sizeof(struct Get15118EVCertificate_20));
  4476. DEBUG_INFO("GetBaseReport_20 size: %d\n", sizeof(struct GetBaseReport_20));
  4477. DEBUG_INFO("GetCertificateStatus_20 size: %d\n", sizeof(struct GetCertificateStatus_20));
  4478. DEBUG_INFO("GetChargingProfiles_20 size: %d\n", sizeof(struct GetChargingProfiles_20));
  4479. DEBUG_INFO("GetCompositeSchedule_20 size: %d\n", sizeof(struct GetCompositeSchedule_20));
  4480. DEBUG_INFO("GetDisplayMessages_20 size: %d\n", sizeof(struct GetDisplayMessages_20));
  4481. DEBUG_INFO("GetInstalledCertificateIds_20 size: %d\n", sizeof(struct GetInstalledCertificateIds_20));
  4482. DEBUG_INFO("GetLog_20 size: %d\n", sizeof(struct GetLog_20));
  4483. DEBUG_INFO("GetMonitoringReport_20 size: %d\n", sizeof(struct GetMonitoringReport_20));
  4484. DEBUG_INFO("GetReport_20 size: %d\n", sizeof(struct GetReport_20));
  4485. DEBUG_INFO("GetTransactionStatus_20 size: %d\n", sizeof(struct GetTransactionStatus_20));
  4486. DEBUG_INFO("GetVariables_20 size: %d\n", sizeof(struct GetVariables_20));
  4487. DEBUG_INFO("InstallCertificate_20 size: %d\n", sizeof(struct InstallCertificate_20));
  4488. DEBUG_INFO("LogStatusNotification_20 size: %d\n", sizeof(struct LogStatusNotification_20));
  4489. DEBUG_INFO("MeterValues_20 size: %d\n", sizeof(struct MeterValues_20));
  4490. DEBUG_INFO("NotifyChargingLimit_20 size: %d\n", sizeof(struct NotifyChargingLimit_20));
  4491. DEBUG_INFO("NotifyCustomerInformation_20 size: %d\n", sizeof(struct NotifyCustomerInformation_20));
  4492. DEBUG_INFO("NotifyDisplayMessages_20 size: %d\n", sizeof(struct NotifyDisplayMessages_20));
  4493. DEBUG_INFO("NotifyEVChargingNeeds_20 size: %d\n", sizeof(struct NotifyEVChargingNeeds_20));
  4494. DEBUG_INFO("NotifyEVChargingSchedule_20 size: %d\n", sizeof(struct NotifyEVChargingSchedule_20));
  4495. DEBUG_INFO("NotifyEvent_20 size: %d\n", sizeof(struct NotifyEvent_20));
  4496. DEBUG_INFO("NotifyMonitoringReport_20 size: %d\n", sizeof(struct NotifyMonitoringReport_20));
  4497. DEBUG_INFO("NotifyReport_20 size: %d\n", sizeof(struct NotifyReport_20));
  4498. DEBUG_INFO("PublishFirmware_20 size: %d\n", sizeof(struct PublishFirmware_20));
  4499. DEBUG_INFO("PublishFirmwareStatusNotification_20 size: %d\n", sizeof(struct PublishFirmwareStatusNotification_20));
  4500. DEBUG_INFO("ReportChargingProfiles_20 size: %d\n", sizeof(struct ReportChargingProfiles_20));
  4501. DEBUG_INFO("RequestStartTransaction_20 size: %d\n", sizeof(struct RequestStartTransaction_20));
  4502. DEBUG_INFO("RequestStopTransaction_20 size: %d\n", sizeof(struct RequestStopTransaction_20));
  4503. DEBUG_INFO("ReservationStatusUpdate_20 size: %d\n", sizeof(struct ReservationStatusUpdate_20));
  4504. DEBUG_INFO("ReserveNow_20 size: %d\n", sizeof(struct ReserveNow_20));
  4505. DEBUG_INFO("Reset_20 size: %d\n", sizeof(struct Reset_20));
  4506. DEBUG_INFO("SecurityEventNotification_20 size: %d\n", sizeof(struct SecurityEventNotification_20));
  4507. DEBUG_INFO("SendLocalList_20 size: %d\n", sizeof(struct SendLocalList_20));
  4508. DEBUG_INFO("SetChargingProfile_20 size: %d\n", sizeof(struct SetChargingProfile_20));
  4509. DEBUG_INFO("SetDisplayMessage_20 size: %d\n", sizeof(struct SetDisplayMessage_20));
  4510. DEBUG_INFO("SetMonitoringBase_20 size: %d\n", sizeof(struct SetMonitoringBase_20));
  4511. DEBUG_INFO("SetMonitoringLevel_20 size: %d\n", sizeof(struct SetMonitoringLevel_20));
  4512. DEBUG_INFO("SetNetworkProfile_20 size: %d\n", sizeof(struct SetNetworkProfile_20));
  4513. DEBUG_INFO("SetVariableMonitoring_20 size: %d\n", sizeof(struct SetVariableMonitoring_20));
  4514. DEBUG_INFO("SetVariables_20 size: %d\n", sizeof(struct SetVariables_20));
  4515. DEBUG_INFO("SignCertificate_20 size: %d\n", sizeof(struct SignCertificate_20));
  4516. DEBUG_INFO("StatusNotification_20 size: %d\n", sizeof(struct StatusNotification_20));
  4517. DEBUG_INFO("TransactionEvent_20 size: %d\n", sizeof(struct TransactionEvent_20));
  4518. DEBUG_INFO("TriggerMessage_20 size: %d\n", sizeof(struct TriggerMessage_20));
  4519. DEBUG_INFO("UnlockConnector_20 size: %d\n", sizeof(struct UnlockConnector_20));
  4520. DEBUG_INFO("UnpublishFirmware_20 size: %d\n", sizeof(struct UnpublishFirmware_20));
  4521. DEBUG_INFO("UpdateFirmware_20 size: %d\n", sizeof(struct UpdateFirmware_20));
  4522. DEBUG_INFO("ChargingProfileType size: %d\n", sizeof(struct ChargingProfileType));
  4523. */
  4524. return result;
  4525. }
  4526. int ProcessShareMemory()
  4527. {
  4528. if(InitShareMemory() == FAIL)
  4529. {
  4530. DEBUG_ERROR("InitShareMemory NG\n");
  4531. if(ShmStatusCodeData!=NULL)
  4532. {
  4533. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  4534. }
  4535. sleep(5);
  4536. return FAIL;
  4537. }
  4538. return PASS;
  4539. }
  4540. //---------------------common routine---------------------------//
  4541. void checkNetworkProfile(void)
  4542. {
  4543. memcpy(ShmOCPP20Data->OcppServerURL, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmOCPP20Data->OcppServerURL));
  4544. json_object *priority;
  4545. priority = json_tokener_parse((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_NetworkConfigurationPriority].variableAttribute[0].value);
  4546. if(!is_error(priority))
  4547. {
  4548. for(uint8_t idxPriority=0;idxPriority<json_object_array_length(priority);idxPriority++)
  4549. {
  4550. for(uint8_t idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile);idx++)
  4551. {
  4552. if((ShmOCPP20Data->NetworkConnectionProfile[idx].slot == json_object_get_int(json_object_array_get_idx(priority, idxPriority))) &&
  4553. (strlen((char*)ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl) > 0) &&
  4554. (ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount < 3))
  4555. {
  4556. memcpy(ShmOCPP20Data->OcppServerURL, ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->NetworkConnectionProfile[idx].connectionData.ocppCsmsUrl));
  4557. ShmOCPP20Data->NetworkConnectionProfile[idx].retryCount++;
  4558. break;
  4559. }
  4560. }
  4561. }
  4562. }
  4563. json_object_put(priority);
  4564. DEBUG_INFO("Get network profile URL: %s\n", ShmOCPP20Data->OcppServerURL);
  4565. }
  4566. void CheckSystemValue(void)
  4567. {
  4568. char filenmae[100]={0};
  4569. char str[100]={0};
  4570. int tempIndex = 0;
  4571. //===============================
  4572. // EVSE operation check
  4573. //===============================
  4574. //===============================
  4575. // Heartbeat check
  4576. //===============================
  4577. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  4578. {
  4579. clientTime.Heartbeat = time((time_t*)NULL);
  4580. if(server_sign == TRUE)
  4581. {
  4582. HeartBeatWaitTime = ShmOCPP20Data->BootNotification.Response_interval;
  4583. }
  4584. else
  4585. {
  4586. HeartBeatWaitTime = atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value);
  4587. }
  4588. }
  4589. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  4590. {
  4591. //parameter for test
  4592. sendHeartbeatRequest(0);
  4593. //==============================================
  4594. // Reset Waiting Time
  4595. //==============================================
  4596. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  4597. }
  4598. //===============================
  4599. // CSU Trigger Authorize Request
  4600. //===============================
  4601. if(isWebsocketSendable &&
  4602. (server_sign == TRUE) &&
  4603. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON) &&
  4604. (authorizeRetryTimes < 3))
  4605. {
  4606. sendAuthorizeRequest(0);
  4607. authorizeRetryTimes = authorizeRetryTimes + 1;
  4608. if(authorizeRetryTimes < 3)
  4609. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  4610. }
  4611. else if((server_sign == TRUE) &&
  4612. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON) &&
  4613. (authorizeRetryTimes >= 3))
  4614. {
  4615. authorizeRetryTimes = 0;
  4616. SetOcppConnStatus(FALSE);
  4617. server_sign = FALSE;
  4618. }
  4619. else if((server_sign == FALSE) &&
  4620. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalAuthorizeOffline].variableAttribute[0].value, "TRUE") == 0) &&
  4621. (strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_Enabled].variableAttribute[0].value, "TRUE") == 0) &&
  4622. (ShmOCPP20Data->OcppConnStatus == OFF) &&
  4623. (ShmOCPP20Data->SpMsg.bits.AuthorizeReq == ON))
  4624. {
  4625. sendAuthorizeRequest(0);
  4626. }
  4627. if(isWebsocketSendable &&
  4628. (server_sign == TRUE) &&
  4629. (ShmOCPP20Data->GetMonitoringReport.requestId > 0))
  4630. {
  4631. for(uint8_t idxCriterion=0;idxCriterion<ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.monitoringCriteria);idxCriterion++)
  4632. {
  4633. if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_ThresholdMonitoring]) == 0)
  4634. {
  4635. /*
  4636. * TODO:
  4637. * 1. Report component that are ThresholdMonitoring
  4638. */
  4639. }
  4640. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_DeltaMonitoring]) == 0)
  4641. {
  4642. /*
  4643. * TODO:
  4644. * 1. Report component that are DeltaMonitoring
  4645. */
  4646. }
  4647. else if(strcmp((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria[idxCriterion], MonitoringCriterionEnumTypeStr[MonitoringCriterionEnumType_PeriodicMonitoring]) == 0)
  4648. {
  4649. /*
  4650. * TODO:
  4651. * 1. Report component that are PeriodicMonitoring
  4652. */
  4653. }
  4654. else
  4655. {
  4656. /*
  4657. * TODO:
  4658. * 1. Process unknown criteria condition
  4659. */
  4660. }
  4661. }
  4662. ShmOCPP20Data->GetMonitoringReport.requestId = 0;
  4663. }
  4664. if(isWebsocketSendable &&
  4665. (server_sign == TRUE) &&
  4666. (ShmOCPP20Data->GetReport.requestId > 0))
  4667. {
  4668. for(uint8_t idxCriterion=0;idxCriterion<ARRAY_SIZE(ShmOCPP20Data->GetReport.componentCriteria);idxCriterion++)
  4669. {
  4670. if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Active]) == 0)
  4671. {
  4672. /*
  4673. * TODO:
  4674. * 1. Report component that are active
  4675. */
  4676. }
  4677. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Available]) == 0)
  4678. {
  4679. /*
  4680. * TODO:
  4681. * 1. Report component that are available
  4682. */
  4683. }
  4684. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Enabled]) == 0)
  4685. {
  4686. /*
  4687. * TODO:
  4688. * 1. Report component that are enable
  4689. */
  4690. }
  4691. else if(strcmp((char*)ShmOCPP20Data->GetReport.componentCriteria[idxCriterion], ComponentCriterionEnumTypeStr[ComponentCriterionEnumType_Problem]) == 0)
  4692. {
  4693. /*
  4694. * TODO:
  4695. * 1. Report component that are problem
  4696. */
  4697. }
  4698. else
  4699. {
  4700. /*
  4701. * TODO:
  4702. * 1. Process unknown criteria condition
  4703. */
  4704. }
  4705. }
  4706. ShmOCPP20Data->GetReport.requestId = 0;
  4707. }
  4708. if(isWebsocketSendable &&
  4709. (server_sign == TRUE) &&
  4710. (ShmOCPP20Data->GetBaseReport.requestId > 0))
  4711. {
  4712. uint8_t reportIdx = 0;
  4713. ShmOCPP20Data->NotifyReport.requestId = ShmOCPP20Data->GetBaseReport.requestId;
  4714. if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_ConfigurationInventory]) == 0)
  4715. {
  4716. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  4717. {
  4718. if(reportIdx < ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData))
  4719. {
  4720. 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))
  4721. {
  4722. memcpy(&ShmOCPP20Data->NotifyReport.reportData[reportIdx], &ShmOCPP20Data->ControllerComponentVariable[idx_var], sizeof(struct ReportDataType));
  4723. reportIdx++;
  4724. }
  4725. }
  4726. else
  4727. {
  4728. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  4729. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  4730. ShmOCPP20Data->NotifyReport.seqNo += 1;
  4731. else
  4732. ShmOCPP20Data->NotifyReport.seqNo = 0;
  4733. sendNotifyReportRequest();
  4734. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  4735. reportIdx = 0;
  4736. }
  4737. }
  4738. }
  4739. else if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_FullInventory]) == 0)
  4740. {
  4741. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  4742. {
  4743. if(reportIdx < ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData))
  4744. {
  4745. memcpy(&ShmOCPP20Data->NotifyReport.reportData[reportIdx], &ShmOCPP20Data->ControllerComponentVariable[idx_var], sizeof(struct ReportDataType));
  4746. reportIdx++;
  4747. }
  4748. else
  4749. {
  4750. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  4751. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  4752. ShmOCPP20Data->NotifyReport.seqNo += 1;
  4753. else
  4754. ShmOCPP20Data->NotifyReport.seqNo = 0;
  4755. sendNotifyReportRequest();
  4756. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  4757. reportIdx = 0;
  4758. }
  4759. }
  4760. }
  4761. else
  4762. {
  4763. /*
  4764. * TODO:
  4765. * 1. Fill out summary inventory to response message, currently not support
  4766. */
  4767. }
  4768. if(reportIdx > 0)
  4769. {
  4770. getNowDatetime(ShmOCPP20Data->NotifyReport.generatedAt);
  4771. if(ShmOCPP20Data->NotifyReport.seqNo < INT_MAX)
  4772. ShmOCPP20Data->NotifyReport.seqNo += 1;
  4773. else
  4774. ShmOCPP20Data->NotifyReport.seqNo = 0;
  4775. sendNotifyReportRequest();
  4776. memset(&ShmOCPP20Data->NotifyReport.reportData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData)*sizeof(struct ReportDataType));
  4777. reportIdx = 0;
  4778. }
  4779. ShmOCPP20Data->GetBaseReport.requestId = 0;
  4780. }
  4781. if(isWebsocketSendable &&
  4782. (server_sign == TRUE) &&
  4783. ShmOCPP20Data->SpMsg.bits.NotifyEventReq)
  4784. {
  4785. getNowDatetime(ShmOCPP20Data->NotifyEvent.generatedAt);
  4786. ShmOCPP20Data->NotifyEvent.tbc = FALSE;
  4787. if(ShmOCPP20Data->NotifyEvent.seqNo < INT_MAX)
  4788. ShmOCPP20Data->NotifyEvent.seqNo += 1;
  4789. else
  4790. ShmOCPP20Data->NotifyEvent.seqNo = 0;
  4791. sendNotifyEventRequest();
  4792. memset(&ShmOCPP20Data->NotifyEvent.eventData[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData)* sizeof(struct EventDataType ));
  4793. ShmOCPP20Data->SpMsg.bits.NotifyEventReq = OFF;
  4794. }
  4795. if(isWebsocketSendable &&
  4796. (server_sign == TRUE) &&
  4797. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq)
  4798. {
  4799. if(strcmp((char*)ShmOCPP20Data->Get15118EVCertificate.action, CertificateActionEnumTypeStr[CertificateActionEnumType_Install]) == 0)
  4800. {
  4801. /*
  4802. * TODO:
  4803. * 1.
  4804. */
  4805. }
  4806. else if(strcmp((char*)ShmOCPP20Data->Get15118EVCertificate.action, CertificateActionEnumTypeStr[CertificateActionEnumType_Update]) == 0)
  4807. {
  4808. /*
  4809. * TODO:
  4810. * 1.
  4811. */
  4812. }
  4813. else
  4814. {
  4815. /*
  4816. * TODO:
  4817. * 1.
  4818. */
  4819. }
  4820. sendGet15118EVCertificateRequest();
  4821. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq = OFF;
  4822. }
  4823. //===============================
  4824. // Each connector operation check
  4825. //===============================
  4826. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  4827. {
  4828. //==========================================
  4829. // csu trigger DataTransferReq
  4830. //==========================================
  4831. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].DataTransferReq == ON))
  4832. {
  4833. sendDataTransferRequest(gun_index);
  4834. ShmOCPP20Data->CsMsg.bits[gun_index].DataTransferReq = OFF;
  4835. }
  4836. //==============================================
  4837. // Charger start transaction
  4838. //==============================================
  4839. /*
  4840. if((ShmOCPP20Data->CpMsg.bits[gun_index].StartTransactionReq == ON))
  4841. {
  4842. ShmOCPP20Data->CpMsg.bits[gun_index].StartTransactionReq = OFF;
  4843. sendStartTransactionRequest(gun_index);
  4844. clientTime.StartTransaction = time((time_t*)NULL);
  4845. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  4846. }*/
  4847. //==============================================
  4848. // Charger stop transaction
  4849. //==============================================
  4850. /*
  4851. if(((ShmOCPP20Data->CpMsg.bits[gun_index].StopTransactionReq == ON)))
  4852. {
  4853. ShmOCPP20Data->CpMsg.bits[gun_index].StopTransactionReq =OFF;
  4854. sendStopTransactionRequest(gun_index);
  4855. clientTime.StopTransaction = time((time_t*)NULL);
  4856. }*/
  4857. //==============================================
  4858. // Charger status notification & Transaction event report
  4859. //==============================================
  4860. //--- Check Mode Change ---//
  4861. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  4862. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  4863. {
  4864. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4865. {
  4866. tempIndex = ((gun_index==2) ? 1: 0);
  4867. }
  4868. else
  4869. {
  4870. tempIndex = gun_index;
  4871. }
  4872. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4873. {
  4874. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4875. {
  4876. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  4877. {
  4878. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  4879. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  4880. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  4881. if((SystemInitial == 0) &&
  4882. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING) &&
  4883. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_COMPLETE))
  4884. {
  4885. cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
  4886. }
  4887. }
  4888. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  4889. {
  4890. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4891. if((access(filenmae,F_OK))!=-1)
  4892. {
  4893. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4894. sprintf(str,"rm -f %s",filenmae);
  4895. system(str);
  4896. }
  4897. }
  4898. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4899. #if 1 // for TempStopTransaction
  4900. if(((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4901. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  4902. {
  4903. checkTempStopTransaction(gun_index);
  4904. }
  4905. #endif
  4906. }
  4907. }
  4908. }
  4909. else if(gunType[gun_index] == GUN_TYPE_CCS)
  4910. {
  4911. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4912. {
  4913. tempIndex = ((gun_index==2) ? 1: 0);
  4914. }
  4915. else
  4916. {
  4917. tempIndex = gun_index;
  4918. }
  4919. for (int index = 0; index < CCS_QUANTITY; index++)
  4920. {
  4921. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4922. {
  4923. 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]*/ )
  4924. {
  4925. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  4926. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  4927. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  4928. if((SystemInitial == 0) &&
  4929. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_PREPARING) &&
  4930. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_COMPLETE))
  4931. {
  4932. cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
  4933. }
  4934. }
  4935. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  4936. {
  4937. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4938. if((access(filenmae,F_OK))!=-1)
  4939. {
  4940. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4941. sprintf(str,"rm -f %s",filenmae);
  4942. system(str);
  4943. }
  4944. }
  4945. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4946. #if 1 // for TempStopTransaction
  4947. if(((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4948. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  4949. {
  4950. checkTempStopTransaction(gun_index);
  4951. }
  4952. #endif
  4953. }
  4954. }
  4955. }
  4956. else if(gunType[gun_index] == GUN_TYPE_GBT)
  4957. {
  4958. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4959. {
  4960. tempIndex = ((gun_index==2) ? 1: 0);
  4961. }
  4962. else
  4963. {
  4964. tempIndex = gun_index;
  4965. }
  4966. for (int index = 0; index < GB_QUANTITY; index++)
  4967. {
  4968. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4969. {
  4970. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  4971. {
  4972. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  4973. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  4974. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  4975. if((SystemInitial == 0) &&
  4976. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_PREPARING) &&
  4977. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_COMPLETE))
  4978. {
  4979. cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
  4980. }
  4981. }
  4982. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  4983. {
  4984. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  4985. if((access(filenmae,F_OK))!=-1)
  4986. {
  4987. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  4988. sprintf(str,"rm -f %s",filenmae);
  4989. system(str);
  4990. }
  4991. }
  4992. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  4993. #if 1 // for TempStopTransaction
  4994. if(((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  4995. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  4996. {
  4997. checkTempStopTransaction(gun_index);
  4998. }
  4999. #endif
  5000. }
  5001. }
  5002. }
  5003. else if(gunType[gun_index] == GUN_TYPE_DO)
  5004. {
  5005. tempIndex = gun_index;
  5006. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5007. {
  5008. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5009. {
  5010. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  5011. {
  5012. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  5013. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  5014. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  5015. if((SystemInitial == 0) &&
  5016. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_PREPARING) &&
  5017. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_COMPLETE))
  5018. {
  5019. cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
  5020. }
  5021. }
  5022. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // complete
  5023. {
  5024. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5025. if((access(filenmae,F_OK))!=-1)
  5026. {
  5027. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5028. sprintf(str,"rm -f %s",filenmae);
  5029. system(str);
  5030. }
  5031. }
  5032. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5033. #if 1 // for TempStopTransaction
  5034. if(((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)) &&
  5035. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  5036. {
  5037. checkTempStopTransaction(gun_index);
  5038. }
  5039. #endif
  5040. }
  5041. }
  5042. }
  5043. else
  5044. {
  5045. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5046. {
  5047. tempIndex = 2;
  5048. }
  5049. else
  5050. {
  5051. tempIndex = gun_index;
  5052. }
  5053. for (int index = 0; index < AC_QUANTITY; index++)
  5054. {
  5055. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5056. {
  5057. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  5058. {
  5059. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  5060. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  5061. cpinitateMsg.bits[gun_index].StatusNotificationReq = ON;
  5062. if((SystemInitial == 0) &&
  5063. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_PREPARING) &&
  5064. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_COMPLETE))
  5065. {
  5066. cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
  5067. }
  5068. }
  5069. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  5070. {
  5071. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  5072. if((access(filenmae,F_OK))!=-1)
  5073. {
  5074. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  5075. sprintf(str,"rm -f %s",filenmae);
  5076. system(str);
  5077. }
  5078. }
  5079. cpinitateMsg.bits[gun_index].isOnCharging = ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)?1:0);
  5080. #if 1 // for TempStopTransaction
  5081. if(((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_BOOTING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE)) &&
  5082. (ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq == OFF))
  5083. {
  5084. checkTempStopTransaction(gun_index);
  5085. }
  5086. #endif
  5087. }
  5088. }// END
  5089. }
  5090. if(isWebsocketSendable && (server_sign == TRUE) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 5) &&
  5091. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == ON) || (cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq == ON)) )
  5092. {
  5093. if(SystemInitial > 0)
  5094. SystemInitial -= 1;
  5095. sendStatusNotificationRequest(gun_index);
  5096. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  5097. }
  5098. //===============================
  5099. // CSU Trigger Smart Charging Profilw
  5100. //===============================
  5101. if(ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq == ON)
  5102. {
  5103. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP20Data->SmartChargingProfile[gun_index], 0, TRUE);
  5104. ShmOCPP20Data->CSUMsg.bits[gun_index].ChargingProfileReq = OFF;
  5105. }
  5106. if(isWebsocketSendable && (server_sign == TRUE) && (cpinitateMsg.bits[gun_index].TransactionEventReq == ON))
  5107. {
  5108. sendTransactionEventRequest(gun_index);
  5109. cpinitateMsg.bits[gun_index].TransactionEventReq = OFF;
  5110. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0], 0x00, sizeof(struct MeterValueType));
  5111. }
  5112. //==============================================
  5113. // Meter report
  5114. //==============================================
  5115. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValueReq)
  5116. {
  5117. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Trigger);
  5118. cpinitateMsg.bits[gun_index].TriggerMeterValueReq = OFF;
  5119. }
  5120. // ClockAlign MeterValue
  5121. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value) > 0)?((getTimePassSinceToday(gun_index)%(atoi((char*)ShmOCPP20Data->ControllerComponentVariable[AlignedDataCtrlr_Interval].variableAttribute[0].value)))==0):FALSE))
  5122. {
  5123. //check Transaction active
  5124. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5125. {
  5126. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5127. {
  5128. tempIndex = ((gun_index==2) ? 1: 0);
  5129. }
  5130. else
  5131. {
  5132. tempIndex = gun_index;
  5133. }
  5134. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5135. {
  5136. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5137. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5138. {
  5139. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  5140. }
  5141. }// End for CHAdeMO
  5142. }
  5143. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5144. {
  5145. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5146. {
  5147. tempIndex = ((gun_index==2) ? 1: 0);
  5148. }
  5149. else
  5150. {
  5151. tempIndex = gun_index;
  5152. }
  5153. for (int index = 0; index < CCS_QUANTITY; index++)
  5154. {
  5155. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5156. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5157. {
  5158. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  5159. }
  5160. } // End for CCS
  5161. }
  5162. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5163. {
  5164. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5165. {
  5166. tempIndex = ((gun_index==2) ? 1: 0);
  5167. }
  5168. else
  5169. {
  5170. tempIndex = gun_index;
  5171. }
  5172. for (int index = 0; index < GB_QUANTITY; index++)
  5173. {
  5174. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5175. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5176. {
  5177. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  5178. }
  5179. }// End for GB
  5180. }
  5181. else if(gunType[gun_index] == GUN_TYPE_DO)
  5182. {
  5183. tempIndex = gun_index;
  5184. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5185. {
  5186. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5187. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5188. {
  5189. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  5190. }
  5191. }
  5192. }
  5193. else
  5194. {
  5195. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5196. {
  5197. tempIndex = 2;
  5198. }
  5199. else
  5200. {
  5201. tempIndex = gun_index;
  5202. }
  5203. for (int index = 0; index < AC_QUANTITY; index++)
  5204. {
  5205. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5206. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5207. {
  5208. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = ON;
  5209. }
  5210. }//End for AC
  5211. }
  5212. if(cpinitateMsg.bits[gun_index].ClockAlignMeterReq == ON)
  5213. {
  5214. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Clock);
  5215. cpinitateMsg.bits[gun_index].ClockAlignMeterReq = OFF;
  5216. }
  5217. }
  5218. // Sample period MeterValue
  5219. if((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > ((atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value)>10)?(atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value)- 1):10))
  5220. {
  5221. //check Transaction active
  5222. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5223. {
  5224. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5225. {
  5226. tempIndex = ((gun_index==2) ? 1: 0);
  5227. }
  5228. else
  5229. {
  5230. tempIndex = gun_index;
  5231. }
  5232. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5233. {
  5234. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5235. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5236. {
  5237. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5238. {
  5239. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  5240. }
  5241. }
  5242. }// End for CHAdeMO
  5243. }
  5244. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5245. {
  5246. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5247. {
  5248. tempIndex = ((gun_index==2) ? 1: 0);
  5249. }
  5250. else
  5251. {
  5252. tempIndex = gun_index;
  5253. }
  5254. for (int index = 0; index < CCS_QUANTITY; index++)
  5255. {
  5256. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5257. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5258. {
  5259. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5260. {
  5261. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  5262. }
  5263. }
  5264. } // End for CCS
  5265. }
  5266. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5267. {
  5268. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5269. {
  5270. tempIndex = ((gun_index==2) ? 1: 0);
  5271. }
  5272. else
  5273. {
  5274. tempIndex = gun_index;
  5275. }
  5276. for (int index = 0; index < GB_QUANTITY; index++)
  5277. {
  5278. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5279. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5280. {
  5281. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5282. {
  5283. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  5284. }
  5285. }
  5286. }// End for GB
  5287. }
  5288. else if(gunType[gun_index] == GUN_TYPE_DO)
  5289. {
  5290. tempIndex = gun_index;
  5291. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5292. {
  5293. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5294. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5295. {
  5296. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  5297. {
  5298. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  5299. }
  5300. }
  5301. }
  5302. }
  5303. else
  5304. {
  5305. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5306. {
  5307. tempIndex = 2;
  5308. }
  5309. else
  5310. {
  5311. tempIndex = gun_index;
  5312. }
  5313. for (int index = 0; index < AC_QUANTITY; index++)
  5314. {
  5315. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  5316. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5317. {
  5318. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  5319. {
  5320. cpinitateMsg.bits[gun_index].SampleMeterReq = ON;
  5321. }
  5322. }
  5323. }//End for AC
  5324. }
  5325. if(cpinitateMsg.bits[gun_index].SampleMeterReq == ON)
  5326. {
  5327. if(atoi((const char *)ShmOCPP20Data->ControllerComponentVariable[SampledDataCtrlr_TxUpdatedInterval].variableAttribute[0].value) > 0)
  5328. sendMeterValuesRequest(gun_index, ReadingContextEnumType_Sample_Periodic);
  5329. storeTempStopTransaction(gun_index);
  5330. cpinitateMsg.bits[gun_index].SampleMeterReq = OFF;
  5331. }
  5332. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  5333. }
  5334. //==============================================
  5335. // Check Connector reserved
  5336. //==============================================
  5337. //===============================
  5338. // Check if Reserve is expired
  5339. //===============================
  5340. if((server_sign == TRUE) && (ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime[0] != 0) )
  5341. {
  5342. double diff_t;
  5343. struct tm tp;
  5344. // current time
  5345. time_t t = time(NULL);
  5346. strptime((char *)ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime, "%Y-%m-%dT%H:%M:%S", &tp);
  5347. tp.tm_isdst = -1;
  5348. time_t utc = mktime(&tp);
  5349. diff_t = difftime(utc, t);
  5350. if(diff_t <= 0)
  5351. {
  5352. DEBUG_INFO("reserve expired.\n");
  5353. memset(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime,0,ARRAY_SIZE(ShmOCPP20Data->ReserveNow[gun_index].expiryDateTime));
  5354. }
  5355. }//END OF Check if Reserve is expired
  5356. //==========================================
  5357. // csu trigger FirmwareStatusNotificationReq
  5358. //==========================================
  5359. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq == ON))
  5360. {
  5361. sendFirmwareStatusNotificationRequest((char *)ShmOCPP20Data->FirmwareStatusNotification.status);
  5362. }
  5363. //==========================================
  5364. // csu cleared charging limit request
  5365. //==========================================
  5366. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq == ON))
  5367. {
  5368. sendClearedChargingLimitRequest(gun_index);
  5369. }
  5370. //==========================================
  5371. // csu trigger CancelReservationConf
  5372. //==========================================
  5373. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationConf == ON))
  5374. {
  5375. sendCancelReservationConfirmation((char *)ShmOCPP20Data->CancelReservation[gun_index].guid, gun_index);
  5376. }
  5377. //==========================================
  5378. // csu notify EV charging need request
  5379. //==========================================
  5380. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CSUMsg.bits[gun_index].NotifyEVChargingNeedsReq == ON))
  5381. {
  5382. sendNotifyEVChargingNeedsRequest(gun_index);
  5383. }
  5384. //==========================================
  5385. // csu trigger ChangeAvailabilityConf
  5386. //==========================================
  5387. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == ON))
  5388. {
  5389. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP20Data->ChangeAvailability[gun_index].ResponseStatus);
  5390. }
  5391. //==========================================
  5392. // csu trigger UnlockConnectorConf
  5393. //==========================================
  5394. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf == ON))
  5395. {
  5396. sendUnlockConnectorConfirmation((char *)ShmOCPP20Data->UnlockConnector[gun_index].guid, gun_index);
  5397. }
  5398. //==========================================
  5399. // csu trigger ReserveNowConf
  5400. //==========================================
  5401. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf == ON))
  5402. {
  5403. sendReserveNowConfirmation((char *)ShmOCPP20Data->ReserveNow[gun_index].guid, gun_index);
  5404. }
  5405. //==========================================
  5406. // csu trigger ReserveNowConf
  5407. //==========================================
  5408. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq == ON))
  5409. {
  5410. sendReservationStatusUpdateRequest(gun_index);
  5411. }
  5412. //==========================================
  5413. // csu trigger LogStatusNotificationReq
  5414. //==========================================
  5415. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq == ON))
  5416. {
  5417. sendLogStatusNotificationRequest((char *)ShmOCPP20Data->LogStatusNotification.status);
  5418. }
  5419. //==========================================
  5420. // csu trigger SignCertificateReq
  5421. //==========================================
  5422. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP20Data->SpMsg.bits.SignCertificateReq == ON))
  5423. {
  5424. if((access("/Storage/OCPP/certCP.csr",F_OK) != -1) &&
  5425. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) == 0) )
  5426. {
  5427. sendSignCertificateRequest(CertificateSignedStatusEnumType_ChargingStationCertificate);
  5428. }
  5429. else if((access("/Storage/OCPP/certV2G.csr",F_OK) != -1) &&
  5430. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0))
  5431. {
  5432. sendSignCertificateRequest(CertificateSignedStatusEnumType_V2GCertificate);
  5433. }
  5434. }
  5435. }
  5436. }
  5437. //==========================================
  5438. // send request routine
  5439. //==========================================
  5440. int sendAuthorizeRequest(int gun_index)
  5441. {
  5442. mtrace();
  5443. int result = FAIL;
  5444. char message[4096]={0};
  5445. char guid[37];
  5446. char tempdata[128]={0};
  5447. json_object *Authorize = json_object_new_object();
  5448. json_object *idToken = json_object_new_object();
  5449. DEBUG_INFO("sendAuthorizeRequest...\n");
  5450. memset(&(ShmOCPP20Data->Authorize.Response_idTokenInfo),0,sizeof(struct IdTokenInfoType));
  5451. //Local Authorize
  5452. if ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_OfflineTxForUnknownIdEnabled].variableAttribute[0].value, "TRUE")==0) && (ShmOCPP20Data->OcppConnStatus == 0))
  5453. {
  5454. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  5455. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "");
  5456. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, "");
  5457. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]);
  5458. result = PASS;
  5459. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  5460. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  5461. authorizeRetryTimes = 0;
  5462. return result;
  5463. }
  5464. 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)) ||
  5465. ((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCtrlr_LocalPreAuthorize].variableAttribute[0].value, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "TRUE") == 0)))
  5466. {
  5467. // Query idtag from cache
  5468. DB_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId, TRUE);
  5469. // Query idtag from list
  5470. if((strcmp((char*)idTagQuery.idToken.idToken,"") == 0) || (strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0) )
  5471. DB_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId, FALSE);
  5472. if((strcmp((char*)idTagQuery.idToken.idToken,"") == 0) || (strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0) )
  5473. {
  5474. if(strcmp((char*)idTagQuery.idToken.idToken,"") == 0)
  5475. {
  5476. DEBUG_INFO("Card %s does not find in list or cache\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5477. }
  5478. if(strcmp((char*)idTagQuery.idTokenInfo.status,AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != 0)
  5479. {
  5480. DEBUG_INFO("Card %s does not accepted in list and cache\n", ShmSysConfigAndInfo->SysConfig.UserId);
  5481. }
  5482. // Return authorize result if does not connect to server
  5483. if(!ShmOCPP20Data->OcppConnStatus)
  5484. {
  5485. DEBUG_INFO("Local Authorization Fail.\n");
  5486. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "");
  5487. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5488. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Invalid]);
  5489. DEBUG_INFO("ShmOCPP20Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
  5490. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  5491. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  5492. authorizeRetryTimes = 0;
  5493. return result;
  5494. }
  5495. }
  5496. else
  5497. {
  5498. DEBUG_INFO("Local Authorization get result.\n");
  5499. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, (char*)idTagQuery.idTokenInfo.cacheExpiryDateTime);
  5500. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, (char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5501. if(isOvertNow((uint8_t*)&idTagQuery.idTokenInfo.cacheExpiryDateTime[0]))
  5502. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Expired]);
  5503. else
  5504. strcpy((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, (char*)idTagQuery.idTokenInfo.status);
  5505. DEBUG_INFO("ShmOCPP20Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP20Data->Authorize.Response_idTokenInfo.status);
  5506. result = PASS;
  5507. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  5508. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  5509. authorizeRetryTimes = 0;
  5510. return result;
  5511. }
  5512. }
  5513. //get data from shared memory
  5514. strcpy((char *)ShmOCPP20Data->Authorize.idToken.idToken, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  5515. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.idToken));
  5516. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->Authorize.idToken.type));
  5517. json_object_object_add(Authorize, "idToken", idToken);
  5518. random_uuid(guid);
  5519. sprintf(message,"[%d,\"%s\",\"Authorize\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(Authorize, JSON_C_TO_STRING_PLAIN));
  5520. json_object_put(Authorize);
  5521. LWS_Send(message);
  5522. sprintf(tempdata, "Authorize,%d", gun_index);
  5523. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5524. {
  5525. result = PASS;
  5526. }
  5527. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  5528. return result;
  5529. }
  5530. int sendBootNotificationRequest()
  5531. {
  5532. mtrace();
  5533. int result = FAIL;
  5534. char message[4096]={0};
  5535. char guid[37]={0};
  5536. char tempdata[128]={0};
  5537. json_object *BootNotification = json_object_new_object();
  5538. json_object *chargingStation = json_object_new_object();
  5539. json_object *modem = json_object_new_object();
  5540. DEBUG_INFO("sendBootNotificationRequest...\n");
  5541. // Fill BootNotification fields
  5542. DB_getBooType();
  5543. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.model, "%s", ShmSysConfigAndInfo->SysConfig.ModelName);
  5544. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.vendorName, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  5545. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.serialNumber, "%s", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  5546. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.firmwareVersion, "%s", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  5547. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.modem.iccid, "%s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  5548. sprintf((char *)ShmOCPP20Data->BootNotification.chargingStation.modem.imsi, "%s", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  5549. if((ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'T') || (ShmSysConfigAndInfo->SysConfig.ModelName[10] == 'D'))
  5550. {
  5551. json_object_object_add(modem, "iccid", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.modem.iccid));
  5552. json_object_object_add(modem, "imsi", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.modem.imsi));
  5553. json_object_object_add(chargingStation, "modem", modem);
  5554. }
  5555. json_object_object_add(chargingStation, "model", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.model));
  5556. json_object_object_add(chargingStation, "vendorName", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.vendorName));
  5557. json_object_object_add(chargingStation, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.serialNumber));
  5558. json_object_object_add(chargingStation, "firmwareVersion", json_object_new_string((char*)ShmOCPP20Data->BootNotification.chargingStation.firmwareVersion));
  5559. json_object_object_add(BootNotification, "chargingStation", chargingStation);
  5560. json_object_object_add(BootNotification, "reason", json_object_new_string((char*)ShmOCPP20Data->BootNotification.reason));
  5561. random_uuid(guid);
  5562. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", json_object_to_json_string_ext(BootNotification, JSON_C_TO_STRING_PLAIN));
  5563. json_object_put(BootNotification);
  5564. LWS_Send(message);
  5565. sprintf(tempdata, "BootNotification,0");
  5566. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5567. {
  5568. result = PASS;
  5569. }
  5570. return result;
  5571. }
  5572. int sendClearedChargingLimitRequest(int gun_index)
  5573. {
  5574. mtrace();
  5575. int result = FAIL;
  5576. char message[4096]={0};
  5577. char guid[37]={0};
  5578. char tempdata[128]={0};
  5579. json_object *ClearedChargingLimit = json_object_new_object();
  5580. DEBUG_INFO("sendClearedChargingLimitRequest...\n");
  5581. json_object_object_add(ClearedChargingLimit, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->ClearedChargingLimit[gun_index].chargingLimitSource));
  5582. json_object_object_add(ClearedChargingLimit, "evseId", json_object_new_int(ShmOCPP20Data->ClearedChargingLimit[gun_index].evseId));
  5583. random_uuid(guid);
  5584. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ClearedChargingLimit", json_object_to_json_string_ext(ClearedChargingLimit, JSON_C_TO_STRING_PLAIN));
  5585. json_object_put(ClearedChargingLimit);
  5586. LWS_Send(message);
  5587. sprintf(tempdata, "ClearedChargingLimit,%d", gun_index);
  5588. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5589. {
  5590. result = PASS;
  5591. }
  5592. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq = OFF;
  5593. return result;
  5594. }
  5595. int sendDataTransferRequest(int gun_index)
  5596. {
  5597. mtrace();
  5598. char message[1000]={0};
  5599. char guid[37]={0};
  5600. char tempdata[65]={0};
  5601. int result = FAIL;
  5602. DEBUG_INFO("sendDataTransferRequest...\n");
  5603. random_uuid(guid);
  5604. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  5605. MESSAGE_TYPE_CALL,
  5606. guid,
  5607. ShmOCPP20Data->DataTransfer[gun_index].vendorId,
  5608. ShmOCPP20Data->DataTransfer[gun_index].messageId,
  5609. ShmOCPP20Data->DataTransfer[gun_index].data);
  5610. LWS_Send(message);
  5611. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  5612. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5613. {
  5614. result = PASS;
  5615. }
  5616. return result;
  5617. }
  5618. int sendFirmwareStatusNotificationRequest(char *status)
  5619. {
  5620. mtrace();
  5621. int result = FAIL;
  5622. char message[110]={0};
  5623. char guid[37]={0};
  5624. char tempdata[65]={0};
  5625. json_object *FirmwareStatusNotification = json_object_new_object();
  5626. DEBUG_INFO("sendFirmwareStatusNotificationRequest...\n");
  5627. sprintf((char *)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", (const char *)status);
  5628. ShmOCPP20Data->FirmwareStatusNotification.requestId = ShmOCPP20Data->UpdateFirmware.requestId;
  5629. json_object_object_add(FirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->FirmwareStatusNotification.status));
  5630. json_object_object_add(FirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->FirmwareStatusNotification.requestId));
  5631. random_uuid(guid);
  5632. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(FirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  5633. json_object_put(FirmwareStatusNotification);
  5634. LWS_SendNow(message);
  5635. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  5636. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5637. {
  5638. result = PASS;
  5639. }
  5640. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = OFF;
  5641. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationConf = OFF;
  5642. //record status
  5643. if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded])==0)
  5644. {
  5645. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Downloaded;
  5646. }
  5647. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed])==0)
  5648. {
  5649. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadFailed;
  5650. }
  5651. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading])==0)
  5652. {
  5653. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Downloading;
  5654. }
  5655. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadScheduled])==0)
  5656. {
  5657. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadScheduled;
  5658. }
  5659. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadPaused])==0)
  5660. {
  5661. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_DownloadPaused;
  5662. }
  5663. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle])==0)
  5664. {
  5665. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle;
  5666. }
  5667. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallationFailed])==0)
  5668. {
  5669. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallationFailed;
  5670. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  5671. }
  5672. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Installing])==0)
  5673. {
  5674. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Installing;
  5675. }
  5676. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Installed])==0)
  5677. {
  5678. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Installed;
  5679. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  5680. }
  5681. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallRebooting])==0)
  5682. {
  5683. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallRebooting;
  5684. DB_updateBootType(BootReasonEnumType_FirmwareUpdate);
  5685. }
  5686. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallScheduled])==0)
  5687. {
  5688. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallScheduled;
  5689. }
  5690. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InstallVerificationFailed])==0)
  5691. {
  5692. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InstallVerificationFailed;
  5693. }
  5694. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_InvalidSignature])==0)
  5695. {
  5696. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_InvalidSignature;
  5697. }
  5698. else if(strcmp(status,FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_SignatureVerified])==0)
  5699. {
  5700. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_SignatureVerified;
  5701. }
  5702. return result;
  5703. }
  5704. int sendGet15118EVCertificateRequest()
  5705. {
  5706. mtrace();
  5707. int result = FAIL;
  5708. char message[4096]={0};
  5709. char guid[37]={0};
  5710. char tempdata[128]={0};
  5711. json_object *Get15118EVCertificate = json_object_new_object();
  5712. DEBUG_INFO("sendGet15118EVCertificateRequest...\n");
  5713. json_object_object_add(Get15118EVCertificate, "iso15118SchemaVersion", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.iso15118SchemaVersion));
  5714. json_object_object_add(Get15118EVCertificate, "action", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.action));
  5715. json_object_object_add(Get15118EVCertificate, "exiRequest", json_object_new_string((char*)ShmOCPP20Data->Get15118EVCertificate.exiRequest));
  5716. random_uuid(guid);
  5717. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "Get15118EVCertificate", json_object_to_json_string_ext(Get15118EVCertificate, JSON_C_TO_STRING_PLAIN));
  5718. json_object_put(Get15118EVCertificate);
  5719. LWS_Send(message);
  5720. sprintf(tempdata, "Get15118EVCertificate,0");
  5721. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5722. {
  5723. result = PASS;
  5724. }
  5725. return result;
  5726. }
  5727. int sendGetCertificateStatusRequest()
  5728. {
  5729. mtrace();
  5730. int result = FAIL;
  5731. char message[4096]={0};
  5732. char guid[37]={0};
  5733. char tempdata[128]={0};
  5734. json_object *GetCertificateStatus = json_object_new_object();
  5735. json_object *ocspRequestData = json_object_new_object();
  5736. DEBUG_INFO("sendGetCertificateStatusRequest...\n");
  5737. json_object_object_add(ocspRequestData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.hashAlgorithm));
  5738. json_object_object_add(ocspRequestData, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.issuerNameHash));
  5739. json_object_object_add(ocspRequestData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.issuerKeyHash));
  5740. json_object_object_add(ocspRequestData, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.serialNumber));
  5741. json_object_object_add(ocspRequestData, "responderURL", json_object_new_string((char*)ShmOCPP20Data->GetCertificateStatus.ocspRequestData.responderURL));
  5742. json_object_object_add(GetCertificateStatus, "ocspRequestData", ocspRequestData);
  5743. random_uuid(guid);
  5744. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "GetCertificateStatus", json_object_to_json_string_ext(GetCertificateStatus, JSON_C_TO_STRING_PLAIN));
  5745. json_object_put(GetCertificateStatus);
  5746. LWS_Send(message);
  5747. sprintf(tempdata, "GetCertificateStatus,0");
  5748. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5749. {
  5750. result = PASS;
  5751. }
  5752. return result;
  5753. }
  5754. int sendHeartbeatRequest()
  5755. {
  5756. mtrace();
  5757. int result = FAIL;
  5758. char message[40096]={0};
  5759. char guid[37]={0};
  5760. char tempdata[128]={0};
  5761. DEBUG_INFO("sendHeartbeatRequest...\n");
  5762. random_uuid(guid);
  5763. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  5764. , MESSAGE_TYPE_CALL
  5765. , guid );
  5766. LWS_Send(message);
  5767. sprintf(tempdata, "Heartbeat,%d", 0);
  5768. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5769. {
  5770. result = PASS;
  5771. }
  5772. return result;
  5773. }
  5774. int sendLogStatusNotificationRequest(char *status)
  5775. {
  5776. mtrace();
  5777. int result = FAIL;
  5778. char message[4096]={0};
  5779. char guid[37]={0};
  5780. char tempdata[128]={0};
  5781. json_object *LogStatusNotification = json_object_new_object();
  5782. DEBUG_INFO("sendLogStatusNotificationRequest...\n");
  5783. ShmOCPP20Data->LogStatusNotification.requestId = ShmOCPP20Data->GetLog.requestId;
  5784. sprintf((char *)ShmOCPP20Data->LogStatusNotification.status,"%s",(const char *)status);
  5785. json_object_object_add(LogStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->LogStatusNotification.status));
  5786. json_object_object_add(LogStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->LogStatusNotification.requestId));
  5787. random_uuid(guid);
  5788. sprintf(message,"[%d,\"%s\",\"LogStatusNotification\",%s]",MESSAGE_TYPE_CALL, guid, json_object_to_json_string_ext(LogStatusNotification, JSON_C_TO_STRING_PLAIN));
  5789. json_object_put(LogStatusNotification);
  5790. LWS_SendNow(message);
  5791. sprintf(tempdata, "LogStatusNotification,%d", 0);
  5792. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  5793. {
  5794. result = PASS;
  5795. }
  5796. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  5797. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationConf = OFF;
  5798. //record status
  5799. if(strcmp(status,"BadMessage")==0)
  5800. {
  5801. LogStatusNotificationStatus = UploadLogStatusEnumType_BadMessage;
  5802. }
  5803. else if(strcmp(status,"Idle")==0)
  5804. {
  5805. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle;
  5806. }
  5807. else if(strcmp(status,"NotSupportedOperation")==0)
  5808. {
  5809. LogStatusNotificationStatus = UploadLogStatusEnumType_NotSupportedOperation;
  5810. }
  5811. else if(strcmp(status,"PermissionDenied")==0)
  5812. {
  5813. LogStatusNotificationStatus = UploadLogStatusEnumType_PermissionDenied;
  5814. }
  5815. else if(strcmp(status,"Uploaded")==0)
  5816. {
  5817. LogStatusNotificationStatus = UploadLogStatusEnumType_Uploaded;
  5818. }
  5819. else if(strcmp(status,"UploadFailure")==0)
  5820. {
  5821. LogStatusNotificationStatus = UploadLogStatusEnumType_UploadFailure;
  5822. }
  5823. else if(strcmp(status,"Uploading")==0)
  5824. {
  5825. LogStatusNotificationStatus = UploadLogStatusEnumType_Uploading;
  5826. }
  5827. return result;
  5828. }
  5829. int sendMeterValuesRequest(int gun_index, ReadingContextEnumType dataType)
  5830. {
  5831. mtrace();
  5832. int result = FAIL;
  5833. char guid[37]={0};
  5834. char tempdata[65]={0};
  5835. int tempIndex = 0;
  5836. json_object *MeterValueReq = json_object_new_object();
  5837. json_object *meterValues = json_object_new_array();
  5838. json_object *sampledValues = json_object_new_array();
  5839. DEBUG_INFO("sendMeterValuesRequest...\n");
  5840. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  5841. //set value
  5842. ShmOCPP20Data->MeterValues[gun_index].evseId = gun_index + 1; // gun start from 1~
  5843. //UTC Date time
  5844. struct timeval tmnow;
  5845. struct tm *tm;
  5846. char buf[28];//, usec_buf[6];
  5847. gettimeofday(&tmnow, NULL);
  5848. time_t t;
  5849. t = time(NULL);
  5850. /*UTC time and date*/
  5851. tm = gmtime(&t);
  5852. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  5853. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].timestamp, buf);
  5854. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  5855. //idx_sample=0;
  5856. //********************************(1)Current.Import L1************************************************/
  5857. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5858. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5859. {
  5860. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5861. {
  5862. tempIndex = ((gun_index==2) ? 1: 0);
  5863. }
  5864. else
  5865. {
  5866. tempIndex = gun_index;
  5867. }
  5868. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5869. {
  5870. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5871. {
  5872. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent;
  5873. }
  5874. }
  5875. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5876. }
  5877. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5878. {
  5879. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5880. {
  5881. tempIndex = ((gun_index==2) ? 1: 0);
  5882. }
  5883. else
  5884. {
  5885. tempIndex = gun_index;
  5886. }
  5887. for (int index = 0; index < CCS_QUANTITY; index++)
  5888. {
  5889. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5890. {
  5891. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent;
  5892. }
  5893. }
  5894. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5895. }
  5896. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5897. {
  5898. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5899. {
  5900. tempIndex = ((gun_index==2) ? 1: 0);
  5901. }
  5902. else
  5903. {
  5904. tempIndex = gun_index;
  5905. }
  5906. for (int index = 0; index < GB_QUANTITY; index++)
  5907. {
  5908. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  5909. {
  5910. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent;
  5911. }
  5912. }
  5913. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5914. }
  5915. else if(gunType[gun_index] == GUN_TYPE_DO)
  5916. {
  5917. tempIndex = gun_index;
  5918. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5919. {
  5920. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  5921. {
  5922. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent;
  5923. }
  5924. }
  5925. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5926. }
  5927. else
  5928. {
  5929. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5930. {
  5931. tempIndex = 2;
  5932. }
  5933. else
  5934. {
  5935. tempIndex = gun_index;
  5936. }
  5937. for (int index = 0; index < AC_QUANTITY; index++)
  5938. {
  5939. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  5940. {
  5941. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent;
  5942. }
  5943. }
  5944. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  5945. }
  5946. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].context, ReadingContextEnumTypeStr[dataType]);
  5947. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  5948. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  5949. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].unitOfMeasure.uint , "A");
  5950. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[0].unitOfMeasure.multiplier = 0;
  5951. //idx_sample=1;
  5952. //********************************(2)Energy.Active.Import.Register ************************************************/
  5953. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5954. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  5955. {
  5956. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5957. {
  5958. tempIndex = ((gun_index==2) ? 1: 0);
  5959. }
  5960. else
  5961. {
  5962. tempIndex = gun_index;
  5963. }
  5964. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5965. {
  5966. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  5967. {
  5968. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption;
  5969. }
  5970. }
  5971. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5972. }
  5973. else if(gunType[gun_index] == GUN_TYPE_CCS)
  5974. {
  5975. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5976. {
  5977. tempIndex = ((gun_index==2) ? 1: 0);
  5978. }
  5979. else
  5980. {
  5981. tempIndex = gun_index;
  5982. }
  5983. for (int index = 0; index < CCS_QUANTITY; index++)
  5984. {
  5985. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  5986. {
  5987. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption;
  5988. }
  5989. }
  5990. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  5991. }
  5992. else if(gunType[gun_index] == GUN_TYPE_GBT)
  5993. {
  5994. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  5995. {
  5996. tempIndex = ((gun_index==2) ? 1: 0);
  5997. }
  5998. else
  5999. {
  6000. tempIndex = gun_index;
  6001. }
  6002. for (int index = 0; index < GB_QUANTITY; index++)
  6003. {
  6004. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6005. {
  6006. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption;
  6007. }
  6008. }
  6009. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6010. }
  6011. else if(gunType[gun_index] == GUN_TYPE_DO)
  6012. {
  6013. tempIndex = gun_index;
  6014. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6015. {
  6016. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6017. {
  6018. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption;
  6019. }
  6020. }
  6021. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6022. }
  6023. else
  6024. {
  6025. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6026. {
  6027. tempIndex = 2;
  6028. }
  6029. else
  6030. {
  6031. tempIndex = gun_index;
  6032. }
  6033. for (int index = 0; index < AC_QUANTITY; index++)
  6034. {
  6035. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6036. {
  6037. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption;
  6038. }
  6039. }
  6040. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  6041. }
  6042. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].context, ReadingContextEnumTypeStr[dataType]);
  6043. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Register]);
  6044. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  6045. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[1].unitOfMeasure.uint , "kWh");
  6046. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.multiplier = 0;
  6047. //idx_sample=2;
  6048. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  6049. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6050. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6051. {
  6052. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6053. {
  6054. tempIndex = ((gun_index==2) ? 1: 0);
  6055. }
  6056. else
  6057. {
  6058. tempIndex = gun_index;
  6059. }
  6060. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6061. {
  6062. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6063. {
  6064. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy;
  6065. }
  6066. } // END OF FOR CHAdeMO_QUANTITY
  6067. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6068. }
  6069. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6070. {
  6071. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6072. {
  6073. tempIndex = ((gun_index==2) ? 1: 0);
  6074. }
  6075. else
  6076. {
  6077. tempIndex = gun_index;
  6078. }
  6079. for (int index = 0; index < CCS_QUANTITY; index++)
  6080. {
  6081. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6082. {
  6083. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy;
  6084. }
  6085. } // END OF CCS_QUANTITY
  6086. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6087. }
  6088. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6089. {
  6090. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6091. {
  6092. tempIndex = ((gun_index==2) ? 1: 0);
  6093. }
  6094. else
  6095. {
  6096. tempIndex = gun_index;
  6097. }
  6098. for (int index = 0; index < GB_QUANTITY; index++)
  6099. {
  6100. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6101. {
  6102. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy;
  6103. }
  6104. } // END OF GB_QUANTITY
  6105. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6106. }
  6107. else if(gunType[gun_index] == GUN_TYPE_DO)
  6108. {
  6109. tempIndex = gun_index;
  6110. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6111. {
  6112. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6113. {
  6114. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy;
  6115. }
  6116. }
  6117. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6118. }
  6119. else
  6120. {
  6121. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6122. {
  6123. tempIndex = 2;
  6124. }
  6125. else
  6126. {
  6127. tempIndex = gun_index;
  6128. }
  6129. for (int index = 0; index < AC_QUANTITY; index++)
  6130. {
  6131. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6132. {
  6133. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy;
  6134. }
  6135. }
  6136. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  6137. }
  6138. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].context, ReadingContextEnumTypeStr[dataType]);
  6139. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Energy_Active_Import_Interval]);
  6140. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  6141. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.uint , "kWh");
  6142. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[2].unitOfMeasure.multiplier = 0;
  6143. //idx_sample=3;
  6144. //********************************(4)Power.Active.Import************************************************/
  6145. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6146. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6147. {
  6148. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6149. {
  6150. tempIndex = ((gun_index==2) ? 1: 0);
  6151. }
  6152. else
  6153. {
  6154. tempIndex = gun_index;
  6155. }
  6156. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6157. {
  6158. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6159. {
  6160. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower;
  6161. }
  6162. } // END OF FOR
  6163. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6164. }
  6165. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6166. {
  6167. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6168. {
  6169. tempIndex = ((gun_index==2) ? 1: 0);
  6170. }
  6171. else
  6172. {
  6173. tempIndex = gun_index;
  6174. }
  6175. for (int index = 0; index < CCS_QUANTITY; index++)
  6176. {
  6177. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6178. {
  6179. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower;
  6180. }
  6181. }
  6182. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6183. }
  6184. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6185. {
  6186. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6187. {
  6188. tempIndex = ((gun_index==2) ? 1: 0);
  6189. }
  6190. else
  6191. {
  6192. tempIndex = gun_index;
  6193. }
  6194. for (int index = 0; index < GB_QUANTITY; index++)
  6195. {
  6196. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6197. {
  6198. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6199. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower;
  6200. }
  6201. }
  6202. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6203. }
  6204. else if(gunType[gun_index] == GUN_TYPE_DO)
  6205. {
  6206. tempIndex = gun_index;
  6207. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6208. {
  6209. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6210. {
  6211. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  6212. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower;
  6213. }
  6214. }
  6215. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6216. }
  6217. else
  6218. {
  6219. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6220. {
  6221. tempIndex = 2;
  6222. }
  6223. else
  6224. {
  6225. tempIndex = gun_index;
  6226. }
  6227. for (int index = 0; index < AC_QUANTITY; index++)
  6228. {
  6229. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6230. {
  6231. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower;
  6232. }
  6233. }
  6234. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  6235. }
  6236. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].context, ReadingContextEnumTypeStr[dataType]);
  6237. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Power_Active_Import]);
  6238. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  6239. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].unitOfMeasure.uint , "kW");
  6240. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[3].unitOfMeasure.multiplier = 0;
  6241. //idx_sample=4;
  6242. //***********************************************(5)VOLTAGE L1******************************************************/
  6243. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  6244. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6245. {
  6246. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6247. {
  6248. tempIndex = ((gun_index==2) ? 1: 0);
  6249. }
  6250. else
  6251. {
  6252. tempIndex = gun_index;
  6253. }
  6254. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6255. {
  6256. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6257. {
  6258. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage;
  6259. }
  6260. }
  6261. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6262. }
  6263. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6264. {
  6265. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6266. {
  6267. tempIndex = ((gun_index==2) ? 1: 0);
  6268. }
  6269. else
  6270. {
  6271. tempIndex = gun_index;
  6272. }
  6273. for (int index = 0; index < CCS_QUANTITY; index++)
  6274. {
  6275. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6276. {
  6277. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage;
  6278. }
  6279. }
  6280. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6281. }
  6282. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6283. {
  6284. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6285. {
  6286. tempIndex = ((gun_index==2) ? 1: 0);
  6287. }
  6288. else
  6289. {
  6290. tempIndex = gun_index;
  6291. }
  6292. for (int index = 0; index < GB_QUANTITY; index++)
  6293. {
  6294. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6295. {
  6296. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage;
  6297. }
  6298. }
  6299. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6300. }
  6301. else if(gunType[gun_index] == GUN_TYPE_DO)
  6302. {
  6303. tempIndex = gun_index;
  6304. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6305. {
  6306. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6307. {
  6308. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage;
  6309. }
  6310. }
  6311. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6312. }
  6313. else
  6314. {
  6315. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6316. {
  6317. tempIndex = 2;
  6318. }
  6319. else
  6320. {
  6321. tempIndex = gun_index;
  6322. }
  6323. for (int index = 0; index < AC_QUANTITY; index++)
  6324. {
  6325. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6326. {
  6327. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage;
  6328. }
  6329. }
  6330. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].phase, PhaseEnumTypeStr[PhaseEnumType_L1_N]);
  6331. }
  6332. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].context, ReadingContextEnumTypeStr[dataType]);
  6333. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  6334. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  6335. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].unitOfMeasure.uint , "V");
  6336. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[4].unitOfMeasure.multiplier = 0;
  6337. //***********************************************(6)SOC******************************************************/
  6338. 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))
  6339. {
  6340. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != GUN_TYPE_DO))
  6341. {
  6342. tempIndex = ((gun_index==2) ? 1: 0);
  6343. }
  6344. else
  6345. {
  6346. tempIndex = gun_index;
  6347. }
  6348. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  6349. {
  6350. //tempIndex = ((gun_index==2) ? 1: 0);
  6351. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6352. {
  6353. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  6354. {
  6355. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc;
  6356. }
  6357. }
  6358. }
  6359. else if(gunType[gun_index] == GUN_TYPE_CCS)
  6360. {
  6361. //tempIndex = ((gun_index==2) ? 1: 0);
  6362. for (int index = 0; index < CCS_QUANTITY; index++)
  6363. {
  6364. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6365. {
  6366. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc;
  6367. }
  6368. }
  6369. }
  6370. else if(gunType[gun_index] == GUN_TYPE_GBT)
  6371. {
  6372. //tempIndex = ((gun_index==2) ? 1: 0);
  6373. for (int index = 0; index < GB_QUANTITY; index++)
  6374. {
  6375. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  6376. {
  6377. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc;
  6378. }
  6379. }
  6380. }
  6381. else if(gunType[gun_index] == GUN_TYPE_DO)
  6382. {
  6383. //tempIndex = ((gun_index==2) ? 1: 0);
  6384. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  6385. {
  6386. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  6387. {
  6388. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].value = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc;
  6389. }
  6390. }
  6391. }
  6392. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].context, ReadingContextEnumTypeStr[dataType]);
  6393. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].measurand, MeasurandEnumTypeStr[MeasurandEnumType_SoC]);
  6394. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6395. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].location, LocationEnumTypeStr[LocationEnumType_EV]);
  6396. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].unitOfMeasure.uint , "Percent");
  6397. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[5].unitOfMeasure.multiplier = 0;
  6398. }
  6399. //********************************(7)Current.Import L2************************************************/
  6400. // Only for AC 3 phase
  6401. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  6402. {
  6403. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6404. {
  6405. tempIndex = 2;
  6406. }
  6407. else
  6408. {
  6409. tempIndex = gun_index;
  6410. }
  6411. for (int index = 0; index < AC_QUANTITY; index++)
  6412. {
  6413. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6414. {
  6415. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2;
  6416. }
  6417. }
  6418. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].phase, PhaseEnumTypeStr[PhaseEnumType_L2_N]);
  6419. }
  6420. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].context, ReadingContextEnumTypeStr[dataType]);
  6421. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  6422. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  6423. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].unitOfMeasure.uint , "A");
  6424. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[6].unitOfMeasure.multiplier = 0;
  6425. //********************************(8)Current.Import L3************************************************/
  6426. // Only for AC 3 phase
  6427. if( (gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  6428. {
  6429. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6430. {
  6431. tempIndex = 2;
  6432. }
  6433. else
  6434. {
  6435. tempIndex = gun_index;
  6436. }
  6437. for (int index = 0; index < AC_QUANTITY; index++)
  6438. {
  6439. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6440. {
  6441. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3;
  6442. }
  6443. }
  6444. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6445. }
  6446. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].context, ReadingContextEnumTypeStr[dataType]);
  6447. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Current_Import]);
  6448. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  6449. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].unitOfMeasure.uint , "A");
  6450. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[7].unitOfMeasure.multiplier = 0;
  6451. //***********************************************(9)VOLTAGE L2******************************************************/
  6452. if( (gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  6453. {
  6454. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6455. {
  6456. tempIndex = 2;
  6457. }
  6458. else
  6459. {
  6460. tempIndex = gun_index;
  6461. }
  6462. for (int index = 0; index < AC_QUANTITY; index++)
  6463. {
  6464. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6465. {
  6466. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2;
  6467. }
  6468. }
  6469. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].phase, PhaseEnumTypeStr[PhaseEnumType_L2_N]);
  6470. }
  6471. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].context, ReadingContextEnumTypeStr[dataType]);
  6472. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  6473. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  6474. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].unitOfMeasure.uint , "V");
  6475. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[8].unitOfMeasure.multiplier = 0;
  6476. //***********************************************(10)VOLTAGE L3******************************************************/
  6477. if((gunType[gun_index] == GUN_TYPE_AC) && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'D')))
  6478. {
  6479. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  6480. {
  6481. tempIndex = 2;
  6482. }
  6483. else
  6484. {
  6485. tempIndex = gun_index;
  6486. }
  6487. for (int index = 0; index < AC_QUANTITY; index++)
  6488. {
  6489. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  6490. {
  6491. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].value = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3;
  6492. }
  6493. }
  6494. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].phase, PhaseEnumTypeStr[PhaseEnumType_L3_N]);
  6495. }
  6496. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].context, ReadingContextEnumTypeStr[dataType]);
  6497. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].measurand, MeasurandEnumTypeStr[MeasurandEnumType_Voltage]);
  6498. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].location, LocationEnumTypeStr[LocationEnumType_Outlet]);
  6499. strcpy((char *)ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].unitOfMeasure.uint , "V");
  6500. ShmOCPP20Data->MeterValues[gun_index].meterValue[0].sampledValue[9].unitOfMeasure.multiplier = 0;
  6501. // Message create ====================================================================================================
  6502. random_uuid(guid);
  6503. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->MeterValues[gun_index].meterValue);idxMeter++)
  6504. {
  6505. json_object *meterValue = json_object_new_object();
  6506. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  6507. {
  6508. if(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].value > 0)
  6509. {
  6510. json_object *sampledValue = json_object_new_object();
  6511. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  6512. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  6513. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  6514. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  6515. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  6516. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  6517. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  6518. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  6519. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  6520. if(strlen((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  6521. {
  6522. json_object *unitOfMeasure = json_object_new_object();
  6523. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  6524. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  6525. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  6526. }
  6527. json_object_array_add(sampledValues, sampledValue);
  6528. }
  6529. }
  6530. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->MeterValues[gun_index].meterValue[idxMeter].timestamp));
  6531. json_object_object_add(meterValue, "sampledValue", sampledValues);
  6532. json_object_array_add(meterValues, meterValue);
  6533. idxMeter++;
  6534. }
  6535. json_object_object_add(MeterValueReq, "meterValue", meterValues);
  6536. json_object_object_add(MeterValueReq, "evseId", json_object_new_int(ShmOCPP20Data->MeterValues[gun_index].evseId));
  6537. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  6538. ,gun_index + 1
  6539. ,MESSAGE_TYPE_CALL
  6540. ,guid
  6541. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  6542. json_object_put(MeterValueReq);
  6543. if((strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]) == 0) ||
  6544. (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]) == 0) ||
  6545. (strcmp((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]) == 0))
  6546. {
  6547. // Transaction meter value send by TransactionEvent message
  6548. memcpy(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0], &ShmOCPP20Data->MeterValues[gun_index].meterValue[0], sizeof(struct MeterValueType));
  6549. cpinitateMsg.bits[gun_index].TransactionEventReq = ON;
  6550. result = PASS;
  6551. }
  6552. else
  6553. {
  6554. // Put request guid to hash map
  6555. sprintf(tempdata, "MeterValues,%d", (gun_index));
  6556. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6557. {
  6558. result = PASS;
  6559. }
  6560. if((dataType != ReadingContextEnumType_Trigger) &&
  6561. (dataType != ReadingContextEnumType_Sample_Clock))
  6562. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  6563. else
  6564. {
  6565. if(FirstHeartBeat)
  6566. LWS_Send(queuedata +2);
  6567. }
  6568. }
  6569. return result;
  6570. }
  6571. int sendNotifyChargingLimitRequest(int gun_index)
  6572. {
  6573. mtrace();
  6574. int result = FAIL;
  6575. char message[4096]={0};
  6576. char guid[37]={0};
  6577. char tempdata[128]={0};
  6578. json_object *NotifyChargingLimit = json_object_new_object();
  6579. json_object *chargingLimit = json_object_new_object();
  6580. DEBUG_INFO("sendNotifyChargingLimitRequest...\n");
  6581. json_object_object_add(NotifyChargingLimit, "evseId", json_object_new_int(ShmOCPP20Data->NotifyChargingLimit[gun_index].evseId));
  6582. json_object_object_add(chargingLimit, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->NotifyChargingLimit[gun_index].chargingLimit.chargingLimitSource));
  6583. json_object_object_add(chargingLimit, "chargingLimitSource", json_object_new_boolean(ShmOCPP20Data->NotifyChargingLimit[gun_index].chargingLimit.isGridCritical));
  6584. json_object_object_add(NotifyChargingLimit, "chargingLimit", NotifyChargingLimit);
  6585. random_uuid(guid);
  6586. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyChargingLimit", json_object_to_json_string_ext(NotifyChargingLimit, JSON_C_TO_STRING_PLAIN));
  6587. json_object_put(NotifyChargingLimit);
  6588. LWS_Send(message);
  6589. sprintf(tempdata, "NotifyChargingLimit,%d", gun_index);
  6590. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6591. {
  6592. result = PASS;
  6593. }
  6594. return result;
  6595. }
  6596. int sendNotifyCustomerInformationRequest()
  6597. {
  6598. mtrace();
  6599. int result = FAIL;
  6600. char message[4096]={0};
  6601. char guid[37]={0};
  6602. char tempdata[128]={0};
  6603. json_object *NotifyCustomerInformation = json_object_new_object();
  6604. DEBUG_INFO("sendNotifyCustomerInformationRequest...\n");
  6605. json_object_object_add(NotifyCustomerInformation, "data", json_object_new_string((char*)ShmOCPP20Data->NotifyCustomerInformation.data));
  6606. json_object_object_add(NotifyCustomerInformation, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyCustomerInformation.tbc));
  6607. json_object_object_add(NotifyCustomerInformation, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyCustomerInformation.seqNo));
  6608. json_object_object_add(NotifyCustomerInformation, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyCustomerInformation.generatedAt));
  6609. json_object_object_add(NotifyCustomerInformation, "requestId", json_object_new_int(ShmOCPP20Data->NotifyCustomerInformation.requestId));
  6610. random_uuid(guid);
  6611. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyCustomerInformation", json_object_to_json_string_ext(NotifyCustomerInformation, JSON_C_TO_STRING_PLAIN));
  6612. json_object_put(NotifyCustomerInformation);
  6613. LWS_Send(message);
  6614. sprintf(tempdata, "NotifyCustomerInformation,0");
  6615. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6616. {
  6617. result = PASS;
  6618. }
  6619. return result;
  6620. }
  6621. int sendNotifyDisplayMessagesRequest()
  6622. {
  6623. mtrace();
  6624. int result = FAIL;
  6625. char message[4096]={0};
  6626. char guid[37]={0};
  6627. char tempdata[128]={0};
  6628. json_object *NotifyDisplayMessages = json_object_new_object();
  6629. json_object *messageInfos = json_object_new_array();
  6630. DEBUG_INFO("sendNotifyDisplayMessagesRequest...\n");
  6631. json_object_object_add(NotifyDisplayMessages, "requestId", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.requestId));
  6632. json_object_object_add(NotifyDisplayMessages, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyDisplayMessages.tbc));
  6633. for(int idxMsg=0;idxMsg<ARRAY_SIZE(ShmOCPP20Data->NotifyDisplayMessages.messageInfo);idxMsg++)
  6634. {
  6635. if(strlen((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.content) > 0)
  6636. {
  6637. json_object *messageInfo = json_object_new_object();
  6638. json_object *message = json_object_new_object();
  6639. json_object *display = json_object_new_object();
  6640. json_object *evse = json_object_new_object();
  6641. json_object_object_add(messageInfo, "id", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].id));
  6642. json_object_object_add(messageInfo, "priority", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].priority));
  6643. json_object_object_add(messageInfo, "state", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].state));
  6644. json_object_object_add(messageInfo, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].startDateTime));
  6645. json_object_object_add(messageInfo, "endDateTime", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].endDateTime));
  6646. json_object_object_add(messageInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].transactionId));
  6647. json_object_object_add(message, "format", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.format));
  6648. json_object_object_add(message, "language", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.language));
  6649. json_object_object_add(message, "content", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].message.content));
  6650. json_object_object_add(messageInfo, "message", message);
  6651. json_object_object_add(display, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.name));
  6652. json_object_object_add(display, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.instance));
  6653. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.evse.id));
  6654. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyDisplayMessages.messageInfo[idxMsg].display.evse.connectorId));
  6655. json_object_object_add(display, "evse",evse);
  6656. json_object_object_add(messageInfo, "evse", display);
  6657. json_object_array_add(messageInfos, messageInfo);
  6658. }
  6659. }
  6660. json_object_object_add(NotifyDisplayMessages, "messageInfo", messageInfos);
  6661. random_uuid(guid);
  6662. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyDisplayMessages", json_object_to_json_string_ext(NotifyDisplayMessages, JSON_C_TO_STRING_PLAIN));
  6663. json_object_put(NotifyDisplayMessages);
  6664. LWS_Send(message);
  6665. sprintf(tempdata, "NotifyDisplayMessages,0");
  6666. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6667. {
  6668. result = PASS;
  6669. }
  6670. return result;
  6671. }
  6672. int sendNotifyEVChargingNeedsRequest(int gun_index)
  6673. {
  6674. mtrace();
  6675. int result = FAIL;
  6676. char message[4096]={0};
  6677. char guid[37]={0};
  6678. char tempdata[128]={0};
  6679. json_object *NotifyEVChargingNeeds = json_object_new_object();
  6680. json_object *chargingNeeds = json_object_new_object();
  6681. json_object *acChargingParameters = json_object_new_object();
  6682. json_object *dcChargingParameters = json_object_new_object();
  6683. DEBUG_INFO("sendNotifyEVChargingNeedsRequest...\n");
  6684. json_object_object_add(NotifyEVChargingNeeds, "maxScheduleTuples", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].maxScheduleTuples));
  6685. json_object_object_add(NotifyEVChargingNeeds, "evseId", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].evseId));
  6686. json_object_object_add(chargingNeeds, "requestedEnergyTransfer", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.requestedEnergyTransfer));
  6687. json_object_object_add(chargingNeeds, "departureTime", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.departureTime));
  6688. json_object_object_add(acChargingParameters, "energyAmount", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.energyAmount));
  6689. json_object_object_add(acChargingParameters, "evMinCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMinCurrent));
  6690. json_object_object_add(acChargingParameters, "evMaxCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMaxCurrent));
  6691. json_object_object_add(acChargingParameters, "evMaxVoltage", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.acChargingParameters.evMaxVoltage));
  6692. json_object_object_add(chargingNeeds, "acChargingParameters", acChargingParameters);
  6693. json_object_object_add(dcChargingParameters, "evMaxCurrent", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxCurrent));
  6694. json_object_object_add(dcChargingParameters, "evMaxVoltage", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxVoltage));
  6695. json_object_object_add(dcChargingParameters, "energyAmount", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.energyAmount));
  6696. json_object_object_add(dcChargingParameters, "evMaxPower", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evMaxPower));
  6697. json_object_object_add(dcChargingParameters, "stateOfCharge", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.stateOfCharge));
  6698. json_object_object_add(dcChargingParameters, "evEnergyCapacity", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.evEnergyCapacity));
  6699. json_object_object_add(dcChargingParameters, "fullSoC", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.fullSoC));
  6700. json_object_object_add(dcChargingParameters, "bulkSoC", json_object_new_int(ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].chargingNeeds.dcChargingParameters.bulkSoC));
  6701. json_object_object_add(chargingNeeds, "dcChargingParameters", dcChargingParameters);
  6702. json_object_object_add(NotifyEVChargingNeeds, "chargingNeeds", chargingNeeds);
  6703. random_uuid(guid);
  6704. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEVChargingNeeds", json_object_to_json_string_ext(NotifyEVChargingNeeds, JSON_C_TO_STRING_PLAIN));
  6705. json_object_put(NotifyEVChargingNeeds);
  6706. LWS_Send(message);
  6707. sprintf(tempdata, "NotifyEVChargingNeeds,%d", gun_index);
  6708. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6709. {
  6710. result = PASS;
  6711. }
  6712. return result;
  6713. }
  6714. int sendNotifyEVChargingScheduleRequest(int gun_index)
  6715. {
  6716. mtrace();
  6717. int result = FAIL;
  6718. char message[4096]={0};
  6719. char guid[37]={0};
  6720. char tempdata[128]={0};
  6721. json_object *NotifyEVChargingSchedule = json_object_new_object();
  6722. json_object *chargingSchedule = json_object_new_object();
  6723. json_object *periods = json_object_new_array();
  6724. DEBUG_INFO("sendNotifyEVChargingScheduleRequest...\n");
  6725. json_object_object_add(NotifyEVChargingSchedule, "timeBase", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].timeBase));
  6726. json_object_object_add(NotifyEVChargingSchedule, "evseId", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].evseId));
  6727. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.startSchedule));
  6728. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.duration));
  6729. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingRateUnit));
  6730. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.minChargingRate));
  6731. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.id));
  6732. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  6733. {
  6734. if(((ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  6735. (ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  6736. {
  6737. json_object *Period = json_object_new_object();
  6738. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  6739. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  6740. if(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  6741. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  6742. if(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  6743. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  6744. json_object_array_add(periods, Period);
  6745. }
  6746. }
  6747. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", periods);
  6748. json_object_object_add(NotifyEVChargingSchedule, "chargingSchedule", chargingSchedule);
  6749. random_uuid(guid);
  6750. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEVChargingSchedule", json_object_to_json_string_ext(NotifyEVChargingSchedule, JSON_C_TO_STRING_PLAIN));
  6751. json_object_put(NotifyEVChargingSchedule);
  6752. LWS_Send(message);
  6753. sprintf(tempdata, "NotifyEVChargingSchedule,%d", gun_index);
  6754. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6755. {
  6756. result = PASS;
  6757. }
  6758. return result;
  6759. }
  6760. int sendNotifyEventRequest()
  6761. {
  6762. mtrace();
  6763. int result = FAIL;
  6764. char message[4096]={0};
  6765. char guid[37]={0};
  6766. char tempdata[128]={0};
  6767. json_object *NotifyEvent = json_object_new_object();
  6768. json_object *eventDatas = json_object_new_array();
  6769. DEBUG_INFO("sendNotifyEventRequest...\n");
  6770. json_object_object_add(NotifyEvent, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.generatedAt));
  6771. json_object_object_add(NotifyEvent, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyEvent.tbc));
  6772. json_object_object_add(NotifyEvent, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyEvent.seqNo));
  6773. for(int idxEvent=0;idxEvent<ARRAY_SIZE(ShmOCPP20Data->NotifyEvent.eventData);idxEvent++)
  6774. {
  6775. if(strlen((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp) > 0)
  6776. {
  6777. json_object *eventData = json_object_new_object();
  6778. json_object *component = json_object_new_object();
  6779. json_object *evse = json_object_new_object();
  6780. json_object *variable = json_object_new_object();
  6781. json_object_object_add(eventData, "eventId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventId));
  6782. json_object_object_add(eventData, "timestamp", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].timestamp));
  6783. json_object_object_add(eventData, "trigger", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].trigger));
  6784. json_object_object_add(eventData, "cause", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cause));
  6785. json_object_object_add(eventData, "actualValue", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].actualValue));
  6786. json_object_object_add(eventData, "techCode", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techcode));
  6787. json_object_object_add(eventData, "techInfo", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].techInfo));
  6788. json_object_object_add(eventData, "cleared", json_object_new_boolean(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].cleared));
  6789. json_object_object_add(eventData, "transactionId", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].transactionId));
  6790. json_object_object_add(eventData, "variableMonitoringId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variableMonitoringId));
  6791. json_object_object_add(eventData, "eventNotificationType", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].eventNotificationType));
  6792. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.name));
  6793. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.instance));
  6794. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.id));
  6795. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyEvent.eventData[idxEvent].component.evse.connectorId));
  6796. json_object_object_add(component, "evse",evse);
  6797. json_object_object_add(eventData, "component", component);
  6798. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.name));
  6799. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyEvent.eventData[idxEvent].variable.instance));
  6800. json_object_object_add(eventData, "variable", variable);
  6801. json_object_array_add(eventDatas, eventData);
  6802. }
  6803. }
  6804. json_object_object_add(NotifyEvent, "eventData", eventDatas);
  6805. random_uuid(guid);
  6806. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyEvent", json_object_to_json_string_ext(NotifyEvent, JSON_C_TO_STRING_PLAIN));
  6807. json_object_put(NotifyEvent);
  6808. LWS_Send(message);
  6809. sprintf(tempdata, "NotifyEvent,0");
  6810. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6811. {
  6812. result = PASS;
  6813. }
  6814. return result;
  6815. }
  6816. int sendNotifyMonitoringReportRequest()
  6817. {
  6818. mtrace();
  6819. int result = FAIL;
  6820. char message[4096]={0};
  6821. char guid[37]={0};
  6822. char tempdata[128]={0};
  6823. json_object *NotifyMonitoringReport = json_object_new_object();
  6824. json_object *monitors = json_object_new_array();
  6825. DEBUG_INFO("sendNotifyMonitoringReportRequest...\n");
  6826. json_object_object_add(NotifyMonitoringReport, "requestId", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.requestId));
  6827. json_object_object_add(NotifyMonitoringReport, "tbc", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.tbc));
  6828. json_object_object_add(NotifyMonitoringReport, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.seqNo));
  6829. json_object_object_add(NotifyMonitoringReport, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.generatedAt));
  6830. for(int idxMonitor=0;idxMonitor<ARRAY_SIZE(ShmOCPP20Data->NotifyMonitoringReport.monitor);idxMonitor++)
  6831. {
  6832. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.name) > 0)
  6833. {
  6834. json_object *monitor = json_object_new_object();
  6835. json_object *component = json_object_new_object();
  6836. json_object *evse = json_object_new_object();
  6837. json_object *variable = json_object_new_object();
  6838. json_object *variableMonitorings = json_object_new_array();
  6839. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.name));
  6840. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.instance));
  6841. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.evse.id));
  6842. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].component.evse.connectorId));
  6843. json_object_object_add(component, "evse",evse);
  6844. json_object_object_add(monitor, "component", component);
  6845. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variable.name));
  6846. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variable.instance));
  6847. json_object_object_add(monitor, "variable", variable);
  6848. for(int idxVar=0;idxVar<ARRAY_SIZE(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring);idxVar++)
  6849. {
  6850. if(strlen((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].type) > 0)
  6851. {
  6852. json_object *variableMonitoring = json_object_new_object();
  6853. json_object_object_add(variableMonitoring, "id", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].id));
  6854. json_object_object_add(variableMonitoring, "value", json_object_new_double(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].value));
  6855. json_object_object_add(variableMonitoring, "type", json_object_new_string((char*)ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].type));
  6856. json_object_object_add(variableMonitoring, "severity", json_object_new_int(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].severity));
  6857. json_object_object_add(variableMonitoring, "transaction", json_object_new_boolean(ShmOCPP20Data->NotifyMonitoringReport.monitor[idxMonitor].variableMonitoring[idxVar].transaction));
  6858. json_object_array_add(variableMonitorings, variableMonitoring);
  6859. }
  6860. }
  6861. json_object_object_add(monitor, "variableMonitoring", variableMonitorings);
  6862. json_object_array_add(monitors, monitor);
  6863. }
  6864. }
  6865. json_object_object_add(NotifyMonitoringReport, "monitor", monitors);
  6866. random_uuid(guid);
  6867. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyMonitoringReport", json_object_to_json_string_ext(NotifyMonitoringReport, JSON_C_TO_STRING_PLAIN));
  6868. json_object_put(NotifyMonitoringReport);
  6869. LWS_Send(message);
  6870. sprintf(tempdata, "NotifyMonitoringReport,0");
  6871. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6872. {
  6873. result = PASS;
  6874. }
  6875. return result;
  6876. }
  6877. int sendNotifyReportRequest()
  6878. {
  6879. mtrace();
  6880. int result = FAIL;
  6881. char message[4096]={0};
  6882. char guid[37]={0};
  6883. char tempdata[128]={0};
  6884. json_object *NotifyReport = json_object_new_object();
  6885. json_object *reportDatas = json_object_new_array();
  6886. DEBUG_INFO("sendNotifyReportRequest...\n");
  6887. json_object_object_add(NotifyReport, "requestId", json_object_new_int(ShmOCPP20Data->NotifyReport.requestId));
  6888. json_object_object_add(NotifyReport, "generatedAt", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.generatedAt));
  6889. json_object_object_add(NotifyReport, "tbc", json_object_new_boolean(ShmOCPP20Data->NotifyReport.tbc));
  6890. json_object_object_add(NotifyReport, "seqNo", json_object_new_int(ShmOCPP20Data->NotifyReport.seqNo));
  6891. for(int idxReport=0;idxReport<ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData);idxReport++)
  6892. {
  6893. if(strlen((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.name) > 0)
  6894. {
  6895. json_object *reportData = json_object_new_object();
  6896. json_object *component = json_object_new_object();
  6897. json_object *evse = json_object_new_object();
  6898. json_object *variable = json_object_new_object();
  6899. json_object *variableAttributes = json_object_new_array();
  6900. json_object *variableCharacteristics = json_object_new_object();
  6901. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.name));
  6902. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].component.instance));
  6903. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->NotifyReport.reportData[idxReport].component.evse.id));
  6904. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->NotifyReport.reportData[idxReport].component.evse.connectorId));
  6905. json_object_object_add(component, "evse",evse);
  6906. json_object_object_add(reportData, "component", component);
  6907. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variable.name));
  6908. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variable.instance));
  6909. json_object_object_add(reportData, "variable",variable);
  6910. json_object_object_add(variableCharacteristics, "unit", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.unit));
  6911. json_object_object_add(variableCharacteristics, "dataType", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.dataType));
  6912. json_object_object_add(variableCharacteristics, "minLimit", json_object_new_double(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.minLimit));
  6913. json_object_object_add(variableCharacteristics, "maxLimit", json_object_new_double(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableCharacteristics.maxLimit));
  6914. json_object_object_add(reportData, "variableCharacteristics",variableCharacteristics);
  6915. for(int idxAttr=0;idxAttr<ARRAY_SIZE(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute);idxAttr++)
  6916. {
  6917. if(strlen((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].value) > 0)
  6918. {
  6919. json_object *variableAttribute = json_object_new_object();
  6920. json_object_object_add(variableAttribute, "type", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].type));
  6921. json_object_object_add(variableAttribute, "value", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].value));
  6922. json_object_object_add(variableAttribute, "mutability", json_object_new_string((char*)ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].mutability));
  6923. json_object_object_add(variableAttribute, "persistent", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].persistent));
  6924. json_object_object_add(variableAttribute, "constant", json_object_new_boolean(ShmOCPP20Data->NotifyReport.reportData[idxReport].variableAttribute[idxAttr].constant));
  6925. json_object_array_add(variableAttributes, variableAttribute);
  6926. }
  6927. }
  6928. json_object_object_add(reportData, "variableAttribute", variableAttributes);
  6929. json_object_array_add(reportDatas, reportData);
  6930. }
  6931. }
  6932. json_object_object_add(NotifyReport, "reportData", reportDatas);
  6933. random_uuid(guid);
  6934. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "NotifyReport", json_object_to_json_string_ext(NotifyReport, JSON_C_TO_STRING_PLAIN));
  6935. json_object_put(NotifyReport);
  6936. LWS_SendNow(message);
  6937. sprintf(tempdata, "NotifyReport,0");
  6938. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6939. {
  6940. result = PASS;
  6941. }
  6942. return result;
  6943. }
  6944. int sendPublishFirmwareStatusNotificationRequest()
  6945. {
  6946. mtrace();
  6947. int result = FAIL;
  6948. char message[4096]={0};
  6949. char guid[37]={0};
  6950. char tempdata[128]={0};
  6951. json_object *PublishFirmwareStatusNotification = json_object_new_object();
  6952. json_object *locations = json_object_new_array();
  6953. DEBUG_INFO("sendPublishFirmwareStatusNotificationRequest...\n");
  6954. json_object_object_add(PublishFirmwareStatusNotification, "status", json_object_new_string((char*)ShmOCPP20Data->PublishFirmwareStatusNotificatio.status));
  6955. json_object_object_add(PublishFirmwareStatusNotification, "requestId", json_object_new_int(ShmOCPP20Data->PublishFirmwareStatusNotificatio.requestId));
  6956. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->PublishFirmwareStatusNotificatio.location);idx++)
  6957. {
  6958. json_object_array_add(locations, json_object_new_string((char*)ShmOCPP20Data->PublishFirmwareStatusNotificatio.location[idx]));
  6959. }
  6960. json_object_object_add(PublishFirmwareStatusNotification, "location", locations);
  6961. random_uuid(guid);
  6962. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "PublishFirmwareStatusNotification", json_object_to_json_string_ext(PublishFirmwareStatusNotification, JSON_C_TO_STRING_PLAIN));
  6963. json_object_put(PublishFirmwareStatusNotification);
  6964. LWS_Send(message);
  6965. sprintf(tempdata, "PublishFirmwareStatusNotification,0");
  6966. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  6967. {
  6968. result = PASS;
  6969. }
  6970. return result;
  6971. }
  6972. int sendReportChargingProfilesRequest(int gun_index)
  6973. {
  6974. mtrace();
  6975. int result = FAIL;
  6976. char message[4096]={0};
  6977. char guid[37]={0};
  6978. char tempdata[128]={0};
  6979. json_object *ReportChargingProfiles = json_object_new_object();
  6980. json_object *chargingProfiles = json_object_new_array();
  6981. DEBUG_INFO("sendReportChargingProfilesRequest...\n");
  6982. json_object_object_add(ReportChargingProfiles, "requestId", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].requestId));
  6983. json_object_object_add(ReportChargingProfiles, "chargingLimitSource", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingLimitSource));
  6984. json_object_object_add(ReportChargingProfiles, "tbc", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].tbc));
  6985. json_object_object_add(ReportChargingProfiles, "evseId", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].evseId));
  6986. for(int idxProfile=0;idxProfile<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile);idxProfile++)
  6987. {
  6988. json_object *chargingProfile = json_object_new_object();
  6989. json_object *chargingSchedules = json_object_new_array();
  6990. json_object_object_add(chargingProfile, "id", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].id));
  6991. json_object_object_add(chargingProfile, "stackLevel", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].stackLevel));
  6992. json_object_object_add(chargingProfile, "chargingProfilePurpose", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingProfilePurpose));
  6993. json_object_object_add(chargingProfile, "chargingProfileKind", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingProfileKind));
  6994. json_object_object_add(chargingProfile, "recurrencyKind", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].recurrencyKind));
  6995. json_object_object_add(chargingProfile, "validFrom", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].validFrom));
  6996. json_object_object_add(chargingProfile, "validTo", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].validTo));
  6997. json_object_object_add(chargingProfile, "transactionId", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].transactionId));
  6998. for(int idxSchedule=0;idxSchedule<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule);idxSchedule++)
  6999. {
  7000. json_object *chargingSchedule = json_object_new_object();
  7001. json_object *chargingSchedulePeriods = json_object_new_array();
  7002. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].startSchedule));
  7003. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].duration));
  7004. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingRateUnit));
  7005. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].minChargingRate));
  7006. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].id));
  7007. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod);idxPeriod++)
  7008. {
  7009. json_object *chargingSchedulePeriod = json_object_new_object();
  7010. json_object_object_add(chargingSchedulePeriod, "startPeriod", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].startPeriod));
  7011. json_object_object_add(chargingSchedulePeriod, "limit", json_object_new_double(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].limit));
  7012. json_object_object_add(chargingSchedulePeriod, "numberPhases", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].numberPhases));
  7013. json_object_object_add(chargingSchedulePeriod, "phaseToUse", json_object_new_int(ShmOCPP20Data->ReportChargingProfiles[gun_index].chargingProfile[idxProfile].chargingSchedule[idxSchedule].chargingSchedulePeriod[idxPeriod].phaseToUse));
  7014. json_object_array_add(chargingSchedulePeriods, chargingSchedulePeriod);
  7015. }
  7016. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriods);
  7017. json_object_array_add(chargingSchedules, chargingSchedule);
  7018. }
  7019. json_object_object_add(chargingProfile, "chargingSchedule", chargingSchedules);
  7020. json_object_array_add(chargingProfiles, chargingProfile);
  7021. }
  7022. json_object_object_add(ReportChargingProfiles, "chargingProfile", chargingProfiles);
  7023. random_uuid(guid);
  7024. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ReportChargingProfiles", json_object_to_json_string_ext(ReportChargingProfiles, JSON_C_TO_STRING_PLAIN));
  7025. json_object_put(ReportChargingProfiles);
  7026. LWS_Send(message);
  7027. sprintf(tempdata, "ReportChargingProfiles,%d", gun_index);
  7028. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7029. {
  7030. result = PASS;
  7031. }
  7032. return result;
  7033. }
  7034. int sendReservationStatusUpdateRequest(int gun_index)
  7035. {
  7036. mtrace();
  7037. int result = FAIL;
  7038. char message[4096]={0};
  7039. char guid[37]={0};
  7040. char tempdata[128]={0};
  7041. json_object *ReservationStatusUpdate = json_object_new_object();
  7042. DEBUG_INFO("sendReservationStatusUpdateRequest...\n");
  7043. json_object_object_add(ReservationStatusUpdate, "reservationId", json_object_new_int(ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationId));
  7044. json_object_object_add(ReservationStatusUpdate, "reservationUpdateStatus", json_object_new_string((char*)ShmOCPP20Data->ReservationStatusUpdate[gun_index].reservationUpdateStatus));
  7045. random_uuid(guid);
  7046. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "ReservationStatusUpdate", json_object_to_json_string_ext(ReservationStatusUpdate, JSON_C_TO_STRING_PLAIN));
  7047. json_object_put(ReservationStatusUpdate);
  7048. LWS_Send(message);
  7049. sprintf(tempdata, "ReservationStatusUpdate,%d", gun_index);
  7050. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7051. {
  7052. result = PASS;
  7053. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = OFF;
  7054. }
  7055. return result;
  7056. }
  7057. int sendSecurityEventNotificationRequest()
  7058. {
  7059. mtrace();
  7060. int result = FAIL;
  7061. char message[4096]={0};
  7062. char guid[37]={0};
  7063. char tempdata[128]={0};
  7064. json_object *SecurityEventNotification = json_object_new_object();
  7065. DEBUG_INFO("sendSecurityEventNotificationRequest...\n");
  7066. json_object_object_add(SecurityEventNotification, "type", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.type));
  7067. json_object_object_add(SecurityEventNotification, "timestamp", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.timestamp));
  7068. json_object_object_add(SecurityEventNotification, "techInfo", json_object_new_string((char*)ShmOCPP20Data->SecurityEventNotification.techInfo));
  7069. random_uuid(guid);
  7070. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SecurityEventNotification", json_object_to_json_string_ext(SecurityEventNotification, JSON_C_TO_STRING_PLAIN));
  7071. json_object_put(SecurityEventNotification);
  7072. LWS_Send(message);
  7073. sprintf(tempdata, "SecurityEventNotification,0");
  7074. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7075. {
  7076. result = PASS;
  7077. }
  7078. return result;
  7079. }
  7080. int sendSignCertificateRequest(CertificateSigningUseEnumType certType)
  7081. {
  7082. mtrace();
  7083. int result = FAIL;
  7084. char message[4096]={0};
  7085. char guid[37]={0};
  7086. char tempdata[128]={0};
  7087. json_object *SignCertificate = json_object_new_object();
  7088. DEBUG_INFO("sendSignCertificateRequest...\n");
  7089. // Read csr file content
  7090. memset(ShmOCPP20Data->SignCertificate.csr, 0x00, ARRAY_SIZE(ShmOCPP20Data->SignCertificate.csr));
  7091. FILE *fp=fopen(((certType == CertificateSignedStatusEnumType_V2GCertificate)?"/Storage/OCPP/certV2G.csr":"/Storage/OCPP/certCP.csr"),"r");
  7092. char *line = NULL;
  7093. size_t len = 0;
  7094. while(getline(&line, &len, fp) != -1)
  7095. {
  7096. if((strstr(line, "BEGIN CERTIFICATE REQUEST") == NULL) && (strstr(line, "END CERTIFICATE REQUEST") == NULL))
  7097. {
  7098. memcpy(&ShmOCPP20Data->SignCertificate.csr[strlen((char*)ShmOCPP20Data->SignCertificate.csr)], line, (strlen(line)-1));
  7099. }
  7100. }
  7101. fclose(fp);
  7102. json_object_object_add(SignCertificate, "csr", json_object_new_string((char*)ShmOCPP20Data->SignCertificate.csr));
  7103. sprintf((char*)ShmOCPP20Data->SignCertificate.certificateType, CertificateSigningUseEnumTypeStr[certType]);
  7104. json_object_object_add(SignCertificate, "certificateType", json_object_new_string((char*)ShmOCPP20Data->SignCertificate.certificateType));
  7105. random_uuid(guid);
  7106. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "SignCertificate", json_object_to_json_string_ext(SignCertificate, JSON_C_TO_STRING_PLAIN));
  7107. json_object_put(SignCertificate);
  7108. LWS_Send(message);
  7109. sprintf(tempdata, "SignCertificate,0");
  7110. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7111. {
  7112. result = PASS;
  7113. }
  7114. return result;
  7115. }
  7116. int sendStatusNotificationRequest(int gun_index)
  7117. {
  7118. mtrace();
  7119. int result = FAIL;
  7120. char message[600]={0};
  7121. char guid[37];
  7122. int currentStatus = 0;
  7123. struct timeval tmnow;
  7124. struct tm *tm;
  7125. char buf[28];//, usec_buf[6];
  7126. char tempdata[65]={0};
  7127. int tempIndex = 0;
  7128. uint8_t isStateChanged = TRUE;
  7129. DEBUG_INFO("sendStatusNotificationRequest...\n");
  7130. gettimeofday(&tmnow, NULL);
  7131. time_t t;
  7132. t = time(NULL);
  7133. /*UTC time and date*/
  7134. tm = gmtime(&t);
  7135. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  7136. #if 0 // remove temporally
  7137. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  7138. strcat(buf,".");
  7139. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  7140. strcat(buf,usec_buf);
  7141. #endif
  7142. printf("%s",buf);
  7143. ShmOCPP20Data->StatusNotification[gun_index].evseId = (gun_index + 1);
  7144. ShmOCPP20Data->StatusNotification[gun_index].connectorId = (gun_index + 1);
  7145. strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].timestamp, buf);
  7146. //strcpy(ShmOCPP20Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  7147. /*
  7148. enum _SYSTEM_STATUS
  7149. {
  7150. S_BOOTING = 0,
  7151. S_IDLE, = 1
  7152. S_AUTHORIZING, =2
  7153. S_REASSIGN_CHECK, =3
  7154. S_REASSIGN, =4
  7155. S_PRECHARGE, =5
  7156. S_PREPARING_FOR_EV, =6
  7157. S_PREPARING_FOR_EVSE, =7
  7158. S_CHARGING, =8
  7159. S_TERMINATING, =9
  7160. S_COMPLETE, =10
  7161. S_ALARM, =11
  7162. S_FAULT =12
  7163. }
  7164. */
  7165. //check Transaction active
  7166. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  7167. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7168. {
  7169. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7170. {
  7171. tempIndex = ((gun_index==2) ? 1: 0);
  7172. }
  7173. else
  7174. {
  7175. tempIndex = gun_index;
  7176. }
  7177. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7178. {
  7179. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  7180. {
  7181. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  7182. {
  7183. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  7184. {
  7185. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  7186. }
  7187. else
  7188. {
  7189. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  7190. }
  7191. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  7192. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  7193. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  7194. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  7195. }
  7196. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  7197. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  7198. ) //S_PRECHARGE
  7199. {
  7200. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  7201. }
  7202. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  7203. {
  7204. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  7205. }
  7206. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  7207. {
  7208. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  7209. }
  7210. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  7211. {
  7212. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  7213. }
  7214. 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
  7215. {
  7216. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  7217. }
  7218. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  7219. {
  7220. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  7221. }
  7222. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  7223. {
  7224. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  7225. }
  7226. } //end of the same index
  7227. }//end of for CHAdeMO_QUANTITY
  7228. }
  7229. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7230. {
  7231. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7232. {
  7233. tempIndex = ((gun_index==2) ? 1: 0);
  7234. }
  7235. else
  7236. {
  7237. tempIndex = gun_index;
  7238. }
  7239. for (int index = 0; index < CCS_QUANTITY; index++)
  7240. {
  7241. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7242. {
  7243. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7244. {
  7245. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  7246. {
  7247. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  7248. }
  7249. else
  7250. {
  7251. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  7252. }
  7253. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  7254. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  7255. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  7256. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  7257. }
  7258. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  7259. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  7260. ) //S_PRECHARGE
  7261. {
  7262. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  7263. }
  7264. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  7265. {
  7266. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  7267. }
  7268. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  7269. {
  7270. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  7271. }
  7272. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  7273. {
  7274. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  7275. }
  7276. 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
  7277. {
  7278. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status : Unavailable
  7279. }
  7280. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  7281. {
  7282. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  7283. }
  7284. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  7285. {
  7286. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  7287. }
  7288. } //end of the same index
  7289. } // end of for CCS_QUANTITY
  7290. }
  7291. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7292. {
  7293. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7294. {
  7295. tempIndex = ((gun_index==2) ? 1: 0);
  7296. }
  7297. else
  7298. {
  7299. tempIndex = gun_index;
  7300. }
  7301. for (int index = 0; index < GB_QUANTITY; index++)
  7302. {
  7303. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7304. {
  7305. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7306. {
  7307. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  7308. {
  7309. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  7310. }
  7311. else
  7312. {
  7313. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  7314. }
  7315. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  7316. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  7317. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  7318. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  7319. }
  7320. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_AUTHORIZING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  7321. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  7322. ) //S_PRECHARGE
  7323. {
  7324. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  7325. }
  7326. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  7327. {
  7328. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  7329. }
  7330. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  7331. {
  7332. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  7333. }
  7334. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  7335. {
  7336. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  7337. }
  7338. 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
  7339. {
  7340. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  7341. }
  7342. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  7343. {
  7344. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  7345. }
  7346. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  7347. {
  7348. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  7349. }
  7350. } //end of the same index
  7351. } // end of for GB_QUANTITY
  7352. }
  7353. else if(gunType[gun_index] == GUN_TYPE_DO)
  7354. {
  7355. tempIndex = gun_index;
  7356. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7357. {
  7358. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7359. {
  7360. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7361. {
  7362. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  7363. {
  7364. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  7365. }
  7366. else
  7367. {
  7368. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  7369. }
  7370. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  7371. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  7372. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  7373. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  7374. }
  7375. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_AUTHORIZING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  7376. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  7377. ) //S_PRECHARGE
  7378. {
  7379. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  7380. }
  7381. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  7382. {
  7383. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  7384. }
  7385. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  7386. {
  7387. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  7388. }
  7389. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  7390. {
  7391. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  7392. }
  7393. 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
  7394. {
  7395. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  7396. }
  7397. 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
  7398. {
  7399. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  7400. }
  7401. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  7402. {
  7403. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  7404. }
  7405. } //end of the same index
  7406. }
  7407. }
  7408. else
  7409. {
  7410. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7411. {
  7412. tempIndex = 2;
  7413. }
  7414. else
  7415. {
  7416. tempIndex = gun_index;
  7417. }
  7418. for (int index = 0; index < AC_QUANTITY; index++)
  7419. {
  7420. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7421. {
  7422. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  7423. {
  7424. 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))
  7425. {
  7426. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  7427. }
  7428. else
  7429. {
  7430. currentStatus = ConnectorStatusEnumType_Available; //OCPP Status: Available
  7431. }
  7432. memset(&ShmOCPP20Data->TransactionEvent[gun_index].eventType[0], 0x00, ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  7433. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  7434. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  7435. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  7436. }
  7437. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  7438. {
  7439. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Preparing
  7440. }
  7441. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  7442. {
  7443. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Charging
  7444. }
  7445. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  7446. {
  7447. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: Finishing
  7448. }
  7449. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  7450. {
  7451. currentStatus = ConnectorStatusEnumType_Occupied; //OCPP Status: SuspendedEV
  7452. }
  7453. 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
  7454. {
  7455. currentStatus = ConnectorStatusEnumType_Unavailable; //OCPP Status: Unavailable
  7456. }
  7457. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  7458. {
  7459. currentStatus = ConnectorStatusEnumType_Faulted; //OCPP Status: Faulted
  7460. }
  7461. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  7462. {
  7463. currentStatus = ConnectorStatusEnumType_Reserved; //OCPP Status: Reserved
  7464. }
  7465. }//end of the same index
  7466. }//end of for AC_QUANTITY
  7467. }
  7468. //it's option
  7469. if((strstr((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]) != NULL) &&
  7470. !cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq)
  7471. {
  7472. isStateChanged = FALSE;
  7473. }
  7474. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  7475. strcpy((char *)ShmOCPP20Data->StatusNotification[gun_index].connectorStatus, ConnectorStatusEnumTypeStr[currentStatus]);
  7476. random_uuid(guid);
  7477. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"evseId\":%d,\"connectorStatus\":\"%s\",\"timestamp\":\"%s\"}]"
  7478. , MESSAGE_TYPE_CALL
  7479. , guid
  7480. , ShmOCPP20Data->StatusNotification[gun_index].connectorId
  7481. , ShmOCPP20Data->StatusNotification[gun_index].evseId
  7482. , ShmOCPP20Data->StatusNotification[gun_index].connectorStatus
  7483. , ShmOCPP20Data->StatusNotification[gun_index].timestamp);
  7484. if((server_sign == TRUE) && isStateChanged)
  7485. {
  7486. LWS_Send(message);
  7487. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  7488. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  7489. {
  7490. result = PASS;
  7491. }
  7492. }
  7493. else
  7494. {
  7495. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  7496. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  7497. result = PASS;
  7498. }
  7499. return result;
  7500. }
  7501. int sendTransactionEventRequest(int gun_index)
  7502. {
  7503. mtrace();
  7504. int result = FAIL;
  7505. char message[1024*20]={0};
  7506. char guid[37]={0};
  7507. char tempdata[128]={0};
  7508. uint8_t tempIndex;
  7509. json_object *TransactionEvent = json_object_new_object();
  7510. json_object *transactionInfo = json_object_new_object();
  7511. json_object *idToken = json_object_new_object();
  7512. json_object *evse = json_object_new_object();
  7513. json_object *meterValues = json_object_new_array();
  7514. char TempStopTransaction[256];
  7515. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  7516. DEBUG_INFO("sendTransactionEventRequest...\n");
  7517. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  7518. {
  7519. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7520. {
  7521. tempIndex = ((gun_index==2) ? 1: 0);
  7522. }
  7523. else
  7524. {
  7525. tempIndex = gun_index;
  7526. }
  7527. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7528. {
  7529. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  7530. {
  7531. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  7532. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  7533. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  7534. else
  7535. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  7536. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  7537. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  7538. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  7539. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  7540. {
  7541. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  7542. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  7543. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  7544. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7545. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  7546. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  7547. {
  7548. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  7549. }
  7550. else
  7551. {
  7552. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  7553. }
  7554. }
  7555. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  7556. {
  7557. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7558. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  7559. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  7560. }
  7561. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  7562. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  7563. ) //S_PRECHARGE
  7564. {
  7565. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  7566. {
  7567. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  7568. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartUserId);
  7569. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", ShmOCPP20Data->Authorize.idToken.type);
  7570. storeTempStopTransaction(gun_index);
  7571. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7572. }
  7573. else
  7574. {
  7575. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7576. }
  7577. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  7578. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7579. }
  7580. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  7581. {
  7582. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7583. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  7584. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7585. }
  7586. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  7587. {
  7588. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  7589. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  7590. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7591. if((access(TempStopTransaction,F_OK))!=-1)
  7592. {
  7593. remove(TempStopTransaction); // remove file "TempStopTransaction"
  7594. }
  7595. }
  7596. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  7597. {
  7598. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7599. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  7600. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7601. }
  7602. 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
  7603. {
  7604. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7605. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7606. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7607. }
  7608. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  7609. {
  7610. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7611. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7612. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7613. }
  7614. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  7615. {
  7616. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7617. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7618. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7619. }
  7620. } //end of the same index
  7621. }//end of for CHAdeMO_QUANTITY
  7622. }
  7623. else if(gunType[gun_index] == GUN_TYPE_CCS)
  7624. {
  7625. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7626. {
  7627. tempIndex = ((gun_index==2) ? 1: 0);
  7628. }
  7629. else
  7630. {
  7631. tempIndex = gun_index;
  7632. }
  7633. for (int index = 0; index < CCS_QUANTITY; index++)
  7634. {
  7635. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7636. {
  7637. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  7638. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  7639. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  7640. else
  7641. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  7642. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  7643. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  7644. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  7645. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7646. {
  7647. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  7648. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  7649. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  7650. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7651. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  7652. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  7653. {
  7654. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  7655. }
  7656. else
  7657. {
  7658. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  7659. }
  7660. }
  7661. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  7662. {
  7663. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7664. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  7665. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  7666. }
  7667. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  7668. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  7669. ) //S_PRECHARGE
  7670. {
  7671. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  7672. {
  7673. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  7674. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartUserId);
  7675. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", ShmOCPP20Data->Authorize.idToken.type);
  7676. storeTempStopTransaction(gun_index);
  7677. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7678. }
  7679. else
  7680. {
  7681. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7682. }
  7683. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  7684. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7685. }
  7686. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  7687. {
  7688. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7689. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  7690. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7691. }
  7692. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  7693. {
  7694. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  7695. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  7696. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7697. if((access(TempStopTransaction,F_OK))!=-1)
  7698. {
  7699. remove(TempStopTransaction); // remove file "TempStopTransaction"
  7700. }
  7701. }
  7702. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  7703. {
  7704. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7705. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  7706. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7707. }
  7708. 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
  7709. {
  7710. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7711. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7712. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7713. }
  7714. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  7715. {
  7716. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7717. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7718. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7719. }
  7720. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  7721. {
  7722. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7723. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7724. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7725. }
  7726. } //end of the same index
  7727. } // end of for CCS_QUANTITY
  7728. }
  7729. else if(gunType[gun_index] == GUN_TYPE_GBT)
  7730. {
  7731. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7732. {
  7733. tempIndex = ((gun_index==2) ? 1: 0);
  7734. }
  7735. else
  7736. {
  7737. tempIndex = gun_index;
  7738. }
  7739. for (int index = 0; index < GB_QUANTITY; index++)
  7740. {
  7741. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7742. {
  7743. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  7744. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  7745. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  7746. else
  7747. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  7748. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  7749. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  7750. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  7751. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7752. {
  7753. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  7754. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  7755. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  7756. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7757. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  7758. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  7759. {
  7760. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  7761. }
  7762. else
  7763. {
  7764. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  7765. }
  7766. }
  7767. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  7768. {
  7769. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7770. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  7771. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  7772. }
  7773. else if ( ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  7774. ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  7775. ) //S_PRECHARGE
  7776. {
  7777. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  7778. {
  7779. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  7780. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.GbChargingData[index].StartUserId);
  7781. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", ShmOCPP20Data->Authorize.idToken.type);
  7782. storeTempStopTransaction(gun_index);
  7783. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7784. }
  7785. else
  7786. {
  7787. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7788. }
  7789. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  7790. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7791. }
  7792. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  7793. {
  7794. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7795. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  7796. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7797. }
  7798. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  7799. {
  7800. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  7801. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  7802. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7803. if((access(TempStopTransaction,F_OK))!=-1)
  7804. {
  7805. remove(TempStopTransaction); // remove file "TempStopTransaction"
  7806. }
  7807. }
  7808. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  7809. {
  7810. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7811. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  7812. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7813. }
  7814. 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
  7815. {
  7816. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7817. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7818. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7819. }
  7820. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  7821. {
  7822. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7823. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7824. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7825. }
  7826. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  7827. {
  7828. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7829. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7830. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7831. }
  7832. } //end of the same index
  7833. } // end of for GB_QUANTITY
  7834. }
  7835. else if(gunType[gun_index] == GUN_TYPE_DO)
  7836. {
  7837. tempIndex = gun_index;
  7838. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7839. {
  7840. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7841. {
  7842. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  7843. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  7844. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  7845. else
  7846. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  7847. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  7848. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  7849. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  7850. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7851. {
  7852. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  7853. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  7854. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  7855. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7856. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  7857. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  7858. {
  7859. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  7860. }
  7861. else
  7862. {
  7863. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  7864. }
  7865. }
  7866. else if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  7867. {
  7868. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7869. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  7870. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  7871. }
  7872. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  7873. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  7874. ) //S_PRECHARGE
  7875. {
  7876. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  7877. {
  7878. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  7879. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.StartUserId);
  7880. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", ShmOCPP20Data->Authorize.idToken.type);
  7881. storeTempStopTransaction(gun_index);
  7882. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7883. }
  7884. else
  7885. {
  7886. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7887. }
  7888. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  7889. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7890. }
  7891. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  7892. {
  7893. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7894. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  7895. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7896. }
  7897. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  7898. {
  7899. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  7900. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  7901. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7902. if((access(TempStopTransaction,F_OK))!=-1)
  7903. {
  7904. remove(TempStopTransaction); // remove file "TempStopTransaction"
  7905. }
  7906. }
  7907. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  7908. {
  7909. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7910. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  7911. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7912. }
  7913. 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
  7914. {
  7915. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7916. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7917. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7918. }
  7919. 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
  7920. {
  7921. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7922. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7923. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7924. }
  7925. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  7926. {
  7927. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7928. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  7929. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  7930. }
  7931. } //end of the same index
  7932. }
  7933. }
  7934. else
  7935. {
  7936. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  7937. {
  7938. tempIndex = 2;
  7939. }
  7940. else
  7941. {
  7942. tempIndex = gun_index;
  7943. }
  7944. for (int index = 0; index < AC_QUANTITY; index++)
  7945. {
  7946. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7947. {
  7948. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  7949. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  7950. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  7951. else
  7952. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  7953. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  7954. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  7955. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  7956. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  7957. {
  7958. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  7959. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  7960. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  7961. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7962. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  7963. 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))
  7964. {
  7965. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  7966. }
  7967. else
  7968. {
  7969. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  7970. }
  7971. }
  7972. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  7973. {
  7974. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7975. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  7976. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  7977. }
  7978. else if ( ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  7979. ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  7980. ) //S_PRECHARGE
  7981. {
  7982. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  7983. {
  7984. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  7985. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.AcChargingData[index].StartUserId);
  7986. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", ShmOCPP20Data->Authorize.idToken.type);
  7987. storeTempStopTransaction(gun_index);
  7988. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  7989. }
  7990. else
  7991. {
  7992. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  7993. }
  7994. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  7995. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  7996. }
  7997. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  7998. {
  7999. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8000. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  8001. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8002. }
  8003. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  8004. {
  8005. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  8006. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  8007. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8008. if((access(TempStopTransaction,F_OK))!=-1)
  8009. {
  8010. remove(TempStopTransaction); // remove file "TempStopTransaction"
  8011. }
  8012. }
  8013. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  8014. {
  8015. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8016. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  8017. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  8018. }
  8019. 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
  8020. {
  8021. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8022. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8023. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8024. }
  8025. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  8026. {
  8027. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  8028. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8029. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8030. }
  8031. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  8032. {
  8033. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  8034. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  8035. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  8036. }
  8037. }//end of the same index
  8038. }//end of for AC_QUANTITY
  8039. }
  8040. // Message
  8041. json_object_object_add(TransactionEvent, "eventType", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  8042. json_object_object_add(TransactionEvent, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].timestamp));
  8043. json_object_object_add(TransactionEvent, "triggerReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason));
  8044. json_object_object_add(TransactionEvent, "seqNo", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].seqNo));
  8045. json_object_object_add(TransactionEvent, "offline", json_object_new_boolean(ShmOCPP20Data->TransactionEvent[gun_index].offline));
  8046. if(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed > 0)
  8047. json_object_object_add(TransactionEvent, "numberOfPhasesUsed", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed));
  8048. if(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent > 0)
  8049. json_object_object_add(TransactionEvent, "cableMaxCurrent", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent));
  8050. if(ShmOCPP20Data->TransactionEvent[gun_index].reservationId > 0)
  8051. json_object_object_add(TransactionEvent, "reservationId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].reservationId));
  8052. json_object_object_add(transactionInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId));
  8053. json_object_object_add(transactionInfo, "chargingState", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState));
  8054. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging > 0)
  8055. json_object_object_add(transactionInfo, "timeSpentCharging", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging));
  8056. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason) > 0)
  8057. json_object_object_add(transactionInfo, "stoppedReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason));
  8058. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId > 0)
  8059. json_object_object_add(transactionInfo, "remoteStartId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId));
  8060. json_object_object_add(TransactionEvent, "transactionInfo", transactionInfo);
  8061. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken) > 0)
  8062. {
  8063. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
  8064. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type));
  8065. json_object_object_add(TransactionEvent, "idToken", idToken);
  8066. }
  8067. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.id));
  8068. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId));
  8069. json_object_object_add(TransactionEvent, "evse", evse);
  8070. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0].timestamp) > 0)
  8071. {
  8072. for(int idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue);idxMeter++)
  8073. {
  8074. json_object *meterValue = json_object_new_object();
  8075. json_object *sampledValues = json_object_new_array();
  8076. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].timestamp));
  8077. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  8078. {
  8079. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0) &&
  8080. ((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)))
  8081. {
  8082. json_object *sampledValue = json_object_new_object();
  8083. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  8084. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  8085. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  8086. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  8087. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  8088. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  8089. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  8090. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  8091. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  8092. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  8093. {
  8094. json_object *unitOfMeasure = json_object_new_object();
  8095. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  8096. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  8097. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  8098. }
  8099. json_object_array_add(sampledValues, sampledValue);
  8100. }
  8101. }
  8102. json_object_object_add(meterValue, "sampledValue", sampledValues);
  8103. json_object_array_add(meterValues, meterValue);
  8104. }
  8105. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  8106. }
  8107. random_uuid(guid);
  8108. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "TransactionEvent", json_object_to_json_string_ext(TransactionEvent, JSON_C_TO_STRING_PLAIN));
  8109. json_object_put(TransactionEvent);
  8110. sprintf(tempdata, "TransactionEvent,%d", gun_index);
  8111. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == PASS)
  8112. {
  8113. result = PASS;
  8114. }
  8115. queue_operation(QUEUE_OPERATION_ADD, guid, message);
  8116. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Started]) != NULL)
  8117. OCPP_insert_transaction_msg(YES, message);
  8118. else if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]) != NULL)
  8119. OCPP_insert_transaction_msg(NO, message);
  8120. return result;
  8121. }
  8122. //==========================================
  8123. // send confirm routine
  8124. //==========================================
  8125. int sendCancelReservationConfirmation(char *uuid, unsigned char gun_index)
  8126. {
  8127. mtrace();
  8128. int result = FAIL;
  8129. char message[4096]={0};
  8130. json_object *CancelReservation = json_object_new_object();
  8131. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  8132. json_object_object_add(CancelReservation, "status", json_object_new_string((char*)ShmOCPP20Data->CancelReservation[gun_index].Response_status));
  8133. sprintf(message,"[%d,\"%s\",%s]"
  8134. ,MESSAGE_TYPE_CALLRESULT
  8135. ,uuid
  8136. ,json_object_to_json_string_ext(CancelReservation, JSON_C_TO_STRING_PLAIN));
  8137. json_object_put(CancelReservation);
  8138. ShmOCPP20Data->CsMsg.bits[gun_index].CancelReservationConf = OFF;
  8139. LWS_Send(message);
  8140. result = TRUE;
  8141. return result;
  8142. }
  8143. int sendCertificateSignedConfirmation(char *uuid)
  8144. {
  8145. mtrace();
  8146. int result = FAIL;
  8147. char message[4096]={0};
  8148. json_object *CertificateSigned = json_object_new_object();
  8149. json_object *statusInfo = json_object_new_object();
  8150. DEBUG_INFO("sendCertificateSignedConfirmation...\n");
  8151. json_object_object_add(CertificateSigned, "status", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_status));
  8152. if(strlen((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.reasonCode) > 0)
  8153. {
  8154. json_object_object_add(statusInfo, "reasonCode", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.reasonCode));
  8155. if(strlen((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.additionalInfo) > 0)
  8156. json_object_object_add(statusInfo, "statadditionalInfous", json_object_new_string((char*)ShmOCPP20Data->CertificateSigned.Response_statusInfo.additionalInfo));
  8157. }
  8158. json_object_object_add(CertificateSigned, "statusInfo", statusInfo);
  8159. sprintf(message,"[%d,\"%s\",%s]"
  8160. ,MESSAGE_TYPE_CALLRESULT
  8161. ,uuid
  8162. ,json_object_to_json_string_ext(CertificateSigned, JSON_C_TO_STRING_PLAIN));
  8163. json_object_put(CertificateSigned);
  8164. LWS_Send(message);
  8165. result = TRUE;
  8166. return result;
  8167. }
  8168. int sendChangeAvailabilityConfirmation(char *uuid, unsigned char gun_index)
  8169. {
  8170. mtrace();
  8171. int result = FAIL;
  8172. char message[4096]={0};
  8173. json_object *ChangeAvailability = json_object_new_object();
  8174. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  8175. json_object_object_add(ChangeAvailability, "status", json_object_new_string((char*)ShmOCPP20Data->ChangeAvailability[gun_index].Response_status));
  8176. sprintf(message,"[%d,\"%s\",%s]"
  8177. ,MESSAGE_TYPE_CALLRESULT
  8178. ,uuid
  8179. ,json_object_to_json_string_ext(ChangeAvailability, JSON_C_TO_STRING_PLAIN));
  8180. json_object_put(ChangeAvailability);
  8181. LWS_Send(message);
  8182. result = TRUE;
  8183. return result;
  8184. }
  8185. int sendClearCacheConfirmation(char *uuid)
  8186. {
  8187. mtrace();
  8188. int result = FAIL;
  8189. char message[4096]={0};
  8190. json_object *ClearCache = json_object_new_object();
  8191. DEBUG_INFO("sendClearCacheConfirmation...\n");
  8192. json_object_object_add(ClearCache, "status", json_object_new_string((char*)ShmOCPP20Data->ClearCache.Response_status));
  8193. sprintf(message,"[%d,\"%s\",%s]"
  8194. ,MESSAGE_TYPE_CALLRESULT
  8195. ,uuid
  8196. ,json_object_to_json_string_ext(ClearCache, JSON_C_TO_STRING_PLAIN));
  8197. json_object_put(ClearCache);
  8198. LWS_Send(message);
  8199. result = TRUE;
  8200. return result;
  8201. }
  8202. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  8203. {
  8204. mtrace();
  8205. int result = FAIL;
  8206. char message[500]={0};
  8207. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  8208. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  8209. LWS_Send(message);
  8210. return result;
  8211. }
  8212. int sendClearDisplayMessageConfirmation(char *uuid)
  8213. {
  8214. mtrace();
  8215. int result = FAIL;
  8216. char message[4096]={0};
  8217. json_object *ClearDisplayMessage = json_object_new_object();
  8218. DEBUG_INFO("sendClearDisplayMessageConfirmation...\n");
  8219. json_object_object_add(ClearDisplayMessage, "status", json_object_new_string((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status));
  8220. sprintf(message,"[%d,\"%s\",%s]"
  8221. ,MESSAGE_TYPE_CALLRESULT
  8222. ,uuid
  8223. ,json_object_to_json_string_ext(ClearDisplayMessage, JSON_C_TO_STRING_PLAIN));
  8224. json_object_put(ClearDisplayMessage);
  8225. LWS_Send(message);
  8226. result = TRUE;
  8227. return result;
  8228. }
  8229. int sendClearVariableMonitoringConfirmation(char *uuid, unsigned char variableQuantity)
  8230. {
  8231. mtrace();
  8232. int result = FAIL;
  8233. char message[4096]={0};
  8234. json_object *ClearVariableMonitoring = json_object_new_object();
  8235. json_object *clearMonitoringResults = json_object_new_array();
  8236. DEBUG_INFO("sendClearVariableMonitoringConfirmation...\n");
  8237. for(int idx=0;idx<variableQuantity;idx++)
  8238. {
  8239. json_object *clearMonitoringResult = json_object_new_object();
  8240. json_object_object_add(clearMonitoringResult, "id", json_object_new_int(ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].id));
  8241. json_object_object_add(clearMonitoringResult, "status", json_object_new_string((char*)ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].status));
  8242. json_object_array_add(clearMonitoringResults, clearMonitoringResult);
  8243. }
  8244. json_object_object_add(ClearVariableMonitoring, "clearMonitoringResult", clearMonitoringResults);
  8245. sprintf(message,"[%d,\"%s\",%s]"
  8246. ,MESSAGE_TYPE_CALLRESULT
  8247. ,uuid
  8248. ,json_object_to_json_string_ext(ClearVariableMonitoring, JSON_C_TO_STRING_PLAIN));
  8249. json_object_put(ClearVariableMonitoring);
  8250. LWS_Send(message);
  8251. result = TRUE;
  8252. return result;
  8253. }
  8254. int sendCostUpdatedConfirmation(char *uuid)
  8255. {
  8256. mtrace();
  8257. int result = FAIL;
  8258. char message[4096]={0};
  8259. DEBUG_INFO("sendCostUpdatedConfirmation...\n");
  8260. sprintf(message,"[%d,\"%s\",{}]"
  8261. ,MESSAGE_TYPE_CALLRESULT
  8262. ,uuid);
  8263. LWS_Send(message);
  8264. result = TRUE;
  8265. return result;
  8266. }
  8267. int sendCustomerInformationConfirmation(char *uuid)
  8268. {
  8269. mtrace();
  8270. int result = FAIL;
  8271. char message[4096]={0};
  8272. json_object *CustomerInformation = json_object_new_object();
  8273. DEBUG_INFO("sendCustomerInformationConfirmation...\n");
  8274. json_object_object_add(CustomerInformation, "status", json_object_new_string((char*)ShmOCPP20Data->CustomerInformation.Response_status));
  8275. sprintf(message,"[%d,\"%s\",%s]"
  8276. ,MESSAGE_TYPE_CALLRESULT
  8277. ,uuid
  8278. ,json_object_to_json_string_ext(CustomerInformation, JSON_C_TO_STRING_PLAIN));
  8279. json_object_put(CustomerInformation);
  8280. LWS_Send(message);
  8281. result = TRUE;
  8282. return result;
  8283. }
  8284. int sendDataTransferConfirmation(char *uuid, unsigned char gun_index)
  8285. {
  8286. mtrace();
  8287. int result = FAIL;
  8288. char message[4096]={0};
  8289. json_object *DataTransfer = json_object_new_object();
  8290. DEBUG_INFO("sendDataTransferConfirmation...\n");
  8291. json_object_object_add(DataTransfer, "status", json_object_new_string((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_status));
  8292. json_object_object_add(DataTransfer, "data", json_object_new_string((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_data));
  8293. sprintf(message,"[%d,\"%s\",%s]"
  8294. ,MESSAGE_TYPE_CALLRESULT
  8295. ,uuid
  8296. ,json_object_to_json_string_ext(DataTransfer, JSON_C_TO_STRING_PLAIN));
  8297. json_object_put(DataTransfer);
  8298. LWS_Send(message);
  8299. result = TRUE;
  8300. return result;
  8301. }
  8302. int sendDeleteCertificateConfirmation(char *uuid)
  8303. {
  8304. mtrace();
  8305. int result = FAIL;
  8306. char message[4096]={0};
  8307. json_object *DeleteCertificate = json_object_new_object();
  8308. DEBUG_INFO("sendDeleteCertificateConfirmation...\n");
  8309. json_object_object_add(DeleteCertificate, "status", json_object_new_string((char*)ShmOCPP20Data->DeleteCertificate.Response_status));
  8310. sprintf(message,"[%d,\"%s\",%s]"
  8311. ,MESSAGE_TYPE_CALLRESULT
  8312. ,uuid
  8313. ,json_object_to_json_string_ext(DeleteCertificate, JSON_C_TO_STRING_PLAIN));
  8314. json_object_put(DeleteCertificate);
  8315. LWS_Send(message);
  8316. result = TRUE;
  8317. return result;
  8318. }
  8319. int sendGetBaseReportConfirmation(char *uuid)
  8320. {
  8321. mtrace();
  8322. int result = FAIL;
  8323. char message[4096]={0};
  8324. json_object *GetBaseReport = json_object_new_object();
  8325. DEBUG_INFO("sendGetBaseReportConfirmation...\n");
  8326. json_object_object_add(GetBaseReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetBaseReport.Response_status));
  8327. sprintf(message,"[%d,\"%s\",%s]"
  8328. ,MESSAGE_TYPE_CALLRESULT
  8329. ,uuid
  8330. ,json_object_to_json_string_ext(GetBaseReport, JSON_C_TO_STRING_PLAIN));
  8331. json_object_put(GetBaseReport);
  8332. LWS_Send(message);
  8333. result = TRUE;
  8334. return result;
  8335. }
  8336. int sendGetChargingProfilesConfirmation(char *uuid, unsigned char gun_index)
  8337. {
  8338. mtrace();
  8339. int result = FAIL;
  8340. char message[4096]={0};
  8341. json_object *GetChargingProfiles = json_object_new_object();
  8342. DEBUG_INFO("sendGetChargingProfilesConfirmation...\n");
  8343. json_object_object_add(GetChargingProfiles, "status", json_object_new_string((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status));
  8344. sprintf(message,"[%d,\"%s\",%s]"
  8345. ,MESSAGE_TYPE_CALLRESULT
  8346. ,uuid
  8347. ,json_object_to_json_string_ext(GetChargingProfiles, JSON_C_TO_STRING_PLAIN));
  8348. json_object_put(GetChargingProfiles);
  8349. LWS_Send(message);
  8350. result = TRUE;
  8351. return result;
  8352. }
  8353. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  8354. {
  8355. mtrace();
  8356. int result = FAIL;
  8357. char message[4096]={0};
  8358. int CompositeScheduleIndex = 0;
  8359. json_object *GetCompositeSchedule = json_object_new_object();
  8360. json_object *schedule = json_object_new_object();
  8361. json_object *chargingSchedule = json_object_new_object();
  8362. json_object *chargingSchedulePeriod = json_object_new_array();
  8363. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  8364. json_object_object_add(GetCompositeSchedule, "status", json_object_new_string(payload));
  8365. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  8366. if(nPeriod == 0)
  8367. {
  8368. if(strcmp((const char *)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime,"")!=0)
  8369. {
  8370. if(strlen((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule))
  8371. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule));
  8372. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration > 0)
  8373. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration));
  8374. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit));
  8375. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate > 0)
  8376. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate));
  8377. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.id));
  8378. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  8379. {
  8380. if(((ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  8381. (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  8382. {
  8383. json_object *Period = json_object_new_object();
  8384. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  8385. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  8386. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  8387. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  8388. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  8389. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  8390. json_object_array_add(chargingSchedulePeriod, Period);
  8391. }
  8392. }
  8393. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriod);
  8394. json_object_object_add(schedule, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime));
  8395. json_object_object_add(schedule, "chargingSchedule", chargingSchedule);
  8396. json_object_object_add(GetCompositeSchedule, "schedule", schedule);
  8397. }
  8398. }
  8399. else
  8400. {
  8401. if(strlen((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule))
  8402. json_object_object_add(chargingSchedule, "startSchedule", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.startSchedule));
  8403. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration > 0)
  8404. json_object_object_add(chargingSchedule, "duration", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.duration));
  8405. json_object_object_add(chargingSchedule, "chargingRateUnit", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingRateUnit));
  8406. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate > 0)
  8407. json_object_object_add(chargingSchedule, "minChargingRate", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.minChargingRate));
  8408. json_object_object_add(chargingSchedule, "id", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.id));
  8409. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod);idxPeriod++)
  8410. {
  8411. if(((ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod == 0) && (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit>0)) ||
  8412. (ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod > 0))
  8413. {
  8414. json_object *Period = json_object_new_object();
  8415. json_object_object_add(Period, "startPeriod", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].startPeriod));
  8416. json_object_object_add(Period, "limit", json_object_new_double(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].limit));
  8417. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases > 0)
  8418. json_object_object_add(Period, "numberPhases", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].numberPhases));
  8419. if(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse > 0)
  8420. json_object_object_add(Period, "phaseToUse", json_object_new_int(ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.chargingSchedule.chargingSchedulePeriod[idxPeriod].phaseToUse));
  8421. json_object_array_add(chargingSchedulePeriod, Period);
  8422. }
  8423. }
  8424. json_object_object_add(chargingSchedule, "chargingSchedulePeriod", chargingSchedulePeriod);
  8425. json_object_object_add(schedule, "startDateTime", json_object_new_string((char*)ShmOCPP20Data->GetCompositeSchedule[CompositeScheduleIndex].Response_schedule.startDateTime));
  8426. json_object_object_add(schedule, "chargingSchedule", chargingSchedule);
  8427. json_object_object_add(GetCompositeSchedule, "schedule", schedule);
  8428. }
  8429. sprintf(message,"[%d,\"%s\",%s]"
  8430. ,MESSAGE_TYPE_CALLRESULT
  8431. ,uuid
  8432. ,json_object_to_json_string_ext(GetCompositeSchedule, JSON_C_TO_STRING_PLAIN));
  8433. json_object_put(GetCompositeSchedule);
  8434. LWS_Send(message);
  8435. result = TRUE;
  8436. return result;
  8437. }
  8438. int sendGetGetDisplayMessagesConfirmation(char *uuid)
  8439. {
  8440. mtrace();
  8441. int result = FAIL;
  8442. char message[4096]={0};
  8443. json_object *GetGetDisplayMessages = json_object_new_object();
  8444. DEBUG_INFO("sendGetGetDisplayMessagesConfirmation...\n");
  8445. json_object_object_add(GetGetDisplayMessages, "status", json_object_new_string((char*)ShmOCPP20Data->GetDisplayMessages.Response_status));
  8446. sprintf(message,"[%d,\"%s\",%s]"
  8447. ,MESSAGE_TYPE_CALLRESULT
  8448. ,uuid
  8449. ,json_object_to_json_string_ext(GetGetDisplayMessages, JSON_C_TO_STRING_PLAIN));
  8450. json_object_put(GetGetDisplayMessages);
  8451. LWS_Send(message);
  8452. result = TRUE;
  8453. return result;
  8454. }
  8455. int sendGetInstalledCertificateIdsConfirmation(char *uuid, unsigned char certQuantity)
  8456. {
  8457. mtrace();
  8458. int result = FAIL;
  8459. char message[4096]={0};
  8460. json_object *GetInstalledCertificateIds = json_object_new_object();
  8461. json_object *certificateHashDataChains = json_object_new_array();
  8462. DEBUG_INFO("sendGetInstalledCertificateIdsConfirmation...\n");
  8463. json_object_object_add(GetInstalledCertificateIds, "status", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status));
  8464. for(int idx=0;idx<certQuantity;idx++)
  8465. {
  8466. json_object *cert = json_object_new_object();
  8467. json_object *certificateHashData = json_object_new_object();
  8468. json_object_object_add(certificateHashData, "hashAlgorithm", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.hashAlgorithm));
  8469. json_object_object_add(certificateHashData, "issuerNameHash", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.issuerNameHash));
  8470. json_object_object_add(certificateHashData, "issuerKeyHash", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.issuerKeyHash));
  8471. json_object_object_add(certificateHashData, "serialNumber", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateHashData.serialNumber));
  8472. json_object_object_add(cert, "certificateHashData", certificateHashData);
  8473. json_object_object_add(cert, "certificateType", json_object_new_string((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_certificateHashDataChain[idx].certificateType));
  8474. json_object_array_add(certificateHashDataChains, cert);
  8475. }
  8476. json_object_object_add(GetInstalledCertificateIds , "certificateHashDataChain", certificateHashDataChains);
  8477. sprintf(message,"[%d,\"%s\",%s]"
  8478. ,MESSAGE_TYPE_CALLRESULT
  8479. ,uuid
  8480. ,json_object_to_json_string_ext(GetInstalledCertificateIds, JSON_C_TO_STRING_PLAIN));
  8481. json_object_put(GetInstalledCertificateIds);
  8482. LWS_Send(message);
  8483. result = TRUE;
  8484. return result;
  8485. }
  8486. int sendGetLocalListVersionConfirmation(char *uuid)
  8487. {
  8488. mtrace();
  8489. int result = FAIL;
  8490. char message[4096]={0};
  8491. json_object *GetLocalListVersion = json_object_new_object();
  8492. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  8493. json_object_object_add(GetLocalListVersion, "versionNumber", json_object_new_int(ShmOCPP20Data->GetLocalListVersion.Response_versionNumber));
  8494. sprintf(message,"[%d,\"%s\",%s]"
  8495. ,MESSAGE_TYPE_CALLRESULT
  8496. ,uuid
  8497. ,json_object_to_json_string_ext(GetLocalListVersion, JSON_C_TO_STRING_PLAIN));
  8498. json_object_put(GetLocalListVersion);
  8499. LWS_Send(message);
  8500. result = TRUE;
  8501. return result;
  8502. }
  8503. int sendGetLogConfirmation(char *uuid)
  8504. {
  8505. mtrace();
  8506. int result = FAIL;
  8507. char message[4096]={0};
  8508. json_object *GetLog = json_object_new_object();
  8509. DEBUG_INFO("sendGetLogConfirmation...\n");
  8510. json_object_object_add(GetLog, "status", json_object_new_string((char*)ShmOCPP20Data->GetLog.Response_status));
  8511. json_object_object_add(GetLog, "filename", json_object_new_string((char*)ShmOCPP20Data->GetLog.Response_filename));
  8512. sprintf(message,"[%d,\"%s\",%s]"
  8513. ,MESSAGE_TYPE_CALLRESULT
  8514. ,uuid
  8515. ,json_object_to_json_string_ext(GetLog, JSON_C_TO_STRING_PLAIN));
  8516. json_object_put(GetLog);
  8517. LWS_Send(message);
  8518. result = TRUE;
  8519. return result;
  8520. }
  8521. int sendGetMonitoringReportConfirmation(char *uuid)
  8522. {
  8523. mtrace();
  8524. int result = FAIL;
  8525. char message[4096]={0};
  8526. json_object *GetMonitoringReport = json_object_new_object();
  8527. DEBUG_INFO("sendGetMonitoringReportConfirmation...\n");
  8528. json_object_object_add(GetMonitoringReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetMonitoringReport.Response_status));
  8529. sprintf(message,"[%d,\"%s\",%s]"
  8530. ,MESSAGE_TYPE_CALLRESULT
  8531. ,uuid
  8532. ,json_object_to_json_string_ext(GetMonitoringReport, JSON_C_TO_STRING_PLAIN));
  8533. json_object_put(GetMonitoringReport);
  8534. LWS_Send(message);
  8535. result = TRUE;
  8536. return result;
  8537. }
  8538. int sendGetReportConfirmation(char *uuid)
  8539. {
  8540. mtrace();
  8541. int result = FAIL;
  8542. char message[4096]={0};
  8543. json_object *GetReport = json_object_new_object();
  8544. DEBUG_INFO("sendGetReportConfirmation...\n");
  8545. json_object_object_add(GetReport, "status", json_object_new_string((char*)ShmOCPP20Data->GetReport.Response_status));
  8546. sprintf(message,"[%d,\"%s\",%s]"
  8547. ,MESSAGE_TYPE_CALLRESULT
  8548. ,uuid
  8549. ,json_object_to_json_string_ext(GetReport, JSON_C_TO_STRING_PLAIN));
  8550. json_object_put(GetReport);
  8551. LWS_Send(message);
  8552. result = TRUE;
  8553. return result;
  8554. }
  8555. int sendGetTransactionStatusConfirmation(char *uuid, unsigned char gun_index)
  8556. {
  8557. mtrace();
  8558. int result = FAIL;
  8559. char message[4096]={0};
  8560. json_object *GetTransactionStatus = json_object_new_object();
  8561. DEBUG_INFO("sendGetTransactionStatusConfirmation...\n");
  8562. json_object_object_add(GetTransactionStatus, "ongoingIndicator", json_object_new_boolean(ShmOCPP20Data->GetTransactionStatus[gun_index].Response_ongoingIndicator));
  8563. json_object_object_add(GetTransactionStatus, "messagesInQueue", json_object_new_boolean(ShmOCPP20Data->GetTransactionStatus[gun_index].Response_messagesInQueue));
  8564. sprintf(message,"[%d,\"%s\",%s]"
  8565. ,MESSAGE_TYPE_CALLRESULT
  8566. ,uuid
  8567. ,json_object_to_json_string_ext(GetTransactionStatus, JSON_C_TO_STRING_PLAIN));
  8568. json_object_put(GetTransactionStatus);
  8569. LWS_Send(message);
  8570. result = TRUE;
  8571. return result;
  8572. }
  8573. int sendGetVariablesConfirmation(char *uuid, unsigned char variableQuantity)
  8574. {
  8575. mtrace();
  8576. int result = FAIL;
  8577. char message[4096]={0};
  8578. json_object *GetVariables = json_object_new_object();
  8579. json_object *getVariableResults = json_object_new_array();
  8580. DEBUG_INFO("sendGetVariablesConfirmation...\n");
  8581. for(int idx=0;idx<variableQuantity;idx++)
  8582. {
  8583. json_object *variableResult = json_object_new_object();
  8584. json_object *component = json_object_new_object();
  8585. json_object *variable = json_object_new_object();
  8586. json_object *evse = json_object_new_object();
  8587. json_object_object_add(variableResult, "attributeType", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType));
  8588. json_object_object_add(variableResult, "attributeStatus", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus));
  8589. json_object_object_add(variableResult, "attributeValue", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue));
  8590. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.id));
  8591. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.evse.connectorId));
  8592. json_object_object_add(component, "evse", evse);
  8593. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.name));
  8594. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component.instance));
  8595. json_object_object_add(variableResult, "component", component);
  8596. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.name));
  8597. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable.instance));
  8598. json_object_object_add(variableResult, "variable", variable);
  8599. json_object_array_add(getVariableResults, variableResult);
  8600. }
  8601. json_object_object_add(GetVariables , "getVariableResult", getVariableResults);
  8602. sprintf(message,"[%d,\"%s\",%s]"
  8603. ,MESSAGE_TYPE_CALLRESULT
  8604. ,uuid
  8605. ,json_object_to_json_string_ext(GetVariables, JSON_C_TO_STRING_PLAIN));
  8606. json_object_put(GetVariables);
  8607. LWS_Send(message);
  8608. result = TRUE;
  8609. return result;
  8610. }
  8611. int sendInstallCertificateConfirmation(char *uuid)
  8612. {
  8613. mtrace();
  8614. int result = FAIL;
  8615. char message[4096]={0};
  8616. json_object *InstallCertificate = json_object_new_object();
  8617. DEBUG_INFO("sendInstallCertificateConfirmation...\n");
  8618. json_object_object_add(InstallCertificate, "status", json_object_new_string((char*)ShmOCPP20Data->InstallCertificate.Response_status));
  8619. sprintf(message,"[%d,\"%s\",%s]"
  8620. ,MESSAGE_TYPE_CALLRESULT
  8621. ,uuid
  8622. ,json_object_to_json_string_ext(InstallCertificate, JSON_C_TO_STRING_PLAIN));
  8623. json_object_put(InstallCertificate);
  8624. LWS_Send(message);
  8625. result = TRUE;
  8626. return result;
  8627. }
  8628. int sendPublishFirmwareConfirmation(char *uuid)
  8629. {
  8630. mtrace();
  8631. int result = FAIL;
  8632. char message[4096]={0};
  8633. json_object *PublishFirmware = json_object_new_object();
  8634. json_object_object_add(PublishFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->PublishFirmware.Response_status));
  8635. DEBUG_INFO("sendPublishFirmwareConfirmation...\n");
  8636. sprintf(message,"[%d,\"%s\",%s]"
  8637. ,MESSAGE_TYPE_CALLRESULT
  8638. ,uuid
  8639. ,json_object_to_json_string_ext(PublishFirmware, JSON_C_TO_STRING_PLAIN));
  8640. json_object_put(PublishFirmware);
  8641. LWS_Send(message);
  8642. result = TRUE;
  8643. return result;
  8644. }
  8645. int sendRemoteStartTransactionConfirmation(char *uuid, unsigned char gun_index)
  8646. {
  8647. mtrace();
  8648. int result = FAIL;
  8649. char message[4096]={0};
  8650. json_object *RemoteStartTransaction = json_object_new_object();
  8651. json_object_object_add(RemoteStartTransaction, "status", json_object_new_string((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_status));
  8652. json_object_object_add(RemoteStartTransaction, "transactionId", json_object_new_string((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].Response_transactionId));
  8653. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  8654. sprintf(message,"[%d,\"%s\",%s]"
  8655. ,MESSAGE_TYPE_CALLRESULT
  8656. ,uuid
  8657. ,json_object_to_json_string_ext(RemoteStartTransaction, JSON_C_TO_STRING_PLAIN));
  8658. json_object_put(RemoteStartTransaction);
  8659. LWS_Send(message);
  8660. result = TRUE;
  8661. return result;
  8662. }
  8663. int sendRemoteStopTransactionConfirmation(char *uuid, unsigned char gun_index)
  8664. {
  8665. mtrace();
  8666. int result = FAIL;
  8667. char message[4096]={0};
  8668. json_object *RemoteStopTransaction = json_object_new_object();
  8669. json_object_object_add(RemoteStopTransaction, "status", json_object_new_string((char*)ShmOCPP20Data->RequestStopTransaction[gun_index].Response_status));
  8670. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  8671. sprintf(message,"[%d,\"%s\",%s]"
  8672. ,MESSAGE_TYPE_CALLRESULT
  8673. ,uuid
  8674. ,json_object_to_json_string_ext(RemoteStopTransaction, JSON_C_TO_STRING_PLAIN));
  8675. json_object_put(RemoteStopTransaction);
  8676. LWS_Send(message);
  8677. result = TRUE;
  8678. return result;
  8679. }
  8680. int sendReserveNowConfirmation(char *uuid, unsigned char gun_index)
  8681. {
  8682. mtrace();
  8683. int result = FAIL;
  8684. char message[4096]={0};
  8685. json_object *ReserveNow = json_object_new_object();
  8686. json_object_object_add(ReserveNow, "status", json_object_new_string((char*)ShmOCPP20Data->ReserveNow[gun_index].Response_status));
  8687. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  8688. sprintf(message,"[%d,\"%s\",%s]"
  8689. ,MESSAGE_TYPE_CALLRESULT
  8690. ,uuid
  8691. ,json_object_to_json_string_ext(ReserveNow, JSON_C_TO_STRING_PLAIN));
  8692. json_object_put(ReserveNow);
  8693. LWS_Send(message);
  8694. result = TRUE;
  8695. ShmOCPP20Data->CsMsg.bits[gun_index].ReserveNowConf = OFF;
  8696. return result;
  8697. }
  8698. int sendResetConfirmation(char *uuid)
  8699. {
  8700. mtrace();
  8701. int result = FAIL;
  8702. char message[4096]={0};
  8703. json_object *Reset = json_object_new_object();
  8704. DEBUG_INFO("sendResetConfirmation...\n");
  8705. ShmOCPP20Data->MsMsg.bits.ResetConf = OFF;
  8706. json_object_object_add(Reset, "status", json_object_new_string((char*)ShmOCPP20Data->Reset.Response_status));
  8707. sprintf(message,"[%d,\"%s\",%s]"
  8708. ,MESSAGE_TYPE_CALLRESULT
  8709. ,uuid
  8710. ,json_object_to_json_string_ext(Reset, JSON_C_TO_STRING_PLAIN));
  8711. json_object_put(Reset);
  8712. LWS_Send(message);
  8713. if(strcmp((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]) == 0)
  8714. {
  8715. DB_updateBootType(BootReasonEnumType_RemoteReset);
  8716. }
  8717. else if(strcmp((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Scheduled]) == 0)
  8718. {
  8719. DB_updateBootType(BootReasonEnumType_ScheduledReset);
  8720. }
  8721. result = TRUE;
  8722. return result;
  8723. }
  8724. int sendSendLocalListConfirmation(char *uuid)
  8725. {
  8726. mtrace();
  8727. int result = FAIL;
  8728. char message[4096]={0};
  8729. json_object *SendLocalList = json_object_new_object();
  8730. json_object_object_add(SendLocalList, "status", json_object_new_string((char*)ShmOCPP20Data->SendLocalList.Response_status));
  8731. sprintf(message,"[%d,\"%s\",%s]"
  8732. ,MESSAGE_TYPE_CALLRESULT
  8733. ,uuid
  8734. ,json_object_to_json_string_ext(SendLocalList, JSON_C_TO_STRING_PLAIN));
  8735. json_object_put(SendLocalList);
  8736. LWS_Send(message);
  8737. result = TRUE;
  8738. return result;
  8739. }
  8740. int sendSetChargingProfileConfirmation(char *uuid, unsigned char gun_index)
  8741. {
  8742. mtrace();
  8743. int result = FAIL;
  8744. char message[4096]={0};
  8745. json_object *SetChargingProfile = json_object_new_object();
  8746. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  8747. json_object_object_add(SetChargingProfile, "status", json_object_new_string((char*)ShmOCPP20Data->SetChargingProfile[gun_index].Response_status));
  8748. sprintf(message,"[%d,\"%s\",%s]"
  8749. ,MESSAGE_TYPE_CALLRESULT
  8750. ,uuid
  8751. ,json_object_to_json_string_ext(SetChargingProfile, JSON_C_TO_STRING_PLAIN));
  8752. json_object_put(SetChargingProfile);
  8753. LWS_Send(message);
  8754. result = TRUE;
  8755. return result;
  8756. }
  8757. int sendSetDisplayMessagesConfirmation(char *uuid)
  8758. {
  8759. mtrace();
  8760. int result = FAIL;
  8761. char message[4096]={0};
  8762. json_object *SetDisplayMessage = json_object_new_object();
  8763. DEBUG_INFO("sendSetDisplayMessageConfirmation...\n");
  8764. json_object_object_add(SetDisplayMessage, "status", json_object_new_string((char*)ShmOCPP20Data->SetDisplayMessage.Response_status));
  8765. sprintf(message,"[%d,\"%s\",%s]"
  8766. ,MESSAGE_TYPE_CALLRESULT
  8767. ,uuid
  8768. ,json_object_to_json_string_ext(SetDisplayMessage, JSON_C_TO_STRING_PLAIN));
  8769. json_object_put(SetDisplayMessage);
  8770. LWS_Send(message);
  8771. result = TRUE;
  8772. return result;
  8773. }
  8774. int sendSetMonitoringBaseConfirmation(char *uuid)
  8775. {
  8776. mtrace();
  8777. int result = FAIL;
  8778. char message[4096]={0};
  8779. json_object *SetMonitoringBase = json_object_new_object();
  8780. DEBUG_INFO("sendSetMonitoringBaseConfirmation...\n");
  8781. json_object_object_add(SetMonitoringBase, "status", json_object_new_string((char*)ShmOCPP20Data->SetMonitoringBase.Response_status));
  8782. sprintf(message,"[%d,\"%s\",%s]"
  8783. ,MESSAGE_TYPE_CALLRESULT
  8784. ,uuid
  8785. ,json_object_to_json_string_ext(SetMonitoringBase, JSON_C_TO_STRING_PLAIN));
  8786. json_object_put(SetMonitoringBase);
  8787. LWS_Send(message);
  8788. result = TRUE;
  8789. return result;
  8790. }
  8791. int sendSetMonitoringLevelConfirmation(char *uuid)
  8792. {
  8793. mtrace();
  8794. int result = FAIL;
  8795. char message[4096]={0};
  8796. json_object *SetMonitoringLevel = json_object_new_object();
  8797. DEBUG_INFO("sendSetMonitoringLevelConfirmation...\n");
  8798. json_object_object_add(SetMonitoringLevel, "status", json_object_new_string((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status));
  8799. sprintf(message,"[%d,\"%s\",%s]"
  8800. ,MESSAGE_TYPE_CALLRESULT
  8801. ,uuid
  8802. ,json_object_to_json_string_ext(SetMonitoringLevel, JSON_C_TO_STRING_PLAIN));
  8803. json_object_put(SetMonitoringLevel);
  8804. LWS_Send(message);
  8805. result = TRUE;
  8806. return result;
  8807. }
  8808. int sendSetNetworkProfileConfirmation(char *uuid)
  8809. {
  8810. mtrace();
  8811. int result = FAIL;
  8812. char message[4096]={0};
  8813. json_object *SetNetworkProfile = json_object_new_object();
  8814. DEBUG_INFO("sendSetNetworkProfileConfirmation...\n");
  8815. json_object_object_add(SetNetworkProfile, "status", json_object_new_string((char*)ShmOCPP20Data->SetNetworkProfile.Response_status));
  8816. sprintf(message,"[%d,\"%s\",%s]"
  8817. ,MESSAGE_TYPE_CALLRESULT
  8818. ,uuid
  8819. ,json_object_to_json_string_ext(SetNetworkProfile, JSON_C_TO_STRING_PLAIN));
  8820. json_object_put(SetNetworkProfile);
  8821. LWS_Send(message);
  8822. result = TRUE;
  8823. return result;
  8824. }
  8825. int sendSetVariableMonitoringConfirmation(char *uuid, unsigned char variableQuantity)
  8826. {
  8827. mtrace();
  8828. int result = FAIL;
  8829. char message[4096]={0};
  8830. json_object *SetVariableMonitoring = json_object_new_object();
  8831. json_object *setMonitoringResults = json_object_new_array();
  8832. DEBUG_INFO("sendSetVariableMonitoringConfirmation...\n");
  8833. for(int idx=0;idx<variableQuantity;idx++)
  8834. {
  8835. json_object *variableMonitorResult = json_object_new_object();
  8836. json_object *component = json_object_new_object();
  8837. json_object *variable = json_object_new_object();
  8838. json_object *evse = json_object_new_object();
  8839. json_object_object_add(variableMonitorResult, "id", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].id));
  8840. json_object_object_add(variableMonitorResult, "type", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type));
  8841. json_object_object_add(variableMonitorResult, "severity", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].severity));
  8842. json_object_object_add(variableMonitorResult, "status", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status));
  8843. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.id));
  8844. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.evse.connectorId));
  8845. json_object_object_add(component, "component", evse);
  8846. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.name));
  8847. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component.instance));
  8848. json_object_object_add(variableMonitorResult, "component", component);
  8849. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.name));
  8850. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable.instance));
  8851. json_object_object_add(variableMonitorResult, "variable", variable);
  8852. json_object_array_add(setMonitoringResults, variableMonitorResult);
  8853. }
  8854. json_object_object_add(SetVariableMonitoring , "setMonitoringResult", setMonitoringResults);
  8855. sprintf(message,"[%d,\"%s\",%s]"
  8856. ,MESSAGE_TYPE_CALLRESULT
  8857. ,uuid
  8858. ,json_object_to_json_string_ext(SetVariableMonitoring, JSON_C_TO_STRING_PLAIN));
  8859. json_object_put(SetVariableMonitoring);
  8860. LWS_Send(message);
  8861. result = TRUE;
  8862. return result;
  8863. }
  8864. int sendSetVariableConfirmation(char *uuid, unsigned char variableQuantity)
  8865. {
  8866. mtrace();
  8867. int result = FAIL;
  8868. char message[4096]={0};
  8869. json_object *SetVariable = json_object_new_object();
  8870. json_object *setVariableResults = json_object_new_array();
  8871. DEBUG_INFO("sendSetVariableConfirmation...\n");
  8872. for(int idx=0;idx<variableQuantity;idx++)
  8873. {
  8874. json_object *variableResult = json_object_new_object();
  8875. json_object *component = json_object_new_object();
  8876. json_object *variable = json_object_new_object();
  8877. json_object *evse = json_object_new_object();
  8878. json_object_object_add(variableResult, "attributeType", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType));
  8879. json_object_object_add(variableResult, "attributeStatus", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus));
  8880. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.id));
  8881. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.evse.connectorId));
  8882. json_object_object_add(component, "component", evse);
  8883. json_object_object_add(component, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.name));
  8884. json_object_object_add(component, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component.instance));
  8885. json_object_object_add(variableResult, "component", component);
  8886. json_object_object_add(variable, "name", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.name));
  8887. json_object_object_add(variable, "instance", json_object_new_string((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable.instance));
  8888. json_object_object_add(variableResult, "variable", variable);
  8889. json_object_array_add(setVariableResults, variableResult);
  8890. }
  8891. json_object_object_add(SetVariable , "setVariableResult", setVariableResults);
  8892. sprintf(message,"[%d,\"%s\",%s]"
  8893. ,MESSAGE_TYPE_CALLRESULT
  8894. ,uuid
  8895. ,json_object_to_json_string_ext(SetVariable, JSON_C_TO_STRING_PLAIN));
  8896. json_object_put(SetVariable);
  8897. LWS_Send(message);
  8898. result = TRUE;
  8899. return result;
  8900. }
  8901. int sendTriggerMessageConfirmation(char *uuid)
  8902. {
  8903. mtrace();
  8904. int result = FAIL;
  8905. char message[4096]={0};
  8906. json_object *TriggerMessage = json_object_new_object();
  8907. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  8908. json_object_object_add(TriggerMessage, "status", json_object_new_string((char*)ShmOCPP20Data->TriggerMessage.Response_status));
  8909. sprintf(message,"[%d,\"%s\",%s]",
  8910. MESSAGE_TYPE_CALLRESULT,
  8911. uuid,
  8912. json_object_to_json_string_ext(TriggerMessage, JSON_C_TO_STRING_PLAIN));
  8913. json_object_put(TriggerMessage);
  8914. LWS_Send(message);
  8915. result = TRUE;
  8916. return result;
  8917. }
  8918. int sendUnlockConnectorConfirmation(char *uuid, unsigned char gun_index)
  8919. {
  8920. mtrace();
  8921. int result = FAIL;
  8922. char message[4096]={0};
  8923. json_object *UnlockConnector = json_object_new_object();
  8924. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  8925. json_object_object_add(UnlockConnector, "status", json_object_new_string((char*)ShmOCPP20Data->UnlockConnector[gun_index].Response_status));
  8926. sprintf(message,"[%d,\"%s\",%s]",
  8927. MESSAGE_TYPE_CALLRESULT,
  8928. uuid,
  8929. json_object_to_json_string_ext(UnlockConnector, JSON_C_TO_STRING_PLAIN));
  8930. json_object_put(UnlockConnector);
  8931. LWS_Send(message);
  8932. result = TRUE;
  8933. ShmOCPP20Data->CsMsg.bits[gun_index].UnlockConnectorConf = OFF;
  8934. return result;
  8935. }
  8936. int sendUnpublishFirmwareConfirmation(char *uuid)
  8937. {
  8938. mtrace();
  8939. int result = FAIL;
  8940. char message[4096]={0};
  8941. json_object *UnpublishFirmware = json_object_new_object();
  8942. DEBUG_INFO("sendUnpublishFirmwareConfirmation...\n");
  8943. json_object_object_add(UnpublishFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->UnpublishFirmware.Response_status));
  8944. sprintf(message,"[%d,\"%s\",%s]"
  8945. ,MESSAGE_TYPE_CALLRESULT
  8946. ,uuid
  8947. ,json_object_to_json_string_ext(UnpublishFirmware, JSON_C_TO_STRING_PLAIN));
  8948. json_object_put(UnpublishFirmware);
  8949. LWS_Send(message);
  8950. result = TRUE;
  8951. return result;
  8952. }
  8953. int sendUpdateFirmwareConfirmation(char *uuid)
  8954. {
  8955. mtrace();
  8956. int result = FAIL;
  8957. char message[4096]={0};
  8958. json_object *UpdateFirmware = json_object_new_object();
  8959. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  8960. sprintf((char*)ShmOCPP20Data->UpdateFirmware.Response_status, "%s", UpdateFirmwareStatusEnumTypeStr[UpdateFirmwareStatusEnumType_Accepted]);
  8961. json_object_object_add(UpdateFirmware, "status", json_object_new_string((char*)ShmOCPP20Data->UpdateFirmware.Response_status));
  8962. sprintf(message,"[%d,\"%s\",%s]"
  8963. ,MESSAGE_TYPE_CALLRESULT
  8964. ,uuid
  8965. ,json_object_to_json_string_ext(UpdateFirmware, JSON_C_TO_STRING_PLAIN));
  8966. json_object_put(UpdateFirmware);
  8967. LWS_Send(message);
  8968. result = TRUE;
  8969. return result;
  8970. }
  8971. int sendUnknownConfirmation(char *uuid)
  8972. {
  8973. mtrace();
  8974. int result = FAIL;
  8975. char message[256]={0};
  8976. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  8977. DEBUG_INFO("sendUnknownConfirmation...\n");
  8978. sprintf(message,"[%d,\"%s\",\"NotImplemented\",\"Requested Action is not known by receiver\",{}]", MESSAGE_TYPE_CALLERROR, uuid);
  8979. LWS_Send(message);
  8980. result = TRUE;
  8981. return result;
  8982. }
  8983. //==========================================
  8984. // send CallError routine
  8985. //==========================================
  8986. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  8987. {
  8988. mtrace();
  8989. char message[220]={0};
  8990. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  8991. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  8992. LWS_Send(message);
  8993. }
  8994. //==========================================
  8995. // Handle server request routine Start
  8996. //==========================================
  8997. int handleCancelReservationRequest(char *uuid, char *payload)
  8998. {
  8999. mtrace();
  9000. int result = FAIL;
  9001. int gunNO = 0;
  9002. int reservationIdInt = -1;
  9003. DEBUG_INFO("handleCancelReservationRequest...\n");
  9004. json_object *CancelReservation;
  9005. CancelReservation = json_tokener_parse(payload);
  9006. if(!is_error(CancelReservation))
  9007. {
  9008. // Required data
  9009. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  9010. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  9011. }
  9012. json_object_put(CancelReservation);
  9013. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  9014. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->CancelReservation);idx++)
  9015. sprintf((char*)ShmOCPP20Data->CancelReservation[idx].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Rejected]);
  9016. if(reservationIdInt != -1)
  9017. {
  9018. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  9019. //check Transaction active
  9020. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  9021. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9022. {
  9023. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  9024. {
  9025. sprintf((char*)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  9026. if(gunType[2] == GUN_TYPE_CHAdeMO)
  9027. {
  9028. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  9029. }
  9030. else
  9031. {
  9032. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  9033. }
  9034. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  9035. goto end;
  9036. }
  9037. }
  9038. for (int index = 0; index < CCS_QUANTITY; index++)
  9039. {
  9040. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  9041. {
  9042. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  9043. if(gunType[2] == GUN_TYPE_CCS)
  9044. {
  9045. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  9046. }
  9047. else
  9048. {
  9049. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  9050. }
  9051. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  9052. goto end;
  9053. }
  9054. }
  9055. for (int index = 0; index < GB_QUANTITY; index++)
  9056. {
  9057. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  9058. {
  9059. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  9060. if(gunType[2] == GUN_TYPE_GBT)
  9061. {
  9062. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  9063. }
  9064. else
  9065. {
  9066. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  9067. }
  9068. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  9069. goto end;
  9070. }
  9071. }
  9072. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9073. {
  9074. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  9075. {
  9076. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  9077. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  9078. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  9079. goto end;
  9080. }
  9081. }
  9082. for (int index = 0; index < AC_QUANTITY; index++)
  9083. {
  9084. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  9085. {
  9086. sprintf((char *)ShmOCPP20Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].Response_status, "%s", CancelReservationStatusEnumTypeStr[CancelReservationStatusEnumType_Accepted]);
  9087. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9088. {
  9089. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  9090. }
  9091. else
  9092. {
  9093. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  9094. }
  9095. ShmOCPP20Data->CsMsg.bits[gunNO].CancelReservationReq = ON;
  9096. goto end;
  9097. }
  9098. }
  9099. }
  9100. //The reservationId does NOT match the reservationId
  9101. sendCancelReservationConfirmation(uuid, gunNO);
  9102. end:
  9103. // Fill in ocpp packet uuid
  9104. strcpy((char *)ShmOCPP20Data->CancelReservation[gunNO].guid, uuid);
  9105. return result;
  9106. }
  9107. int handleCertificateSignedRequest(char *uuid, char *payload)
  9108. {
  9109. mtrace();
  9110. int result = FAIL;
  9111. json_object *CertificateSigned;
  9112. DEBUG_INFO("handleCertificateSignedRequest...\n");
  9113. CertificateSigned = json_tokener_parse(payload);
  9114. if(!is_error(CertificateSigned))
  9115. {
  9116. memset(&ShmOCPP20Data->CertificateSigned, 0, sizeof(struct CertificateSigned_20));
  9117. memcpy(&ShmOCPP20Data->CertificateSigned.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->CertificateSigned.guid));
  9118. // Required data
  9119. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateChain, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateChain")));
  9120. // Optional data
  9121. if(json_object_object_get(CertificateSigned, "certificateType") != NULL)
  9122. {
  9123. sprintf((char*)ShmOCPP20Data->CertificateSigned.certificateType, "%s", json_object_get_string(json_object_object_get(CertificateSigned, "certificateType")));
  9124. if(strcmp((char*)ShmOCPP20Data->CertificateSigned.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_ChargingStationCertificate]) == 0)
  9125. {
  9126. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  9127. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  9128. fclose(fp);
  9129. }
  9130. else if(strcmp((char*)ShmOCPP20Data->CertificateSigned.certificateType, CertificateSigningUseEnumTypeStr[CertificateSignedStatusEnumType_V2GCertificate]) == 0)
  9131. {
  9132. FILE *fp = fopen("/Storage/OCPP/certV2G.crt", "w");
  9133. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  9134. fclose(fp);
  9135. }
  9136. }
  9137. else
  9138. {
  9139. FILE *fp = fopen("/Storage/OCPP/certCP.crt", "w");
  9140. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  9141. fclose(fp);
  9142. fp = fopen("/Storage/OCPP/certV2G.crt", "w");
  9143. fprintf(fp, "%s", ShmOCPP20Data->CertificateSigned.certificateChain);
  9144. fclose(fp);
  9145. }
  9146. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9147. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Accepted]);
  9148. }
  9149. else
  9150. strcpy((char*)ShmOCPP20Data->CertificateSigned.Response_status, CertificateSignedStatusEnumTypeStr[CertificateSignedStatusEnumType_Rejected]);
  9151. json_object_put(CertificateSigned);
  9152. sendCertificateSignedConfirmation(uuid);
  9153. return result;
  9154. }
  9155. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  9156. {
  9157. mtrace();
  9158. int result = FAIL;
  9159. int evseId = 0, gunIndex = 0;
  9160. char operationalStatus[16]={0};
  9161. char comfirmstr[20];
  9162. int specificId = FALSE;
  9163. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  9164. json_object *ChangeAvailability;
  9165. ChangeAvailability = json_tokener_parse(payload);
  9166. if(!is_error(ChangeAvailability))
  9167. {
  9168. // Required data
  9169. if(json_object_object_get(ChangeAvailability, "operationalStatus") != NULL)
  9170. sprintf((char*)operationalStatus, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "operationalStatus")));
  9171. if(json_object_object_get(ChangeAvailability, "evse") != NULL)
  9172. {
  9173. evseId = json_object_get_int(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "id"));
  9174. if(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "connectorId") != NULL)
  9175. gunIndex = json_object_get_int(json_object_object_get(json_object_object_get(ChangeAvailability, "evse"), "connectorId"));
  9176. }
  9177. }
  9178. json_object_put(ChangeAvailability);
  9179. if((evseId != 0) && (evseId <= gunTotalNumber))
  9180. {
  9181. ShmOCPP20Data->ChangeAvailability[evseId - 1].evse.connectorId = evseId;
  9182. sprintf((char *)ShmOCPP20Data->ChangeAvailability[evseId - 1].operationalStatus, "%s", operationalStatus);
  9183. }
  9184. else if(evseId == 0)
  9185. {
  9186. for(int i=0; i < gunTotalNumber; i++)
  9187. {
  9188. ShmOCPP20Data->ChangeAvailability[i].evse.connectorId = evseId;
  9189. sprintf((char *)ShmOCPP20Data->ChangeAvailability[i].operationalStatus, "%s", operationalStatus);
  9190. }
  9191. }
  9192. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9193. {
  9194. ShmOCPP20Data->ChangeAvailability[gunIndex - 1].evse.connectorId = gunIndex;
  9195. sprintf((char *)ShmOCPP20Data->ChangeAvailability[gunIndex - 1].operationalStatus, "%s", operationalStatus);
  9196. }
  9197. else if(gunIndex == 0)
  9198. {
  9199. for(int i=0; i < gunTotalNumber; i++)
  9200. {
  9201. ShmOCPP20Data->ChangeAvailability[i].evse.connectorId = gunIndex;
  9202. sprintf((char *)ShmOCPP20Data->ChangeAvailability[i].operationalStatus, "%s", operationalStatus);
  9203. }
  9204. }
  9205. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  9206. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9207. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  9208. {
  9209. specificId = TRUE;
  9210. }
  9211. if(specificId == FALSE)
  9212. goto end;
  9213. if(strcmp((const char *)operationalStatus, OperationalStatusEnumTypeStr[OperationalStatusEnumType_Inoperative]) == 0)
  9214. {
  9215. //----------------------gunIndex is 0 ------------------------------------------------//
  9216. if(gunIndex == 0)
  9217. {
  9218. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9219. {
  9220. for(int i=0; i < gunTotalNumber; i++)
  9221. {
  9222. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9223. {
  9224. if ((gunType[i] == GUN_TYPE_CHAdeMO)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  9225. {
  9226. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  9227. {
  9228. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9229. goto end;
  9230. }
  9231. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9232. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9233. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9234. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9235. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9236. {
  9237. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9238. goto end;
  9239. }
  9240. }
  9241. }//END FOR CHAdeMO_QUANTITY
  9242. for (int index = 0; index < CCS_QUANTITY; index++)
  9243. {
  9244. if ((gunType[i] == GUN_TYPE_CCS)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  9245. {
  9246. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  9247. {
  9248. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9249. goto end;
  9250. }
  9251. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9252. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9253. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9254. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9255. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9256. {
  9257. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9258. goto end;
  9259. }
  9260. }
  9261. }//END FOR CCS_QUANTITY
  9262. for (int index = 0; index < GB_QUANTITY; index++)
  9263. {
  9264. if ((gunType[i] == GUN_TYPE_GBT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  9265. {
  9266. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  9267. {
  9268. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9269. goto end;
  9270. }
  9271. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9272. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9273. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9274. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9275. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9276. {
  9277. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9278. goto end;
  9279. }
  9280. }
  9281. }// END FOR GB_QUANTITY
  9282. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9283. {
  9284. if ((gunType[i] == GUN_TYPE_DO)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  9285. {
  9286. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  9287. {
  9288. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9289. goto end;
  9290. }
  9291. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  9292. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  9293. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  9294. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  9295. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9296. {
  9297. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9298. goto end;
  9299. }
  9300. }
  9301. }// END FOR DO_QUANTITY
  9302. for (int index = 0; index < AC_QUANTITY; index++)
  9303. {
  9304. if ((gunType[i] == GUN_TYPE_AC)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  9305. {
  9306. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  9307. {
  9308. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9309. goto end;
  9310. }
  9311. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9312. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9313. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9314. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9315. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9316. {
  9317. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9318. goto end;
  9319. }
  9320. }
  9321. }//END FOR AC_QUANTITY
  9322. }// END FOR gunTotalNumber
  9323. }
  9324. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  9325. {
  9326. for(int i=0; i < gunTotalNumber; i++)
  9327. {
  9328. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  9329. {
  9330. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9331. goto end;
  9332. }
  9333. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9334. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  9335. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  9336. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  9337. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9338. {
  9339. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9340. goto end;
  9341. }
  9342. }
  9343. }
  9344. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  9345. goto end;
  9346. }
  9347. //----------------------gunIndex is not 0 ------------------------------------------------//
  9348. //check Transaction active
  9349. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9350. {
  9351. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO))
  9352. {
  9353. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  9354. {
  9355. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9356. goto end;
  9357. }
  9358. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9359. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9360. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9361. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9362. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9363. {
  9364. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9365. goto end;
  9366. }
  9367. else
  9368. {
  9369. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  9370. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  9371. goto end;
  9372. }
  9373. }
  9374. }//END FOR CHAdeMO_QUANTITY
  9375. for (int index = 0; index < CCS_QUANTITY; index++)
  9376. {
  9377. if ((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS))
  9378. {
  9379. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  9380. {
  9381. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9382. goto end;
  9383. }
  9384. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9385. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9386. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9387. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9388. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9389. {
  9390. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9391. goto end;
  9392. }
  9393. else
  9394. {
  9395. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  9396. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  9397. goto end;
  9398. }
  9399. }
  9400. }//END FOR CCS_QUANTITY
  9401. for (int index = 0; index < GB_QUANTITY; index++)
  9402. {
  9403. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))
  9404. {
  9405. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  9406. {
  9407. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9408. goto end;
  9409. }
  9410. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9411. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9412. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9413. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9414. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9415. {
  9416. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9417. goto end;
  9418. }
  9419. else
  9420. {
  9421. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  9422. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  9423. goto end;
  9424. }
  9425. }
  9426. }// END FOR GB_QUANTITY
  9427. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9428. {
  9429. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))
  9430. {
  9431. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  9432. {
  9433. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9434. goto end;
  9435. }
  9436. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  9437. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  9438. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  9439. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  9440. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9441. {
  9442. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9443. goto end;
  9444. }
  9445. else
  9446. {
  9447. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  9448. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  9449. goto end;
  9450. }
  9451. }
  9452. }// END FOR DO_QUANTITY
  9453. for (int index = 0; index < AC_QUANTITY; index++)
  9454. {
  9455. if ((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC))
  9456. {
  9457. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  9458. {
  9459. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9460. goto end;
  9461. }
  9462. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  9463. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  9464. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  9465. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  9466. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  9467. {
  9468. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Scheduled] );
  9469. goto end;
  9470. }
  9471. else
  9472. {
  9473. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  9474. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  9475. goto end;
  9476. }
  9477. }
  9478. }//END FOR AC_QUANTITY
  9479. }//END FOR AvailabilityEnumTypeStr[Inoperative]
  9480. if(strcmp((const char *)operationalStatus, OperationalStatusEnumTypeStr[OperationalStatusEnumType_Operative]) == 0)
  9481. {
  9482. //----------------------gunIndex is 0 ------------------------------------------------//
  9483. if(gunIndex == 0)
  9484. {
  9485. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  9486. {
  9487. for(int i=0; i < gunTotalNumber; i++)
  9488. {
  9489. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9490. {
  9491. 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
  9492. {
  9493. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9494. goto end;
  9495. }
  9496. }//END FOR CHAdeMO_QUANTITY
  9497. for (int index = 0; index < CCS_QUANTITY; index++)
  9498. {
  9499. 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
  9500. {
  9501. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9502. goto end;
  9503. }
  9504. }//END FOR CCS_QUANTITY
  9505. for (int index = 0; index < GB_QUANTITY; index++)
  9506. {
  9507. 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
  9508. {
  9509. //ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  9510. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9511. goto end;
  9512. }
  9513. }// END FOR GB_QUANTITY
  9514. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9515. {
  9516. 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
  9517. {
  9518. //ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  9519. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9520. goto end;
  9521. }
  9522. }// END FOR DO_QUANTITY
  9523. for (int index = 0; index < AC_QUANTITY; index++)
  9524. {
  9525. 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
  9526. {
  9527. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9528. goto end;
  9529. }
  9530. }//END FOR CHAdeMO_QUANTITY
  9531. }// END FOR gunTotalNumber
  9532. }
  9533. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  9534. {
  9535. for(int i=0; i < gunTotalNumber; i++)
  9536. {
  9537. for (int index = 0; index < AC_QUANTITY; index++)
  9538. {
  9539. 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
  9540. {
  9541. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected] );
  9542. goto end;
  9543. }
  9544. }//END FOR CHAdeMO_QUANTITY
  9545. } // END FOR gunTotalNumber
  9546. }
  9547. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  9548. goto end;
  9549. }
  9550. //----------------------gunIndex is not 0 ------------------------------------------------//
  9551. //check Transaction active
  9552. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9553. {
  9554. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_CHAdeMO) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9555. {
  9556. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  9557. goto end;
  9558. }
  9559. }//END FOR CHAdeMO_QUANTITY
  9560. for (int index = 0; index < CCS_QUANTITY; index++)
  9561. {
  9562. if ((((gunIndex > 0)&&(gunType[gunIndex - 1] == GUN_TYPE_CCS)) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9563. {
  9564. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  9565. goto end;
  9566. }
  9567. }//END FOR CCS_QUANTITY
  9568. for (int index = 0; index < GB_QUANTITY; index++)
  9569. {
  9570. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_GBT))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9571. {
  9572. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  9573. goto end;
  9574. }
  9575. }// END FOR GB_QUANTITY
  9576. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9577. {
  9578. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_DO))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9579. {
  9580. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  9581. goto end;
  9582. }
  9583. }// END FOR DO_QUANTITY
  9584. for (int index = 0; index < AC_QUANTITY; index++)
  9585. {
  9586. if (((gunIndex > 0)&&(gunType[gunIndex-1] == GUN_TYPE_AC)) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  9587. {
  9588. sprintf(comfirmstr, "%s", ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Accepted] );
  9589. goto end;
  9590. }
  9591. }//END FOR AC_QUANTITY
  9592. }//END FOR AvailabilityEnumTypeStr[Operative]
  9593. end:
  9594. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9595. {
  9596. sprintf((char *)ShmOCPP20Data->ChangeAvailability[gunIndex - 1].Response_status, "%s", comfirmstr );
  9597. }
  9598. else
  9599. {
  9600. sprintf((char *)ShmOCPP20Data->ChangeAvailability[0].Response_status, "%s", comfirmstr );
  9601. }
  9602. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  9603. {
  9604. if(strstr(comfirmstr, ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected]) == NULL)
  9605. ShmOCPP20Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = ON;
  9606. }
  9607. else if(gunIndex == 0)
  9608. {
  9609. if(strstr(comfirmstr, ChangeAvailabilityStatusEnumTypeStr[ChangeAvailabilityStatusEnumType_Rejected]) == NULL)
  9610. {
  9611. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  9612. ShmOCPP20Data->CsMsg.bits[i].ChangeAvailabilityReq = ON;
  9613. }
  9614. }
  9615. sendChangeAvailabilityConfirmation(uuid, (gunIndex==0?gunIndex:gunIndex-1));
  9616. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9617. return result;
  9618. }
  9619. int handleClearCacheRequest(char *uuid, char *payload)
  9620. {
  9621. mtrace();
  9622. int result = FAIL;
  9623. char rmFileCmd[100]={0};
  9624. struct stat stats;
  9625. DEBUG_INFO("handleClearCacheRequest...\n");
  9626. stat("/Storage/OCPP", &stats);
  9627. // Check for directory existence
  9628. if (S_ISDIR(stats.st_mode) == 1)
  9629. {}
  9630. else
  9631. {
  9632. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  9633. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  9634. system(rmFileCmd);
  9635. }
  9636. /*
  9637. * TODO:
  9638. * 1. Clear cache from sqlite db
  9639. */
  9640. if(1)
  9641. {
  9642. DEBUG_INFO("open AuthorizationCache file failed\n");
  9643. sprintf((char*)ShmOCPP20Data->ClearCache.Response_status, "%s", ClearCacheStatusEnumTypeStr[ClearCacheStatusEnumType_Rejected] );
  9644. }
  9645. else
  9646. {
  9647. DEBUG_INFO("open AuthorizationCache file successful\n");
  9648. sprintf((char*)ShmOCPP20Data->ClearCache.Response_status, "%s", ClearCacheStatusEnumTypeStr[ClearCacheStatusEnumType_Accepted] );
  9649. }
  9650. sendClearCacheConfirmation(uuid);
  9651. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  9652. return result;
  9653. }
  9654. int handleClearChargingProfileRequest(char *uuid, char *payload)
  9655. {
  9656. mtrace();
  9657. int result = FAIL;
  9658. int resultRename;
  9659. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  9660. char chargingProfilePurposeStr[26]={0};
  9661. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  9662. char tempchargingProfilePurposeStr[26]={0};
  9663. char sstr[160]={0};
  9664. char str[100]={0};
  9665. int c = 0;
  9666. char *loc;
  9667. char fname[200]={0};
  9668. char comfirmstr[20]={0};
  9669. char word[1600]={0};
  9670. int clearflag = FALSE;
  9671. int chargingProfileIdIsNULL = FALSE;
  9672. int connectorIsNULL = FALSE;
  9673. int chargingProfilePurposeIsNULL = FALSE;
  9674. int stackLevelIsNULL = FALSE;
  9675. //int GotoEnd = FALSE;
  9676. FILE *fptr1, *fptr2;
  9677. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  9678. int n_chargingProfile=0;
  9679. int isEmptyFile = FALSE;
  9680. char sLineWord[1600]={0};
  9681. char chargingProfiles[10][100]={0};
  9682. int ChargeProfileCount = 0;
  9683. int ch;
  9684. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  9685. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  9686. json_object *ClearChargingProfile;
  9687. ClearChargingProfile = json_tokener_parse(payload);
  9688. if(!is_error(ClearChargingProfile))
  9689. {
  9690. // Optional data
  9691. if(json_object_object_get(ClearChargingProfile, "chargingProfileId") != NULL)
  9692. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "chargingProfileId"));
  9693. else
  9694. chargingProfileIdIsNULL = TRUE;
  9695. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "evseId") != NULL)
  9696. connectorIdInt = json_object_get_int(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "evseId"));
  9697. else
  9698. connectorIsNULL = TRUE;
  9699. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "chargingProfilePurpose") != NULL)
  9700. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "chargingProfilePurpose")));
  9701. else
  9702. chargingProfilePurposeIsNULL = TRUE;
  9703. if(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "stackLevel") != NULL)
  9704. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(ClearChargingProfile, "chargingProfileCriteria"), "stackLevel"));
  9705. else
  9706. stackLevelIsNULL = TRUE;
  9707. }
  9708. json_object_put(ClearChargingProfile);
  9709. if(connectorIsNULL == FALSE)
  9710. {
  9711. switch(connectorIdInt)
  9712. {
  9713. case 0:
  9714. if(chargingProfilePurposeIsNULL == TRUE)
  9715. {
  9716. int l = 0;
  9717. strcpy(fname, ChargePointMaxProfile_JSON);
  9718. if((access(fname,F_OK))!=-1)
  9719. {
  9720. strcpy(chargingProfiles[l], fname);
  9721. l = l + 1;
  9722. }
  9723. strcpy(fname, TxDefaultProfile_0_JSON);
  9724. if((access(fname,F_OK))!=-1)
  9725. {
  9726. strcpy(chargingProfiles[l], fname);
  9727. l = l + 1;
  9728. }
  9729. ChargeProfileCount = l;
  9730. }
  9731. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  9732. {
  9733. strcpy(fname, ChargePointMaxProfile_JSON);
  9734. if((access(fname,F_OK))!=-1)
  9735. {
  9736. strcpy(chargingProfiles[0], fname);
  9737. ChargeProfileCount = 1;
  9738. }
  9739. }
  9740. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9741. {
  9742. strcpy(fname, TxDefaultProfile_0_JSON);
  9743. if((access(fname,F_OK))!=-1)
  9744. {
  9745. strcpy(chargingProfiles[0], fname);
  9746. ChargeProfileCount = 1;
  9747. }
  9748. }
  9749. break;
  9750. default:
  9751. if(chargingProfilePurposeIsNULL == TRUE)
  9752. {
  9753. int m = 0;
  9754. memset(fname, 0, ARRAY_SIZE(fname));
  9755. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9756. if((access(fname,F_OK))!=-1)
  9757. {
  9758. strcpy(chargingProfiles[m], fname);
  9759. m = m + 1;
  9760. }
  9761. memset(fname, 0, ARRAY_SIZE(fname));
  9762. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9763. if((access(fname,F_OK))!=-1)
  9764. {
  9765. strcpy(chargingProfiles[m], fname);
  9766. m = m + 1;
  9767. }
  9768. ChargeProfileCount = m;
  9769. }
  9770. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  9771. {
  9772. //strcpy(fname, TxDefaultProfile_1_JSON);
  9773. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  9774. if((access(fname,F_OK))!=-1)
  9775. {
  9776. strcpy(chargingProfiles[0], fname);
  9777. ChargeProfileCount = 1;
  9778. }
  9779. }
  9780. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  9781. {
  9782. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  9783. if((access(fname,F_OK))!=-1)
  9784. {
  9785. strcpy(chargingProfiles[0], fname);
  9786. ChargeProfileCount = 1;
  9787. }
  9788. }
  9789. //strcpy(fname, ChargePointMaxProfile_JSON );
  9790. break;
  9791. }
  9792. }
  9793. else // Check all Charging Profiles
  9794. {
  9795. int i = 0;
  9796. char fnametemp[200]={0};
  9797. ChargeProfileCount = 0;
  9798. //Check ChargePointMaxProfile.json exit
  9799. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  9800. {
  9801. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  9802. i = i + 1;
  9803. }
  9804. //Check TxDefaultProfile_0.json exit
  9805. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  9806. {
  9807. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  9808. i = i + 1;
  9809. }
  9810. //Check TxDefaultProfile_%d.json
  9811. for(int j=1; j <= gunTotalNumber; j++)
  9812. {
  9813. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9814. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  9815. if((access(fnametemp,F_OK))!=-1)
  9816. {
  9817. strcpy(chargingProfiles[i], fnametemp);
  9818. i = i + 1;
  9819. }
  9820. }
  9821. //Check TxProfile_%d.json
  9822. for(int j=1; j <= gunTotalNumber; j++)
  9823. {
  9824. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  9825. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  9826. if((access(fnametemp,F_OK))!=-1)
  9827. {
  9828. strcpy(chargingProfiles[i], fnametemp);
  9829. i = i + 1;
  9830. }
  9831. }
  9832. ChargeProfileCount = i;
  9833. }// End connectorIsNULL is TRUE
  9834. if(ChargeProfileCount == 0)
  9835. {
  9836. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  9837. goto end;
  9838. }
  9839. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  9840. {
  9841. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  9842. goto end;
  9843. }
  9844. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  9845. {
  9846. memset(str, 0, ARRAY_SIZE(str));
  9847. // clear temp file
  9848. sprintf(str,"rm -f %s",temp);
  9849. system(str);
  9850. for(int k=0; k < ChargeProfileCount; k++)
  9851. {
  9852. memset(str, 0, ARRAY_SIZE(str));
  9853. //clear file in C
  9854. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9855. system(str);
  9856. }
  9857. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  9858. goto end;
  9859. }
  9860. else if(connectorIsNULL == TRUE)
  9861. {
  9862. for(int k=0; k < ChargeProfileCount; k++)
  9863. {
  9864. fptr1 = fopen(chargingProfiles[k], "r");
  9865. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  9866. //Check Charging Profile Count
  9867. while(fscanf(fptr1, "%s", word) != EOF)
  9868. {
  9869. //DEBUG_INFO("word=%s\n",word);
  9870. if(strstr(word, "chargingProfileId")!= NULL)
  9871. {
  9872. //DEBUG_INFO("test chargingProfileId \n");
  9873. n_chargingProfile = n_chargingProfile + 1;
  9874. //DEBUG_INFO("chargingProfileId Found\n");
  9875. }
  9876. }
  9877. rewind(fptr1);
  9878. //search Charging Profile Element
  9879. //int i= 0;
  9880. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9881. {
  9882. //------------------------tempconnectorIdInt------------------------//
  9883. loc = strstr(sLineWord, "connectorId");
  9884. c = 0;
  9885. memset(sstr ,0, sizeof(sstr) );
  9886. while (loc[strlen("connectorId")+2+c] != ',')
  9887. {
  9888. sstr[c] = loc[strlen("connectorId")+2+c];
  9889. c++;
  9890. }
  9891. sstr[c] = '\0';
  9892. tempconnectorIdInt = atoi(sstr);
  9893. printf("file's gun number is %d\n", tempconnectorIdInt);
  9894. //--------------------------chargingProfileId--------------------//
  9895. c = 0;
  9896. loc = strstr(sLineWord, "chargingProfileId");
  9897. memset(sstr ,0, ARRAY_SIZE(sstr));
  9898. while (loc[strlen("chargingProfileId")+2+c] != ',')
  9899. {
  9900. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  9901. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9902. c++;
  9903. }
  9904. sstr[c] = '\0';
  9905. tempchargingProfileIdInt = atoi(sstr);
  9906. //stackLevel
  9907. c = 0;
  9908. loc = strstr(sLineWord, "stackLevel");
  9909. memset(sstr ,0, ARRAY_SIZE(sstr));
  9910. while (loc[strlen("stackLevel")+2+c] != ',')
  9911. {
  9912. sstr[c] = loc[strlen("stackLevel")+2+c];
  9913. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9914. c++;
  9915. }
  9916. sstr[c] = '\0';
  9917. tempstackLevelInt = atoi(sstr);
  9918. c = 0;
  9919. loc = strstr(sLineWord, "chargingProfilePurpose");
  9920. memset(sstr ,0, ARRAY_SIZE(sstr));
  9921. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  9922. {
  9923. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  9924. c++;
  9925. }
  9926. sstr[c] = '\0';
  9927. strcpy(tempchargingProfilePurposeStr, sstr);
  9928. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  9929. {
  9930. //------- not write to fptr2-------//
  9931. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  9932. //clearflag = TRUE;
  9933. }
  9934. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9935. {
  9936. //------- not write to fptr2-------//
  9937. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  9938. }
  9939. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  9940. {
  9941. //------- not write to fptr2-------//
  9942. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  9943. }
  9944. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  9945. {
  9946. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  9947. }
  9948. else
  9949. {
  9950. fprintf(fptr2, sLineWord);//writing data into file
  9951. }
  9952. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9953. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  9954. if(clearflag == TRUE)
  9955. {
  9956. fclose(fptr1);
  9957. fclose(fptr2);
  9958. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9959. system(str);
  9960. // clear temp file
  9961. sprintf(str,"rm -f %s",temp);
  9962. system(str);
  9963. }
  9964. else
  9965. {
  9966. fclose(fptr1);
  9967. fclose(fptr2);
  9968. memset(str, 0, ARRAY_SIZE(str));
  9969. sprintf(str,"rm -f %s",chargingProfiles[k]);
  9970. system(str);
  9971. resultRename = rename(temp, chargingProfiles[k]);
  9972. if(resultRename == 0)
  9973. {
  9974. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  9975. }
  9976. else
  9977. {
  9978. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  9979. }
  9980. if(comfirmstr[0]== 0)
  9981. {
  9982. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  9983. }
  9984. //Check chargingProfile is empty file
  9985. /*------ Read the file ----------------*/
  9986. fptr1=fopen(chargingProfiles[k],"r");
  9987. ch=fgetc(fptr1);
  9988. rewind(fptr1);
  9989. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  9990. if(ch!=EOF)
  9991. {
  9992. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  9993. {
  9994. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  9995. if(sLineWord[0]=='\0')
  9996. {
  9997. isEmptyFile = TRUE;
  9998. break;
  9999. }
  10000. else
  10001. {
  10002. isEmptyFile = FALSE;
  10003. break;
  10004. }
  10005. }
  10006. }
  10007. else
  10008. isEmptyFile = TRUE;
  10009. fclose(fptr1);
  10010. if(isEmptyFile == TRUE)
  10011. {
  10012. memset(str, 0, ARRAY_SIZE(str));
  10013. sprintf(str,"rm -f %s",chargingProfiles[k]);
  10014. system(str);
  10015. }
  10016. }
  10017. }// End of while(int k=0; k < ChargePointCount; k++)
  10018. }
  10019. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  10020. {
  10021. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  10022. for(int k=0; k < ChargeProfileCount; k++)
  10023. {
  10024. fptr1 = fopen(chargingProfiles[k], "r");
  10025. fptr2 = fopen(temp, "w+");
  10026. //Check Charging Profile Count
  10027. while(fscanf(fptr1, "%s", word) != EOF)
  10028. {
  10029. //DEBUG_INFO("word=%s\n",word);
  10030. if(strstr(word, "chargingProfileId")!= NULL)
  10031. {
  10032. n_chargingProfile = n_chargingProfile + 1;
  10033. }
  10034. }
  10035. rewind(fptr1);
  10036. //search Charging Profile Element
  10037. //int i= 0;
  10038. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  10039. {
  10040. //*************************tempconnectorIdInt*********************************/
  10041. loc = strstr(sLineWord, "connectorId");
  10042. c = 0;
  10043. memset(sstr ,0, ARRAY_SIZE(sstr));
  10044. while (loc[strlen("connectorId")+2+c] != ',')
  10045. {
  10046. sstr[c] = loc[strlen("connectorId")+2+c];
  10047. c++;
  10048. }
  10049. sstr[c] = '\0';
  10050. tempconnectorIdInt = atoi(sstr);
  10051. //chargingProfileId
  10052. c = 0;
  10053. loc = strstr(sLineWord, "chargingProfileId");
  10054. memset(sstr ,0, ARRAY_SIZE(sstr));
  10055. while (loc[strlen("chargingProfileId")+2+c] != ',')
  10056. {
  10057. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  10058. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10059. c++;
  10060. }
  10061. sstr[c] = '\0';
  10062. tempchargingProfileIdInt = atoi(sstr);
  10063. //stackLevel
  10064. c = 0;
  10065. loc = strstr(sLineWord, "stackLevel");
  10066. memset(sstr ,0, ARRAY_SIZE(sstr));
  10067. while (loc[strlen("stackLevel")+2+c] != ',')
  10068. {
  10069. sstr[c] = loc[strlen("stackLevel")+2+c];
  10070. //printf("i=%d sstr=%c\n",c, sstr[c]);
  10071. c++;
  10072. }
  10073. sstr[c] = '\0';
  10074. tempstackLevelInt = atoi(sstr);
  10075. c = 0;
  10076. loc = strstr(sLineWord, "chargingProfilePurpose");
  10077. memset(sstr ,0, ARRAY_SIZE(sstr));
  10078. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  10079. {
  10080. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  10081. c++;
  10082. }
  10083. sstr[c] = '\0';
  10084. strcpy(tempchargingProfilePurposeStr, sstr);
  10085. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  10086. {
  10087. //------- not write to fptr2-------//
  10088. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  10089. //clearflag = TRUE;
  10090. }
  10091. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  10092. {
  10093. //------- not write to fptr2-------//
  10094. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  10095. }
  10096. else if(stackLevelIsNULL == TRUE)
  10097. {
  10098. //Clear Whole File
  10099. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted] );
  10100. clearflag = TRUE;
  10101. break;
  10102. }
  10103. else
  10104. {
  10105. fprintf(fptr2, sLineWord);//writing data into file
  10106. }
  10107. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  10108. }
  10109. if(clearflag == TRUE)
  10110. {
  10111. fclose(fptr1);
  10112. fclose(fptr2);
  10113. sprintf(str,"rm -f %s",chargingProfiles[k]);
  10114. system(str);
  10115. // clear temp file
  10116. sprintf(str,"rm -f %s",temp);
  10117. system(str);
  10118. }
  10119. else
  10120. {
  10121. fclose(fptr1);
  10122. fclose(fptr2);
  10123. sprintf(str,"rm -f %s",chargingProfiles[k]);
  10124. system(str);
  10125. resultRename = rename(temp, chargingProfiles[k]);
  10126. if(resultRename == 0)
  10127. {
  10128. DEBUG_INFO("File ChargingProfile renamed successfully");
  10129. }
  10130. else
  10131. {
  10132. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  10133. }
  10134. if(comfirmstr[0]== 0)
  10135. {
  10136. sprintf(comfirmstr, "%s", ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Unknown] );
  10137. }
  10138. //Check chargingProfile is empty file
  10139. /*------ Read the file ----------------*/
  10140. fptr1=fopen(chargingProfiles[k],"r");
  10141. ch=fgetc(fptr1);
  10142. rewind(fptr1);
  10143. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  10144. if(ch!=EOF)
  10145. {
  10146. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  10147. {
  10148. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  10149. if(sLineWord[0]=='\0')
  10150. {
  10151. isEmptyFile = TRUE;
  10152. break;
  10153. }
  10154. else
  10155. {
  10156. isEmptyFile = FALSE;
  10157. break;
  10158. }
  10159. }
  10160. }
  10161. else
  10162. isEmptyFile = TRUE;
  10163. fclose(fptr1);
  10164. if(isEmptyFile == TRUE)
  10165. {
  10166. memset(str, 0, ARRAY_SIZE(str));
  10167. sprintf(str,"rm -f %s",chargingProfiles[k]);
  10168. system(str);
  10169. }
  10170. /*------- End of reading ---------------*/
  10171. }
  10172. } // while(int k=0; k < ChargeProfileCount; k++)
  10173. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  10174. end:
  10175. if(strcmp(comfirmstr, ClearChargingProfileStatusEnumTypeStr[ClearChargingProfileStatusEnumType_Accepted]) == 0)
  10176. {
  10177. if(connectorIdInt == 0)
  10178. {
  10179. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  10180. {
  10181. checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx], 0, TRUE);
  10182. }
  10183. }
  10184. else
  10185. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP20Data->SmartChargingProfile[connectorIdInt-1], 0, TRUE);
  10186. }
  10187. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  10188. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10189. return result;
  10190. }
  10191. int handleClearDisplayMessageRequest(char *uuid, char *payload)
  10192. {
  10193. mtrace();
  10194. int result = FAIL;
  10195. json_object *ClearDisplayMessage;
  10196. DEBUG_INFO("handleClearDisplayMessageRequest...\n");
  10197. sprintf((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status, ClearMessageStatusEnumTypeStr[ClearMessageStatusEnumType_Unknown]);
  10198. ClearDisplayMessage = json_tokener_parse(payload);
  10199. if(!is_error(ClearDisplayMessage))
  10200. {
  10201. // Required data
  10202. if(json_object_object_get(ClearDisplayMessage, "id") != NULL)
  10203. {
  10204. ShmOCPP20Data->ClearDisplayMessage.id = json_object_get_double(json_object_object_get(ClearDisplayMessage, "id"));
  10205. sprintf((char*)ShmOCPP20Data->ClearDisplayMessage.Response_status, ClearMessageStatusEnumTypeStr[ClearMessageStatusEnumType_Accepted]);
  10206. }
  10207. }
  10208. json_object_put(ClearDisplayMessage);
  10209. sendCostUpdatedConfirmation(uuid);
  10210. return result;
  10211. }
  10212. int handleClearVariableMonitoringRequest(char *uuid, char *payload)
  10213. {
  10214. mtrace();
  10215. int result = FAIL;
  10216. json_object *ClearVariableMonitorin;
  10217. DEBUG_INFO("handleClearVariableMonitoringRequest...\n");
  10218. ClearVariableMonitorin = json_tokener_parse(payload);
  10219. if(!is_error(ClearVariableMonitorin))
  10220. {
  10221. // Required data
  10222. if(json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id")) <= ARRAY_SIZE(ShmOCPP20Data->ClearVariableMonitoring.id))
  10223. {
  10224. for(int idx=0;idx<json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id"));idx++)
  10225. {
  10226. ShmOCPP20Data->ClearVariableMonitoring.id[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(ClearVariableMonitorin, "id"), idx));
  10227. /*
  10228. * TODO:
  10229. * 1. Check response
  10230. */
  10231. ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].id = ShmOCPP20Data->ClearVariableMonitoring.id[idx];
  10232. strcpy((char*)ShmOCPP20Data->ClearVariableMonitoring.Response_clearMonitoringResult[idx].status, ClearMonitoringStatusEnumTypeStr[ClearMonitoringStatusEnumType_Accepted]);
  10233. }
  10234. sendClearVariableMonitoringConfirmation(uuid, json_object_array_length(json_object_object_get(ClearVariableMonitorin, "id")));
  10235. }
  10236. }
  10237. json_object_put(ClearVariableMonitorin);
  10238. return result;
  10239. }
  10240. int handleCostUpdatedRequest(char *uuid, char *payload)
  10241. {
  10242. mtrace();
  10243. int result = FAIL;
  10244. json_object *CostUpdate;
  10245. DEBUG_INFO("handleCostUpdatedRequest...\n");
  10246. CostUpdate = json_tokener_parse(payload);
  10247. if(!is_error(CostUpdate))
  10248. {
  10249. // Required data
  10250. if(json_object_object_get(CostUpdate, "totalCost") != NULL)
  10251. {
  10252. ShmOCPP20Data->CostUpdated.totalCost = json_object_get_double(json_object_object_get(CostUpdate, "totalCost"));
  10253. }
  10254. if(json_object_object_get(CostUpdate, "transactionId") != NULL)
  10255. {
  10256. sprintf((char*)ShmOCPP20Data->CostUpdated.transactionId, "%s", json_object_get_string(json_object_object_get(CostUpdate, "transactionId")));
  10257. }
  10258. }
  10259. json_object_put(CostUpdate);
  10260. sendCostUpdatedConfirmation(uuid);
  10261. return result;
  10262. }
  10263. int handleCustomerInformationRequest(char *uuid, char *payload)
  10264. {
  10265. mtrace();
  10266. int result = FAIL;
  10267. json_object *CustomerInformation;
  10268. DEBUG_INFO("handleCustomerInformationRequest...\n");
  10269. CustomerInformation = json_tokener_parse(payload);
  10270. if(!is_error(CustomerInformation))
  10271. {
  10272. // Required data
  10273. if(json_object_object_get(CustomerInformation, "requestId") != NULL)
  10274. {
  10275. ShmOCPP20Data->CustomerInformation.requestId = json_object_get_int(json_object_object_get(CustomerInformation, "requestId"));
  10276. }
  10277. if(json_object_object_get(CustomerInformation, "report") != NULL)
  10278. {
  10279. ShmOCPP20Data->CustomerInformation.report = json_object_get_boolean(json_object_object_get(CustomerInformation, "report"));
  10280. }
  10281. if(json_object_object_get(CustomerInformation, "clear") != NULL)
  10282. {
  10283. ShmOCPP20Data->CustomerInformation.report = json_object_get_boolean(json_object_object_get(CustomerInformation, "clear"));
  10284. }
  10285. // Optional data
  10286. if(json_object_object_get(CustomerInformation, "idToken") != NULL)
  10287. {
  10288. if(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "idToken") != NULL)
  10289. {
  10290. sprintf((char*)ShmOCPP20Data->CustomerInformation.idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "idToken")));
  10291. }
  10292. if(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "type") != NULL)
  10293. {
  10294. sprintf((char*)ShmOCPP20Data->CustomerInformation.idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "idToken"), "type")));
  10295. }
  10296. }
  10297. if(json_object_object_get(CustomerInformation, "customerCertificate") != NULL)
  10298. {
  10299. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "hashAlgorithm") != NULL)
  10300. {
  10301. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "hashAlgorithm")));
  10302. }
  10303. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerNameHash") != NULL)
  10304. {
  10305. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerNameHash")));
  10306. }
  10307. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerKeyHash") != NULL)
  10308. {
  10309. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "issuerKeyHash")));
  10310. }
  10311. if(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "serialNumber") != NULL)
  10312. {
  10313. sprintf((char*)ShmOCPP20Data->CustomerInformation.customerCertificate.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(CustomerInformation, "customerCertificate"), "serialNumber")));
  10314. }
  10315. }
  10316. strcpy((char*)ShmOCPP20Data->CustomerInformation.Response_status, CustomerInformationStatusEnumTypeStr[CustomerInformationStatusEnumType_Accepted]);
  10317. }
  10318. else
  10319. strcpy((char*)ShmOCPP20Data->CustomerInformation.Response_status, CustomerInformationStatusEnumTypeStr[CustomerInformationStatusEnumType_Rejected]);
  10320. json_object_put(CustomerInformation);
  10321. sendCustomerInformationConfirmation(uuid);
  10322. return result;
  10323. }
  10324. void createFirmwareVersionByDataTransfer(void)
  10325. {
  10326. json_object *FirmwareDataTransfer = json_object_new_object();
  10327. // AC & DC model
  10328. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  10329. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  10330. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  10331. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  10332. // DC model
  10333. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]!='O')
  10334. {
  10335. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  10336. {
  10337. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  10338. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  10339. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  10340. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  10341. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  10342. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  10343. }
  10344. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  10345. ((gunType[1] != GUN_TYPE_UNKNOWN) || (gunType[2] != GUN_TYPE_UNKNOWN) || (gunType[3] != GUN_TYPE_UNKNOWN)))
  10346. {
  10347. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  10348. }
  10349. }
  10350. else
  10351. {
  10352. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  10353. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  10354. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  10355. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  10356. json_object_object_add(FirmwareDataTransfer, "DD0_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuBootLoadFwRev));
  10357. json_object_object_add(FirmwareDataTransfer, "DD0_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuKernelFwRev));
  10358. json_object_object_add(FirmwareDataTransfer, "DD0_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuRootFsFwRev));
  10359. json_object_object_add(FirmwareDataTransfer, "DD0_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].CsuPrimFwRev));
  10360. json_object_object_add(FirmwareDataTransfer, "DD0_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].FanModuleFwRev));
  10361. json_object_object_add(FirmwareDataTransfer, "DD0_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].RelayModuleFwRev));
  10362. json_object_object_add(FirmwareDataTransfer, "DD0_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].LedModuleFwRev));
  10363. json_object_object_add(FirmwareDataTransfer, "DD0_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector1FwRev));
  10364. json_object_object_add(FirmwareDataTransfer, "DD0_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[0].Connector2FwRev));
  10365. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev) > 0)
  10366. json_object_object_add(FirmwareDataTransfer, "DD1_CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuBootLoadFwRev));
  10367. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev) > 0)
  10368. json_object_object_add(FirmwareDataTransfer, "DD1_CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuKernelFwRev));
  10369. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev) > 0)
  10370. json_object_object_add(FirmwareDataTransfer, "DD1_CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuRootFsFwRev));
  10371. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev) > 0)
  10372. json_object_object_add(FirmwareDataTransfer, "DD1_CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].CsuPrimFwRev));
  10373. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev) > 0)
  10374. json_object_object_add(FirmwareDataTransfer, "DD1_FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].FanModuleFwRev));
  10375. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev) > 0)
  10376. json_object_object_add(FirmwareDataTransfer, "DD1_RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].RelayModuleFwRev));
  10377. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev) > 0)
  10378. json_object_object_add(FirmwareDataTransfer, "DD1_LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].LedModuleFwRev));
  10379. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev) > 0)
  10380. json_object_object_add(FirmwareDataTransfer, "DD1_Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector1FwRev));
  10381. if(strlen((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev) > 0)
  10382. json_object_object_add(FirmwareDataTransfer, "DD1_Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[1].Connector2FwRev));
  10383. }
  10384. // 4G model
  10385. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  10386. {
  10387. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  10388. }
  10389. sprintf((char*)ShmOCPP20Data->DataTransfer[0].vendorId, "%s", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  10390. sprintf((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_FirmwareVersion");
  10391. sprintf((char*)ShmOCPP20Data->DataTransfer[0].data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  10392. json_object_put(FirmwareDataTransfer);
  10393. }
  10394. int handleDataTransferRequest(char *uuid, char *payload)
  10395. {
  10396. mtrace();
  10397. int result = PASS;
  10398. DEBUG_INFO("handleDataTransferRequest...\n");
  10399. if((uuid != NULL) && (payload != NULL))
  10400. {
  10401. json_object *DataTransfer;
  10402. DataTransfer = json_tokener_parse(payload);
  10403. if(!is_error(DataTransfer))
  10404. {
  10405. // Required data
  10406. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  10407. sprintf((char*)ShmOCPP20Data->DataTransfer[0].vendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  10408. // Optional data
  10409. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  10410. sprintf((char*)ShmOCPP20Data->DataTransfer[0].messageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  10411. if(json_object_object_get(DataTransfer, "data") != NULL)
  10412. sprintf((char*)ShmOCPP20Data->DataTransfer[0].data, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  10413. result = PASS;
  10414. }
  10415. json_object_put(DataTransfer);
  10416. if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_FirmwareVersion") != NULL)
  10417. {
  10418. // Send all moudle firmware version on EVSE
  10419. createFirmwareVersionByDataTransfer();
  10420. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  10421. }
  10422. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_Tmate") != NULL)
  10423. {
  10424. system("/usr/bin/run_tmate_restart.sh &");
  10425. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  10426. }
  10427. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "SetLEDBar") != NULL)
  10428. {
  10429. json_object *data;
  10430. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  10431. if(!is_error(data))
  10432. {
  10433. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  10434. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  10435. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  10436. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  10437. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  10438. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  10439. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  10440. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  10441. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  10442. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  10443. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  10444. }
  10445. else
  10446. {
  10447. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  10448. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  10449. }
  10450. json_object_put(data);
  10451. }
  10452. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_ConfigQR") != NULL)
  10453. {
  10454. json_object *data;
  10455. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  10456. if(!is_error(data))
  10457. {
  10458. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  10459. if(json_object_object_get(data, "Content_Type") != NULL)
  10460. {
  10461. if((0 <= json_object_get_int(json_object_object_get(data, "Content_Type"))) && (json_object_get_int(json_object_object_get(data, "Content_Type")) <= 1))
  10462. {
  10463. ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode = json_object_get_int(json_object_object_get(data, "Content_Type"));
  10464. if(json_object_object_get(data, "Customization_Conent") != NULL)
  10465. {
  10466. sprintf((char*)ShmSysConfigAndInfo->SysConfig.QRCodeContent, "%s", json_object_get_string(json_object_object_get(data, "Customization_Conent")));
  10467. }
  10468. }
  10469. else
  10470. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  10471. }
  10472. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10473. }
  10474. else
  10475. {
  10476. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  10477. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  10478. }
  10479. json_object_put(data);
  10480. }
  10481. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_DsiplayLcdPage") != NULL)
  10482. {
  10483. json_object *data;
  10484. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  10485. if(!is_error(data))
  10486. {
  10487. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  10488. if(json_object_object_get(data, "Page_Index") != NULL)
  10489. {
  10490. ShmSysConfigAndInfo->SysConfig.LcdOveride.page_index = json_object_get_int(json_object_object_get(data, "Page_Index"));
  10491. }
  10492. if(json_object_object_get(data, "Duration") != NULL)
  10493. {
  10494. ShmSysConfigAndInfo->SysConfig.LcdOveride.duration = json_object_get_int(json_object_object_get(data, "Duration"));
  10495. }
  10496. ShmSysConfigAndInfo->SysConfig.LcdOveride.isOverideReq = 1;
  10497. }
  10498. else
  10499. {
  10500. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  10501. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  10502. }
  10503. json_object_put(data);
  10504. }
  10505. else if(strstr((char*)ShmOCPP20Data->DataTransfer[0].messageId, "ID_CpConfiguration") != NULL)
  10506. {
  10507. json_object *data;
  10508. data = json_tokener_parse((char*)ShmOCPP20Data->DataTransfer[0].data);
  10509. if(!is_error(data))
  10510. {
  10511. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]);
  10512. if(json_object_object_get(data, "MaxChargingCurrent") != NULL)
  10513. {
  10514. if(json_object_get_int(json_object_object_get(data, "MaxChargingCurrent")) >= 0)
  10515. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent = json_object_get_int(json_object_object_get(data, "MaxChargingCurrent"));
  10516. else
  10517. {
  10518. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  10519. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  10520. }
  10521. }
  10522. if(json_object_object_get(data, "MaxChargingDuration") != NULL)
  10523. {
  10524. if(json_object_get_int(json_object_object_get(data, "MaxChargingDuration")) >= 0)
  10525. ShmSysConfigAndInfo->SysConfig.MaxChargingDuration = json_object_get_int(json_object_object_get(data, "MaxChargingDuration"));
  10526. else
  10527. {
  10528. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  10529. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  10530. }
  10531. }
  10532. if(json_object_object_get(data, "MaxChargingEnergy") != NULL)
  10533. {
  10534. if(json_object_get_int(json_object_object_get(data, "MaxChargingEnergy")) >= 0)
  10535. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy = json_object_get_int(json_object_object_get(data, "MaxChargingEnergy"));
  10536. else
  10537. {
  10538. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  10539. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  10540. }
  10541. }
  10542. if(json_object_object_get(data, "MaxChargingPower") != NULL)
  10543. {
  10544. if(json_object_get_int(json_object_object_get(data, "MaxChargingPower")) >= 0)
  10545. ShmSysConfigAndInfo->SysConfig.MaxChargingPower = json_object_get_int(json_object_object_get(data, "MaxChargingPower"));
  10546. else
  10547. {
  10548. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  10549. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  10550. }
  10551. }
  10552. if(json_object_object_get(data, "OfflineMaxChargeEnergy") != NULL)
  10553. {
  10554. if(json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy")) >= 0)
  10555. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = json_object_get_int(json_object_object_get(data, "OfflineMaxChargeEnergy"));
  10556. else
  10557. {
  10558. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  10559. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  10560. }
  10561. }
  10562. if(json_object_object_get(data, "OfflinePolicy") != NULL)
  10563. {
  10564. if((json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 0) ||
  10565. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 2) ||
  10566. (json_object_get_int(json_object_object_get(data, "OfflinePolicy")) == 3))
  10567. ShmSysConfigAndInfo->SysConfig.OfflinePolicy = json_object_get_int(json_object_object_get(data, "OfflinePolicy"));
  10568. else
  10569. {
  10570. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  10571. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  10572. }
  10573. }
  10574. if(strstr((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Accepted]) != NULL)
  10575. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  10576. }
  10577. else
  10578. {
  10579. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_Rejected]);
  10580. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data, "Configuration content something wrong.");
  10581. }
  10582. json_object_put(data);
  10583. }
  10584. else
  10585. {
  10586. // Can not find valid message id
  10587. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_UnknownMessageId]);
  10588. sprintf((char*)ShmOCPP20Data->DataTransfer[0].Response_data,"vendorId: %s messageId: %s data: %s"
  10589. ,ShmOCPP20Data->DataTransfer[0].vendorId
  10590. ,ShmOCPP20Data->DataTransfer[0].messageId
  10591. ,ShmOCPP20Data->DataTransfer[0].data);
  10592. }
  10593. }
  10594. else
  10595. {
  10596. strcpy((char*)ShmOCPP20Data->DataTransfer[0].Response_status, DataTransferStatusEnumTypeStr[DataTransferStatusEnumType_UnknownMessageId]);
  10597. result = FAIL;
  10598. }
  10599. sendDataTransferConfirmation(uuid, 0);
  10600. return result;
  10601. }
  10602. int handleDeleteCertificateRequest(char *uuid, char *payload)
  10603. {
  10604. mtrace();
  10605. int result = FAIL;
  10606. json_object *DeleteCertificate;
  10607. DEBUG_INFO("handleDeleteCertificateRequest...\n");
  10608. DeleteCertificate = json_tokener_parse(payload);
  10609. if(!is_error(DeleteCertificate))
  10610. {
  10611. memset(&ShmOCPP20Data->DeleteCertificate, 0, sizeof(struct DeleteCertificate_20));
  10612. memcpy(&ShmOCPP20Data->DeleteCertificate.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->DeleteCertificate.guid));
  10613. // Required data
  10614. if(json_object_object_get(DeleteCertificate, "certificateHashData") != NULL)
  10615. {
  10616. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm") != NULL)
  10617. {
  10618. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.hashAlgorithm, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "hashAlgorithm")));
  10619. }
  10620. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash") != NULL)
  10621. {
  10622. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerNameHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerNameHash")));
  10623. }
  10624. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash") != NULL)
  10625. {
  10626. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.issuerKeyHash, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "issuerKeyHash")));
  10627. }
  10628. if(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber") != NULL)
  10629. {
  10630. sprintf((char*)ShmOCPP20Data->DeleteCertificate.certificateHashData.serialNumber, "%s", json_object_get_string(json_object_object_get(json_object_object_get(DeleteCertificate, "certificateHashData"), "serialNumber")));
  10631. }
  10632. /*
  10633. * TODO:
  10634. * 1. Delete certification and response
  10635. */
  10636. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, DeleteCertificateStatusEnumTypeStr[DeleteCertificateStatusEnumType_Accepted]);
  10637. }
  10638. }
  10639. else
  10640. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, DeleteCertificateStatusEnumTypeStr[DeleteCertificateStatusEnumType_Failed]);
  10641. json_object_put(DeleteCertificate);
  10642. sendDeleteCertificateConfirmation(uuid);
  10643. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  10644. return result;
  10645. }
  10646. int handleGetBaseReportRequest(char *uuid, char *payload)
  10647. {
  10648. mtrace();
  10649. int result = FAIL;
  10650. json_object *GetBaseRepor;
  10651. DEBUG_INFO("handleGetBaseReportRequest...\n");
  10652. GetBaseRepor = json_tokener_parse(payload);
  10653. if(!is_error(GetBaseRepor))
  10654. {
  10655. memset(&ShmOCPP20Data->GetBaseReport, 0, sizeof(struct GetBaseReport_20));
  10656. memcpy(&ShmOCPP20Data->GetBaseReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetBaseReport.guid));
  10657. // Required data
  10658. if(json_object_object_get(GetBaseRepor, "requestId") != NULL)
  10659. {
  10660. ShmOCPP20Data->GetBaseReport.requestId = json_object_get_int(json_object_object_get(GetBaseRepor, "requestId"));
  10661. }
  10662. if(json_object_object_get(GetBaseRepor, "reportBase") != NULL)
  10663. {
  10664. sprintf((char*)ShmOCPP20Data->GetBaseReport.reportBase, "%s", json_object_get_string(json_object_object_get(GetBaseRepor, "reportBase")));
  10665. }
  10666. if(strcmp((char*)ShmOCPP20Data->GetBaseReport.reportBase, ReportBaseEnumTypeStr[ReportBaseEnumType_SummaryInventory]) == 0)
  10667. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  10668. else
  10669. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  10670. }
  10671. else
  10672. strcpy((char*)ShmOCPP20Data->GetBaseReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_NotSupported]);
  10673. json_object_put(GetBaseRepor);
  10674. sendGetBaseReportConfirmation(uuid);
  10675. return result;
  10676. }
  10677. int handleGetChargingProfilesRequest(char *uuid, char *payload)
  10678. {
  10679. mtrace();
  10680. int result = FAIL;
  10681. int gun_index = -1;
  10682. json_object *GetChargingProfiles;
  10683. DEBUG_INFO("handleGetChargingProfilesRequest...\n");
  10684. GetChargingProfiles = json_tokener_parse(payload);
  10685. if(!is_error(GetChargingProfiles))
  10686. {
  10687. if(json_object_object_get(GetChargingProfiles, "evseId") != NULL)
  10688. {
  10689. 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;
  10690. }
  10691. if(gun_index >-1)
  10692. {
  10693. memset(&ShmOCPP20Data->GetChargingProfiles[gun_index], 0, sizeof(struct GetChargingProfiles_20));
  10694. memcpy(&ShmOCPP20Data->GetChargingProfiles[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetChargingProfiles[gun_index].guid));
  10695. // Required data
  10696. if(json_object_object_get(GetChargingProfiles, "requestId") != NULL)
  10697. {
  10698. ShmOCPP20Data->GetChargingProfiles[gun_index].requestId = json_object_get_int(json_object_object_get(GetChargingProfiles, "requestId"));
  10699. }
  10700. if(json_object_object_get(GetChargingProfiles, "chargingProfile") != NULL)
  10701. {
  10702. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfilePurpose") != NULL)
  10703. {
  10704. sprintf((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.chargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfilePurpose")));
  10705. }
  10706. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "stackLevel") != NULL)
  10707. {
  10708. ShmOCPP20Data->GetChargingProfiles[gun_index].chargingProfile.stackLevel = json_object_get_int(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "stackLevel"));
  10709. }
  10710. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingLimitSource") != NULL)
  10711. {
  10712. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingLimitSource"));idx++)
  10713. {
  10714. 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)));
  10715. }
  10716. }
  10717. if(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfileId") != NULL)
  10718. {
  10719. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(GetChargingProfiles, "chargingProfile"), "chargingProfileId"));idx++)
  10720. {
  10721. 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));
  10722. }
  10723. }
  10724. }
  10725. strcpy((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status, GetChargingProfileStatusEnumTypeStr[GetChargingProfileStatusEnumType_Accepted]);
  10726. }
  10727. else
  10728. strcpy((char*)ShmOCPP20Data->GetChargingProfiles[gun_index].Response_status, GetChargingProfileStatusEnumTypeStr[GetChargingProfileStatusEnumType_NoProfiles]);
  10729. }
  10730. json_object_put(GetChargingProfiles);
  10731. sendGetChargingProfilesConfirmation(uuid, gun_index);
  10732. return result;
  10733. }
  10734. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  10735. {
  10736. mtrace();
  10737. int result = FAIL;
  10738. int connectorIdInt, durationInt;
  10739. char chargingRateUnitStr[4]={0};
  10740. char comfirmstr[20];
  10741. int confirmPeriods = 0;
  10742. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  10743. json_object *GetCompositeSchedule;
  10744. GetCompositeSchedule = json_tokener_parse(payload);
  10745. if(!is_error(GetCompositeSchedule))
  10746. {
  10747. // Required data
  10748. if(json_object_object_get(GetCompositeSchedule, "evseId") != NULL)
  10749. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "evseId"));
  10750. else
  10751. connectorIdInt = -1;
  10752. if(json_object_object_get(GetCompositeSchedule, "duration"))
  10753. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  10754. else
  10755. durationInt = 86400;
  10756. // Optional data
  10757. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  10758. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  10759. }
  10760. json_object_put(GetCompositeSchedule);
  10761. memset(ShmOCPP20Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  10762. if((connectorIdInt == 0) ||
  10763. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  10764. {
  10765. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  10766. struct ChargingProfileType tmpProfile[1];
  10767. memset(&ShmOCPP20Data->GetCompositeSchedule[gun_index], 0, sizeof(struct GetCompositeSchedule_20));
  10768. memcpy(&ShmOCPP20Data->GetCompositeSchedule[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].guid));
  10769. if(strstr(chargingRateUnitStr, "W") != NULL)
  10770. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], 0, FALSE);
  10771. else
  10772. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0], 0, TRUE);
  10773. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod);idx++)
  10774. {
  10775. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].chargingSchedule[0].chargingSchedulePeriod[idx].startPeriod);
  10776. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].chargingSchedule[0].chargingSchedulePeriod[idx].limit);
  10777. }
  10778. memcpy(&ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule, &tmpProfile[0].chargingSchedule[0], sizeof(struct CompositeScheduleType));
  10779. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod);idx++)
  10780. {
  10781. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].startPeriod);
  10782. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit);
  10783. if((ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].startPeriod==0) &&
  10784. (ShmOCPP20Data->GetCompositeSchedule[gun_index].Response_schedule.chargingSchedule.chargingSchedulePeriod[idx].limit==0) &&
  10785. (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))
  10786. {
  10787. confirmPeriods = idx;
  10788. break;
  10789. }
  10790. }
  10791. if((confirmPeriods == 0) && (tmpProfile[0].id > 0))
  10792. {
  10793. confirmPeriods += 1;
  10794. }
  10795. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  10796. }
  10797. else
  10798. {
  10799. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusEnumTypeStr[GenericStatusEnumType_Rejected]);
  10800. }
  10801. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  10802. return result;
  10803. }
  10804. int handleGetDisplayMessagesRequest(char *uuid, char *payload)
  10805. {
  10806. mtrace();
  10807. int result = FAIL;
  10808. json_object *GetDisplayMessages;
  10809. DEBUG_INFO("handleGetDisplayMessagesRequest...\n");
  10810. GetDisplayMessages = json_tokener_parse(payload);
  10811. if(!is_error(GetDisplayMessages))
  10812. {
  10813. memset(&ShmOCPP20Data->GetDisplayMessages, 0, sizeof(struct GetDisplayMessages_20));
  10814. memcpy(&ShmOCPP20Data->GetDisplayMessages.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetDisplayMessages.guid));
  10815. // Required data
  10816. if(json_object_object_get(GetDisplayMessages, "requestId") != NULL)
  10817. {
  10818. ShmOCPP20Data->GetDisplayMessages.requestId = json_object_get_int(json_object_object_get(GetDisplayMessages, "requestId"));
  10819. }
  10820. // Optional data
  10821. if(json_object_object_get(GetDisplayMessages, "priority") != NULL)
  10822. {
  10823. sprintf((char*)ShmOCPP20Data->GetDisplayMessages.priority, "%s", json_object_get_string(json_object_object_get(GetDisplayMessages, "priority")));
  10824. }
  10825. if(json_object_object_get(GetDisplayMessages, "state") != NULL)
  10826. {
  10827. sprintf((char*)ShmOCPP20Data->GetDisplayMessages.state, "%s", json_object_get_string(json_object_object_get(GetDisplayMessages, "state")));
  10828. }
  10829. if(json_object_array_length(json_object_object_get(GetDisplayMessages, "id")) <= ARRAY_SIZE(ShmOCPP20Data->GetDisplayMessages.id))
  10830. {
  10831. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetDisplayMessages, "id"));idx++)
  10832. {
  10833. ShmOCPP20Data->GetDisplayMessages.id[idx] = json_object_get_int(json_object_array_get_idx(json_object_object_get(GetDisplayMessages, "id"), idx));
  10834. }
  10835. strcpy((char*)ShmOCPP20Data->GetDisplayMessages.Response_status, GetDisplayMessagesStatusEnumTypeStr[GetDisplayMessagesStatusEnumType_Accepted]);
  10836. ShmOCPP20Data->MsMsg.bits.GetDisplayMessagesReq = ON;
  10837. }
  10838. else
  10839. strcpy((char*)ShmOCPP20Data->GetDisplayMessages.Response_status, GetDisplayMessagesStatusEnumTypeStr[GetDisplayMessagesStatusEnumType_Unknown]);
  10840. }
  10841. json_object_put(GetDisplayMessages);
  10842. return result;
  10843. }
  10844. int handleGetInstalledCertificateIdsRequest(char *uuid, char *payload)
  10845. {
  10846. mtrace();
  10847. int result = FAIL;
  10848. json_object *GetInstalledCertificateIds;
  10849. DEBUG_INFO("handleGetInstalledCertificateIdsRequest...\n");
  10850. GetInstalledCertificateIds = json_tokener_parse(payload);
  10851. if(!is_error(GetInstalledCertificateIds))
  10852. {
  10853. memset(&ShmOCPP20Data->GetInstalledCertificateIds, 0, sizeof(struct GetInstalledCertificateIds_20));
  10854. memcpy(&ShmOCPP20Data->GetInstalledCertificateIds.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetInstalledCertificateIds.guid));
  10855. // Optional data
  10856. if(json_object_array_length(json_object_object_get(GetInstalledCertificateIds, "certificateType")) <= ARRAY_SIZE(ShmOCPP20Data->GetInstalledCertificateIds.certificateType))
  10857. {
  10858. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetInstalledCertificateIds, "certificateType"));idx++)
  10859. {
  10860. sprintf((char*)ShmOCPP20Data->GetInstalledCertificateIds.certificateType[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetInstalledCertificateIds, "certificateType"), idx)));
  10861. /*
  10862. * TODO:
  10863. * 1. Get installed certificate info for response
  10864. */
  10865. }
  10866. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_Accepted]);
  10867. }
  10868. else
  10869. strcpy((char*)ShmOCPP20Data->GetInstalledCertificateIds.Response_status, GetInstalledCertificateStatusEnumTypeStr[GetInstalledCertificateStatusEnumType_NotFound]);
  10870. }
  10871. json_object_put(GetInstalledCertificateIds);
  10872. sendInstallCertificateConfirmation(uuid);
  10873. return result;
  10874. }
  10875. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  10876. {
  10877. mtrace();
  10878. int result = FAIL;
  10879. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  10880. if(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "FALSE") == 0)
  10881. {
  10882. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  10883. localversion = -1;
  10884. }
  10885. else
  10886. {
  10887. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  10888. DB_getListVerion();
  10889. }
  10890. ShmOCPP20Data->GetLocalListVersion.Response_versionNumber = localversion;
  10891. sendGetLocalListVersionConfirmation(uuid);
  10892. return result;
  10893. }
  10894. static char fnamePlusPath[100]={0};
  10895. static char fnamePWithNoPath[60]={0};
  10896. void checkUploadLog(void)
  10897. {
  10898. FILE *fp;
  10899. /* Open the command for reading. */
  10900. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  10901. if (fp == NULL) {
  10902. printf("Failed to run command\n" );
  10903. exit(1);
  10904. }
  10905. int ftppathlen = 0;
  10906. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  10907. int i = 0;
  10908. /* Read the output a line at a time - output it. */
  10909. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  10910. if(i==0)
  10911. {
  10912. ftppathlen = strlen(fnamePlusPath);
  10913. printf("%s\n", fnamePlusPath);
  10914. fnamePlusPath[ftppathlen]='\0';
  10915. break;
  10916. }
  10917. i= i+1;
  10918. }
  10919. /* close */
  10920. pclose(fp);
  10921. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  10922. {
  10923. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  10924. {
  10925. fnamePlusPath[k]='\0';
  10926. }
  10927. }
  10928. i=1;
  10929. //char fname[60]={0};
  10930. while(i < ftppathlen)
  10931. {
  10932. int len=ftppathlen-i;
  10933. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  10934. {
  10935. printf("compare '/' all right\n");
  10936. break;
  10937. }
  10938. i=i+1;
  10939. }
  10940. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  10941. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  10942. fnamePWithNoPath[i+1] = '\0';
  10943. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  10944. {
  10945. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  10946. {
  10947. fnamePWithNoPath[j]='\0';
  10948. }
  10949. }
  10950. FILE* fp1 = fopen(fnamePlusPath, "r");
  10951. if (fp1)
  10952. {
  10953. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  10954. // file exists
  10955. fclose(fp1);
  10956. }
  10957. else
  10958. {
  10959. // file doesn't exist
  10960. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  10961. }
  10962. }
  10963. void* GetLogProcess(void* data)
  10964. {
  10965. pthread_detach(pthread_self());
  10966. mtrace();
  10967. int requestId, retriesInt=0, retryIntervalInt=0;
  10968. char logType[32], remoteLocation[1024]={0}, oldestTimestamp[30]={0}, latestTimestamp[30]={0};
  10969. 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};
  10970. int port=0;
  10971. int isSuccess = FALSE;
  10972. char ftpbuf[1024]={0};
  10973. char cmdBuf[2048];
  10974. struct tm *tmNow;
  10975. time_t CurrentTime;
  10976. struct tm tmStart;
  10977. struct tm tmStop;
  10978. CurrentTime = time(NULL);
  10979. tmNow=localtime(&CurrentTime);
  10980. uint16_t targetYear, targetMonth;
  10981. json_object *GetLog;
  10982. DEBUG_INFO("GetGetProcess...\n");
  10983. GetLog = json_tokener_parse(data);
  10984. if(!is_error(GetLog))
  10985. {
  10986. // Required data
  10987. if(json_object_object_get(GetLog, "requestId") != NULL)
  10988. requestId = json_object_get_int(json_object_object_get(GetLog, "requestId"));
  10989. if(json_object_object_get(GetLog, "logType") != NULL)
  10990. sprintf(logType, "%s", json_object_get_string(json_object_object_get(GetLog, "logType")));
  10991. if(json_object_object_get(GetLog, "log") != NULL)
  10992. {
  10993. if(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation") != NULL)
  10994. sprintf(remoteLocation, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "remoteLocation")));
  10995. if(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp") != NULL)
  10996. sprintf(oldestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "oldestTimestamp")));
  10997. if(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp") != NULL)
  10998. sprintf(latestTimestamp, "%s", json_object_get_string(json_object_object_get(json_object_object_get(GetLog, "log"), "latestTimestamp")));
  10999. }
  11000. // Optional data
  11001. if(json_object_object_get(GetLog, "retries") != NULL)
  11002. retriesInt = json_object_get_int(json_object_object_get(GetLog, "retries"));
  11003. else
  11004. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  11005. if(json_object_object_get(GetLog, "retryInterval") != NULL)
  11006. retryIntervalInt = json_object_get_int(json_object_object_get(GetLog, "retryInterval"));
  11007. else
  11008. retryIntervalInt = 30;
  11009. }
  11010. json_object_put(GetLog);
  11011. ShmOCPP20Data->GetLog.requestId = requestId;
  11012. // Pack log to compress file
  11013. 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) &&
  11014. (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))
  11015. {
  11016. // Pack system log
  11017. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11018. sprintf(cmdBuf, "exec zip -9 --password %04d%02d%s /mnt/system.zip", tmNow->tm_year+1900, tmNow->tm_mon+1, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  11019. targetYear = tmStart.tm_year;
  11020. targetMonth = tmStart.tm_mon;
  11021. do
  11022. {
  11023. sprintf(cmdBuf, "%s /Storage/SystemLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11024. sprintf(cmdBuf, "%s /Storage/OCPP/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11025. if(targetMonth+1>=13)
  11026. {
  11027. targetYear += 1;
  11028. targetMonth = 1;
  11029. }
  11030. else
  11031. {
  11032. targetMonth += 1;
  11033. }
  11034. }while((targetYear < (tmNow->tm_year+1900)) ||
  11035. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11036. sprintf(cmdBuf, "%s /Storage/CCS*.zip", cmdBuf);
  11037. system(cmdBuf);
  11038. // Pack charging & event log
  11039. memset(cmdBuf, 0x00, ARRAY_SIZE(cmdBuf));
  11040. sprintf(cmdBuf, "exec zip -9 /mnt/charging_event.zip");
  11041. targetYear = tmStart.tm_year;
  11042. targetMonth = tmStart.tm_mon;
  11043. do
  11044. {
  11045. sprintf(cmdBuf, "%s /Storage/EventLog/*%04d*%02d*", cmdBuf, targetYear, targetMonth);
  11046. if(targetMonth+1>=13)
  11047. {
  11048. targetYear += 1;
  11049. targetMonth = 1;
  11050. }
  11051. else
  11052. {
  11053. targetMonth += 1;
  11054. }
  11055. }while((targetYear < (tmNow->tm_year+1900)) ||
  11056. ((targetYear <= (tmNow->tm_year+1900)) && (targetMonth <= (tmNow->tm_mon+1))));
  11057. sprintf(cmdBuf, "%s /Storage/ChargeLog/*.db", cmdBuf);
  11058. sprintf(cmdBuf, "%s /Storage/EventLog/*.db", cmdBuf);
  11059. system(cmdBuf);
  11060. // Combine log file
  11061. system("exec zip -9 /mnt/log.zip /mnt/system.zip /mnt/charging_event.zip");
  11062. system("exec rm -f /mnt/system.zip /mnt/charging_event.zip");
  11063. }
  11064. else
  11065. {
  11066. system("exec /root/logPackTools 'log' 6");
  11067. }
  11068. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP20Data->GetLog.Response_filename);
  11069. system(cmdBuf);
  11070. checkUploadLog();
  11071. //****************location*******************/
  11072. if(strcmp(remoteLocation,"")==0)
  11073. {
  11074. DEBUG_INFO("remoteLocation is <Empty>!\n");
  11075. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  11076. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  11077. goto end;
  11078. }
  11079. memset(protocol, 0, ARRAY_SIZE(protocol));
  11080. memset(user, 0, ARRAY_SIZE(user) );
  11081. memset(password, 0, ARRAY_SIZE(password));
  11082. memset(host, 0, ARRAY_SIZE(host));
  11083. memset(path, 0, ARRAY_SIZE(path));
  11084. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  11085. memset(host1, 0, ARRAY_SIZE(host1));
  11086. memset(path1, 0, ARRAY_SIZE(path1));
  11087. /*location: ftp://user:password@host:port/path*/
  11088. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  11089. if((access(fnamePlusPath,F_OK))!=-1)
  11090. {
  11091. DEBUG_INFO("fnamePlusPath exist.\n");
  11092. }
  11093. else
  11094. {
  11095. DEBUG_INFO("fnamePlusPath not exist!\n");
  11096. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  11097. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  11098. goto end;
  11099. }
  11100. if(strchr(remoteLocation,'@')==NULL)
  11101. {
  11102. sscanf(remoteLocation,
  11103. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  11104. protocol, host, &port, path);
  11105. strcpy(user,"anonymous");
  11106. strcpy(password,"");
  11107. }
  11108. else
  11109. {
  11110. //DEBUG_INFO("pch=%s\n", pch);
  11111. sscanf(remoteLocation,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  11112. protocol, user, password, host, &port, path);
  11113. }
  11114. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0)&&(strcmp(protocol,"https")!=0))
  11115. {
  11116. DEBUG_INFO("protocol is not ftp/http ! \n");
  11117. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  11118. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  11119. goto end;
  11120. }
  11121. if(strncmp(remoteLocation,"http", 4) == 0)
  11122. {
  11123. sscanf(remoteLocation,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  11124. sprintf(ftppath,"/%s", path);
  11125. do
  11126. {
  11127. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploading]);
  11128. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  11129. sleep(3);
  11130. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, remoteLocation);
  11131. if(!isSuccess)
  11132. {
  11133. DEBUG_INFO("sendLogStatusNotificationRequest fail...retries: %d\n", retriesInt);
  11134. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  11135. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  11136. sleep(retryIntervalInt);
  11137. }
  11138. else
  11139. {
  11140. DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
  11141. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
  11142. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  11143. }
  11144. retriesInt--;
  11145. }while((isSuccess == 0)&&(retriesInt >= 0));
  11146. }
  11147. else
  11148. {
  11149. sscanf(host,"%[^/]%s",host1, path1);
  11150. if(strlen(path) > 0)
  11151. sprintf(ftppath,"/%s", path);
  11152. else
  11153. sprintf(ftppath,"/%s", path1);
  11154. int ftppathlen=strlen(ftppath);
  11155. int i=1;
  11156. char filenametemp[50];
  11157. while(i < ftppathlen)
  11158. {
  11159. int len=ftppathlen-i;
  11160. if(ftppath[len]== 47) // '/' ascll code: 47
  11161. {
  11162. DEBUG_INFO("find '/' all right\n");
  11163. break;
  11164. }
  11165. i=i+1;
  11166. }
  11167. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  11168. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  11169. filenametemp[i+1] = 0;
  11170. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  11171. if(port == 0)
  11172. port = 21;
  11173. do
  11174. {
  11175. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploading]);
  11176. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  11177. sleep(3);
  11178. isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  11179. if(!isSuccess)
  11180. {
  11181. DEBUG_INFO("sendLogStatusNotificationRequest fail...retries: %d\n", retriesInt);
  11182. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_UploadFailure]);
  11183. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  11184. sleep(retryIntervalInt);
  11185. }
  11186. else
  11187. {
  11188. DEBUG_INFO("sendLogStatusNotificationRequest Uploaded\n");
  11189. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Uploaded]);
  11190. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  11191. }
  11192. retriesInt--;
  11193. }while((!isSuccess)&&(retriesInt >= 0));
  11194. }
  11195. end:
  11196. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle;
  11197. pthread_exit(NULL);
  11198. }
  11199. int handleGetLogRequest(char *uuid, char *payload)
  11200. {
  11201. mtrace();
  11202. int result = FAIL;
  11203. char fName[258];
  11204. time_t CurrentTime;
  11205. struct tm *tm;
  11206. pthread_t th_Status;
  11207. CurrentTime = time(NULL);
  11208. tm = localtime(&CurrentTime);
  11209. 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);
  11210. sprintf((char*)ShmOCPP20Data->GetLog.Response_filename, "%s", fName);
  11211. sprintf((char*)ShmOCPP20Data->GetLog.Response_status, "%s", LogStatusEnumTypeStr[LogStatusEnumType_Accepted]);
  11212. sendGetLogConfirmation(uuid);
  11213. pthread_create(&th_Status, NULL, GetLogProcess, stringtrimspace(payload));
  11214. return result;
  11215. }
  11216. int handleGetMonitoringReportRequest(char *uuid, char *payload)
  11217. {
  11218. mtrace();
  11219. int result = FAIL;
  11220. json_object *GetMonitoringReport;
  11221. DEBUG_INFO("handleGetMonitoringReportRequest...\n");
  11222. GetMonitoringReport = json_tokener_parse(payload);
  11223. if(!is_error(GetMonitoringReport))
  11224. {
  11225. memset(&ShmOCPP20Data->GetMonitoringReport, 0, sizeof(struct GetMonitoringReport_20));
  11226. memcpy(&ShmOCPP20Data->GetMonitoringReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.guid));
  11227. // Required data
  11228. if(json_object_object_get(GetMonitoringReport, "requestId") != NULL)
  11229. {
  11230. ShmOCPP20Data->GetMonitoringReport.requestId = json_object_get_int(json_object_object_get(GetMonitoringReport, "requestId"));
  11231. }
  11232. // Optional data
  11233. if(json_object_object_get(GetMonitoringReport, "monitoringCriteria") != NULL)
  11234. {
  11235. sprintf((char*)ShmOCPP20Data->GetMonitoringReport.monitoringCriteria, "%s", json_object_get_string(json_object_object_get(GetMonitoringReport, "monitoringCriteria")));
  11236. }
  11237. if(json_object_object_get(GetMonitoringReport, "componentVariable") != NULL)
  11238. {
  11239. if(json_object_array_length(json_object_object_get(GetMonitoringReport, "componentVariable")) <= ARRAY_SIZE(ShmOCPP20Data->GetMonitoringReport.componentVariable))
  11240. {
  11241. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetMonitoringReport, "componentVariable"));idx++)
  11242. {
  11243. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component") != NULL)
  11244. {
  11245. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "name") != NULL)
  11246. {
  11247. 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")));
  11248. }
  11249. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "instance") != NULL)
  11250. {
  11251. 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")));
  11252. }
  11253. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "component"), "evse") != NULL)
  11254. {
  11255. 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)
  11256. {
  11257. 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"));
  11258. }
  11259. 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)
  11260. {
  11261. 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"));
  11262. }
  11263. }
  11264. }
  11265. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable") != NULL)
  11266. {
  11267. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "name") != NULL)
  11268. {
  11269. 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")));
  11270. }
  11271. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetMonitoringReport, "componentVariable"), idx), "variable"), "instance") != NULL)
  11272. {
  11273. 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")));
  11274. }
  11275. }
  11276. }
  11277. }
  11278. }
  11279. }
  11280. json_object_put(GetMonitoringReport);
  11281. /*
  11282. * TODO:
  11283. * 1. Response result
  11284. */
  11285. strcpy((char*)ShmOCPP20Data->GetReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  11286. sendGetMonitoringReportConfirmation(uuid);
  11287. return result;
  11288. }
  11289. int handleGetReportRequest(char *uuid, char *payload)
  11290. {
  11291. mtrace();
  11292. int result = FAIL;
  11293. json_object *GetReport;
  11294. DEBUG_INFO("handleGetReportRequest...\n");
  11295. GetReport = json_tokener_parse(payload);
  11296. if(!is_error(GetReport))
  11297. {
  11298. memset(&ShmOCPP20Data->GetReport, 0, sizeof(struct GetReport_20));
  11299. memcpy(&ShmOCPP20Data->GetReport.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetReport.guid));
  11300. // Required data
  11301. if(json_object_object_get(GetReport, "requestId") != NULL)
  11302. {
  11303. ShmOCPP20Data->GetReport.requestId = json_object_get_int(json_object_object_get(GetReport, "requestId"));
  11304. }
  11305. // Optional data
  11306. if(json_object_object_get(GetReport, "componentCriteria") != NULL)
  11307. {
  11308. sprintf((char*)ShmOCPP20Data->GetReport.componentCriteria, "%s", json_object_get_string(json_object_object_get(GetReport, "componentCriteria")));
  11309. }
  11310. if(json_object_object_get(GetReport, "componentVariable") != NULL)
  11311. {
  11312. if(json_object_array_length(json_object_object_get(GetReport, "componentVariable")) <= ARRAY_SIZE(ShmOCPP20Data->GetReport.componentVariable))
  11313. {
  11314. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetReport, "componentVariable"));idx++)
  11315. {
  11316. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component") != NULL)
  11317. {
  11318. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "name") != NULL)
  11319. {
  11320. 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")));
  11321. }
  11322. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "instance") != NULL)
  11323. {
  11324. 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")));
  11325. }
  11326. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "component"), "evse") != NULL)
  11327. {
  11328. 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)
  11329. {
  11330. 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"));
  11331. }
  11332. 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)
  11333. {
  11334. 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"));
  11335. }
  11336. }
  11337. }
  11338. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable") != NULL)
  11339. {
  11340. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "name") != NULL)
  11341. {
  11342. 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")));
  11343. }
  11344. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetReport, "componentVariable"), idx), "variable"), "instance") != NULL)
  11345. {
  11346. 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")));
  11347. }
  11348. }
  11349. }
  11350. }
  11351. }
  11352. }
  11353. json_object_put(GetReport);
  11354. /*
  11355. * TODO:
  11356. * 1. Response result
  11357. */
  11358. strcpy((char*)ShmOCPP20Data->GetReport.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  11359. sendGetReportConfirmation(uuid);
  11360. return result;
  11361. }
  11362. int handleGetTransactionStatusRequest(char *uuid, char *payload)
  11363. {
  11364. mtrace();
  11365. int result = FAIL;
  11366. int8_t gun_index = -1;
  11367. json_object *GetTransactionStatus;
  11368. DEBUG_INFO("handleGetTransactionStatusRequest...\n");
  11369. GetTransactionStatus = json_tokener_parse(payload);
  11370. if(!is_error(GetTransactionStatus))
  11371. {
  11372. /*
  11373. * TODO:
  11374. * 1. Check transaction locate which connector
  11375. */
  11376. memset(&ShmOCPP20Data->GetTransactionStatus[gun_index], 0, sizeof(struct GetTransactionStatus_20));
  11377. memcpy(&ShmOCPP20Data->GetTransactionStatus[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetTransactionStatus[gun_index].guid));
  11378. if(json_object_object_get(GetTransactionStatus, "transactionId") != NULL)
  11379. {
  11380. sprintf((char*)ShmOCPP20Data->GetTransactionStatus[gun_index].transactionId, "%s", json_object_get_string(json_object_object_get(GetTransactionStatus, "transactionId")));
  11381. }
  11382. ShmOCPP20Data->GetTransactionStatus[gun_index].Response_messagesInQueue = FALSE;
  11383. ShmOCPP20Data->GetTransactionStatus[gun_index].Response_ongoingIndicator = FALSE;
  11384. }
  11385. json_object_put(GetTransactionStatus);
  11386. sendGetTransactionStatusConfirmation(uuid, gun_index);
  11387. return result;
  11388. }
  11389. int handleGetVariablesRequest(char *uuid, char *payload)
  11390. {
  11391. mtrace();
  11392. int result = FAIL;
  11393. json_object *GetVariables;
  11394. DEBUG_INFO("handleGetVariablesRequest...\n");
  11395. GetVariables = json_tokener_parse(payload);
  11396. if(!is_error(GetVariables))
  11397. {
  11398. memset(&ShmOCPP20Data->GetVariables, 0, sizeof(struct SetVariables_20));
  11399. memcpy(&ShmOCPP20Data->GetVariables.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->GetVariables.guid));
  11400. // Required data
  11401. if(json_object_array_length(json_object_object_get(GetVariables, "getVariableData")) <= ARRAY_SIZE(ShmOCPP20Data->GetVariables.getVariableData))
  11402. {
  11403. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetVariables, "getVariableData"));idx++)
  11404. {
  11405. if(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx) != NULL)
  11406. {
  11407. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "attributeType") != NULL)
  11408. {
  11409. 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")));
  11410. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeType, (char*)ShmOCPP20Data->GetVariables.getVariableData[idx].attributeType);
  11411. }
  11412. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component") != NULL)
  11413. {
  11414. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "name") != NULL)
  11415. {
  11416. 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")));
  11417. }
  11418. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "instance") != NULL)
  11419. {
  11420. 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")));
  11421. }
  11422. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "component"), "evse") != NULL)
  11423. {
  11424. 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)
  11425. {
  11426. 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"));
  11427. }
  11428. 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)
  11429. {
  11430. 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"));
  11431. }
  11432. }
  11433. memcpy(&ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].component, &ShmOCPP20Data->GetVariables.getVariableData[idx].component, sizeof(struct ComponentType));
  11434. }
  11435. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable") != NULL)
  11436. {
  11437. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "name") != NULL)
  11438. {
  11439. 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")));
  11440. }
  11441. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(GetVariables, "getVariableData"), idx), "variable"), "instance") != NULL)
  11442. {
  11443. 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")));
  11444. }
  11445. memcpy(&ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].variable , &ShmOCPP20Data->GetVariables.getVariableData[idx].variable, sizeof(struct VariableType));
  11446. }
  11447. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  11448. {
  11449. if((strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name) == 0) &&
  11450. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.instance, (char*)ShmOCPP20Data->GetVariables.getVariableData[idx].component.instance) == 0) &&
  11451. (strcmp((char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.name, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name) == 0) &&
  11452. (strcmp((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.instance, (char*)ShmOCPP20Data->GetVariables.getVariableData[idx].variable.instance) == 0))
  11453. {
  11454. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_Accepted]);
  11455. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, (char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value);
  11456. break;
  11457. }
  11458. else
  11459. {
  11460. strcpy((char*)ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeStatus, GetVariableStatusEnumTypeStr[GetVariableStatusEnumType_UnknownComponent]);
  11461. memset(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue, 0x00, ARRAY_SIZE(ShmOCPP20Data->GetVariables.Response_getVariableResult[idx].attributeValue));
  11462. }
  11463. }
  11464. }
  11465. }
  11466. }
  11467. sendGetVariablesConfirmation(uuid, json_object_array_length(json_object_object_get(GetVariables, "getVariableData")));
  11468. }
  11469. json_object_put(GetVariables);
  11470. return result;
  11471. }
  11472. int handleInstallCertificateRequest(char *uuid, char *payload)
  11473. {
  11474. mtrace();
  11475. int result = FAIL;
  11476. json_object *InstallCertificate;
  11477. DEBUG_INFO("handleInstallCertificateRequest...\n");
  11478. InstallCertificate = json_tokener_parse(payload);
  11479. if(!is_error(InstallCertificate))
  11480. {
  11481. memset(&ShmOCPP20Data->InstallCertificate, 0, sizeof(struct InstallCertificate_20));
  11482. memcpy(&ShmOCPP20Data->InstallCertificate.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->InstallCertificate.guid));
  11483. // Required data
  11484. if(json_object_object_get(InstallCertificate, "certificateType") != NULL)
  11485. {
  11486. sprintf((char*)ShmOCPP20Data->InstallCertificate.certificateType, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificateType")));
  11487. }
  11488. if(json_object_object_get(InstallCertificate, "certificate") != NULL)
  11489. {
  11490. sprintf((char*)ShmOCPP20Data->InstallCertificate.certificate, "%s", json_object_get_string(json_object_object_get(InstallCertificate, "certificate")));
  11491. }
  11492. }
  11493. json_object_put(InstallCertificate);
  11494. /*
  11495. * TODO:
  11496. * 1. Install certification preocess and response
  11497. */
  11498. strcpy((char*)ShmOCPP20Data->InstallCertificate.Response_status, InstallCertificateStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  11499. sendInstallCertificateConfirmation(uuid);
  11500. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  11501. return result;
  11502. }
  11503. int handlePublishFirmwareRequest(char *uuid, char *payload)
  11504. {
  11505. mtrace();
  11506. int result = FAIL;
  11507. json_object *PublishFirmware;
  11508. DEBUG_INFO("handlePublishFirmwareRequest...\n");
  11509. PublishFirmware = json_tokener_parse(payload);
  11510. if(!is_error(PublishFirmware))
  11511. {
  11512. memset(&ShmOCPP20Data->PublishFirmware, 0, sizeof(struct PublishFirmware_20));
  11513. memcpy(&ShmOCPP20Data->PublishFirmware.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->PublishFirmware.guid));
  11514. // Required data
  11515. if(json_object_object_get(PublishFirmware, "requestId") != NULL)
  11516. {
  11517. ShmOCPP20Data->PublishFirmware.requestId = json_object_get_int(json_object_object_get(PublishFirmware, "requestId"));
  11518. }
  11519. if(json_object_object_get(PublishFirmware, "checksum") != NULL)
  11520. {
  11521. sprintf((char*)ShmOCPP20Data->PublishFirmware.requestId, "%s", json_object_get_string(json_object_object_get(PublishFirmware, "checksum")));
  11522. }
  11523. // Optional data
  11524. if(json_object_object_get(PublishFirmware, "location") != NULL)
  11525. {
  11526. sprintf((char*)ShmOCPP20Data->PublishFirmware.location, "%s", json_object_get_string(json_object_object_get(PublishFirmware, "location")));
  11527. }
  11528. if(json_object_object_get(PublishFirmware, "retries") != NULL)
  11529. {
  11530. ShmOCPP20Data->PublishFirmware.retries = json_object_get_int(json_object_object_get(PublishFirmware, "retries"));
  11531. }
  11532. if(json_object_object_get(PublishFirmware, "retryInterval") != NULL)
  11533. {
  11534. ShmOCPP20Data->PublishFirmware.retryInterval = json_object_get_int(json_object_object_get(PublishFirmware, "retryInterval"));
  11535. }
  11536. }
  11537. json_object_put(PublishFirmware);
  11538. /*
  11539. * TODO:
  11540. * 1. Publish firmware preocess and response
  11541. */
  11542. strcpy((char*)ShmOCPP20Data->PublishFirmware.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  11543. sendPublishFirmwareConfirmation(uuid);
  11544. return result;
  11545. }
  11546. int handleRemoteStartTransactionRequest(char *uuid, char *payload)
  11547. {
  11548. mtrace();
  11549. int result = FAIL;
  11550. int8_t gun_index = -1;
  11551. uint8_t isPeriodOverMax = FALSE;
  11552. uint8_t isProfileOverMax = FALSE;
  11553. uint8_t isConnectorMismatch = FALSE;
  11554. uint8_t isTxProfile = FALSE;
  11555. uint8_t existProfileQuantity = 0;
  11556. uint8_t filename[128]={0};
  11557. uint8_t word[2048]={0};
  11558. FILE *filePtr;
  11559. json_object *RemoteStartTransaction;
  11560. DEBUG_INFO("handleRemoteStartTransactionRequest...\n");
  11561. RemoteStartTransaction = json_tokener_parse(payload);
  11562. if(!is_error(RemoteStartTransaction))
  11563. {
  11564. if(json_object_object_get(RemoteStartTransaction, "evseId") != NULL)
  11565. {
  11566. gun_index = json_object_get_int(json_object_object_get(RemoteStartTransaction, "evseId"));
  11567. }
  11568. else
  11569. {
  11570. /*
  11571. * TODO:
  11572. * 1. Selected connector process
  11573. */
  11574. gun_index = 0;
  11575. }
  11576. memset(&ShmOCPP20Data->RequestStartTransaction[gun_index], 0, sizeof(struct RequestStartTransaction_20));
  11577. memcpy(&ShmOCPP20Data->RequestStartTransaction[gun_index].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->RequestStartTransaction[gun_index].guid));
  11578. // Required data
  11579. if(json_object_object_get(RemoteStartTransaction, "remoteStartId") != NULL)
  11580. {
  11581. ShmOCPP20Data->RequestStartTransaction[gun_index].remoteStartId = json_object_get_int(json_object_object_get(RemoteStartTransaction, "remoteStartId"));
  11582. }
  11583. if(json_object_object_get(RemoteStartTransaction, "idToken") != NULL)
  11584. {
  11585. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken") != NULL)
  11586. {
  11587. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "idToken")));
  11588. }
  11589. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type") != NULL)
  11590. {
  11591. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "idToken"), "type")));
  11592. }
  11593. }
  11594. // Optional data
  11595. if(json_object_object_get(RemoteStartTransaction, "groupIdToken") != NULL)
  11596. {
  11597. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken") != NULL)
  11598. {
  11599. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "idToken")));
  11600. }
  11601. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type") != NULL)
  11602. {
  11603. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[gun_index].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "groupIdToken"), "type")));
  11604. }
  11605. }
  11606. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  11607. {
  11608. // Check periods is over max configuration
  11609. if(json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod")) > 10)
  11610. {
  11611. isPeriodOverMax = TRUE;
  11612. }
  11613. // Check periods is over max configuration
  11614. if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  11615. {
  11616. if(gun_index > 0)
  11617. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", gun_index);
  11618. else
  11619. isConnectorMismatch = TRUE;
  11620. if(!isConnectorMismatch)
  11621. {
  11622. filePtr = fopen((char*)filename, "r");
  11623. if (!filePtr)
  11624. {
  11625. DEBUG_INFO("%s not exist, create it.\n", filename);
  11626. filePtr = fopen((char*)filename, "w+");
  11627. }
  11628. else
  11629. {
  11630. //Check Charging Profile Count
  11631. while(fscanf(filePtr, "%s", word) != EOF)
  11632. {
  11633. //DEBUG_INFO("word=%s\n",word);
  11634. if(strstr((char*)word, "chargingProfileId")!= NULL)
  11635. {
  11636. existProfileQuantity += 1;
  11637. }
  11638. }
  11639. }
  11640. fclose(filePtr);
  11641. }
  11642. }
  11643. else
  11644. {
  11645. }
  11646. if(existProfileQuantity > 3)
  11647. isProfileOverMax = TRUE;
  11648. }
  11649. // Profile replace or add info
  11650. if((gun_index > 0) && !isPeriodOverMax && !isProfileOverMax && !isConnectorMismatch && !isTxProfile)
  11651. {
  11652. FILE *infile;
  11653. FILE *outfile;
  11654. char tmpProfileName[32];
  11655. char rmFileCmd[128];
  11656. char tempchargingProfilePurposeStr[30]={0};
  11657. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  11658. sprintf((char*)tmpProfileName, "/Storage/OCPP/tmpProfileRemote");
  11659. infile = fopen ((char*)filename, "r");
  11660. outfile = fopen ((char*)tmpProfileName, "w");
  11661. int d = fgetc(infile);
  11662. rewind(infile);
  11663. if(d == EOF)
  11664. {
  11665. // Profile is empty
  11666. fprintf(outfile,"%s\n", payload);
  11667. fclose(infile);
  11668. fclose(outfile);
  11669. sprintf(rmFileCmd,"rm -f %s",filename);
  11670. system(rmFileCmd);
  11671. rename((char*)tmpProfileName, (char*)filename);
  11672. }
  11673. else
  11674. {
  11675. // Profile is not empty
  11676. char buf[2048]={0};
  11677. int ChargingProfileAdded = FALSE;
  11678. while (fgets(buf, sizeof(buf), infile) != NULL)
  11679. {
  11680. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  11681. json_object *tmpChargingProfile;
  11682. tmpChargingProfile = json_tokener_parse(buf);
  11683. if(!is_error(tmpChargingProfile))
  11684. {
  11685. if(json_object_object_get(tmpChargingProfile, "evseId") != NULL)
  11686. {
  11687. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "evseId") );
  11688. }
  11689. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  11690. {
  11691. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  11692. {
  11693. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  11694. }
  11695. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  11696. {
  11697. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  11698. }
  11699. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  11700. {
  11701. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  11702. }
  11703. }
  11704. }
  11705. json_object_put(tmpChargingProfile);
  11706. if((tempconnectorIdInt == gun_index) &&
  11707. (tempchargingProfileIdInt == json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "csChargingProfiles"), "chargingProfileId"))))
  11708. {
  11709. if((tempstackLevelInt == json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "csChargingProfiles"), "stackLevel"))) &&
  11710. (strcmp(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "csChargingProfiles"), "chargingProfilePurpose"))) == 0))
  11711. {
  11712. if(ChargingProfileAdded == FALSE)
  11713. {
  11714. fprintf(outfile,"%s\n",payload);
  11715. ChargingProfileAdded = TRUE;
  11716. }
  11717. }
  11718. else
  11719. {
  11720. if(tempstackLevelInt < json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "csChargingProfiles"), "stackLevel")))
  11721. {
  11722. if(ChargingProfileAdded == FALSE)
  11723. {
  11724. fprintf(outfile,"%s\n",buf);
  11725. fprintf(outfile,"%s\n",payload);
  11726. ChargingProfileAdded = TRUE;
  11727. }
  11728. else
  11729. {
  11730. fprintf(outfile,"%s\n",buf);
  11731. }
  11732. }
  11733. else
  11734. {
  11735. if(ChargingProfileAdded == FALSE)
  11736. {
  11737. fprintf(outfile,"%s\n",buf);
  11738. fprintf(outfile,"%s\n",payload);
  11739. ChargingProfileAdded = TRUE;
  11740. }
  11741. else
  11742. {
  11743. fprintf(outfile,"%s\n",buf);
  11744. }
  11745. }
  11746. }
  11747. }
  11748. else
  11749. {
  11750. if(tempchargingProfileIdInt < json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "csChargingProfiles"), "chargingProfileId")))
  11751. {
  11752. if(ChargingProfileAdded == FALSE)
  11753. {
  11754. fprintf(outfile,"%s\n",buf);
  11755. fprintf(outfile,"%s\n",payload);
  11756. ChargingProfileAdded = TRUE;
  11757. }
  11758. else
  11759. {
  11760. fprintf(outfile,"%s\n",buf);
  11761. }
  11762. }
  11763. else if(tempstackLevelInt < json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "csChargingProfiles"), "stackLevel")))
  11764. {
  11765. if(ChargingProfileAdded == FALSE)
  11766. {
  11767. fprintf(outfile,"%s\n",buf);
  11768. fprintf(outfile,"%s\n",payload);
  11769. ChargingProfileAdded = TRUE;
  11770. }
  11771. else
  11772. {
  11773. fprintf(outfile,"%s\n",buf);
  11774. }
  11775. }
  11776. else
  11777. {
  11778. if(ChargingProfileAdded == FALSE)
  11779. {
  11780. fprintf(outfile,"%s\n",buf);
  11781. fprintf(outfile,"%s\n",payload);
  11782. ChargingProfileAdded = TRUE;
  11783. }
  11784. else
  11785. {
  11786. fprintf(outfile,"%s\n",buf);
  11787. }
  11788. }
  11789. }
  11790. } // end of while loop
  11791. fclose(infile);
  11792. fclose(outfile);
  11793. sprintf(rmFileCmd,"rm -f %s",filename);
  11794. system(rmFileCmd);
  11795. rename((char*)tmpProfileName, (char*)filename);
  11796. }
  11797. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[(gun_index==0?gun_index:gun_index-1)].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted] );
  11798. random_uuid((char*)ShmOCPP20Data->RequestStartTransaction[(gun_index==0?gun_index:gun_index-1)].Response_transactionId);
  11799. result = PASS;
  11800. }
  11801. else
  11802. {
  11803. if(gun_index <= 0)
  11804. DEBUG_WARN("Connector id is wrong.\n");
  11805. if(isConnectorMismatch)
  11806. DEBUG_WARN("Connector id is mismatch.\n");
  11807. if(isPeriodOverMax)
  11808. DEBUG_WARN("Profile periods quantity is over spec.\n");
  11809. if(isProfileOverMax)
  11810. DEBUG_WARN("Profile quantity is over spec.\n");
  11811. if(!isTxProfile)
  11812. DEBUG_WARN("Profile purpose is not TxProfile.\n");
  11813. sprintf((char*)ShmOCPP20Data->RequestStartTransaction[(gun_index==0?gun_index:gun_index-1)].Response_status, "%s", RequestStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected] );
  11814. }
  11815. }
  11816. json_object_put(RemoteStartTransaction);
  11817. sendRemoteStartTransactionConfirmation(uuid, gun_index);
  11818. return result;
  11819. }
  11820. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  11821. {
  11822. mtrace();
  11823. int result = FAIL;
  11824. int match = FALSE;
  11825. int GunNO = 0;
  11826. int tempIndex = 0;
  11827. char transactionIdStr[37];
  11828. int transactionIdIsNULL= TRUE;
  11829. json_object *RemoteStopTransaction;
  11830. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  11831. if(server_pending == TRUE)
  11832. {
  11833. return 0;
  11834. }
  11835. RemoteStopTransaction = json_tokener_parse(payload);
  11836. if(!is_error(RemoteStopTransaction))
  11837. {
  11838. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  11839. {
  11840. sprintf(transactionIdStr, "%s", json_object_get_string(json_object_object_get(RemoteStopTransaction, "transactionId")));
  11841. transactionIdIsNULL = FALSE;
  11842. }
  11843. }
  11844. json_object_put(RemoteStopTransaction);
  11845. if(transactionIdIsNULL == FALSE)
  11846. {
  11847. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  11848. {
  11849. if(strstr((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId, transactionIdStr) != NULL)
  11850. {
  11851. //check Transaction active
  11852. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  11853. {
  11854. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11855. {
  11856. tempIndex = ((gun_index==2) ? 1: 0);
  11857. }
  11858. else
  11859. {
  11860. tempIndex = gun_index;
  11861. }
  11862. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  11863. {
  11864. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  11865. {
  11866. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11867. {
  11868. match = TRUE;
  11869. GunNO = gun_index;
  11870. }
  11871. }
  11872. }// END FOR CHAdeMO_QUANTITY
  11873. }
  11874. else if(gunType[gun_index] == GUN_TYPE_CCS)
  11875. {
  11876. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11877. {
  11878. tempIndex = ((gun_index==2) ? 1: 0);
  11879. }
  11880. else
  11881. {
  11882. tempIndex = gun_index;
  11883. }
  11884. for (int index = 0; index < CCS_QUANTITY; index++)
  11885. {
  11886. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  11887. {
  11888. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11889. {
  11890. match = TRUE;
  11891. GunNO = gun_index;
  11892. }
  11893. }
  11894. }// END FOR CCS_QUANTITY
  11895. }
  11896. else if(gunType[gun_index] == GUN_TYPE_GBT)
  11897. {
  11898. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  11899. {
  11900. tempIndex = ((gun_index==2) ? 1: 0);
  11901. }
  11902. else
  11903. {
  11904. tempIndex = gun_index;
  11905. }
  11906. for (int index = 0; index < GB_QUANTITY; index++)
  11907. {
  11908. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  11909. {
  11910. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11911. {
  11912. match = TRUE;
  11913. GunNO = gun_index;
  11914. }
  11915. }
  11916. }// END FOR GB_QUANTITY
  11917. }
  11918. else if(gunType[gun_index] == GUN_TYPE_DO)
  11919. {
  11920. tempIndex = gun_index;
  11921. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  11922. {
  11923. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  11924. {
  11925. 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
  11926. {
  11927. match = TRUE;
  11928. GunNO = gun_index;
  11929. }
  11930. }
  11931. }// END FOR GB_QUANTITY
  11932. }
  11933. else
  11934. {
  11935. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  11936. {
  11937. tempIndex = 2;
  11938. }
  11939. else
  11940. {
  11941. tempIndex = gun_index;
  11942. }
  11943. for (int index = 0; index < AC_QUANTITY; index++)
  11944. {
  11945. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  11946. {
  11947. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  11948. {
  11949. match = TRUE;
  11950. GunNO = gun_index;
  11951. }
  11952. }
  11953. }// END FOR CHAdeMO_QUANTITY
  11954. } // END FOR AC ELSE
  11955. }// CHECK IF ResponseTransactionId == transactionIdInt
  11956. }//END FOR
  11957. if( match == TRUE)
  11958. {
  11959. ShmOCPP20Data->CsMsg.bits[GunNO].RequestStopTransactionReq = ON; // inform csu of StopTransaction
  11960. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Accepted]);
  11961. }
  11962. else
  11963. {
  11964. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  11965. }
  11966. }
  11967. else
  11968. strcpy((char*)ShmOCPP20Data->RequestStopTransaction[GunNO].Response_status, RemoteStartStopStatusEnumTypeStr[RequestStartStopStatusEnumType_Rejected]);
  11969. sendRemoteStopTransactionConfirmation(uuid, GunNO);
  11970. return result;
  11971. }
  11972. int handleReserveNowRequest(char *uuid, char *payload)
  11973. {
  11974. mtrace();
  11975. int result = FAIL;
  11976. int connectorIdInt=0, reservationIdInt=0;
  11977. int tempIndex = 0;
  11978. json_object *ReserveNow;
  11979. DEBUG_INFO("handleReserveNowRequest ...\n");
  11980. ReserveNow = json_tokener_parse(payload);
  11981. if(!is_error(ReserveNow))
  11982. {
  11983. if(json_object_object_get(ReserveNow, "evseId") != NULL)
  11984. {
  11985. connectorIdInt = json_object_get_int(json_object_object_get(ReserveNow, "evseId"));
  11986. connectorIdInt = (connectorIdInt==0)?1:connectorIdInt;
  11987. memset(&ShmOCPP20Data->ReserveNow[connectorIdInt-1], 0x00, sizeof(struct ReserveNow_20));
  11988. ShmOCPP20Data->ReserveNow[connectorIdInt-1].evseId = json_object_get_int(json_object_object_get(ReserveNow, "evseId"));
  11989. }
  11990. // Required data
  11991. if(json_object_object_get(ReserveNow, "reservationId") != NULL)
  11992. ShmOCPP20Data->ReserveNow[connectorIdInt-1].id = json_object_get_int(json_object_object_get(ReserveNow, "reservationId"));
  11993. if(json_object_object_get(ReserveNow, "expiryDateTime") != NULL)
  11994. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].expiryDateTime, "%s", json_object_get_string(json_object_object_get(ReserveNow, "expiryDateTime")));
  11995. if(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "idToken") != NULL)
  11996. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].idToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "idToken")));
  11997. if(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "type") != NULL)
  11998. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].idToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "idToken"), "type")));
  11999. // Optional data
  12000. if(json_object_object_get(ReserveNow, "connectorType") != NULL)
  12001. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].connectorType, "%s", json_object_get_string(json_object_object_get(ReserveNow, "connectorType")));
  12002. if(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "idToken") != NULL)
  12003. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].groupIdToken.idToken, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "idToken")));
  12004. if(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "type") != NULL)
  12005. sprintf((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].groupIdToken.type, "%s", json_object_get_string(json_object_object_get(json_object_object_get(ReserveNow, "groupIdToken"), "type")));
  12006. result = PASS;
  12007. }
  12008. json_object_put(ReserveNow);
  12009. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  12010. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  12011. {
  12012. //check Transaction active
  12013. if(gunType[connectorIdInt -1] == GUN_TYPE_CHAdeMO)
  12014. {
  12015. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12016. {
  12017. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12018. }
  12019. else
  12020. {
  12021. tempIndex = connectorIdInt -1;
  12022. }
  12023. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12024. {
  12025. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  12026. {
  12027. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12028. {
  12029. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12030. {
  12031. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12032. {
  12033. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  12034. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  12035. }
  12036. 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'))
  12037. {
  12038. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  12039. }
  12040. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12041. {
  12042. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  12043. }
  12044. else
  12045. {
  12046. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  12047. }
  12048. }
  12049. 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
  12050. {
  12051. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  12052. }
  12053. }
  12054. else
  12055. {
  12056. //replace reservation
  12057. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  12058. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  12059. }
  12060. }
  12061. } // END FOR CHAdeMO_QUANTITY
  12062. }
  12063. else if(gunType[connectorIdInt -1] == GUN_TYPE_CCS)
  12064. {
  12065. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12066. {
  12067. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12068. }
  12069. else
  12070. {
  12071. tempIndex = connectorIdInt -1;
  12072. }
  12073. for (int index = 0; index < CCS_QUANTITY; index++)
  12074. {
  12075. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  12076. {
  12077. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12078. {
  12079. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12080. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  12081. {
  12082. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12083. {
  12084. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  12085. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  12086. }
  12087. 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'))
  12088. {
  12089. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  12090. }
  12091. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  12092. {
  12093. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  12094. }
  12095. else
  12096. {
  12097. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  12098. }
  12099. }
  12100. 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
  12101. {
  12102. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  12103. }
  12104. }
  12105. else
  12106. {
  12107. //replace reservation
  12108. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  12109. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  12110. }
  12111. }
  12112. } // END FOR CCS_QUANTITY
  12113. }
  12114. else if(gunType[connectorIdInt -1] == GUN_TYPE_GBT)
  12115. {
  12116. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  12117. {
  12118. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  12119. }
  12120. else
  12121. {
  12122. tempIndex = connectorIdInt -1;
  12123. }
  12124. for (int index = 0; index < GB_QUANTITY; index++)
  12125. {
  12126. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  12127. {
  12128. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12129. {
  12130. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12131. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12132. {
  12133. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12134. {
  12135. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  12136. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  12137. }
  12138. 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'))
  12139. {
  12140. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  12141. }
  12142. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12143. {
  12144. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  12145. }
  12146. else
  12147. {
  12148. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  12149. }
  12150. }
  12151. 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
  12152. {
  12153. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  12154. }
  12155. }
  12156. else
  12157. {
  12158. //replace reservation
  12159. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  12160. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  12161. }
  12162. }
  12163. }// END FOR GB_QUANTITY
  12164. }
  12165. else if(gunType[connectorIdInt -1] == GUN_TYPE_DO)
  12166. {
  12167. tempIndex = connectorIdInt -1;
  12168. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  12169. {
  12170. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  12171. {
  12172. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  12173. {
  12174. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  12175. 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
  12176. {
  12177. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12178. {
  12179. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  12180. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  12181. }
  12182. 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'))
  12183. {
  12184. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  12185. }
  12186. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12187. {
  12188. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  12189. }
  12190. else
  12191. {
  12192. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  12193. }
  12194. }
  12195. 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
  12196. {
  12197. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  12198. }
  12199. }
  12200. else
  12201. {
  12202. //replace reservation
  12203. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  12204. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  12205. }
  12206. }
  12207. }// END FOR DO_QUANTITY
  12208. }
  12209. else
  12210. {
  12211. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  12212. {
  12213. tempIndex = 2;
  12214. }
  12215. else
  12216. {
  12217. tempIndex = (connectorIdInt -1);
  12218. }
  12219. for (int index = 0; index < AC_QUANTITY; index++)
  12220. {
  12221. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  12222. {
  12223. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12224. {
  12225. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  12226. {
  12227. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12228. {
  12229. 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))
  12230. {
  12231. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  12232. }
  12233. else
  12234. {
  12235. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  12236. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  12237. }
  12238. }
  12239. 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'))
  12240. {
  12241. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  12242. }
  12243. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  12244. {
  12245. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  12246. }
  12247. else
  12248. {
  12249. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  12250. }
  12251. }
  12252. 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
  12253. {
  12254. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  12255. }
  12256. }
  12257. else
  12258. {
  12259. //replace reservation
  12260. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = ON;
  12261. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  12262. }
  12263. }
  12264. } // END FOR AC_QUANTITY
  12265. }
  12266. }
  12267. else if(connectorIdInt == 0)
  12268. {
  12269. //check Transaction active
  12270. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12271. {
  12272. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  12273. {
  12274. 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'))
  12275. {
  12276. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  12277. goto end;
  12278. }
  12279. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12280. {
  12281. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  12282. goto end;
  12283. }
  12284. 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
  12285. {
  12286. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  12287. goto end;
  12288. }
  12289. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12290. {
  12291. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  12292. goto end;
  12293. }
  12294. }
  12295. }// END FOR CHAdeMO_QUANTITY
  12296. for (int index = 0; index < CCS_QUANTITY; index++)
  12297. {
  12298. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  12299. {
  12300. 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'))
  12301. {
  12302. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  12303. goto end;
  12304. }
  12305. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  12306. {
  12307. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  12308. goto end;
  12309. }
  12310. 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
  12311. {
  12312. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  12313. goto end;
  12314. }
  12315. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12316. {
  12317. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  12318. goto end;
  12319. }
  12320. }
  12321. } // END FOR CCS_QUANTITY
  12322. for (int index = 0; index < GB_QUANTITY; index++)
  12323. {
  12324. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  12325. {
  12326. 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'))
  12327. {
  12328. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  12329. goto end;
  12330. }
  12331. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12332. {
  12333. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  12334. goto end;
  12335. }
  12336. 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
  12337. {
  12338. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  12339. goto end;
  12340. }
  12341. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12342. {
  12343. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  12344. goto end;
  12345. }
  12346. }
  12347. } // END FOR GB_QUANTITY
  12348. for (int index = 0; index < AC_QUANTITY; index++)
  12349. {
  12350. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  12351. {
  12352. 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'))
  12353. {
  12354. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Unavailable]);
  12355. goto end;
  12356. }
  12357. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  12358. {
  12359. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  12360. goto end;
  12361. }
  12362. 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
  12363. {
  12364. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Faulted]);
  12365. goto end;
  12366. }
  12367. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  12368. {
  12369. 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))
  12370. {
  12371. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Occupied]);
  12372. goto end;
  12373. }
  12374. }
  12375. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  12376. {
  12377. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  12378. goto end;
  12379. }
  12380. }
  12381. }// END FOR AC_QUANTITY
  12382. //The connectorId is 0
  12383. ShmOCPP20Data->CsMsg.bits[0].ReserveNowReq = ON;
  12384. strcpy((char*)ShmOCPP20Data->ReserveNow[0].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]);
  12385. strcpy((char *)ShmOCPP20Data->ReserveNow[0].guid, uuid);
  12386. result = TRUE;
  12387. return result;
  12388. }
  12389. else
  12390. {
  12391. strcpy((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status, ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Rejected]);
  12392. }
  12393. if(strcmp((char*)ShmOCPP20Data->ReserveNow[connectorIdInt-1].Response_status,ReserveNowStatusEnumTypeStr[ReserveNowStatusEnumType_Accepted]) == 0)
  12394. {
  12395. strcpy((char *)ShmOCPP20Data->ReserveNow[connectorIdInt-1].guid, uuid);
  12396. result = TRUE;
  12397. return result;
  12398. }
  12399. end:
  12400. sendReserveNowConfirmation(uuid, (connectorIdInt==0?connectorIdInt:connectorIdInt-1));
  12401. return result;
  12402. }
  12403. int handleResetRequest(char *uuid, char *payload)
  12404. {
  12405. mtrace();
  12406. int result = FAIL;
  12407. json_object *Reset = json_object_new_object();
  12408. DEBUG_INFO("handleResetRequest...\n");
  12409. Reset = json_tokener_parse(payload);
  12410. if(!is_error(Reset))
  12411. {
  12412. // Required data
  12413. if(json_object_object_get(Reset, "type") != NULL)
  12414. {
  12415. sprintf((char*)ShmOCPP20Data->Reset.type, "%s", json_object_get_string(json_object_object_get(Reset, "type")));
  12416. }
  12417. if(json_object_object_get(Reset, "evseId") != NULL)
  12418. {
  12419. ShmOCPP20Data->Reset.evseId = json_object_get_int(json_object_object_get(Reset, "evseId"));
  12420. }
  12421. }
  12422. json_object_put(Reset);
  12423. if((strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_Immediate])==0) || (strcmp((char*)ShmOCPP20Data->Reset.type, ResetEnumTypeStr[ResetEnumType_OnIdle])==0))
  12424. {
  12425. strcpy((char *)ShmOCPP20Data->Reset.guid, uuid);
  12426. strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Accepted]);
  12427. ShmOCPP20Data->MsMsg.bits.ResetReq = ON;
  12428. result = PASS;
  12429. }
  12430. else
  12431. {
  12432. strcpy((char*)ShmOCPP20Data->Reset.Response_status, ResetStatusEnumTypeStr[ResetStatusEnumType_Rejected]);
  12433. }
  12434. if(strlen((char*)ShmOCPP20Data->Reset.Response_status) > 0)
  12435. sendResetConfirmation(uuid);
  12436. return result;
  12437. }
  12438. int handleSendLocalListRequest(char *uuid, char *payload)
  12439. {
  12440. mtrace();
  12441. int result = FAIL;
  12442. char updateTypestr[15]={0};
  12443. int checkState_Faulted = FALSE;
  12444. json_object *SendLocalList;
  12445. DEBUG_INFO("handleSendLocalListRequest...\n");
  12446. if(strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[LocalAuthListCtrlr_Enabled].variableAttribute[0].value, "FALSE") == 0)
  12447. {
  12448. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  12449. goto end;
  12450. }
  12451. SendLocalList = json_tokener_parse(payload);
  12452. if(!is_error(SendLocalList))
  12453. {
  12454. memset(&ShmOCPP20Data->SendLocalList, 0x00, sizeof(struct SendLocalList_20));
  12455. // Required data
  12456. if(json_object_object_get(SendLocalList, "versionNumber") != NULL)
  12457. {
  12458. ShmOCPP20Data->SendLocalList.versionNumber = json_object_get_int(json_object_object_get(SendLocalList, "versionNumber"));
  12459. }
  12460. if(json_object_object_get(SendLocalList, "updateType") != NULL)
  12461. sprintf((char*)ShmOCPP20Data->SendLocalList.updateType, "%s", json_object_get_string(json_object_object_get(SendLocalList, "updateType")));
  12462. // Optional data
  12463. if(json_object_object_get(SendLocalList, "localAuthorizationList") != NULL)
  12464. {
  12465. for(int idx=0;idx<json_object_array_length(json_object_object_get(SendLocalList, "localAuthorizationList"));idx++)
  12466. {
  12467. // Required data
  12468. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idToken") != NULL)
  12469. {
  12470. 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")));
  12471. 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")));
  12472. }
  12473. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo") != NULL)
  12474. {
  12475. 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")));
  12476. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "cacheExpiryDateTime") != NULL)
  12477. 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")));
  12478. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "chargingPriority") != NULL)
  12479. 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"));
  12480. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SendLocalList, "localAuthorizationList"), idx), "idTagInfo"), "groupIdToken") != NULL)
  12481. {
  12482. 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")));
  12483. 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")));
  12484. }
  12485. }
  12486. }
  12487. }
  12488. }
  12489. json_object_put(SendLocalList);
  12490. //check Charge Point state
  12491. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  12492. {
  12493. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12494. {
  12495. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12496. }
  12497. }
  12498. for (int index = 0; index < CCS_QUANTITY; index++)
  12499. {
  12500. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12501. {
  12502. checkState_Faulted = TRUE; //OCPP Status
  12503. }
  12504. }
  12505. for (int index = 0; index < GB_QUANTITY; index++)
  12506. {
  12507. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12508. {
  12509. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12510. }
  12511. }
  12512. for (int index = 0; index < AC_QUANTITY; index++)
  12513. {
  12514. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  12515. {
  12516. checkState_Faulted = TRUE; //OCPP Status: Faulted
  12517. }
  12518. }
  12519. if(checkState_Faulted == TRUE)
  12520. {
  12521. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  12522. goto end;
  12523. }
  12524. // Check update type
  12525. if(strcmp(updateTypestr, UpdateEnumTypeStr[UpdateEnumType_Full]) == 0)
  12526. {
  12527. //Local list full update
  12528. DEBUG_INFO("Local list full update.\n");
  12529. DB_getListVerion();
  12530. if(ShmOCPP20Data->SendLocalList.versionNumber < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  12531. {
  12532. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  12533. goto end;
  12534. }
  12535. DB_cleanLocalList();
  12536. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->SendLocalList.localAuthorizationList);idx++)
  12537. DB_addLocalList(ShmOCPP20Data->SendLocalList.versionNumber, &ShmOCPP20Data->SendLocalList.localAuthorizationList[idx]);
  12538. }
  12539. else if(strcmp(updateTypestr, UpdateEnumTypeStr[UpdateEnumType_Differential]) == 0)
  12540. {
  12541. //Local list different update
  12542. DEBUG_INFO("Local list different update.\n");
  12543. DB_getListVerion();
  12544. if(ShmOCPP20Data->SendLocalList.versionNumber < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  12545. {
  12546. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_VersionMismatch]);
  12547. goto end;
  12548. }
  12549. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP20Data->SendLocalList.localAuthorizationList);idx++)
  12550. DB_addLocalList(ShmOCPP20Data->SendLocalList.versionNumber, &ShmOCPP20Data->SendLocalList.localAuthorizationList[idx]);
  12551. }
  12552. else
  12553. {
  12554. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Failed]);
  12555. goto end;
  12556. }
  12557. strcpy((char*)ShmOCPP20Data->SendLocalList.Response_status, UpdateStatusEnumTypeStr[UpdateStatusEnumType_Accepted]);
  12558. end:
  12559. sendSendLocalListConfirmation(uuid);
  12560. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12561. return result;
  12562. }
  12563. int handleSetChargingProfileRequest(char *uuid, char *payload)
  12564. {
  12565. mtrace();
  12566. int result = FAIL;
  12567. int8_t gun_index = -1;
  12568. uint8_t isPeriodOverMax = FALSE;
  12569. uint8_t isProfileOverMax = FALSE;
  12570. uint8_t isConnectorMismatch = FALSE;
  12571. uint8_t existProfileQuantity = 0;
  12572. uint8_t filename[128]={0};
  12573. uint8_t word[2048]={0};
  12574. FILE *filePtr;
  12575. json_object *SetChargingProfile;
  12576. DEBUG_INFO("handleSetChargingProfileRequest...\n");
  12577. SetChargingProfile = json_tokener_parse(payload);
  12578. if(!is_error(SetChargingProfile))
  12579. {
  12580. // Required data
  12581. if(json_object_object_get(SetChargingProfile, "evseId") != NULL)
  12582. {
  12583. gun_index = json_object_get_int(json_object_object_get(SetChargingProfile, "evseId"));
  12584. }
  12585. if(json_object_object_get(SetChargingProfile, "chargingProfile") != NULL)
  12586. {
  12587. // Check periods is over max configuration
  12588. if(json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod")) > 10)
  12589. {
  12590. isPeriodOverMax = TRUE;
  12591. }
  12592. // Check periods is over max configuration
  12593. if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationMaxProfile]) != NULL)
  12594. {
  12595. if(gun_index == 0)
  12596. {
  12597. sprintf((char*)filename, ChargePointMaxProfile_JSON);
  12598. filePtr = fopen((char*)filename, "r");
  12599. if (!filePtr)
  12600. {
  12601. DEBUG_INFO("%s not exist, create it.\n", ChargePointMaxProfile_JSON);
  12602. filePtr = fopen((char*)filename, "w+");
  12603. }
  12604. else
  12605. {
  12606. //Check Charging Profile Count
  12607. while(fscanf(filePtr, "%s", word) != EOF)
  12608. {
  12609. //DEBUG_INFO("word=%s\n",word);
  12610. if(strstr((char*)word, "chargingProfileId")!= NULL)
  12611. {
  12612. existProfileQuantity += 1;
  12613. }
  12614. }
  12615. }
  12616. fclose(filePtr);
  12617. }
  12618. else
  12619. isConnectorMismatch = TRUE;
  12620. }
  12621. else if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxDefaultProfile]) != NULL)
  12622. {
  12623. if(gun_index < 5)
  12624. sprintf((char*)filename, "/Storage/OCPP/TxDefaultProfile_%d_OCPP20.json", gun_index);
  12625. else
  12626. isConnectorMismatch = TRUE;
  12627. if(!isConnectorMismatch)
  12628. {
  12629. filePtr = fopen((char*)filename, "r");
  12630. if (!filePtr)
  12631. {
  12632. DEBUG_INFO("%s not exist, create it.\n", filename);
  12633. filePtr = fopen((char*)filename, "w+");
  12634. }
  12635. else
  12636. {
  12637. //Check Charging Profile Count
  12638. while(fscanf(filePtr, "%s", word) != EOF)
  12639. {
  12640. //DEBUG_INFO("word=%s\n",word);
  12641. if(strstr((char*)word, "chargingProfileId")!= NULL)
  12642. {
  12643. existProfileQuantity += 1;
  12644. }
  12645. }
  12646. }
  12647. fclose(filePtr);
  12648. }
  12649. }
  12650. else if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_TxProfile]) != NULL)
  12651. {
  12652. if(gun_index>0)
  12653. sprintf((char*)filename, "/Storage/OCPP/TxProfile_%d_OCPP20.json", gun_index);
  12654. else
  12655. isConnectorMismatch = TRUE;
  12656. if(!isConnectorMismatch)
  12657. {
  12658. filePtr = fopen((char*)filename, "r");
  12659. if (!filePtr)
  12660. {
  12661. DEBUG_INFO("%s not exist, create it.\n", filename);
  12662. filePtr = fopen((char*)filename, "w+");
  12663. }
  12664. else
  12665. {
  12666. //Check Charging Profile Count
  12667. while(fscanf(filePtr, "%s", word) != EOF)
  12668. {
  12669. //DEBUG_INFO("word=%s\n",word);
  12670. if(strstr((char*)word, "chargingProfileId")!= NULL)
  12671. {
  12672. existProfileQuantity += 1;
  12673. }
  12674. }
  12675. }
  12676. fclose(filePtr);
  12677. }
  12678. }
  12679. else if(strstr(json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "chargingProfile"), "chargingProfilePurpose")), ChargingProfilePurposeEnumTypeStr[ChargingProfilePurposeEnumType_ChargingStationExternalConstraints]) != NULL)
  12680. {
  12681. }
  12682. else
  12683. {
  12684. }
  12685. if(existProfileQuantity > 3)
  12686. isProfileOverMax = TRUE;
  12687. }
  12688. // Profile replace or add info
  12689. if((gun_index > -1) && !isPeriodOverMax && !isProfileOverMax && !isConnectorMismatch)
  12690. {
  12691. FILE *infile;
  12692. FILE *outfile;
  12693. char tmpProfileName[32];
  12694. char rmFileCmd[128];
  12695. char tempchargingProfilePurposeStr[30]={0};
  12696. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  12697. sprintf((char*)tmpProfileName, "/Storage/OCPP/tmpProfile");
  12698. infile = fopen ((char*)filename, "r");
  12699. outfile = fopen ((char*)tmpProfileName, "w");
  12700. int d = fgetc(infile);
  12701. rewind(infile);
  12702. if(d == EOF)
  12703. {
  12704. // Profile is empty
  12705. fprintf(outfile,"%s\n", payload);
  12706. fclose(infile);
  12707. fclose(outfile);
  12708. sprintf(rmFileCmd,"rm -f %s",filename);
  12709. system(rmFileCmd);
  12710. rename((char*)tmpProfileName, (char*)filename);
  12711. }
  12712. else
  12713. {
  12714. // Profile is not empty
  12715. char buf[2048]={0};
  12716. int ChargingProfileAdded = FALSE;
  12717. while (fgets(buf, sizeof(buf), infile) != NULL)
  12718. {
  12719. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  12720. json_object *tmpChargingProfile;
  12721. tmpChargingProfile = json_tokener_parse(buf);
  12722. if(!is_error(tmpChargingProfile))
  12723. {
  12724. if(json_object_object_get(tmpChargingProfile, "evseId") != NULL)
  12725. {
  12726. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "evseId") );
  12727. }
  12728. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  12729. {
  12730. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  12731. {
  12732. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  12733. }
  12734. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  12735. {
  12736. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  12737. }
  12738. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  12739. {
  12740. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  12741. }
  12742. }
  12743. }
  12744. json_object_put(tmpChargingProfile);
  12745. if((tempconnectorIdInt == gun_index) &&
  12746. (tempchargingProfileIdInt == json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"))))
  12747. {
  12748. if((tempstackLevelInt == json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"))) &&
  12749. (strcmp(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose"))) == 0))
  12750. {
  12751. //DEBUG_INFO("update set chargingProfile to file -0\n");
  12752. if(ChargingProfileAdded == FALSE)
  12753. {
  12754. fprintf(outfile,"%s\n",payload);
  12755. ChargingProfileAdded = TRUE;
  12756. }
  12757. }
  12758. else
  12759. {
  12760. if(tempstackLevelInt < json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel")))
  12761. {
  12762. if(ChargingProfileAdded == FALSE)
  12763. {
  12764. fprintf(outfile,"%s\n",buf);
  12765. fprintf(outfile,"%s\n",payload);
  12766. ChargingProfileAdded = TRUE;
  12767. }
  12768. else
  12769. {
  12770. fprintf(outfile,"%s\n",buf);
  12771. }
  12772. }
  12773. else
  12774. {
  12775. if(ChargingProfileAdded == FALSE)
  12776. {
  12777. fprintf(outfile,"%s\n",buf);
  12778. fprintf(outfile,"%s\n",payload);
  12779. ChargingProfileAdded = TRUE;
  12780. }
  12781. else
  12782. {
  12783. fprintf(outfile,"%s\n",buf);
  12784. }
  12785. }
  12786. }
  12787. }
  12788. else
  12789. {
  12790. if(tempchargingProfileIdInt < json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId")))
  12791. {
  12792. if(ChargingProfileAdded == FALSE)
  12793. {
  12794. fprintf(outfile,"%s\n",buf);
  12795. fprintf(outfile,"%s\n",payload);
  12796. ChargingProfileAdded = TRUE;
  12797. }
  12798. else
  12799. {
  12800. fprintf(outfile,"%s\n",buf);
  12801. }
  12802. }
  12803. else if(tempstackLevelInt < json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel")))
  12804. {
  12805. if(ChargingProfileAdded == FALSE)
  12806. {
  12807. fprintf(outfile,"%s\n",buf);
  12808. fprintf(outfile,"%s\n",payload);
  12809. ChargingProfileAdded = TRUE;
  12810. }
  12811. else
  12812. {
  12813. fprintf(outfile,"%s\n",buf);
  12814. }
  12815. }
  12816. else
  12817. {
  12818. if(ChargingProfileAdded == FALSE)
  12819. {
  12820. fprintf(outfile,"%s\n",buf);
  12821. fprintf(outfile,"%s\n",payload);
  12822. ChargingProfileAdded = TRUE;
  12823. }
  12824. else
  12825. {
  12826. fprintf(outfile,"%s\n",buf);
  12827. }
  12828. }
  12829. }
  12830. } // end of while loop
  12831. fclose(infile);
  12832. fclose(outfile);
  12833. sprintf(rmFileCmd,"rm -f %s",filename);
  12834. system(rmFileCmd);
  12835. rename((char*)tmpProfileName, (char*)filename);
  12836. }
  12837. sprintf((char*)ShmOCPP20Data->SetChargingProfile[(gun_index==0?gun_index:gun_index-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted] );
  12838. result = PASS;
  12839. }
  12840. else
  12841. {
  12842. if(gun_index == -1)
  12843. DEBUG_WARN("Connector id is wrong.\n");
  12844. if(isConnectorMismatch)
  12845. DEBUG_WARN("Connector id is mismatch.\n");
  12846. if(isPeriodOverMax)
  12847. DEBUG_WARN("Profile periods quantity is over spec.\n");
  12848. if(isProfileOverMax)
  12849. DEBUG_WARN("Profile quantity is over spec.\n");
  12850. sprintf((char*)ShmOCPP20Data->SetChargingProfile[(gun_index==0?gun_index:gun_index-1)].Response_status, "%s", ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Rejected] );
  12851. }
  12852. }
  12853. json_object_put(SetChargingProfile);
  12854. if(strcmp((char*)ShmOCPP20Data->SetChargingProfile[(gun_index==0?gun_index:gun_index-1)].Response_status, ChargingProfileStatusEnumTypeStr[ChargingProfileStatusEnumType_Accepted]) == 0)
  12855. {
  12856. if(gun_index == 0)
  12857. {
  12858. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  12859. {
  12860. checkCompositeSchedule((idx+1), 86400, &ShmOCPP20Data->SmartChargingProfile[idx], 0, TRUE);
  12861. }
  12862. }
  12863. else
  12864. checkCompositeSchedule(gun_index, 86400, &ShmOCPP20Data->SmartChargingProfile[gun_index-1], 0, TRUE);
  12865. }
  12866. sendSetChargingProfileConfirmation(uuid, (gun_index==0?gun_index:gun_index-1));
  12867. system("/bin/fsync -d /dev/mtdblock13;/bin/sync &");
  12868. return result;
  12869. }
  12870. int handleSetDisplayMessagesRequest(char *uuid, char *payload)
  12871. {
  12872. mtrace();
  12873. int result = FAIL;
  12874. json_object *SetDisplayMessage;
  12875. DEBUG_INFO("handleSetDisplayMessageRequest...\n");
  12876. SetDisplayMessage = json_tokener_parse(payload);
  12877. if(!is_error(SetDisplayMessage))
  12878. {
  12879. memset(&ShmOCPP20Data->SetDisplayMessage, 0, sizeof(struct SetDisplayMessage_20));
  12880. memcpy(&ShmOCPP20Data->SetDisplayMessage.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetDisplayMessage.guid));
  12881. // Required data
  12882. if(json_object_object_get(SetDisplayMessage, "message") != NULL)
  12883. {
  12884. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "id") != NULL)
  12885. ShmOCPP20Data->SetDisplayMessage.message.id = json_object_get_int(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "id"));
  12886. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "priority") != NULL)
  12887. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.priority, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "priority")));
  12888. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "state") != NULL)
  12889. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.state, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "state")));
  12890. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "startDateTime") != NULL)
  12891. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.startDateTime, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "startDateTime")));
  12892. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "endDateTime") != NULL)
  12893. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.endDateTime, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "endDateTime")));
  12894. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "transactionId") != NULL)
  12895. sprintf((char*)ShmOCPP20Data->SetDisplayMessage.message.transactionId, "%s",json_object_get_string(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "transactionId")));
  12896. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message") != NULL)
  12897. {
  12898. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "format") != NULL)
  12899. 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")));
  12900. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "language") != NULL)
  12901. 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")));
  12902. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "message"), "content") != NULL)
  12903. 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")));
  12904. }
  12905. if(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display") != NULL)
  12906. {
  12907. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "name") != NULL)
  12908. 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")));
  12909. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "instance") != NULL)
  12910. 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")));
  12911. if(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse") != NULL)
  12912. {
  12913. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "id") != NULL)
  12914. 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"));
  12915. if(json_object_object_get(json_object_object_get(json_object_object_get(json_object_object_get(SetDisplayMessage, "message"), "display"), "evse"), "connectorId") != NULL)
  12916. 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"));
  12917. }
  12918. }
  12919. }
  12920. }
  12921. json_object_put(SetDisplayMessage);
  12922. strcpy((char*)ShmOCPP20Data->SetDisplayMessage.Response_status, DisplayMessageStatusEnumTypeStr[DisplayMessageStatusEnumType_Accepted]);
  12923. sendSetDisplayMessagesConfirmation(uuid);
  12924. // Announce CSU there is display request come from server
  12925. ShmOCPP20Data->MsMsg.bits.SetDisplayMessageReq = ON;
  12926. return result;
  12927. }
  12928. int handleSetMonitoringBaseRequest(char *uuid, char *payload)
  12929. {
  12930. mtrace();
  12931. int result = FAIL;
  12932. json_object *SetMonitoringBase;
  12933. DEBUG_INFO("handleSetMonitoringBaseRequest...\n");
  12934. SetMonitoringBase = json_tokener_parse(payload);
  12935. if(!is_error(SetMonitoringBase))
  12936. {
  12937. memset(&ShmOCPP20Data->SetMonitoringBase, 0, sizeof(struct SetMonitoringBase_20));
  12938. memcpy(&ShmOCPP20Data->SetMonitoringBase.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetMonitoringBase.guid));
  12939. // Required data
  12940. if(json_object_object_get(SetMonitoringBase, "monitoringBase") != NULL)
  12941. sprintf((char*)ShmOCPP20Data->SetMonitoringBase.monitoringBase, "%s",json_object_get_string(json_object_object_get(SetMonitoringBase, "monitoringBase")));
  12942. }
  12943. json_object_put(SetMonitoringBase);
  12944. /*
  12945. * TODO:
  12946. * 1. Configure monitor base and response
  12947. */
  12948. strcpy((char*)ShmOCPP20Data->SetMonitoringBase.Response_status, GenericDeviceModelStatusEnumTypeStr[GenericDeviceModelStatusEnumType_Accepted]);
  12949. sendSetMonitoringBaseConfirmation(uuid);
  12950. return result;
  12951. }
  12952. int handleSetMonitoringLevelRequest(char *uuid, char *payload)
  12953. {
  12954. mtrace();
  12955. int result = FAIL;
  12956. json_object *SetMonitoringLevel;
  12957. DEBUG_INFO("handleSetMonitoringLevelRequest...\n");
  12958. SetMonitoringLevel = json_tokener_parse(payload);
  12959. if(!is_error(SetMonitoringLevel))
  12960. {
  12961. memset(&ShmOCPP20Data->SetMonitoringLevel, 0, sizeof(struct SetMonitoringLevel_20));
  12962. memcpy(&ShmOCPP20Data->SetMonitoringLevel.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetMonitoringLevel.guid));
  12963. // Required data
  12964. if(json_object_object_get(SetMonitoringLevel, "severity") != NULL)
  12965. ShmOCPP20Data->SetMonitoringLevel.severity = json_object_get_int(json_object_object_get(SetMonitoringLevel, "severity"));
  12966. }
  12967. json_object_put(SetMonitoringLevel);
  12968. /*
  12969. * TODO:
  12970. * Configure monitor status and response
  12971. */
  12972. strcpy((char*)ShmOCPP20Data->SetMonitoringLevel.Response_status, GenericStatusEnumTypeStr[GenericStatusEnumType_Accepted]);
  12973. sendSetMonitoringLevelConfirmation(uuid);
  12974. return result;
  12975. }
  12976. int handleSetNetworkProfileRequest(char *uuid, char *payload)
  12977. {
  12978. mtrace();
  12979. int result = FAIL;
  12980. json_object *SetNetworkProfile;
  12981. DEBUG_INFO("handleSetNetworkProfileRequest...\n");
  12982. SetNetworkProfile = json_tokener_parse(payload);
  12983. if(!is_error(SetNetworkProfile))
  12984. {
  12985. memset(&ShmOCPP20Data->SetNetworkProfile, 0, sizeof(struct SetNetworkProfile_20));
  12986. memcpy(&ShmOCPP20Data->SetNetworkProfile.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.guid));
  12987. // Required data
  12988. if(json_object_object_get(SetNetworkProfile, "configurationSlot") != NULL)
  12989. ShmOCPP20Data->SetNetworkProfile.configurationSlot = json_object_get_int(json_object_object_get(SetNetworkProfile, "configurationSlot"));
  12990. if(json_object_object_get(SetNetworkProfile, "connectionData") != NULL)
  12991. {
  12992. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppVersion") != NULL)
  12993. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppVersion")));
  12994. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport") != NULL)
  12995. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppTransport")));
  12996. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl") != NULL)
  12997. {
  12998. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppCsmsUrl")));
  12999. memcpy((char*)ShmOCPP20Data->OcppServerURL, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.ocppCsmsUrl));
  13000. }
  13001. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout") != NULL)
  13002. ShmOCPP20Data->SetNetworkProfile.connectionData.messageTimeout = json_object_get_int(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "messageTimeout"));
  13003. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppInterface") != NULL)
  13004. sprintf((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppInterface, "%s", json_object_get_string(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "ocppInterface")));
  13005. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn") != NULL)
  13006. {
  13007. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "server") != NULL)
  13008. 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")));
  13009. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "user") != NULL)
  13010. 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")));
  13011. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "group") != NULL)
  13012. 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")));
  13013. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "password") != NULL)
  13014. 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")));
  13015. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "key") != NULL)
  13016. 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")));
  13017. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "vpn"), "type") != NULL)
  13018. 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")));
  13019. }
  13020. if(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn") != NULL)
  13021. {
  13022. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apn") != NULL)
  13023. {
  13024. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn));
  13025. 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")));
  13026. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apn);
  13027. }
  13028. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnUserName") != NULL)
  13029. {
  13030. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName));
  13031. 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")));
  13032. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapId, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnUserName);
  13033. }
  13034. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnPassword") != NULL)
  13035. {
  13036. memset(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword, 0x00, ARRAY_SIZE(ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword));
  13037. 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")));
  13038. strcpy((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomChapPapPwd, (char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnPassword);
  13039. }
  13040. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "simPin") != NULL)
  13041. 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"));
  13042. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "preferredNetwork") != NULL)
  13043. 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")));
  13044. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "useOnlyPreferredNetwork") != NULL)
  13045. 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"));
  13046. if(json_object_object_get(json_object_object_get(json_object_object_get(SetNetworkProfile, "connectionData"), "apn"), "apnAuthentication") != NULL)
  13047. 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")));
  13048. }
  13049. DB_addNetworkProfile(ShmOCPP20Data->SetNetworkProfile.configurationSlot, (char*)json_object_get_string(json_object_object_get(SetNetworkProfile, "connectionData")));
  13050. }
  13051. }
  13052. json_object_put(SetNetworkProfile);
  13053. /*
  13054. * TODO:
  13055. * 1. Process network configuration and response
  13056. */
  13057. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP12]) == 0)
  13058. {
  13059. }
  13060. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP15]) == 0)
  13061. {
  13062. }
  13063. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP16]) == 0)
  13064. {
  13065. }
  13066. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppVersion, OCPPVersionEnumTypeStr[OCPPVersionEnumType_OCPP20]) == 0)
  13067. {
  13068. }
  13069. else
  13070. {
  13071. }
  13072. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, OCPPTransportEnumTypeStr[OCPPTransportEnumType_JSON]) == 0)
  13073. {
  13074. }
  13075. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.ocppTransport, OCPPTransportEnumTypeStr[OCPPTransportEnumType_SOAP]) == 0)
  13076. {
  13077. }
  13078. else
  13079. {
  13080. }
  13081. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired0]) == 0)
  13082. {
  13083. }
  13084. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired1]) == 0)
  13085. {
  13086. }
  13087. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired2]) == 0)
  13088. {
  13089. }
  13090. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wired3]) == 0)
  13091. {
  13092. }
  13093. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless0]) == 0)
  13094. {
  13095. }
  13096. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless1]) == 0)
  13097. {
  13098. }
  13099. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless2]) == 0)
  13100. {
  13101. }
  13102. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, OCPPInterfaceEnumTypeStr[OCPPInterfaceEnumType_Wireless3]) == 0)
  13103. {
  13104. }
  13105. else
  13106. {
  13107. }
  13108. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_IKEv2]) == 0)
  13109. {
  13110. }
  13111. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_IPSec]) == 0)
  13112. {
  13113. }
  13114. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_L2TP]) == 0)
  13115. {
  13116. }
  13117. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.vpn.type, VPNEnumTypeStr[VPNEnumType_PPTP]) == 0)
  13118. {
  13119. }
  13120. else
  13121. {
  13122. }
  13123. if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_CHAP]) == 0)
  13124. {
  13125. }
  13126. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_NONE]) == 0)
  13127. {
  13128. }
  13129. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_PAP]) == 0)
  13130. {
  13131. }
  13132. else if(strcmp((char*)ShmOCPP20Data->SetNetworkProfile.connectionData.apn.apnAuthentication, APNAuthenticationEnumTypeStr[APNAuthenticationEnumType_AUTO]) == 0)
  13133. {
  13134. }
  13135. else
  13136. {
  13137. }
  13138. strcpy((char*)ShmOCPP20Data->SetNetworkProfile.Response_status, SetNetworkProfileStatusEnumTypeStr[SetNetworkProfileStatusEnumType_Accepted]);
  13139. sendSetNetworkProfileConfirmation(uuid);
  13140. return result;
  13141. }
  13142. int handleSetVariableMonitoringRequest(char *uuid, char *payload)
  13143. {
  13144. mtrace();
  13145. int result = FAIL;
  13146. json_object *SetVariableMonitoring;
  13147. uint8_t variableQuantity = 0;
  13148. DEBUG_INFO("handleSetVariableMonitoringRequest...\n");
  13149. SetVariableMonitoring = json_tokener_parse(payload);
  13150. if(!is_error(SetVariableMonitoring))
  13151. {
  13152. memset(&ShmOCPP20Data->SetVariableMonitoring, 0, sizeof(struct SetVariableMonitoring_20));
  13153. memcpy(&ShmOCPP20Data->SetVariableMonitoring.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetVariableMonitoring.guid));
  13154. // Required data
  13155. for(int idx=0;idx<json_object_array_length(json_object_object_get(SetVariableMonitoring, "setMonitoringData"));idx++)
  13156. {
  13157. variableQuantity++;
  13158. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "id") != NULL)
  13159. {
  13160. 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"));
  13161. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].id = ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].id;
  13162. }
  13163. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "value") != NULL)
  13164. {
  13165. 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"));
  13166. }
  13167. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "type") != NULL)
  13168. {
  13169. 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")));
  13170. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].type, (char*)ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].type);
  13171. }
  13172. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "severity") != NULL)
  13173. {
  13174. 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"));
  13175. ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].severity = ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].severity;
  13176. }
  13177. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "setMonitoringData"), idx), "transaction") != NULL)
  13178. {
  13179. 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"));
  13180. }
  13181. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "component") != NULL)
  13182. {
  13183. 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)
  13184. {
  13185. 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")));
  13186. }
  13187. 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)
  13188. {
  13189. 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")));
  13190. }
  13191. 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)
  13192. {
  13193. 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)
  13194. {
  13195. 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"));
  13196. }
  13197. 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)
  13198. {
  13199. 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"));
  13200. }
  13201. }
  13202. memcpy(&ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].component, &ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].component, sizeof(struct ComponentType));
  13203. }
  13204. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariableMonitoring, "json_object_array_get_idx"), idx), "variable") != NULL)
  13205. {
  13206. 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)
  13207. {
  13208. 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")));
  13209. }
  13210. 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)
  13211. {
  13212. 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")));
  13213. }
  13214. memcpy(&ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].variable , &ShmOCPP20Data->SetVariableMonitoring.setMonitoringData[idx].variable, sizeof(struct VariableType));
  13215. }
  13216. strcpy((char*)ShmOCPP20Data->SetVariableMonitoring.Response_setMonitoringResult[idx].status, SetMonitoringStatusEnumTypeStr[SetMonitoringStatusEnumType_Accepted]);
  13217. }
  13218. }
  13219. json_object_put(SetVariableMonitoring);
  13220. sendSetVariableMonitoringConfirmation(uuid, variableQuantity);
  13221. return result;
  13222. }
  13223. int handleSetVariablesRequest(char *uuid, char *payload)
  13224. {
  13225. mtrace();
  13226. int result = FAIL;
  13227. json_object *SetVariables;
  13228. DEBUG_INFO("handleSetVariablesRequest...\n");
  13229. SetVariables = json_tokener_parse(payload);
  13230. if(!is_error(SetVariables))
  13231. {
  13232. memset(&ShmOCPP20Data->SetVariables, 0, sizeof(struct SetVariables_20));
  13233. memcpy(&ShmOCPP20Data->SetVariables.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->SetVariables.guid));
  13234. // Required data
  13235. for(int idx=0;idx<json_object_array_length(json_object_object_get(SetVariables, "setVariableData"));idx++)
  13236. {
  13237. if(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx) != NULL)
  13238. {
  13239. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component") != NULL)
  13240. {
  13241. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "name") != NULL)
  13242. {
  13243. 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")));
  13244. }
  13245. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "instance") != NULL)
  13246. {
  13247. 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")));
  13248. }
  13249. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "component"), "evse") != NULL)
  13250. {
  13251. 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)
  13252. {
  13253. 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"));
  13254. }
  13255. 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)
  13256. {
  13257. 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"));
  13258. }
  13259. }
  13260. memcpy(&ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].component, &ShmOCPP20Data->SetVariables.setVariableData[idx].component, sizeof(struct ComponentType));
  13261. }
  13262. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable") != NULL)
  13263. {
  13264. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "name") != NULL)
  13265. {
  13266. 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")));
  13267. }
  13268. if(json_object_object_get(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "variable"), "instance") != NULL)
  13269. {
  13270. 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")));
  13271. }
  13272. memcpy(&ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].variable , &ShmOCPP20Data->SetVariables.setVariableData[idx].variable, sizeof(struct VariableType));
  13273. }
  13274. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeType") != NULL)
  13275. {
  13276. 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")));
  13277. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeType, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeType);
  13278. }
  13279. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(SetVariables, "setVariableData"), idx), "attributeValue") != NULL)
  13280. {
  13281. 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")));
  13282. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_UnknownComponent]);
  13283. for(uint8_t idx_var=0;idx_var<CtrlrVariable_CNT;idx_var++)
  13284. {
  13285. if((strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].component.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name) != NULL) &&
  13286. (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) &&
  13287. (strstr((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variable.name, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name) != NULL) &&
  13288. (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))
  13289. {
  13290. strcpy((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value, (char*)ShmOCPP20Data->SetVariables.setVariableData[idx].attributeValue);
  13291. DB_variableSaveToDb(&ShmOCPP20Data->ControllerComponentVariable[idx_var]);
  13292. if(((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL)) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "NetworkConfigurationPriority") != NULL))
  13293. {
  13294. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_RebootRequired]);
  13295. }
  13296. else
  13297. strcpy((char*)ShmOCPP20Data->SetVariables.Response_setVariableResult[idx].attributeStatus, SetVariableStatusEnumTypeStr[SetVariableStatusEnumType_Accepted]);
  13298. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "OCPPCommCtrlr") != NULL) && (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "WebSocketPingInterval") != NULL))
  13299. {
  13300. ChageWebSocketPingInterval(atoi((char*)ShmOCPP20Data->ControllerComponentVariable[idx_var].variableAttribute[0].value));
  13301. }
  13302. if((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].component.name, "SecurityCtrlr") != NULL) &&
  13303. ((strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "SecurityProfile") != NULL) || (strstr((char*)ShmOCPP20Data->SetVariables.setVariableData[idx].variable.name, "BasicAuthPassword") != NULL)))
  13304. {
  13305. StoreUsrConfigData(&ShmSysConfigAndInfo->SysConfig);
  13306. SetOcppConnStatus(FALSE);
  13307. }
  13308. }
  13309. }
  13310. }
  13311. }
  13312. }
  13313. sendSetVariableConfirmation(uuid, json_object_array_length(json_object_object_get(SetVariables, "setVariableData")));
  13314. }
  13315. json_object_put(SetVariables);
  13316. return result;
  13317. }
  13318. int handleTriggerMessageRequest(char *uuid, char *payload)
  13319. {
  13320. mtrace();
  13321. int result = FAIL;
  13322. int connectorIdIsNULL = FALSE;
  13323. int connectorIdInt =0;
  13324. json_object *TriggerMessage;
  13325. DEBUG_INFO("handleTriggerMessageRequest\n");
  13326. TriggerMessage = json_tokener_parse(payload);
  13327. if(!is_error(TriggerMessage))
  13328. {
  13329. memset(&ShmOCPP20Data->TriggerMessage, 0, sizeof(struct TriggerMessage_20));
  13330. memcpy(&ShmOCPP20Data->TriggerMessage.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->TriggerMessage.guid));
  13331. // Required data
  13332. if(json_object_object_get(TriggerMessage, "requestedMessage") != NULL)
  13333. sprintf((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, "%s", json_object_get_string(json_object_object_get(TriggerMessage, "requestedMessage")));
  13334. // Optional data
  13335. if(json_object_object_get(TriggerMessage, "evse") != NULL)
  13336. {
  13337. // Required data
  13338. if(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "id") != NULL)
  13339. ShmOCPP20Data->TriggerMessage.evse.id = json_object_get_int(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "id"));
  13340. // Optional data
  13341. if(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "connectorId") != NULL)
  13342. {
  13343. ShmOCPP20Data->TriggerMessage.evse.connectorId = json_object_get_int(json_object_object_get(json_object_object_get(TriggerMessage, "evse"), "connectorId"));
  13344. connectorIdInt = ShmOCPP20Data->TriggerMessage.evse.connectorId;
  13345. }
  13346. else
  13347. connectorIdIsNULL = TRUE;
  13348. }
  13349. }
  13350. json_object_put(TriggerMessage);
  13351. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  13352. {
  13353. if((strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_BootNotification]) != 0) &&
  13354. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_LogStatusNotification]) != 0) &&
  13355. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_FirmwareStatusNotification]) != 0 ) &&
  13356. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_Heartbeat]) != 0) &&
  13357. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_MeterValues]) != 0) &&
  13358. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) != 0 ) &&
  13359. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignV2GCertificate]) != 0 ) &&
  13360. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_StatusNotification]) != 0 ) &&
  13361. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_TransactionEvent]) != 0 ) &&
  13362. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignCombinedCertificate]) != 0 ) &&
  13363. (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_PublishFirmwareStatusNotification]) != 0 ))
  13364. {
  13365. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_NotImplemented] );
  13366. sendTriggerMessageConfirmation(uuid);
  13367. return TRUE;
  13368. }
  13369. else
  13370. {
  13371. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Accepted] );
  13372. sendTriggerMessageConfirmation(uuid);
  13373. }
  13374. }
  13375. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  13376. {
  13377. sprintf((char*)ShmOCPP20Data->TriggerMessage.Response_status, "%s",TriggerMessageStatusEnumTypeStr[TriggerMessageStatusEnumType_Rejected] );
  13378. sendTriggerMessageConfirmation(uuid);
  13379. return TRUE;
  13380. }
  13381. //==========================
  13382. // Trigger message
  13383. //==========================
  13384. if( strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_FirmwareStatusNotification]) == 0)
  13385. {
  13386. if((strlen((char*)ShmOCPP20Data->FirmwareStatusNotification.status) == 0) ||
  13387. ((FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Downloading) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Downloaded) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Idle) && (FirmwareStatusNotificationStatus != FirmwareStatusEnumType_Installing)))
  13388. {
  13389. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle;
  13390. }
  13391. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  13392. }
  13393. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_LogStatusNotification]) == 0 )
  13394. {
  13395. if(strlen((char*)ShmOCPP20Data->LogStatusNotification.status) == 0)
  13396. sprintf((char*)ShmOCPP20Data->LogStatusNotification.status, "%s", UploadLogStatusEnumTypeStr[UploadLogStatusEnumType_Idle]);
  13397. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = ON;
  13398. }
  13399. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_BootNotification]) == 0 )
  13400. {
  13401. if(DB_updateBootType(BootReasonEnumType_Triggered))
  13402. server_sign = FALSE;
  13403. }
  13404. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_Heartbeat]) == 0 )
  13405. {
  13406. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP20Data->BootNotification.Response_interval);
  13407. }
  13408. else if (strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_MeterValues]) == 0 )
  13409. {
  13410. if(connectorIdIsNULL == FALSE)
  13411. {
  13412. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13413. {
  13414. cpinitateMsg.bits[connectorIdInt-1].TriggerMeterValueReq = ON;
  13415. }
  13416. }
  13417. else
  13418. {
  13419. for(int idx=0;idx< gunTotalNumber;idx++)
  13420. {
  13421. cpinitateMsg.bits[idx].TriggerMeterValueReq = ON;
  13422. }
  13423. }
  13424. }
  13425. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_StatusNotification]) == 0 )
  13426. {
  13427. if(connectorIdIsNULL == FALSE)
  13428. {
  13429. if((connectorIdInt > 0) && ((connectorIdInt-1) < gunTotalNumber))
  13430. {
  13431. cpinitateMsg.bits[connectorIdInt-1].TriggerStatusNotificationReq = ON;
  13432. //clientTime.StatusNotification[connectorIdInt-1] = time((time_t*)NULL);
  13433. }
  13434. }
  13435. else
  13436. {
  13437. for(int idx=0;idx< gunTotalNumber;idx++)
  13438. {
  13439. cpinitateMsg.bits[idx].TriggerStatusNotificationReq = ON;
  13440. //clientTime.StatusNotification[idx] = time((time_t*)NULL);
  13441. }
  13442. }
  13443. }
  13444. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignChargingStationCertificate]) == 0 )
  13445. {
  13446. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  13447. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13448. {
  13449. 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\" &");
  13450. }
  13451. }
  13452. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignV2GCertificate]) == 0 )
  13453. {
  13454. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  13455. if(access("/Storage/OCPP/certV2G.csr",F_OK) == -1)
  13456. {
  13457. 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\" &");
  13458. }
  13459. }
  13460. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_TransactionEvent]) == 0 )
  13461. {
  13462. if(connectorIdIsNULL == FALSE)
  13463. {
  13464. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  13465. {
  13466. cpinitateMsg.bits[connectorIdInt -1].TransactionEventReq = ON;
  13467. }
  13468. }
  13469. else
  13470. {
  13471. for(int idx=0;idx< gunTotalNumber;idx++)
  13472. cpinitateMsg.bits[idx].TransactionEventReq = ON;
  13473. }
  13474. }
  13475. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_SignCombinedCertificate]) == 0 )
  13476. {
  13477. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = ON;
  13478. if(access("/Storage/OCPP/certCP.csr",F_OK) == -1)
  13479. {
  13480. 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\" &");
  13481. }
  13482. if(access("/Storage/OCPP/certV2G.csr",F_OK) == -1)
  13483. {
  13484. 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\" &");
  13485. }
  13486. }
  13487. else if(strcmp((char*)ShmOCPP20Data->TriggerMessage.requestedMessage, MessageTriggerEnumTypeStr[MessageTriggerEnumType_PublishFirmwareStatusNotification]) == 0 )
  13488. {
  13489. ShmOCPP20Data->MsMsg.bits.PublishFirmwareReq = ON;
  13490. }
  13491. return result;
  13492. }
  13493. int handleUnlockConnectorRequest(char *uuid, char *payload)
  13494. {
  13495. mtrace();
  13496. int result = FAIL;
  13497. int connectorIdInt =0;
  13498. int tempIndex = 0;
  13499. json_object *UnlockConnector;
  13500. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  13501. UnlockConnector = json_tokener_parse(payload);
  13502. if(!is_error(UnlockConnector))
  13503. {
  13504. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  13505. {
  13506. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  13507. }
  13508. if(json_object_object_get(UnlockConnector, "evseId") != NULL)
  13509. {
  13510. ShmOCPP20Data->UnlockConnector[(connectorIdInt>0?connectorIdInt-1:0)].evseId = json_object_get_int(json_object_object_get(UnlockConnector, "evseId"));
  13511. }
  13512. }
  13513. json_object_put(UnlockConnector);
  13514. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  13515. if(gunTotalNumber == 0)
  13516. {
  13517. sprintf((char*)ShmOCPP20Data->UnlockConnector[connectorIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  13518. goto end;
  13519. }
  13520. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  13521. {
  13522. sprintf((char*)ShmOCPP20Data->UnlockConnector[connectorIdInt-1].Response_status, "%s", UnlockStatusEnumTypeStr[UnlockStatusEnumType_UnknownConnector] );
  13523. goto end;
  13524. }
  13525. else
  13526. {
  13527. memset(&ShmOCPP20Data->UnlockConnector[connectorIdInt-1], 0, sizeof(struct UnlockConnector_20));
  13528. memcpy(&ShmOCPP20Data->UnlockConnector[connectorIdInt-1].guid, uuid, ARRAY_SIZE(ShmOCPP20Data->UnlockConnector[connectorIdInt-1].guid));
  13529. //check Transaction active
  13530. if(gunType[connectorIdInt-1] == GUN_TYPE_CHAdeMO)
  13531. {
  13532. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13533. {
  13534. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13535. }
  13536. else
  13537. {
  13538. tempIndex = connectorIdInt -1;
  13539. }
  13540. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13541. {
  13542. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  13543. {
  13544. //stop Transaction
  13545. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  13546. }
  13547. }
  13548. }
  13549. else if(gunType[connectorIdInt-1] == GUN_TYPE_CCS)
  13550. {
  13551. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13552. {
  13553. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13554. }
  13555. else
  13556. {
  13557. tempIndex = connectorIdInt -1;
  13558. }
  13559. for (int index = 0; index < CCS_QUANTITY; index++)
  13560. {
  13561. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  13562. {
  13563. //stop Transaction
  13564. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  13565. }
  13566. }
  13567. }
  13568. else if(gunType[connectorIdInt-1] == GUN_TYPE_GBT)
  13569. {
  13570. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13571. {
  13572. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  13573. }
  13574. else
  13575. {
  13576. tempIndex = connectorIdInt -1;
  13577. }
  13578. for (int index = 0; index < GB_QUANTITY; index++)
  13579. {
  13580. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  13581. {
  13582. //stop Transaction
  13583. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  13584. }
  13585. }
  13586. }
  13587. else if(gunType[connectorIdInt-1] == GUN_TYPE_DO)
  13588. {
  13589. tempIndex = connectorIdInt -1;
  13590. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13591. {
  13592. 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)))
  13593. {
  13594. //stop Transaction
  13595. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  13596. }
  13597. }
  13598. }
  13599. else
  13600. {
  13601. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13602. {
  13603. tempIndex = 2;
  13604. }
  13605. else
  13606. {
  13607. tempIndex = connectorIdInt-1;
  13608. }
  13609. for (int index = 0; index < AC_QUANTITY; index++)
  13610. {
  13611. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  13612. {
  13613. ShmOCPP20Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = ON;
  13614. }
  13615. }
  13616. }
  13617. ShmOCPP20Data->UnlockConnector[connectorIdInt-1].connectorId = connectorIdInt;
  13618. strcpy((char *)ShmOCPP20Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  13619. result = TRUE;
  13620. return result;
  13621. }
  13622. end:
  13623. //json_object_put(obj); --- remove temporally
  13624. sendUnlockConnectorConfirmation(uuid, connectorIdInt-1);
  13625. return result;
  13626. }
  13627. int handleUnpublishFirmwareRequest(char *uuid, char *payload)
  13628. {
  13629. mtrace();
  13630. int result = FAIL;
  13631. json_object *UnpublishFirmware;
  13632. DEBUG_INFO("handleUnpublishFirmwareRequest...\n");
  13633. UnpublishFirmware = json_tokener_parse(payload);
  13634. if(!is_error(UnpublishFirmware))
  13635. {
  13636. memset(&ShmOCPP20Data->UnpublishFirmware, 0, sizeof(struct UnpublishFirmware_20));
  13637. memcpy(&ShmOCPP20Data->UnpublishFirmware.guid, uuid, ARRAY_SIZE(ShmOCPP20Data->UnpublishFirmware.guid));
  13638. // Required data
  13639. if(json_object_object_get(UnpublishFirmware, "checksum") != NULL)
  13640. sprintf((char*)ShmOCPP20Data->UnpublishFirmware.checksum, json_object_get_string(json_object_object_get(UnpublishFirmware, "checksum")));
  13641. }
  13642. json_object_put(UnpublishFirmware);
  13643. ShmOCPP20Data->MsMsg.bits.UnpublishFirmwareReq = ON;
  13644. /*
  13645. * TODO:
  13646. * 1. Check unpublished status
  13647. */
  13648. sprintf((char*)ShmOCPP20Data->UnpublishFirmware.Response_status, UnpublishFirmwareStatusEnumTypeStr[Unpublished_NoFirmware]);
  13649. sendUnpublishFirmwareConfirmation(uuid);
  13650. return result;
  13651. }
  13652. static char UpdateFirmwarepayloadData[512]={0};
  13653. void *UpdateFirmwareProcess(void *data)
  13654. {
  13655. pthread_detach(pthread_self());
  13656. mtrace();
  13657. int retriesInt =0, retryIntervalInt=0;
  13658. char protocol[10], user[64],password[64],host[128], path[512], ftppath[512],host1[128],path1[512];
  13659. int port=0;
  13660. char locationstr[1024]={0}, retrieveDatestr[36]={0};
  13661. int isSuccess = 0;
  13662. char ftpbuf[1024];
  13663. char temp[1024];
  13664. char * pch;
  13665. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  13666. json_object *UpdateFirmware;
  13667. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  13668. if(!is_error(UpdateFirmware))
  13669. {
  13670. // Required data
  13671. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  13672. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  13673. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  13674. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  13675. // Optional data
  13676. if(json_object_object_get(UpdateFirmware, "retries"))
  13677. {
  13678. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  13679. }
  13680. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  13681. {
  13682. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  13683. }
  13684. }
  13685. json_object_put(UpdateFirmware);
  13686. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  13687. memset(path, 0, ARRAY_SIZE(path));
  13688. // Wait retrieveData
  13689. if(strlen(retrieveDatestr) > 10)
  13690. {
  13691. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadScheduled]);
  13692. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  13693. do
  13694. {
  13695. sleep(1);
  13696. }while(!isOvertNow((uint8_t*)retrieveDatestr));
  13697. }
  13698. system("rm -f /mnt/*");
  13699. if(strncmp(locationstr,"http", 4) == 0)
  13700. {
  13701. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  13702. sprintf(ftppath,"/%s", path);
  13703. DEBUG_INFO("locationstr: %s\n", locationstr);
  13704. DEBUG_INFO("protocol: %s\n",protocol);
  13705. DEBUG_INFO("host: %s\n",host);
  13706. DEBUG_INFO("path: %s\n",path);
  13707. DEBUG_INFO("ftppath: %s\n",ftppath);
  13708. int ftppathlen=strlen(ftppath);
  13709. int i=1;
  13710. char filenametemp[50];
  13711. while(i < ftppathlen)
  13712. {
  13713. int len=ftppathlen-i;
  13714. if(ftppath[len]== 47) // '/' ascll code: 47
  13715. {
  13716. DEBUG_INFO("compare '/' all right\n");
  13717. break;
  13718. }
  13719. i=i+1;
  13720. }
  13721. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13722. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  13723. filenametemp[i+1] = 0;
  13724. do
  13725. {
  13726. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading]);
  13727. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  13728. sleep(3);
  13729. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  13730. if(!isSuccess)
  13731. {
  13732. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  13733. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  13734. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13735. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  13736. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  13737. }
  13738. else
  13739. {
  13740. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]);
  13741. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  13742. }
  13743. retriesInt--;
  13744. }while((isSuccess == 0)&&(retriesInt >= 0));
  13745. }
  13746. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  13747. {
  13748. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  13749. memset(temp, 0, ARRAY_SIZE(temp));
  13750. strcpy(ftpbuf, locationstr);
  13751. int ftppathlen=strlen(ftpbuf);
  13752. int i=1;
  13753. char filenametemp[50];
  13754. while(i < ftppathlen)
  13755. {
  13756. int len=ftppathlen-i;
  13757. if(ftpbuf[len]== 47) // '/' ascll code: 47
  13758. {
  13759. DEBUG_INFO(" compare '/' all right\n");
  13760. break;
  13761. }
  13762. i=i+1;
  13763. }
  13764. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  13765. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  13766. filenametemp[i+1] = 0;
  13767. strncpy(temp, ftpbuf, ftppathlen-i+1);
  13768. pch=strchr(temp,'@');
  13769. if(pch==NULL)
  13770. {
  13771. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13772. protocol, host, &port, path);
  13773. strcpy(user,"anonymous");
  13774. strcpy(password,"");
  13775. }
  13776. else
  13777. {
  13778. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  13779. protocol, user, password, host, &port, path);
  13780. }
  13781. sscanf(host,"%[^/]%s",host1, path1);
  13782. sprintf(ftppath,"%s", path1);
  13783. if(port == 0)
  13784. {
  13785. port = 21;
  13786. }
  13787. do
  13788. {
  13789. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloading]);
  13790. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  13791. sleep(3);
  13792. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  13793. if(!isSuccess)
  13794. {
  13795. //BulldogUtil.sleepMs(interval*1000);
  13796. DEBUG_INFO("Update firmware request and download file fail.\n");
  13797. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  13798. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  13799. if(retriesInt>0)sleep(retryIntervalInt);else sleep(1);
  13800. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  13801. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  13802. }
  13803. else
  13804. {
  13805. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]);
  13806. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  13807. }
  13808. retriesInt--;
  13809. }while((!isSuccess)&&(retriesInt >= 0));
  13810. }
  13811. else
  13812. {
  13813. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s", FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_DownloadFailed]);
  13814. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  13815. sleep(1);
  13816. sprintf((char*)ShmOCPP20Data->FirmwareStatusNotification.status, "%s",FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Idle]);
  13817. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = ON;
  13818. }
  13819. if(strstr((char*)ShmOCPP20Data->FirmwareStatusNotification.status, FirmwareStatusEnumTypeStr[FirmwareStatusEnumType_Downloaded]) != NULL)ShmOCPP20Data->MsMsg.bits.UpdateFirmwareReq = ON;
  13820. pthread_exit(NULL);
  13821. }
  13822. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  13823. {
  13824. mtrace();
  13825. int result = FAIL;
  13826. pthread_t t;
  13827. sendUpdateFirmwareConfirmation(uuid);
  13828. memset(UpdateFirmwarepayloadData, 0, ARRAY_SIZE(UpdateFirmwarepayloadData));
  13829. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  13830. memset(&ShmOCPP20Data->UpdateFirmware, 0, sizeof(struct UpdateFirmware_20));
  13831. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  13832. ////pthread_join(t, NULL); //
  13833. //pthread_detach(t);
  13834. //sendUpdateFirmwareConfirmation(uuid);
  13835. ShmOCPP20Data->MsMsg.bits.UpdateFirmwareConf = ON;
  13836. return result;
  13837. }
  13838. int handleUnknownRequest(char *uuid, char *payload)
  13839. {
  13840. mtrace();
  13841. int result = FAIL;
  13842. DEBUG_INFO("handleUnknownRequest...\n");
  13843. sendUnknownConfirmation(uuid);
  13844. result = PASS;
  13845. return result;
  13846. }
  13847. //==========================================
  13848. // Handle server response routine
  13849. //==========================================
  13850. void handleAuthorizeResponse(char *payload, int gun_index)
  13851. {
  13852. mtrace();
  13853. DEBUG_INFO("handleAuthorizeResponse...\n");
  13854. json_object *Authorize;
  13855. Authorize = json_tokener_parse(payload);
  13856. if(!is_error(Authorize))
  13857. {
  13858. if(json_object_object_get(Authorize, "idTokenInfo") != NULL)
  13859. {
  13860. // Required data
  13861. sprintf((char *)(char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "status")));
  13862. // Optional data
  13863. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "cacheExpiryDateTime") != NULL)
  13864. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "cacheExpiryDateTime")));
  13865. else
  13866. memset(ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime));
  13867. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "chargingPriority") != NULL)
  13868. ShmOCPP20Data->Authorize.Response_idTokenInfo.chargingPriority = json_object_get_int(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "chargingPriority"));
  13869. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "language1") != NULL)
  13870. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.language1, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language1")));
  13871. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "evseId") != NULL)
  13872. {
  13873. for(int idx=0;idx<json_object_array_length(json_object_object_get(json_object_object_get(Authorize, "idTagInfo"), "evseId"));idx++)
  13874. {
  13875. 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));
  13876. }
  13877. }
  13878. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "language2") != NULL)
  13879. sprintf((char *)ShmOCPP20Data->Authorize.Response_idTokenInfo.language2, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "language2")));
  13880. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "groupIdToken") != NULL)
  13881. {
  13882. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "idToken") != NULL)
  13883. 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")));
  13884. else
  13885. memset(ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken, 0x00, ARRAY_SIZE(ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken));
  13886. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "groupIdToken"), "type") != NULL)
  13887. 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")));
  13888. }
  13889. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "personalMessage") != NULL)
  13890. {
  13891. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "format") != NULL)
  13892. 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")));
  13893. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "language") != NULL)
  13894. 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")));
  13895. if(json_object_object_get(json_object_object_get(json_object_object_get(Authorize,"idTokenInfo"), "personalMessage"), "content") != NULL)
  13896. 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")));
  13897. }
  13898. }
  13899. if(json_object_object_get(Authorize, "certificateStatus") != NULL)
  13900. {
  13901. strcpy((char *)ShmOCPP20Data->Authorize.Response_certificateStatus, json_object_get_string(json_object_object_get(Authorize, "certificateStatus")));
  13902. }
  13903. }
  13904. json_object_put(Authorize);
  13905. //Update idTag information to authorization cache if supported
  13906. if((strcmp((const char *)ShmOCPP20Data->ControllerComponentVariable[AuthCacheCtrlr_Enabled].variableAttribute[0].value, "TRUE") == 0) &&
  13907. (strlen((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.groupIdToken.idToken) > 0) &&
  13908. (strlen((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.cacheExpiryDateTime) >0) &&
  13909. strstr((char*)ShmOCPP20Data->Authorize.Response_idTokenInfo.status, AuthorizationStatusEnumTypeStr[AuthorizationStatusEnumType_Accepted]) != NULL)
  13910. {
  13911. DB_addLocalCache(&ShmOCPP20Data->Authorize.idToken, &ShmOCPP20Data->Authorize.Response_idTokenInfo);
  13912. }
  13913. ShmOCPP20Data->SpMsg.bits.AuthorizeReq = OFF;
  13914. ShmOCPP20Data->SpMsg.bits.AuthorizeConf = ON; // inform csu
  13915. authorizeRetryTimes = 0;
  13916. }
  13917. void handleBootNotificationResponse(char *payload, int gun_index)
  13918. {
  13919. mtrace();
  13920. char statusStr[12]={0};
  13921. char currentTimeStr[30]={0};
  13922. int intervalInt = 0;
  13923. DEBUG_INFO("handleBootNotificationResponse...\n");
  13924. json_object *BootNotification;
  13925. BootNotification = json_tokener_parse(payload);
  13926. if(!is_error(BootNotification))
  13927. {
  13928. // Required data
  13929. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  13930. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  13931. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  13932. }
  13933. json_object_put(BootNotification);
  13934. DEBUG_INFO("statusStr: %s\n", statusStr);
  13935. ShmOCPP20Data->BootNotification.Response_interval = intervalInt;
  13936. BootNotificationInterval = intervalInt;
  13937. HeartBeatWaitTime = intervalInt;
  13938. //write back to ShmOCPP20Data->BootNotification
  13939. strcpy((char *)ShmOCPP20Data->BootNotification.Response_currentTime, currentTimeStr);
  13940. strcpy((char *)ShmOCPP20Data->BootNotification.Response_status, statusStr);
  13941. if((strcmp(statusStr, RegistrationStatusEnumTypeStr[RegistrationStatusEnumType_Accepted]) == 0 ))
  13942. {
  13943. server_sign = TRUE;
  13944. server_pending =FALSE;
  13945. DB_updateBootType(BootReasonEnumType_PowerUp);
  13946. }
  13947. else if(strcmp(statusStr, RegistrationStatusEnumTypeStr[RegistrationStatusEnumType_Pending]) == 0)
  13948. {
  13949. server_pending = TRUE;
  13950. }
  13951. syncDateTimeRTC(ShmOCPP20Data->BootNotification.Response_currentTime);
  13952. srand(time(NULL));
  13953. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP20Data->BootNotification.Response_interval-((rand()%8)+3));
  13954. SetOcppConnStatus(TRUE);
  13955. ShmOCPP20Data->SpMsg.bits.BootNotificationConf = ON;
  13956. }
  13957. void handleClearedChargingLimitResponse(char *payload, int gun_index)
  13958. {
  13959. mtrace();
  13960. json_object *ClearedChargingLimit;
  13961. DEBUG_INFO("handleClearedChargingLimitResponse...\n");
  13962. ClearedChargingLimit = json_tokener_parse(payload);
  13963. if(!is_error(ClearedChargingLimit))
  13964. {
  13965. // Required data
  13966. if(json_object_object_get(ClearedChargingLimit,"status") != NULL)
  13967. sprintf((char*)ShmOCPP20Data->ClearChargingProfile[gun_index].Response_status, json_object_get_string(json_object_object_get(ClearedChargingLimit,"status")));
  13968. }
  13969. json_object_put(ClearedChargingLimit);
  13970. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitReq = OFF;
  13971. ShmOCPP20Data->CSUMsg.bits[gun_index].ClearedChargingLimitConf = ON;
  13972. }
  13973. void handleDataTransferResponse(char *payload, int gun_index)
  13974. {
  13975. mtrace();
  13976. json_object *DataTrans;
  13977. DEBUG_INFO("handleDataTransferResponse...\n");
  13978. DataTrans = json_tokener_parse(payload);
  13979. if(!is_error(DataTrans))
  13980. {
  13981. // Required data
  13982. if(json_object_object_get(DataTrans,"status") != NULL)
  13983. sprintf((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_status, json_object_get_string(json_object_object_get(DataTrans,"status")));
  13984. // Optional data
  13985. if(json_object_object_get(DataTrans,"data") != NULL)
  13986. sprintf((char*)ShmOCPP20Data->DataTransfer[gun_index].Response_data, json_object_get_string(json_object_object_get(DataTrans,"data")));
  13987. }
  13988. json_object_put(DataTrans);
  13989. ShmOCPP20Data->CpMsg.bits[gun_index].DataTransferReq = OFF;
  13990. ShmOCPP20Data->CpMsg.bits[gun_index].DataTransferConf = ON;
  13991. }
  13992. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  13993. {
  13994. mtrace();
  13995. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  13996. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationReq = OFF;
  13997. ShmOCPP20Data->SpMsg.bits.FirmwareStatusNotificationConf = ON;
  13998. }
  13999. void handleGet15118EVCertificateResponse(char *payload, int gun_index)
  14000. {
  14001. mtrace();
  14002. json_object *Get15118EVCertificate;
  14003. DEBUG_INFO("handleGet15118EVCertificateResponse...\n");
  14004. Get15118EVCertificate = json_tokener_parse(payload);
  14005. if(!is_error(Get15118EVCertificate))
  14006. {
  14007. // Required data
  14008. if(json_object_object_get(Get15118EVCertificate,"status") != NULL)
  14009. sprintf((char*)ShmOCPP20Data->Get15118EVCertificate.Response_status, json_object_get_string(json_object_object_get(Get15118EVCertificate,"status")));
  14010. // Optional data
  14011. if(json_object_object_get(Get15118EVCertificate,"exiResponse") != NULL)
  14012. sprintf((char*)ShmOCPP20Data->Get15118EVCertificate.Response_exiResponse, json_object_get_string(json_object_object_get(Get15118EVCertificate,"exiResponse")));
  14013. }
  14014. json_object_put(Get15118EVCertificate);
  14015. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateReq = OFF;
  14016. ShmOCPP20Data->SpMsg.bits.Get15118EVCertificateConf = ON;
  14017. }
  14018. void hanldeGetCertificateStatusResponse(char *payload, int gun_index)
  14019. {
  14020. mtrace();
  14021. json_object *GetCertificateStatus;
  14022. DEBUG_INFO("hanldeGetCertificateStatusResponse...\n");
  14023. GetCertificateStatus = json_tokener_parse(payload);
  14024. if(!is_error(GetCertificateStatus))
  14025. {
  14026. // Required data
  14027. if(json_object_object_get(GetCertificateStatus,"status") != NULL)
  14028. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_status, json_object_get_string(json_object_object_get(GetCertificateStatus,"status")));
  14029. // Optional data
  14030. if(json_object_object_get(GetCertificateStatus,"ocspResult") != NULL)
  14031. sprintf((char*)ShmOCPP20Data->GetCertificateStatus.Response_ocspResult, json_object_get_string(json_object_object_get(GetCertificateStatus,"ocspResult")));
  14032. }
  14033. json_object_put(GetCertificateStatus);
  14034. ShmOCPP20Data->SpMsg.bits.GetCertificateStatusReq = OFF;
  14035. ShmOCPP20Data->SpMsg.bits.GetCertificateStatusConf = ON;
  14036. }
  14037. void handleHeartbeatResponse(char *payload, int gun_index)
  14038. {
  14039. mtrace();
  14040. DEBUG_INFO("handleHeartbeatResponse...\n");
  14041. json_object *Heartbeat;
  14042. Heartbeat = json_tokener_parse(payload);
  14043. if(!is_error(Heartbeat))
  14044. {
  14045. // Required data
  14046. if(json_object_object_get(Heartbeat,"currentTime") != NULL)
  14047. sprintf((char *)ShmOCPP20Data->Heartbeat.Response_currentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  14048. }
  14049. json_object_put(Heartbeat);
  14050. if(FirstHeartBeat == OFF)
  14051. {
  14052. FirstHeartBeat = ON;
  14053. DEBUG_INFO("FirstHeartBeat \n");
  14054. }
  14055. HeartBeatWithNOResponse = 0;
  14056. clientTime.Heartbeat=time((time_t*)NULL);
  14057. syncDateTimeRTC(ShmOCPP20Data->Heartbeat.Response_currentTime);
  14058. }
  14059. void hanldeLogStatusNotificationResponse(char *payload, int gun_index)
  14060. {
  14061. mtrace();
  14062. DEBUG_INFO("hanldeLogStatusNotificationResponse...\n");
  14063. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationReq = OFF;
  14064. ShmOCPP20Data->SpMsg.bits.LogStatusNotificationConf = ON;
  14065. }
  14066. void handleMeterValuesResponse(char *payload, int gun_index)
  14067. {
  14068. mtrace();
  14069. DEBUG_INFO("handleMeterValuesResponse...\n");
  14070. }
  14071. void handleNotifyChargingLimitResponse(char *payload, int gun_index)
  14072. {
  14073. mtrace();
  14074. DEBUG_INFO("handleNotifyChargingLimitResponse...\n");
  14075. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitReq = OFF;
  14076. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitConf = ON;
  14077. }
  14078. void hanldeNotifyCustomerInformationResponse(char *payload, int gun_index)
  14079. {
  14080. mtrace();
  14081. DEBUG_INFO("hanldeNotifyCustomerInformationResponse...\n");
  14082. }
  14083. void hanldeNotifyDisplayMessagesResponse(char *payload, int gun_index)
  14084. {
  14085. mtrace();
  14086. DEBUG_INFO("hanldeNotifyDisplayMessagesResponse...\n");
  14087. ShmOCPP20Data->SpMsg.bits.NotifyDisplayMessagesReq = OFF;
  14088. ShmOCPP20Data->SpMsg.bits.NotifyDisplayMessagesConf = ON;
  14089. }
  14090. void hanldeNotifyEVChargingNeedsResponse(char *payload, int gun_index)
  14091. {
  14092. mtrace();
  14093. json_object *NotifyEVChargingNeeds;
  14094. DEBUG_INFO("hanldeNotifyEVChargingNeedsResponse...\n");
  14095. NotifyEVChargingNeeds = json_tokener_parse(payload);
  14096. if(!is_error(NotifyEVChargingNeeds))
  14097. {
  14098. // Required data
  14099. if(json_object_object_get(NotifyEVChargingNeeds,"status") != NULL)
  14100. sprintf((char*)ShmOCPP20Data->NotifyEVChargingNeeds[gun_index].Response_status, json_object_get_string(json_object_object_get(NotifyEVChargingNeeds,"status")));
  14101. }
  14102. json_object_put(NotifyEVChargingNeeds);
  14103. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitReq = OFF;
  14104. ShmOCPP20Data->SpMsg.bits.NotifyChargingLimitConf = ON;
  14105. }
  14106. void hanldeNotifyEVChargingScheduleResponse(char *payload, int gun_index)
  14107. {
  14108. mtrace();
  14109. json_object *NotifyEVChargingSchedule;
  14110. DEBUG_INFO("hanldeNotifyEVChargingScheduleResponse...\n");
  14111. NotifyEVChargingSchedule = json_tokener_parse(payload);
  14112. if(!is_error(NotifyEVChargingSchedule))
  14113. {
  14114. // Required data
  14115. if(json_object_object_get(NotifyEVChargingSchedule,"status") != NULL)
  14116. sprintf((char*)ShmOCPP20Data->NotifyEVChargingSchedule[gun_index].Response_status, json_object_get_string(json_object_object_get(NotifyEVChargingSchedule,"status")));
  14117. }
  14118. json_object_put(NotifyEVChargingSchedule);
  14119. ShmOCPP20Data->SpMsg.bits.NotifyEVChargingScheduleReq = OFF;
  14120. ShmOCPP20Data->SpMsg.bits.NotifyEVChargingScheduleConf = ON;
  14121. }
  14122. void hanldeNotifyEventResponse(char *payload, int gun_index)
  14123. {
  14124. mtrace();
  14125. DEBUG_INFO("hanldeNotifyEventResponse...\n");
  14126. ShmOCPP20Data->SpMsg.bits.NotifyEventReq = OFF;
  14127. ShmOCPP20Data->SpMsg.bits.NotifyEventConf = ON;
  14128. }
  14129. void hanldeNotifyMonitoringReportResponse(char *payload, int gun_index)
  14130. {
  14131. mtrace();
  14132. DEBUG_INFO("hanldeNotifyMonitoringReportResponse...\n");
  14133. ShmOCPP20Data->SpMsg.bits.NotifyMonitoringReportReq = OFF;
  14134. ShmOCPP20Data->SpMsg.bits.NotifyMonitoringReportConf = ON;
  14135. }
  14136. void hanldeNotifyReportResponse(char *payload, int gun_index)
  14137. {
  14138. mtrace();
  14139. DEBUG_INFO("hanldeNotifyReportResponse...\n");
  14140. ShmOCPP20Data->SpMsg.bits.NotifyReportReq = OFF;
  14141. ShmOCPP20Data->SpMsg.bits.NotifyReportConf = ON;
  14142. }
  14143. void hanldePublishFirmwareStatusNotificationResponse(char *payload, int gun_index)
  14144. {
  14145. mtrace();
  14146. DEBUG_INFO("hanldePublishFirmwareStatusNotificationResponse...\n");
  14147. ShmOCPP20Data->CsMsg.bits[gun_index].PublishFirmwareStatusNotificationReq = OFF;
  14148. ShmOCPP20Data->CsMsg.bits[gun_index].PublishFirmwareStatusNotificationConf = ON;
  14149. }
  14150. void hanldeReportChargingProfilesResponse(char *payload, int gun_index)
  14151. {
  14152. mtrace();
  14153. DEBUG_INFO("hanldeReportChargingProfilesResponse...gun_index: %d\n", gun_index);
  14154. ShmOCPP20Data->SpMsg.bits.ReportChargingProfilesReq = OFF;
  14155. ShmOCPP20Data->SpMsg.bits.ReportChargingProfilesConf = ON;
  14156. }
  14157. void hanldeReservationStatusUpdateResponse(char *payload, int gun_index)
  14158. {
  14159. mtrace();
  14160. DEBUG_INFO("hanldeReservationStatusUpdateResponse...gun_index: %d\n", gun_index);
  14161. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateReq = OFF;
  14162. ShmOCPP20Data->CpMsg.bits[gun_index].ReservationStatusUpdateConf = ON;
  14163. }
  14164. void hanldeSecurityEventNotificationResponse(char *payload, int gun_index)
  14165. {
  14166. mtrace();
  14167. DEBUG_INFO("hanldeSecurityEventNotificationResponse...\n");
  14168. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationReq = OFF;
  14169. ShmOCPP20Data->SpMsg.bits.SecurityEventNotificationConf = ON;
  14170. }
  14171. void hanldeSignCertificateResponse(char *payload, int gun_index)
  14172. {
  14173. mtrace();
  14174. json_object *SignCertificate;
  14175. DEBUG_INFO("hanldeSignCertificateResponse...\n");
  14176. SignCertificate = json_tokener_parse(payload);
  14177. if(!is_error(SignCertificate))
  14178. {
  14179. // Required data
  14180. if(json_object_object_get(SignCertificate,"status") != NULL)
  14181. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_status, json_object_get_string(json_object_object_get(SignCertificate,"status")));
  14182. // Optional data
  14183. if(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "reasonCode") != NULL)
  14184. {
  14185. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_statusInfo.reasonCode, json_object_get_string(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "reasonCode")));
  14186. if(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "additionalInfo") != NULL)
  14187. sprintf((char*)ShmOCPP20Data->SignCertificate.Response_statusInfo.additionalInfo, json_object_get_string(json_object_object_get(json_object_object_get(SignCertificate,"statusInfo"), "additionalInfo")));
  14188. }
  14189. }
  14190. json_object_put(SignCertificate);
  14191. ShmOCPP20Data->SpMsg.bits.SignCertificateReq = OFF;
  14192. ShmOCPP20Data->SpMsg.bits.SignCertificateConf = ON;
  14193. }
  14194. void handleStatusNotificationResponse(char *payload, int gun_index)
  14195. {
  14196. mtrace();
  14197. DEBUG_INFO("handleStatusNotificationResponse...gun_index: %d\n", gun_index);
  14198. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  14199. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  14200. cpinitateMsg.bits[gun_index].StatusNotificationConf = ON;
  14201. }
  14202. void hanldeTransactionEvenResponse(char *payload, int gun_index)
  14203. {
  14204. mtrace();
  14205. json_object *TransactionEven;
  14206. DEBUG_INFO("hanldeTransactionEvenResponse...\n");
  14207. TransactionEven = json_tokener_parse(payload);
  14208. if(!is_error(TransactionEven))
  14209. {
  14210. // Required data
  14211. // Optional data
  14212. if(json_object_object_get(TransactionEven,"totalCost") != NULL)
  14213. ShmOCPP20Data->TransactionEvent[gun_index].Response_totalCost = json_object_get_double(json_object_object_get(TransactionEven,"totalCost"));
  14214. if(json_object_object_get(TransactionEven,"chargingPriority") != NULL)
  14215. ShmOCPP20Data->TransactionEvent[gun_index].Response_chargingPriority = json_object_get_int(json_object_object_get(TransactionEven,"chargingPriority"));
  14216. if(json_object_object_get(TransactionEven,"idTokenInfo") != NULL)
  14217. {
  14218. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "status") != NULL)
  14219. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.status, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "status")));
  14220. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "cacheExpiryDateTime") != NULL)
  14221. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.cacheExpiryDateTime, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "cacheExpiryDateTime")));
  14222. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "chargingPriority") != NULL)
  14223. ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.chargingPriority = json_object_get_int(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "chargingPriority"));
  14224. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "language1") != NULL)
  14225. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].Response_idTokenInfo.language1, json_object_get_string(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "language1")));
  14226. if(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken") != NULL)
  14227. {
  14228. if(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "idToken") != NULL)
  14229. 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")));
  14230. if(json_object_object_get(json_object_object_get(json_object_object_get(TransactionEven,"idTokenInfo"), "groupIdToken"), "type") != NULL)
  14231. 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")));
  14232. }
  14233. }
  14234. }
  14235. json_object_put(TransactionEven);
  14236. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventReq = OFF;
  14237. ShmOCPP20Data->CpMsg.bits[gun_index].TransactionEventConf = ON;
  14238. }
  14239. //==========================================
  14240. // Handle Error routine
  14241. //==========================================
  14242. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  14243. {
  14244. mtrace();
  14245. #ifdef SystemLogMessage
  14246. DEBUG_INFO("errorCode: %s\n", errorCode);
  14247. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  14248. DEBUG_INFO("errorDetails: %s\n", payload);
  14249. #endif
  14250. }
  14251. //===============================================
  14252. // Common routine
  14253. //===============================================
  14254. int initialConfigurationTable(void)
  14255. {
  14256. DEBUG_INFO("initialConfigurationTable...\n");
  14257. memset(&ShmOCPP20Data->ControllerComponentVariable[0], 0, ARRAY_SIZE(ShmOCPP20Data->ControllerComponentVariable));
  14258. DB_variableIsCreate();
  14259. DB_variableLoadFromDb();
  14260. DB_getNetworkProfileFromDb();
  14261. return 0;
  14262. }
  14263. int TransactionMessageAttemptsGet(void)
  14264. {
  14265. return TransactionMessageAttemptsValue;
  14266. }
  14267. int FirstHeartBeatResponse(void)
  14268. {
  14269. return FirstHeartBeat;
  14270. }
  14271. int TransactionMessageRetryIntervalGet(void)
  14272. {
  14273. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP20Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14274. }
  14275. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  14276. {
  14277. int result = TRUE;
  14278. char rmFileCmd[100]={0};
  14279. char FilePath[100]={0};
  14280. char ftpbuf[200];
  14281. int systemresult;
  14282. //DEBUG_INFO("filename=%s\n",filename);
  14283. //DEBUG_INFO("url=%s\n",url);
  14284. sprintf(FilePath,"/mnt/%s",filename);
  14285. system("ping 8.8.8.8 &");
  14286. if((access(FilePath,F_OK))!=-1)
  14287. {
  14288. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14289. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14290. system(rmFileCmd);
  14291. }
  14292. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14293. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14294. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14295. systemresult = system(ftpbuf);
  14296. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14297. if(systemresult != 0)
  14298. {
  14299. DEBUG_INFO("http DownLoad error!\n");
  14300. result = FALSE;
  14301. }
  14302. system("pkill ping");
  14303. return result;
  14304. }
  14305. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  14306. {
  14307. int result = TRUE;
  14308. char rmFileCmd[100]={0};
  14309. char FilePath[100]={0};
  14310. char ftpbuf[200];
  14311. int systemresult;
  14312. //char temp[100];
  14313. sprintf(FilePath,"/mnt/%s",filename);
  14314. system("ping 8.8.8.8 &");
  14315. if((access(FilePath,F_OK))!=-1)
  14316. {
  14317. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14318. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14319. system(rmFileCmd);
  14320. }
  14321. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14322. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  14323. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  14324. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14325. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14326. systemresult = system(ftpbuf);
  14327. //DEBUG_INFO("systemresult=%d\n",systemresult);
  14328. if(systemresult != 0)
  14329. {
  14330. printf("wget error!\n");
  14331. result = FALSE;
  14332. }
  14333. system("pkill ping");
  14334. return result;
  14335. }
  14336. int httpUploadFile(char *location, char *path, char *filename,char *url)
  14337. {
  14338. char rmFileCmd[100]={0};
  14339. char FilePath[100]={0};
  14340. char buf[512];
  14341. int systemresult = 0;
  14342. //DEBUG_INFO("filename=%s\n",filename);
  14343. //DEBUG_INFO("url=%s\n",url);
  14344. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  14345. if((access(FilePath,F_OK))!=-1)
  14346. {
  14347. DEBUG_INFO("filename=%s exist.\n",FilePath);
  14348. sprintf(rmFileCmd,"rm -f %s",FilePath);
  14349. system(rmFileCmd);
  14350. }
  14351. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  14352. if(fp == NULL)
  14353. {
  14354. DEBUG_INFO("log is NULL\n");
  14355. return FALSE;
  14356. }
  14357. else
  14358. {
  14359. fprintf(fp, "%s\n", url);
  14360. fprintf(fp, "%s\n", filename);
  14361. fclose(fp);
  14362. }
  14363. FILE *phpFP = popen("/bin/php-cgi /var/www/ocpp_upload.php", "r");
  14364. if(phpFP == NULL)
  14365. {
  14366. DEBUG_INFO("PHP upload fail.\n");
  14367. return FALSE;
  14368. }
  14369. else
  14370. {
  14371. while(fgets(buf, sizeof(buf), phpFP) != NULL)
  14372. {
  14373. if(strstr(buf, "result") != NULL)
  14374. {
  14375. sscanf(buf, "result: %d", &systemresult);
  14376. DEBUG_INFO("PHP HTTP upload result: %d\n", systemresult);
  14377. }
  14378. }
  14379. pclose(phpFP);
  14380. }
  14381. if(systemresult != 1)
  14382. {
  14383. DEBUG_INFO("HTTP upload error!\n");
  14384. return FALSE;
  14385. }
  14386. return TRUE;
  14387. }
  14388. int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  14389. {
  14390. struct hostent* server;
  14391. char *IPbuffer;
  14392. char ftpbuf[200];
  14393. int systemresult;
  14394. // To retrieve host information
  14395. server = gethostbyname(location);
  14396. // To convert an Internet network
  14397. // address into ASCII string
  14398. IPbuffer = inet_ntoa(*((struct in_addr*)
  14399. server->h_addr_list[0]));
  14400. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  14401. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  14402. /* format : ftpput -u username -p passwd IP target source*/
  14403. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  14404. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  14405. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  14406. systemresult = system(ftpbuf);
  14407. DEBUG_INFO("systemresult=%d\n",systemresult);
  14408. if(systemresult != 0)
  14409. {
  14410. DEBUG_INFO("ftpput error!\n");
  14411. return FALSE;
  14412. }
  14413. return TRUE;
  14414. }
  14415. //=========================================
  14416. // Routine
  14417. //=========================================
  14418. int GetOcppServerURL()
  14419. {
  14420. int result = FALSE;
  14421. struct yuarel url;
  14422. char urlStr[512];
  14423. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  14424. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  14425. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  14426. if((ShmOCPP20Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP20Data->OcppServerURL,"") != 0))
  14427. {
  14428. memcpy(urlStr, ShmOCPP20Data->OcppServerURL, ARRAY_SIZE(ShmOCPP20Data->OcppServerURL));
  14429. if(yuarel_parse(&url, urlStr) != -1)
  14430. {
  14431. sprintf(OcppProtocol, "%s", url.scheme);
  14432. sprintf(OcppHost, "%s", url.host);
  14433. if(url.path == NULL)
  14434. OcppTempPath[0] = '\0';
  14435. else
  14436. sprintf(OcppTempPath, "%s", url.path);
  14437. if(url.port == 0)
  14438. {
  14439. if(strcmp(OcppProtocol, "wss") == 0)
  14440. OcppPort = 443;
  14441. else
  14442. OcppPort = 80;
  14443. }
  14444. else
  14445. OcppPort = url.port;
  14446. result = TRUE;
  14447. }
  14448. }
  14449. else
  14450. {
  14451. strcpy(OcppHost,"");
  14452. }
  14453. return result;
  14454. }
  14455. int GetOcppPath()
  14456. {
  14457. int result = FALSE;
  14458. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  14459. {
  14460. if(OcppTempPath == NULL)
  14461. {
  14462. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14463. }
  14464. else
  14465. {
  14466. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14467. }
  14468. result = TRUE;
  14469. }
  14470. else if((ShmOCPP20Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP20Data->ChargeBoxId,"") != 0))
  14471. {
  14472. if(OcppTempPath == NULL)
  14473. {
  14474. sprintf(OcppPath,"/%s",ShmOCPP20Data->ChargeBoxId);
  14475. }
  14476. else
  14477. {
  14478. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP20Data->ChargeBoxId);
  14479. }
  14480. result = TRUE;
  14481. }
  14482. else
  14483. {
  14484. strcpy(OcppPath,"");
  14485. }
  14486. return result;
  14487. }
  14488. int GetOcppPort()
  14489. {
  14490. return OcppPort;
  14491. }
  14492. int GetOcppConnStatus(void)
  14493. {
  14494. return ShmOCPP20Data->OcppConnStatus;
  14495. }
  14496. void SetOcppConnStatus(uint8_t status)
  14497. {
  14498. ShmOCPP20Data->OcppConnStatus = status;
  14499. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  14500. }
  14501. int GetHeartBeatWithNOResponse(void)
  14502. {
  14503. return HeartBeatWithNOResponse;
  14504. }
  14505. void SetHeartBeatWithNOResponse(void)
  14506. {
  14507. HeartBeatWithNOResponse = 0;
  14508. }
  14509. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  14510. void storeTempStopTransaction(int gun_index)
  14511. {
  14512. char TempStopTransaction[256];
  14513. char message[1024*20]={0};
  14514. char guid[37]={0};
  14515. uint8_t tempIndex;
  14516. json_object *TransactionEvent = json_object_new_object();
  14517. json_object *transactionInfo = json_object_new_object();
  14518. json_object *idToken = json_object_new_object();
  14519. json_object *evse = json_object_new_object();
  14520. json_object *meterValues = json_object_new_array();
  14521. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14522. DEBUG_INFO("storeTempStopTransaction...\n");
  14523. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14524. {
  14525. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14526. {
  14527. tempIndex = ((gun_index==2) ? 1: 0);
  14528. }
  14529. else
  14530. {
  14531. tempIndex = gun_index;
  14532. }
  14533. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14534. {
  14535. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  14536. {
  14537. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  14538. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  14539. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  14540. else
  14541. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  14542. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  14543. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  14544. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  14545. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  14546. {
  14547. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  14548. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  14549. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  14550. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  14551. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  14552. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == ON) // //0: unplug, 1: Plug-in
  14553. {
  14554. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  14555. }
  14556. else
  14557. {
  14558. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  14559. }
  14560. }
  14561. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  14562. {
  14563. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  14564. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  14565. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  14566. }
  14567. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  14568. ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  14569. ) //S_PRECHARGE
  14570. {
  14571. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  14572. {
  14573. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  14574. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].StartUserId);
  14575. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", ShmOCPP20Data->Authorize.idToken.type);
  14576. }
  14577. if(ShmOCPP20Data->TransactionEvent[gun_index].eventType[0] == '\0')
  14578. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  14579. else
  14580. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  14581. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  14582. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  14583. }
  14584. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  14585. {
  14586. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  14587. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  14588. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  14589. }
  14590. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  14591. {
  14592. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  14593. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  14594. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  14595. }
  14596. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  14597. {
  14598. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  14599. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  14600. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  14601. }
  14602. 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
  14603. {
  14604. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  14605. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  14606. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  14607. }
  14608. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  14609. {
  14610. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  14611. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  14612. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  14613. }
  14614. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  14615. {
  14616. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  14617. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  14618. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  14619. }
  14620. } //end of the same index
  14621. }//end of for CHAdeMO_QUANTITY
  14622. }
  14623. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14624. {
  14625. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14626. {
  14627. tempIndex = ((gun_index==2) ? 1: 0);
  14628. }
  14629. else
  14630. {
  14631. tempIndex = gun_index;
  14632. }
  14633. for (int index = 0; index < CCS_QUANTITY; index++)
  14634. {
  14635. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14636. {
  14637. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  14638. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  14639. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  14640. else
  14641. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  14642. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  14643. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  14644. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  14645. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  14646. {
  14647. memset(&ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo, 0x00, sizeof(struct TransactionType));
  14648. memset(&ShmOCPP20Data->TransactionEvent[gun_index].idToken, 0x00, sizeof(struct IdTokenType));
  14649. memset(&ShmOCPP20Data->TransactionEvent[gun_index].meterValue, 0x00, sizeof(struct MeterValueType));
  14650. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  14651. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  14652. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == ON) //0: unplug, 1: Plug-in
  14653. {
  14654. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_CablePluggedIn]);
  14655. }
  14656. else
  14657. {
  14658. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_EVCommunicationLost]);
  14659. }
  14660. }
  14661. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING)//S_IDLE
  14662. {
  14663. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  14664. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Idle]);
  14665. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_Authorized]);
  14666. }
  14667. else if ( ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  14668. ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  14669. ) //S_PRECHARGE
  14670. {
  14671. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId) == 0)
  14672. {
  14673. random_uuid((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId);
  14674. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken, "%s", ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].StartUserId);
  14675. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type, "%s", ShmOCPP20Data->Authorize.idToken.type);
  14676. }
  14677. if(ShmOCPP20Data->TransactionEvent[gun_index].eventType[0] == '\0')
  14678. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  14679. else
  14680. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  14681. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_EVConnected]);
  14682. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  14683. }
  14684. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  14685. {
  14686. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  14687. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  14688. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  14689. }
  14690. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  14691. {
  14692. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  14693. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  14694. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  14695. }
  14696. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  14697. {
  14698. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  14699. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEV]);
  14700. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  14701. }
  14702. 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
  14703. {
  14704. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  14705. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  14706. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  14707. }
  14708. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  14709. {
  14710. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Updated]);
  14711. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  14712. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  14713. }
  14714. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  14715. {
  14716. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Started]);
  14717. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_SuspendedEVSE]);
  14718. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_AbnormalCondition]);
  14719. }
  14720. } //end of the same index
  14721. } // end of for CCS_QUANTITY
  14722. }
  14723. else if(gunType[gun_index] == GUN_TYPE_GBT)
  14724. {
  14725. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14726. {
  14727. tempIndex = ((gun_index==2) ? 1: 0);
  14728. }
  14729. else
  14730. {
  14731. tempIndex = gun_index;
  14732. }
  14733. for (int index = 0; index < GB_QUANTITY; index++)
  14734. {
  14735. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  14736. {
  14737. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  14738. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  14739. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  14740. else
  14741. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  14742. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  14743. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  14744. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  14745. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  14746. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  14747. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  14748. } //end of the same index
  14749. } // end of for GB_QUANTITY
  14750. }
  14751. else if(gunType[gun_index] == GUN_TYPE_DO)
  14752. {
  14753. tempIndex = gun_index;
  14754. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14755. {
  14756. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14757. {
  14758. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  14759. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  14760. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  14761. else
  14762. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  14763. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  14764. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  14765. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  14766. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  14767. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  14768. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  14769. } //end of the same index
  14770. }
  14771. }
  14772. else
  14773. {
  14774. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  14775. {
  14776. tempIndex = 2;
  14777. }
  14778. else
  14779. {
  14780. tempIndex = gun_index;
  14781. }
  14782. for (int index = 0; index < AC_QUANTITY; index++)
  14783. {
  14784. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  14785. {
  14786. getNowDatetime(ShmOCPP20Data->TransactionEvent[gun_index].timestamp);
  14787. if((ShmOCPP20Data->TransactionEvent[gun_index].seqNo + 1) < INT_MAX)
  14788. ShmOCPP20Data->TransactionEvent[gun_index].seqNo++;
  14789. else
  14790. ShmOCPP20Data->TransactionEvent[gun_index].seqNo = 0;
  14791. ShmOCPP20Data->TransactionEvent[gun_index].offline = (!ShmOCPP20Data->OcppConnStatus?TRUE:FALSE);
  14792. ShmOCPP20Data->TransactionEvent[gun_index].evse.id = (gun_index + 1);
  14793. ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId = (gun_index + 1);
  14794. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType, "%s", TransactionEventEnumTypeStr[TransactionEventEnumType_Ended]);
  14795. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState, "%s", ChargingStateEnumTypeStr[ChargingStateEnumType_Charging]);
  14796. sprintf((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason, "%s", TriggerReasonEnumTypeStr[TriggerReasonEnumType_ChargingStateChanged]);
  14797. }//end of the same index
  14798. }//end of for AC_QUANTITY
  14799. }
  14800. // Message
  14801. json_object_object_add(TransactionEvent, "eventType", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].eventType));
  14802. json_object_object_add(TransactionEvent, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].timestamp));
  14803. json_object_object_add(TransactionEvent, "triggerReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].triggerReason));
  14804. json_object_object_add(TransactionEvent, "seqNo", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].seqNo));
  14805. json_object_object_add(TransactionEvent, "offline", json_object_new_boolean(ShmOCPP20Data->TransactionEvent[gun_index].offline));
  14806. if(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed > 0)
  14807. json_object_object_add(TransactionEvent, "numberOfPhasesUsed", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].numberOfPhasesUsed));
  14808. if(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent > 0)
  14809. json_object_object_add(TransactionEvent, "cableMaxCurrent", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].cableMaxCurrent));
  14810. if(ShmOCPP20Data->TransactionEvent[gun_index].reservationId > 0)
  14811. json_object_object_add(TransactionEvent, "reservationId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].reservationId));
  14812. json_object_object_add(transactionInfo, "transactionId", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.transactionId));
  14813. json_object_object_add(transactionInfo, "chargingState", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.chargingState));
  14814. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging > 0)
  14815. json_object_object_add(transactionInfo, "timeSpentCharging", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.timeSpentCharging));
  14816. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason) > 0)
  14817. json_object_object_add(transactionInfo, "stoppedReason", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.stoppedReason));
  14818. if(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId > 0)
  14819. json_object_object_add(transactionInfo, "remoteStartId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].transactionInfo.remoteStartId));
  14820. json_object_object_add(TransactionEvent, "transactionInfo", transactionInfo);
  14821. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken) > 0)
  14822. {
  14823. json_object_object_add(idToken, "idToken", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.idToken));
  14824. json_object_object_add(idToken, "type", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].idToken.type));
  14825. json_object_object_add(TransactionEvent, "idToken", idToken);
  14826. }
  14827. json_object_object_add(evse, "id", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.id));
  14828. json_object_object_add(evse, "connectorId", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].evse.connectorId));
  14829. json_object_object_add(TransactionEvent, "evse", evse);
  14830. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[0].timestamp) > 0)
  14831. {
  14832. for(int idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue);idxMeter++)
  14833. {
  14834. json_object *meterValue = json_object_new_object();
  14835. json_object *sampledValues = json_object_new_array();
  14836. json_object_object_add(meterValue, "timestamp", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].timestamp));
  14837. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue);idxSample++)
  14838. {
  14839. if((strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0) &&
  14840. ((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)))
  14841. {
  14842. json_object *sampledValue = json_object_new_object();
  14843. json_object_object_add(sampledValue, "value", json_object_new_double(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].value));
  14844. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context) > 0)
  14845. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].context));
  14846. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand) > 0)
  14847. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].measurand));
  14848. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase) > 0)
  14849. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].phase));
  14850. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location) > 0)
  14851. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].location));
  14852. if(strlen((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint) > 0)
  14853. {
  14854. json_object *unitOfMeasure = json_object_new_object();
  14855. json_object_object_add(unitOfMeasure, "unit", json_object_new_string((char*)ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.uint));
  14856. json_object_object_add(unitOfMeasure, "multiplier", json_object_new_int(ShmOCPP20Data->TransactionEvent[gun_index].meterValue[idxMeter].sampledValue[idxSample].unitOfMeasure.multiplier));
  14857. json_object_object_add(sampledValue, "unitOfMeasure", unitOfMeasure);
  14858. }
  14859. json_object_array_add(sampledValues, sampledValue);
  14860. }
  14861. }
  14862. json_object_object_add(meterValue, "sampledValue", sampledValues);
  14863. json_object_array_add(meterValues, meterValue);
  14864. }
  14865. json_object_object_add(TransactionEvent, "meterValue", meterValues);
  14866. }
  14867. random_uuid(guid);
  14868. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL
  14869. , guid
  14870. , "TransactionEvent"
  14871. , json_object_to_json_string_ext(TransactionEvent, JSON_C_TO_STRING_PLAIN));
  14872. json_object_put(TransactionEvent);
  14873. // open file for writing
  14874. FILE *outfile;
  14875. outfile = fopen (TempStopTransaction, "w+");
  14876. //DEBUG_INFO("data = %s\n", queuedata);
  14877. fputs(message, outfile);
  14878. fputs("\n", outfile);
  14879. fclose (outfile);
  14880. }
  14881. void checkTempStopTransaction(int gun_index)
  14882. {
  14883. FILE *fptr1;
  14884. char ch;
  14885. char str[QUEUE_MESSAGE_LENGTH]={0};
  14886. char guid[37]={0};
  14887. char tempdata[65]={0};
  14888. char TempStopTransaction[256];
  14889. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14890. fptr1 = fopen(TempStopTransaction, "r");
  14891. if (!fptr1)
  14892. {
  14893. //DEBUG_INFO("TempStopTransaction_%d not found or unable to open the input file!\n", (gun_index+1));
  14894. return ;
  14895. }
  14896. ch=fgetc(fptr1);
  14897. rewind(fptr1);
  14898. if(ch!=EOF)
  14899. {
  14900. // copy all contents to the temporary file except the specific line
  14901. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  14902. {
  14903. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14904. if(str[0]=='\0')
  14905. {
  14906. break;
  14907. }
  14908. strncpy(guid, str+4, 36); //copy guid
  14909. sprintf(tempdata, "TransactionEvent,%d", (gun_index));
  14910. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14911. {
  14912. //DEBUG_INFO("StopTransaction mapitem pass\n");
  14913. }
  14914. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14915. memset(str,0,ARRAY_SIZE(str));
  14916. }
  14917. }
  14918. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14919. fclose(fptr1);
  14920. remove(TempStopTransaction); // remove the original file
  14921. }
  14922. int GetWebSocketPingInterval(void)
  14923. {
  14924. return atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_WebSocketPingInterval].variableAttribute[0].value);
  14925. }
  14926. int GetServerSign(void)
  14927. {
  14928. return server_sign;
  14929. }
  14930. uint8_t GetOcppSecurityProfile()
  14931. {
  14932. return atoi((char*)ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_SecurityProfile].variableAttribute[0].value);
  14933. }
  14934. void GetOcppChargerBoxId(uint8_t *data)
  14935. {
  14936. sprintf((char*)data, "%s", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  14937. }
  14938. void GetOcppSecurityPassword(uint8_t *data)
  14939. {
  14940. sprintf((char*)data, "%s", ShmOCPP20Data->ControllerComponentVariable[SecurityCtrlr_BasicAuthPassword].variableAttribute[0].value);
  14941. }
  14942. void SetServerSign(int value)
  14943. {
  14944. server_sign = value;
  14945. }
  14946. int GetBootNotificationInterval(void)
  14947. {
  14948. return BootNotificationInterval;
  14949. }
  14950. int GetInternetConn(void)
  14951. {
  14952. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14953. }
  14954. int GetBackendConnectionTimeout(void)
  14955. {
  14956. return ShmSysConfigAndInfo->SysConfig.BackendConnTimeout>=0?ShmSysConfigAndInfo->SysConfig.BackendConnTimeout:300;
  14957. }
  14958. int isConnectorInitMode(int gun_index)
  14959. {
  14960. int tempIndex = 0;
  14961. int result = TRUE;
  14962. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  14963. if(gunType[gun_index] == GUN_TYPE_CHAdeMO)
  14964. {
  14965. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14966. {
  14967. tempIndex = ((gun_index==2) ? 1: 0);
  14968. }
  14969. else
  14970. {
  14971. tempIndex = gun_index;
  14972. }
  14973. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14974. {
  14975. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  14976. {
  14977. result = (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14978. } //end of the same index
  14979. }//end of for CHAdeMO_QUANTITY
  14980. }
  14981. else if(gunType[gun_index] == GUN_TYPE_CCS)
  14982. {
  14983. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  14984. {
  14985. tempIndex = ((gun_index==2) ? 1: 0);
  14986. }
  14987. else
  14988. {
  14989. tempIndex = gun_index;
  14990. }
  14991. for (int index = 0; index < CCS_QUANTITY; index++)
  14992. {
  14993. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  14994. {
  14995. result = (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  14996. } //end of the same index
  14997. } // end of for CCS_QUANTITY
  14998. }
  14999. else if(gunType[gun_index] == GUN_TYPE_GBT)
  15000. {
  15001. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  15002. {
  15003. tempIndex = ((gun_index==2) ? 1: 0);
  15004. }
  15005. else
  15006. {
  15007. tempIndex = gun_index;
  15008. }
  15009. for (int index = 0; index < GB_QUANTITY; index++)
  15010. {
  15011. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  15012. {
  15013. result = (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15014. } //end of the same index
  15015. } // end of for GB_QUANTITY
  15016. }
  15017. else if(gunType[gun_index] == GUN_TYPE_DO)
  15018. {
  15019. tempIndex = gun_index;
  15020. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15021. {
  15022. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  15023. {
  15024. result = (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15025. } //end of the same index
  15026. }
  15027. }
  15028. else
  15029. {
  15030. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  15031. {
  15032. tempIndex = 2;
  15033. }
  15034. else
  15035. {
  15036. tempIndex = gun_index;
  15037. }
  15038. for (int index = 0; index < AC_QUANTITY; index++)
  15039. {
  15040. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  15041. {
  15042. result = (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus==SYS_MODE_BOOTING)?TRUE:FALSE;
  15043. }//end of the same index
  15044. }//end of for AC_QUANTITY
  15045. }
  15046. return result;
  15047. }
  15048. void refreshProcDogTimer()
  15049. {
  15050. ShmOCPP20Data->procDogTime = time((time_t*)NULL);
  15051. }
  15052. void InitialSystemValue(void)
  15053. {
  15054. int connectorIndex = 0;
  15055. gunTotalNumber=0;
  15056. SystemInitial = 0;
  15057. localversion=0;
  15058. BootNotificationInterval = 10;
  15059. authorizeRetryTimes = 0;
  15060. GunStatusInterval = 10;
  15061. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttempts].variableAttribute[0].value);
  15062. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_MessageAttemptInterval].variableAttribute[0].value);
  15063. //Hear Beat
  15064. HeartBeatWithNOResponse = 0;
  15065. HeartBeatCountPerHour = 0;
  15066. HeartBeatWaitTime = atoi((char*)ShmOCPP20Data->ControllerComponentVariable[OCPPCommCtrlr_HeartbeatInterval].variableAttribute[0].value);;
  15067. FirstHeartBeat = 0;
  15068. FirmwareStatusNotificationStatus = FirmwareStatusEnumType_Idle; // Idle
  15069. LogStatusNotificationStatus = UploadLogStatusEnumType_Idle; // Idle
  15070. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  15071. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  15072. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  15073. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  15074. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  15075. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  15076. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  15077. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  15078. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  15079. memset(gunType, 0, ARRAY_SIZE(gunType));
  15080. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  15081. {
  15082. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  15083. {
  15084. // DO series
  15085. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  15086. {
  15087. SystemInitial = SystemInitial + 1;
  15088. gunTotalNumber = gunTotalNumber + 1;
  15089. gunType[connectorIndex] = GUN_TYPE_DO;
  15090. connectorIndex = connectorIndex + 1;
  15091. }
  15092. }
  15093. else
  15094. {
  15095. // DM, DW, DS series
  15096. //check connector / socket type (index: 8, 9, 10)
  15097. for(int index=7; index <10 ; index++)
  15098. {
  15099. if(index != 8)
  15100. {
  15101. // DC Connector
  15102. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'J'))
  15103. {
  15104. SystemInitial = SystemInitial + 1;
  15105. gunTotalNumber = gunTotalNumber + 1;
  15106. gunType[connectorIndex] = GUN_TYPE_CHAdeMO;
  15107. connectorIndex = connectorIndex + 1;
  15108. }
  15109. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'D') ||
  15110. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'E') ||
  15111. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'F') ||
  15112. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'U') ||
  15113. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'T') ||
  15114. (ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'V'))
  15115. {
  15116. SystemInitial = SystemInitial + 1;
  15117. gunTotalNumber = gunTotalNumber + 1;
  15118. gunType[connectorIndex] = GUN_TYPE_CCS;
  15119. connectorIndex = connectorIndex + 1;
  15120. }
  15121. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'G'))
  15122. {
  15123. SystemInitial = SystemInitial + 1;
  15124. gunTotalNumber = gunTotalNumber + 1;
  15125. gunType[connectorIndex] = GUN_TYPE_GBT;
  15126. connectorIndex = connectorIndex + 1;
  15127. }
  15128. else if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] == 'O'))
  15129. {
  15130. SystemInitial = SystemInitial + 1;
  15131. gunTotalNumber = gunTotalNumber + 1;
  15132. gunType[connectorIndex] = GUN_TYPE_DO;
  15133. connectorIndex = connectorIndex + 1;
  15134. }
  15135. }
  15136. else
  15137. {
  15138. // AC Connector
  15139. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15140. {
  15141. SystemInitial = SystemInitial + 1;
  15142. gunTotalNumber = gunTotalNumber + 1;
  15143. gunType[connectorIndex] = GUN_TYPE_AC;
  15144. connectorIndex = connectorIndex + 1;
  15145. }
  15146. }
  15147. }
  15148. }
  15149. //DEBUG_INFO("DC ...\n");
  15150. }
  15151. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  15152. {
  15153. //check connector / socket type (index: 8, 9, 10)
  15154. for(int index=7; index <10 ; index++)
  15155. {
  15156. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  15157. {
  15158. SystemInitial = SystemInitial + 1;
  15159. gunTotalNumber = gunTotalNumber + 1;
  15160. gunType[connectorIndex] = GUN_TYPE_AC;
  15161. connectorIndex = connectorIndex + 1;
  15162. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  15163. }
  15164. }
  15165. }
  15166. //Status && ConnectorPlugIn Setting
  15167. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  15168. {
  15169. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  15170. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  15171. }
  15172. for (int index = 0; index < CCS_QUANTITY; index++)
  15173. {
  15174. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  15175. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  15176. }
  15177. for (int index = 0; index < GB_QUANTITY; index++)
  15178. {
  15179. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  15180. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  15181. }
  15182. for (int index = 0; index < AC_QUANTITY; index++)
  15183. {
  15184. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  15185. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  15186. }
  15187. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  15188. {
  15189. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  15190. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  15191. }
  15192. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  15193. {
  15194. cpinitateMsg.bits[gun_index].TriggerStatusNotificationReq = OFF;
  15195. cpinitateMsg.bits[gun_index].StatusNotificationReq = OFF;
  15196. cpinitateMsg.bits[gun_index].StatusNotificationConf = OFF;
  15197. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  15198. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  15199. memset(&ShmOCPP20Data->StatusNotification[gun_index], 0x00, sizeof(struct StatusNotification_20));
  15200. }
  15201. clientTime.Heartbeat=time((time_t*)NULL);
  15202. sleep(1);
  15203. }
  15204. void LWS_Send(char *str)
  15205. {
  15206. //=====================================================
  15207. // Check InternetConn 0: disconnected, 1: connected
  15208. //====================================================
  15209. if(GetOcppConnStatus() == 0)
  15210. {
  15211. DEBUG_INFO("offline now !!!\n");
  15212. return;
  15213. }
  15214. // Only disable isWebsocketSendable operation initiated by charger
  15215. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15216. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15217. || (strstr((char*)str, "\"ClearedChargingLimit\"") != NULL)
  15218. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15219. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15220. || (strstr((char*)str, "\"Get15118EVCertificate\"") != NULL)
  15221. || (strstr((char*)str, "\"GetCertificateStatus\"") != NULL)
  15222. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15223. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15224. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15225. || (strstr((char*)str, "\"NotifyChargingLimit\"") != NULL)
  15226. || (strstr((char*)str, "\"NotifyCustomerInformation\"") != NULL)
  15227. || (strstr((char*)str, "\"NotifyDisplayMessages\"") != NULL)
  15228. || (strstr((char*)str, "\"NotifyEVChargingNeeds\"") != NULL)
  15229. || (strstr((char*)str, "\"NotifyEVChargingSchedule\"") != NULL)
  15230. || (strstr((char*)str, "\"NotifyEvent\"") != NULL)
  15231. || (strstr((char*)str, "\"NotifyMonitoringReport\"") != NULL)
  15232. || (strstr((char*)str, "\"NotifyReport\"") != NULL)
  15233. || (strstr((char*)str, "\"PublishFirmwareStatusNotification\"") != NULL)
  15234. || (strstr((char*)str, "\"ReportChargingProfiles\"") != NULL)
  15235. || (strstr((char*)str, "\"ReservationStatusUpdate\"") != NULL)
  15236. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15237. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15238. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15239. || (strstr((char*)str, "\"TransactionEven\"") != NULL))
  15240. {
  15241. isWebsocketSendable = OFF;
  15242. }
  15243. pthread_mutex_lock(&lock_send);
  15244. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15245. sprintf((char *)SendBuffer, "%s", str);
  15246. SendBufLen = strlen(str);
  15247. pthread_mutex_unlock(&lock_send);
  15248. lws_callback_on_writable(wsi_client);
  15249. //lws_service(context, 0);
  15250. //sleep(1);
  15251. }
  15252. void LWS_SendNow(char *str)
  15253. {
  15254. //=====================================================
  15255. // Check InternetConn 0: disconnected, 1: connected
  15256. //====================================================
  15257. if(GetOcppConnStatus() == 0)
  15258. {
  15259. DEBUG_INFO("offline now !!!\n");
  15260. return;
  15261. }
  15262. // Only disable isWebsocketSendable operation initiated by charger
  15263. if((strstr((char*)str, "\"Authorize\"") != NULL)
  15264. || (strstr((char*)str, "\"BootNotification\"") != NULL)
  15265. || (strstr((char*)str, "\"ClearedChargingLimit\"") != NULL)
  15266. || (strstr((char*)str, "\"DataTransfer\"") != NULL)
  15267. || (strstr((char*)str, "\"FirmwareStatusNotification\"") != NULL)
  15268. || (strstr((char*)str, "\"Get15118EVCertificate\"") != NULL)
  15269. || (strstr((char*)str, "\"GetCertificateStatus\"") != NULL)
  15270. || (strstr((char*)str, "\"Heartbeat\"") != NULL)
  15271. || (strstr((char*)str, "\"LogStatusNotification\"") != NULL)
  15272. || (strstr((char*)str, "\"MeterValues\"") != NULL)
  15273. || (strstr((char*)str, "\"NotifyChargingLimit\"") != NULL)
  15274. || (strstr((char*)str, "\"NotifyCustomerInformation\"") != NULL)
  15275. || (strstr((char*)str, "\"NotifyDisplayMessages\"") != NULL)
  15276. || (strstr((char*)str, "\"NotifyEVChargingNeeds\"") != NULL)
  15277. || (strstr((char*)str, "\"NotifyEVChargingSchedule\"") != NULL)
  15278. || (strstr((char*)str, "\"NotifyEvent\"") != NULL)
  15279. || (strstr((char*)str, "\"NotifyMonitoringReport\"") != NULL)
  15280. || (strstr((char*)str, "\"NotifyReport\"") != NULL)
  15281. || (strstr((char*)str, "\"PublishFirmwareStatusNotification\"") != NULL)
  15282. || (strstr((char*)str, "\"ReportChargingProfiles\"") != NULL)
  15283. || (strstr((char*)str, "\"ReservationStatusUpdate\"") != NULL)
  15284. || (strstr((char*)str, "\"SecurityEventNotification\"") != NULL)
  15285. || (strstr((char*)str, "\"SignCertificate\"") != NULL)
  15286. || (strstr((char*)str, "\"StatusNotification\"") != NULL)
  15287. || (strstr((char*)str, "\"TransactionEven\"") != NULL))
  15288. {
  15289. isWebsocketSendable = OFF;
  15290. }
  15291. pthread_mutex_lock(&lock_send);
  15292. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  15293. sprintf((char *)SendBuffer, "%s", str);
  15294. SendBufLen = strlen(str);
  15295. pthread_mutex_unlock(&lock_send);
  15296. lws_callback_on_writable(wsi_client);
  15297. lws_service(context, 0);
  15298. //sleep(1);
  15299. }