MessageHandler.c 692 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259
  1. #include "Module_OcppBackend.h"
  2. #include "define.h"
  3. //ChargePointMaxProfile
  4. #define ChargePointMaxProfile_JSON "/Storage/OCPP/ChargePointMaxProfile.json"
  5. //TxDefaultProfile
  6. #define TxDefaultProfile_0_JSON "/Storage/OCPP/TxDefaultProfile_0.json"
  7. #define TxDefaultProfile_1_JSON "/Storage/OCPP/TxDefaultProfile_1.json"
  8. #define TxDefaultProfile_2_JSON "/Storage/OCPP/TxDefaultProfile_2.json"
  9. //TxProfile
  10. #define TxProfile_1_JSON "/Storage/OCPP/TxProfile_1.json"
  11. #define TxProfile_2_JSON "/Storage/OCPP/TxProfile_2.json"
  12. #define ChargingProfile_0_JSON "/Storage/OCPP/chargingprofile_0.json"
  13. #define ChargingProfile_1_JSON "/Storage/OCPP/chargingprofile_1.json"
  14. #define ChargingProfile_2_JSON "/Storage/OCPP/chargingprofile_2.json"
  15. #define AuthorizationCache_JSON "/Storage/OCPP/AuthorizationCache.json"
  16. #define LocalAuthorizationList_JSON "/Storage/OCPP/LocalAuthorizationList.json"
  17. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  18. struct StatusCodeData *ShmStatusCodeData;
  19. struct PsuData *ShmPsuData ;
  20. struct OCPP16Data *ShmOCPP16Data;
  21. //ConfigurationMaxKeys
  22. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  23. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  24. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  25. //=================================
  26. // StatusNotification cycle
  27. //=================================
  28. static int server_cycle_Status = 120;
  29. //===============================
  30. // Configuration: unknownkey
  31. //===============================
  32. static char unknownkey[10][20] = {0};
  33. static int UnknownKeynum = 0;
  34. //===============================
  35. // Gun Total Numbers
  36. //===============================
  37. static int gunTotalNumber = 0;
  38. static uint8_t gunType[4] = {0};
  39. //===============================
  40. // Local List Version
  41. //===============================
  42. static int localversion=0;
  43. static char idTagAuthorization[32] = {0};
  44. //===============================
  45. // OCPP sign variable
  46. //===============================
  47. static int server_sign = FALSE;
  48. int server_pending = FALSE;
  49. static int BootNotificationInterval = 0;
  50. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  51. //===============================
  52. // OCPP auth variable
  53. //===============================
  54. static int authorizeRetryTimes = 0; //number of Retry times
  55. //===============================
  56. // OCPP other variables
  57. //===============================
  58. static int HeartBeatWaitTime = 10;
  59. static int FirstHeartBeat = 0;
  60. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  61. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  62. static char CurrentChargingProfileScheduleStr[30] = {0};
  63. //========================================
  64. // OCPP status/previous related variables
  65. //========================================
  66. static int GunStatusInterval = 10;
  67. static uint8_t statusModeChage[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY] = {FALSE};
  68. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  69. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  70. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  71. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  72. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  73. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  74. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  75. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  76. static int TransactionMessageAttemptsValue = 0;
  77. static int TransactionMessageRetryIntervalValue = 0;
  78. static int TempMeterValueInterval = 0;
  79. static struct OCPPAuthLocalElemet
  80. {
  81. int listVersionInt;
  82. char idTagstr[20];
  83. char parentIdTag[20];
  84. char expiryDate[30];
  85. char idTagstatus[16];
  86. }idTagQuery;
  87. //=============================================
  88. // OCPP HeartBeat Response Not Receive Counts
  89. //============================================
  90. static int HeartBeatWithNOResponse = 0;
  91. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  92. extern struct Charger_Info Charger;
  93. extern sqlite3 *db;
  94. int TransactionMessageAttemptsGet(void);
  95. int TransactionMessageRetryIntervalGet(void);
  96. int GetOcppConnStatus(void);
  97. void SetOcppConnStatus(uint8_t status);
  98. int setKeyValue(char *key, char *value);
  99. void OCPP_get_TableAuthlocalAllData(void);
  100. void processUnkownKey(void);
  101. struct StructOCPPMeterValue
  102. {
  103. unsigned char TimeStamp[28];
  104. struct StructSampledValue SampledValue[10];
  105. };
  106. struct ClientTime
  107. {
  108. unsigned int Heartbeat;
  109. unsigned int StatusNotification[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  110. unsigned int StartTransaction;
  111. unsigned int StopTransaction;
  112. unsigned int MeterValues[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  113. }clientTime;
  114. typedef union
  115. {
  116. //Operations Initiated by Central System
  117. unsigned char CsMsgValue[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  118. struct
  119. {
  120. //CsMsgValue[0]
  121. unsigned char StatusNotificationReq:1; //bit 0,
  122. unsigned char StatusNotificationConf:1; //bit 1,
  123. unsigned char TriggerMeterValue:1; //bit 2,
  124. unsigned char :5; //bit 5~7
  125. }bits[CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY];
  126. }CpinitiateMsg;
  127. CpinitiateMsg cpinitateMsg;
  128. //GetConfiguration Array
  129. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  130. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  131. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  132. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  133. #if 0
  134. static char *ChargePointErrorCodeStr[] = {
  135. MACROSTR(ConnectorLockFailure),
  136. MACROSTR(EVCommunicationError),
  137. MACROSTR(GroundFailure),
  138. MACROSTR(HighTemperature),
  139. MACROSTR(InternalError),
  140. MACROSTR(LocalListConflict),
  141. MACROSTR(NoError),
  142. MACROSTR(OtherError),
  143. MACROSTR(OverCurrentFailure),
  144. MACROSTR(OverVoltage),
  145. MACROSTR(PowerMeterFailure),
  146. MACROSTR(PowerSwitchFailure),
  147. MACROSTR(ReaderFailure),
  148. MACROSTR(ResetFailure),
  149. MACROSTR(UnderVoltage),
  150. MACROSTR(WeakSignal)
  151. };
  152. #endif
  153. static char * ChargePointStatusStr[] = {
  154. MACROSTR(Available),
  155. MACROSTR(Preparing),
  156. MACROSTR(Charging),
  157. MACROSTR(SuspendedEVSE),
  158. MACROSTR(SuspendedEV),
  159. MACROSTR(Finishing),
  160. MACROSTR(Reserved),
  161. MACROSTR(Unavailable),
  162. MACROSTR(Faulted)
  163. };
  164. static char *RegistrationStatusStr[] = {
  165. MACROSTR(Accepted),
  166. MACROSTR(Pending),
  167. MACROSTR(Rejected)
  168. };
  169. static char *AvailabilityTypeStr[] = {
  170. MACROSTR(Inoperative),
  171. MACROSTR(Operative)
  172. };
  173. static char *AvailabilityStatusStr[] = {
  174. MACROSTR(Accepted),
  175. MACROSTR(Rejected),
  176. MACROSTR(Scheduled)
  177. };
  178. static char *ConfigurationStatusStr[] = {
  179. MACROSTR(Accepted),
  180. MACROSTR(Rejected),
  181. MACROSTR(RebootRequired),
  182. MACROSTR(NotSupported)
  183. };
  184. static char *ClearCacheStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected)
  187. };
  188. static char *ChargingProfilePurposeTypeStr[] = {
  189. MACROSTR(ChargePointMaxProfile),
  190. MACROSTR(TxDefaultProfile),
  191. MACROSTR(TxProfile)
  192. };
  193. static char *ChargingProfileStatusStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(Rejected),
  196. MACROSTR(NotSupported)
  197. };
  198. static char *ClearChargingProfileStatusStr[] = {
  199. MACROSTR(Accepted),
  200. MACROSTR(Unknown)
  201. };
  202. static char *GetCompositeScheduleStatusStr[] = {
  203. MACROSTR(Accepted),
  204. MACROSTR(Rejected)
  205. };
  206. static char *UpdateTypeStr[] = {
  207. MACROSTR(Differential),
  208. MACROSTR(Full)
  209. };
  210. static char *UpdateStatusStr[] = {
  211. MACROSTR(Accepted),
  212. MACROSTR(Failed),
  213. MACROSTR(NotSupported),
  214. MACROSTR(VersionMismatch)
  215. };
  216. static char *RemoteStartStopStatusStr[] = {
  217. MACROSTR(Accepted),
  218. MACROSTR(Rejected)
  219. };
  220. static char *ReservationStatusStr[] = {
  221. MACROSTR(Accepted),
  222. MACROSTR(Faulted),
  223. MACROSTR(Occupied),
  224. MACROSTR(Rejected),
  225. MACROSTR(Unavailable)
  226. };
  227. static char *ResetTypeStr[] = {
  228. MACROSTR(Hard),
  229. MACROSTR(Soft)
  230. };
  231. static char *ResetStatusStr[] = {
  232. MACROSTR(Accepted),
  233. MACROSTR(Rejected)
  234. };
  235. static char * DiagnosticsStatusStr[] = {
  236. MACROSTR(Idle),
  237. MACROSTR(Uploaded),
  238. MACROSTR(UploadFailed),
  239. MACROSTR(Uploading)
  240. };
  241. static char * FirmwareStatusStr[] = {
  242. MACROSTR(Downloaded),
  243. MACROSTR(DownloadFailed),
  244. MACROSTR(Downloading),
  245. MACROSTR(Idle),
  246. MACROSTR(InstallationFailed),
  247. MACROSTR(Installing),
  248. MACROSTR(Installed)
  249. };
  250. static char * MessageTriggerStr[] = {
  251. MACROSTR(BootNotification),
  252. MACROSTR(DiagnosticsStatusNotification),
  253. MACROSTR(FirmwareStatusNotification),
  254. MACROSTR(Heartbeat),
  255. MACROSTR(MeterValues),
  256. MACROSTR(StatusNotification)
  257. };
  258. static char * TriggerMessageStatusStr[] = {
  259. MACROSTR(Accepted),
  260. MACROSTR(Rejected),
  261. MACROSTR(NotImplemented)
  262. };
  263. static char * UnlockStatusStr[] = {
  264. MACROSTR(Unlocked),
  265. MACROSTR(UnlockFailed),
  266. MACROSTR(NotSupported)
  267. };
  268. #if 0
  269. static char * StopTransactionReasonStr[] = {
  270. MACROSTR(EmergencyStop),
  271. MACROSTR(EVDisconnected),
  272. MACROSTR(HardReset),
  273. MACROSTR(Local),
  274. MACROSTR(Other),
  275. MACROSTR(PowerLoss),
  276. MACROSTR(Reboot),
  277. MACROSTR(Remote),
  278. MACROSTR(SoftReset),
  279. MACROSTR(UnlockCommand),
  280. MACROSTR(DeAuthorized)
  281. };
  282. #endif
  283. static char * CancelReservationStatusStr[] = {
  284. MACROSTR(Accepted),
  285. MACROSTR(Rejected)
  286. };
  287. static char * ReadingContextStr[] = {
  288. MACROSTR(Interruption.Begin),
  289. MACROSTR(Interruption.End),
  290. MACROSTR(Other),
  291. MACROSTR(Sample.Clock),
  292. MACROSTR(Sample.Periodic),
  293. MACROSTR(Transaction.Begin),
  294. MACROSTR(Transaction.End),
  295. MACROSTR(Trigger)
  296. };
  297. static char * ValueFormatStr[] = {
  298. MACROSTR(Raw),
  299. MACROSTR(SignedData)
  300. };
  301. static char * MeasurandStr[] = {
  302. MACROSTR(Current.Export),
  303. MACROSTR(Current.Import),
  304. MACROSTR(Current.Offered),
  305. MACROSTR(Energy.Active.Export.Register),
  306. MACROSTR(Energy.Active.Import.Register),
  307. MACROSTR(Energy.Reactive.Export.Register),
  308. MACROSTR(Energy.Reactive.Import.Register),
  309. MACROSTR(Energy.Active.Export.Interval),
  310. MACROSTR(Energy.Active.Import.Interval),
  311. MACROSTR(Energy.Reactive.Export.Interval),
  312. MACROSTR(Energy.Reactive.Import.Interval),
  313. MACROSTR(Frequency),
  314. MACROSTR(Power.Active.Export),
  315. MACROSTR(Power.Active.Import),
  316. MACROSTR(Power.Factor),
  317. MACROSTR(Power.Offered),
  318. MACROSTR(Power.Reactive.ExportMACROSTR),
  319. MACROSTR(Power.Reactive.Import),
  320. MACROSTR(RPM),
  321. MACROSTR(SoC),
  322. MACROSTR(Temperature),
  323. MACROSTR(Voltage)
  324. };
  325. static char * LocationStr[] = {
  326. MACROSTR(Body),
  327. MACROSTR(Cable),
  328. MACROSTR(EV),
  329. MACROSTR(Inlet),
  330. MACROSTR(Outlet)
  331. };
  332. static char * PhaseStr[] = {
  333. MACROSTR(L1),
  334. MACROSTR(L2),
  335. MACROSTR(L3),
  336. MACROSTR(N),
  337. MACROSTR(L1-N),
  338. MACROSTR(L2-N),
  339. MACROSTR(L3-N),
  340. MACROSTR(L1-L2),
  341. MACROSTR(L2-L3),
  342. MACROSTR(L3-L1)
  343. };
  344. static char * UnitOfMeasureStr[] = {
  345. MACROSTR(Wh),
  346. MACROSTR(kWh),
  347. MACROSTR(varh),
  348. MACROSTR(kvarh),
  349. MACROSTR(W),
  350. MACROSTR(kW),
  351. MACROSTR(VA),
  352. MACROSTR(kVA),
  353. MACROSTR(var),
  354. MACROSTR(kvar),
  355. MACROSTR(A),
  356. MACROSTR(V),
  357. MACROSTR(Celsius),
  358. MACROSTR(Fahrenheit),
  359. MACROSTR(K),
  360. MACROSTR(Percent)
  361. };
  362. //==========================================
  363. // Check time passed since today
  364. //==========================================
  365. long long DiffTimebWithNow(struct timeb ST)
  366. {
  367. //return milli-second
  368. struct timeb ET;
  369. long long StartTime,StopTime;
  370. ftime(&ET);
  371. StartTime=(long long)ST.time;
  372. StopTime=(long long)ET.time;
  373. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  374. }
  375. int getTimePassSinceToday()
  376. {
  377. int result = -1;
  378. time_t t;
  379. struct tm *tmStartToday;
  380. struct timeb tbStartToday;
  381. t=time(NULL);
  382. tmStartToday=localtime(&t);
  383. tmStartToday->tm_hour = 0;
  384. tmStartToday->tm_min = 0;
  385. tmStartToday->tm_sec = 0;
  386. tbStartToday.time = mktime(tmStartToday);
  387. tbStartToday.millitm = 0;
  388. result = DiffTimebWithNow(tbStartToday)/1000;
  389. return result;
  390. }
  391. //==========================================
  392. // GetCompositeSchedule logic related function
  393. //==========================================
  394. int DiffTimebSec(struct timeb ST, struct timeb ET)
  395. {
  396. //return milli-second
  397. unsigned int StartTime,StopTime;
  398. StartTime=(unsigned int)ST.time;
  399. StopTime=(unsigned int)ET.time;
  400. return (StopTime-StartTime);
  401. }
  402. int DiffTimebWithNowSec(struct timeb ST)
  403. {
  404. //return milli-second
  405. struct timeb ET;
  406. unsigned int StartTime,StopTime;
  407. ftime(&ET);
  408. StartTime=(unsigned int)ST.time;
  409. StopTime=(unsigned int)ET.time;
  410. return (StopTime-StartTime);
  411. }
  412. int getStartStop(uint8_t *start, uint8_t *stop)
  413. {
  414. int result = -1;
  415. struct tm tmStart;
  416. struct timeb tbStart;
  417. struct tm tmStop;
  418. struct timeb tbStop;
  419. 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) &&
  420. (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))
  421. {
  422. //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);
  423. //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);
  424. tmStart.tm_year -= 1900;
  425. tmStart.tm_mon -= 1;
  426. tbStart.time = mktime(&tmStart);
  427. tbStart.millitm = 0;
  428. tmStop.tm_year -= 1900;
  429. tmStop.tm_mon -= 1;
  430. tbStop.time = mktime(&tmStop);
  431. tbStop.millitm = 0;
  432. result = DiffTimebSec(tbStart, tbStop);
  433. //DEBUG_INFO("getStartStop(): %d\n", result);
  434. }
  435. else
  436. {
  437. DEBUG_WARN("Start or stop date parsing error.\r\n");
  438. }
  439. return result;
  440. }
  441. int isOvertNow(uint8_t *start)
  442. {
  443. int result = YES;
  444. struct tm tmStart;
  445. struct timeb tbStart;
  446. 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))
  447. {
  448. //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);
  449. tmStart.tm_year -= 1900;
  450. tmStart.tm_mon -= 1;
  451. tbStart.time = mktime(&tmStart);
  452. tbStart.millitm = 0;
  453. if(DiffTimebWithNowSec(tbStart) <= 0)
  454. result = NO;
  455. }
  456. else
  457. {
  458. DEBUG_WARN("Start date parsing error.\r\n");
  459. }
  460. return result;
  461. }
  462. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  463. {
  464. int result = -1;
  465. struct tm tmStart;
  466. struct timeb tbStart;
  467. struct tm tmStop;
  468. struct timeb tbStop;
  469. 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) &&
  470. (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))
  471. {
  472. tmStart.tm_year -= 1900;
  473. tmStart.tm_mon -= 1;
  474. tbStart.time = mktime(&tmStart);
  475. tbStart.millitm = 0;
  476. tmStop.tm_year -= 1900;
  477. tmStop.tm_mon -= 1;
  478. tbStop.time = mktime(&tmStop);
  479. tbStop.millitm = 0;
  480. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  481. }
  482. return result;
  483. }
  484. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile)
  485. {
  486. FILE *fp;
  487. char profileFileName[128];
  488. char *line = NULL;
  489. size_t len = 0;
  490. time_t CurrentTime;
  491. struct tm *tmComposite;
  492. struct StructChargingProfile maxProfile;
  493. struct StructChargingProfile defaultTxProfile;
  494. struct StructChargingProfile txProfile;
  495. struct StructChargingSchedulePeriod tmpPeriod;
  496. uint8_t limitMax=0;
  497. uint8_t limitDef=0;
  498. uint8_t limitTx=0;
  499. int compositePeriodIdx = 0;
  500. CurrentTime = time(NULL);
  501. tmComposite=localtime(&CurrentTime);
  502. sprintf((char*)compositeProfile->ChargingSchedule.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);
  503. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  504. compositeProfile->ChargingSchedule.Duration = durationReq;
  505. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  506. {
  507. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  508. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  509. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  510. }
  511. compositeProfile->ChargingProfileId = 0;
  512. compositeProfile->StackLevel = 99 ;
  513. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  514. maxProfile.ChargingProfileId = -1;
  515. defaultTxProfile.ChargingProfileId = -1;
  516. txProfile.ChargingProfileId = -1;
  517. maxProfile.ChargingSchedule.Duration = -1;
  518. defaultTxProfile.ChargingSchedule.Duration = -1;
  519. txProfile.ChargingSchedule.Duration = -1;
  520. system("yes|rm /tmp/*.json");
  521. system("cp /Storage/OCPP/*.json /tmp");
  522. /*
  523. * Search valid charging profile
  524. */
  525. //DEBUG_INFO("====================================\n");
  526. // Search tx profile
  527. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  528. if((access(profileFileName, F_OK))!=-1)
  529. {
  530. fp = fopen(profileFileName, "r");
  531. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  532. {
  533. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  534. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  535. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  536. }
  537. txProfile.ChargingProfileId = -1;
  538. txProfile.StackLevel = -1;
  539. while(getline(&line, &len, fp) != -1)
  540. {
  541. json_object *obj = NULL;
  542. obj = json_tokener_parse(line);
  543. if(is_error(obj))
  544. {
  545. DEBUG_ERROR("Parse txProfile from file error.\n");
  546. }
  547. else
  548. {
  549. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  550. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  551. )
  552. {
  553. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  554. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  555. )
  556. {
  557. struct tm tmFrom, tmTo;
  558. struct timeb tbFrom, tbTo;
  559. 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) &&
  560. (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))
  561. {
  562. tmFrom.tm_year -= 1900;
  563. tmFrom.tm_mon -= 1;
  564. tbFrom.time = mktime(&tmFrom);
  565. tmTo.tm_year -= 1900;
  566. tmTo.tm_mon -= 1;
  567. tbTo.time = mktime(&tmTo);
  568. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  569. {
  570. if(txProfile.ChargingProfileId == -1)
  571. DEBUG_INFO("TxProfile found.\n");
  572. else
  573. DEBUG_INFO("TxProfile updated.\n");
  574. // Required item
  575. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  576. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  577. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  578. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  579. 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++)
  580. {
  581. txProfile.ChargingSchedule.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"));
  582. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"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: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")));
  583. txProfile.ChargingSchedule.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?
  584. 3:
  585. 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")));
  586. }
  587. // Optional item
  588. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  589. {
  590. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  591. }
  592. else
  593. {
  594. sprintf((char*)txProfile.ValidFrom, " ");
  595. }
  596. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  597. {
  598. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  599. }
  600. else
  601. {
  602. sprintf((char*)txProfile.ValidTo, " ");
  603. }
  604. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  605. {
  606. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  607. }
  608. else
  609. {
  610. sprintf((char*)txProfile.RecurrencyKind, " ");
  611. }
  612. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  613. {
  614. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  615. }
  616. else
  617. {
  618. txProfile.TransactionId = -1;
  619. }
  620. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  621. {
  622. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  623. }
  624. else
  625. {
  626. txProfile.ChargingSchedule.Duration = 86400;
  627. }
  628. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  629. {
  630. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  631. }
  632. else
  633. {
  634. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  635. }
  636. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  637. {
  638. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  639. }
  640. else
  641. {
  642. txProfile.ChargingSchedule.MinChargingRate = -1;
  643. }
  644. }
  645. }
  646. }
  647. else
  648. {
  649. if(txProfile.ChargingProfileId == -1)
  650. DEBUG_INFO("TxProfile found.\n");
  651. else
  652. DEBUG_INFO("TxProfile updated.\n");
  653. // Required item
  654. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  655. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  656. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  657. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  658. 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++)
  659. {
  660. txProfile.ChargingSchedule.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"));
  661. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"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: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")));
  662. txProfile.ChargingSchedule.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?
  663. 3:
  664. 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")));
  665. }
  666. // Optional item
  667. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  668. {
  669. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  670. }
  671. else
  672. {
  673. sprintf((char*)txProfile.ValidFrom, " ");
  674. }
  675. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  676. {
  677. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  678. }
  679. else
  680. {
  681. sprintf((char*)txProfile.ValidTo, " ");
  682. }
  683. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  684. {
  685. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  686. }
  687. else
  688. {
  689. sprintf((char*)txProfile.RecurrencyKind, " ");
  690. }
  691. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  692. {
  693. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  694. }
  695. else
  696. {
  697. txProfile.TransactionId = -1;
  698. }
  699. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  700. {
  701. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  702. }
  703. else
  704. {
  705. txProfile.ChargingSchedule.Duration = 86400;
  706. }
  707. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  708. {
  709. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  710. }
  711. else
  712. {
  713. sprintf((char*)txProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  714. }
  715. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  716. {
  717. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  718. }
  719. else
  720. {
  721. txProfile.ChargingSchedule.MinChargingRate = -1;
  722. }
  723. }
  724. }
  725. }
  726. json_object_put(obj);
  727. }
  728. fclose(fp);
  729. /*
  730. if(txProfile.ChargingProfileId != -1)
  731. {
  732. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  733. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  734. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  735. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  736. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  737. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  738. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  739. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  740. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  741. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  742. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  743. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  744. {
  745. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  746. {
  747. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  748. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  749. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  750. }
  751. }
  752. }
  753. else
  754. DEBUG_INFO("TxProfile not found.\n");*/
  755. }
  756. // Search default tx profile
  757. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  758. if((access(profileFileName, F_OK))==-1)
  759. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  760. if((access(profileFileName, F_OK))!=-1)
  761. {
  762. fp = fopen(profileFileName, "r");
  763. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  764. {
  765. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  766. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  767. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  768. }
  769. defaultTxProfile.ChargingProfileId = -1;
  770. defaultTxProfile.StackLevel = -1;
  771. while(getline(&line, &len, fp) != -1)
  772. {
  773. json_object *obj = NULL;
  774. obj = json_tokener_parse(line);
  775. if(is_error(obj))
  776. {
  777. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  778. }
  779. else
  780. {
  781. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  782. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  783. )
  784. {
  785. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  786. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  787. )
  788. {
  789. struct tm tmFrom, tmTo;
  790. struct timeb tbFrom, tbTo;
  791. 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) &&
  792. (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))
  793. {
  794. tmFrom.tm_year -= 1900;
  795. tmFrom.tm_mon -= 1;
  796. tbFrom.time = mktime(&tmFrom);
  797. tmTo.tm_year -= 1900;
  798. tmTo.tm_mon -= 1;
  799. tbTo.time = mktime(&tmTo);
  800. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  801. {
  802. if(defaultTxProfile.ChargingProfileId == -1)
  803. DEBUG_INFO("TxDefaultProfile found.\n");
  804. else
  805. DEBUG_INFO("TxDefaultProfile updated.\n");
  806. // Required item
  807. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  808. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  809. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  810. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  811. 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++)
  812. {
  813. defaultTxProfile.ChargingSchedule.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"));
  814. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"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: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")));
  815. defaultTxProfile.ChargingSchedule.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?
  816. 3:
  817. 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")));
  818. }
  819. // Optional item
  820. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  821. {
  822. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  823. }
  824. else
  825. {
  826. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  827. }
  828. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  829. {
  830. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  831. }
  832. else
  833. {
  834. sprintf((char*)defaultTxProfile.ValidTo, " ");
  835. }
  836. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  837. {
  838. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  839. }
  840. else
  841. {
  842. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  843. }
  844. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  845. {
  846. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  847. }
  848. else
  849. {
  850. defaultTxProfile.TransactionId = -1;
  851. }
  852. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  853. {
  854. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  855. }
  856. else
  857. {
  858. defaultTxProfile.ChargingSchedule.Duration = 86400;
  859. }
  860. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  861. {
  862. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  863. }
  864. else
  865. {
  866. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  867. }
  868. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  869. {
  870. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  871. }
  872. else
  873. {
  874. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  875. }
  876. }
  877. }
  878. }
  879. else
  880. {
  881. if(defaultTxProfile.ChargingProfileId == -1)
  882. DEBUG_INFO("TxDefaultProfile found.\n");
  883. else
  884. DEBUG_INFO("TxDefaultProfile updated.\n");
  885. // Required item
  886. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  887. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  888. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  889. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  890. 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++)
  891. {
  892. defaultTxProfile.ChargingSchedule.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"));
  893. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"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: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")));
  894. defaultTxProfile.ChargingSchedule.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?
  895. 3:
  896. 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")));
  897. }
  898. // Optional item
  899. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  900. {
  901. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  902. }
  903. else
  904. {
  905. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  906. }
  907. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  908. {
  909. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  910. }
  911. else
  912. {
  913. sprintf((char*)defaultTxProfile.ValidTo, " ");
  914. }
  915. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  916. {
  917. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  918. }
  919. else
  920. {
  921. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  922. }
  923. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  924. {
  925. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  926. }
  927. else
  928. {
  929. defaultTxProfile.TransactionId = -1;
  930. }
  931. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  932. {
  933. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  934. }
  935. else
  936. {
  937. defaultTxProfile.ChargingSchedule.Duration = 86400;
  938. }
  939. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  940. {
  941. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  942. }
  943. else
  944. {
  945. sprintf((char*)defaultTxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  946. }
  947. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  948. {
  949. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  950. }
  951. else
  952. {
  953. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  954. }
  955. }
  956. }
  957. }
  958. json_object_put(obj);
  959. }
  960. fclose(fp);
  961. /*
  962. if(defaultTxProfile.ChargingProfileId != -1)
  963. {
  964. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  965. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  966. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  967. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  968. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  969. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  970. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  971. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  972. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  973. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  974. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  975. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  976. {
  977. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  978. {
  979. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  980. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  981. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  982. }
  983. }
  984. }
  985. else
  986. DEBUG_INFO("TxDefaultProfile not found.\n");
  987. DEBUG_INFO("------------------------------------\n");*/
  988. }
  989. // Search max profile
  990. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  991. if((access(profileFileName, F_OK))!=-1)
  992. {
  993. fp = fopen(profileFileName, "r");
  994. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  995. {
  996. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  997. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  998. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  999. }
  1000. maxProfile.ChargingProfileId = -1;
  1001. maxProfile.StackLevel = -1;
  1002. while(getline(&line, &len, fp) != -1)
  1003. {
  1004. json_object *obj = NULL;
  1005. obj = json_tokener_parse(line);
  1006. if(is_error(obj))
  1007. {
  1008. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1009. }
  1010. else
  1011. {
  1012. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1013. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1014. )
  1015. {
  1016. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1017. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1018. )
  1019. {
  1020. struct tm tmFrom, tmTo;
  1021. struct timeb tbFrom, tbTo;
  1022. 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) &&
  1023. (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))
  1024. {
  1025. tmFrom.tm_year -= 1900;
  1026. tmFrom.tm_mon -= 1;
  1027. tbFrom.time = mktime(&tmFrom);
  1028. tmTo.tm_year -= 1900;
  1029. tmTo.tm_mon -= 1;
  1030. tbTo.time = mktime(&tmTo);
  1031. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1032. {
  1033. if(maxProfile.ChargingProfileId == -1)
  1034. DEBUG_INFO("MaxProfile found.\n");
  1035. else
  1036. DEBUG_INFO("MaxProfile updated.\n");
  1037. // Required item
  1038. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1039. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1040. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1041. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1042. 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++)
  1043. {
  1044. maxProfile.ChargingSchedule.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"));
  1045. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = (strstr(json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")),"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: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")));
  1046. maxProfile.ChargingSchedule.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?
  1047. 3:
  1048. 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")));
  1049. }
  1050. // Optional item
  1051. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1052. {
  1053. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1054. }
  1055. else
  1056. {
  1057. sprintf((char*)maxProfile.ValidFrom, " ");
  1058. }
  1059. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1060. {
  1061. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1062. }
  1063. else
  1064. {
  1065. sprintf((char*)maxProfile.ValidTo, " ");
  1066. }
  1067. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1068. {
  1069. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1070. }
  1071. else
  1072. {
  1073. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1074. }
  1075. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1076. {
  1077. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1078. }
  1079. else
  1080. {
  1081. maxProfile.TransactionId = -1;
  1082. }
  1083. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1084. {
  1085. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1086. }
  1087. else
  1088. {
  1089. maxProfile.ChargingSchedule.Duration = 86400;
  1090. }
  1091. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1092. {
  1093. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1094. }
  1095. else
  1096. {
  1097. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1098. }
  1099. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1100. {
  1101. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1102. }
  1103. else
  1104. {
  1105. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1106. }
  1107. }
  1108. }
  1109. }
  1110. else
  1111. {
  1112. if(maxProfile.ChargingProfileId == -1)
  1113. DEBUG_INFO("MaxProfile found.\n");
  1114. else
  1115. DEBUG_INFO("MaxProfile updated.\n");
  1116. // Required item
  1117. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1118. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1119. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1120. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1121. 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++)
  1122. {
  1123. maxProfile.ChargingSchedule.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"));
  1124. maxProfile.ChargingSchedule.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")),"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: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")));
  1125. maxProfile.ChargingSchedule.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?
  1126. 3:
  1127. 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")));
  1128. }
  1129. // Optional item
  1130. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1131. {
  1132. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1133. }
  1134. else
  1135. {
  1136. sprintf((char*)maxProfile.ValidFrom, " ");
  1137. }
  1138. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1139. {
  1140. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1141. }
  1142. else
  1143. {
  1144. sprintf((char*)maxProfile.ValidTo, " ");
  1145. }
  1146. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1147. {
  1148. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1149. }
  1150. else
  1151. {
  1152. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1153. }
  1154. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1155. {
  1156. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1157. }
  1158. else
  1159. {
  1160. maxProfile.TransactionId = -1;
  1161. }
  1162. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1163. {
  1164. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1165. }
  1166. else
  1167. {
  1168. maxProfile.ChargingSchedule.Duration = 86400;
  1169. }
  1170. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1171. {
  1172. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  1173. }
  1174. else
  1175. {
  1176. sprintf((char*)maxProfile.ChargingSchedule.StartSchedule, "%s", ((strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL) ? compositeProfile->ChargingSchedule.StartSchedule : ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp));
  1177. }
  1178. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1179. {
  1180. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1181. }
  1182. else
  1183. {
  1184. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1185. }
  1186. }
  1187. }
  1188. }
  1189. json_object_put(obj);
  1190. }
  1191. fclose(fp);
  1192. /*
  1193. if(maxProfile.ChargingProfileId !=-1)
  1194. {
  1195. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1196. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1197. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1198. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1199. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1200. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1201. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1202. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1203. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1204. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1205. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1206. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1207. {
  1208. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1209. {
  1210. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1211. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1212. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1213. }
  1214. }
  1215. }
  1216. else
  1217. DEBUG_INFO("MaxProfile not found.\n");
  1218. DEBUG_INFO("------------------------------------\n");*/
  1219. }
  1220. /*
  1221. * Align found profile start schedule & periods
  1222. */
  1223. //DEBUG_INFO("====================================\n");
  1224. /*
  1225. // For local test usage, force modify found profile start schedule info
  1226. sprintf((char*)maxProfile.ChargingSchedule.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);
  1227. sprintf((char*)defaultTxProfile.ChargingSchedule.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);
  1228. sprintf((char*)txProfile.ChargingSchedule.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);
  1229. */
  1230. if(txProfile.ChargingProfileId != -1)
  1231. {
  1232. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1233. {
  1234. if(txProfile.ChargingSchedule.Duration != -1)
  1235. {
  1236. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1237. 0:
  1238. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1239. }
  1240. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1241. {
  1242. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1243. {
  1244. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1245. 0:
  1246. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1247. if(idxPeriod > 0)
  1248. {
  1249. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1250. {
  1251. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1252. }
  1253. }
  1254. }
  1255. }
  1256. }
  1257. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1258. {
  1259. if(txProfile.ChargingSchedule.Duration != -1)
  1260. {
  1261. txProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.Duration:((txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1262. 0:
  1263. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1264. }
  1265. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1266. {
  1267. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1268. {
  1269. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1270. 0:
  1271. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1272. if(idxPeriod > 0)
  1273. {
  1274. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1275. {
  1276. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1277. }
  1278. }
  1279. }
  1280. }
  1281. }
  1282. else
  1283. {
  1284. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1285. {
  1286. if(txProfile.ChargingSchedule.Duration != -1)
  1287. {
  1288. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1289. 0:
  1290. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1291. }
  1292. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1293. {
  1294. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1295. {
  1296. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1297. 0:
  1298. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1299. if(idxPeriod > 0)
  1300. {
  1301. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1302. {
  1303. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1304. }
  1305. }
  1306. }
  1307. }
  1308. }
  1309. else
  1310. {
  1311. if(txProfile.ChargingSchedule.Duration != -1)
  1312. {
  1313. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1314. 0:
  1315. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1316. }
  1317. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1318. {
  1319. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1320. {
  1321. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1322. 0:
  1323. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1324. if(idxPeriod > 0)
  1325. {
  1326. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1327. {
  1328. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1329. }
  1330. }
  1331. }
  1332. }
  1333. }
  1334. }
  1335. /*
  1336. DEBUG_INFO("txProfile after align.\n");
  1337. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1338. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1339. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1340. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1341. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1342. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1343. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1344. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1345. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1346. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1347. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1348. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1349. {
  1350. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1351. {
  1352. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1353. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1354. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1355. }
  1356. }*/
  1357. }
  1358. if(defaultTxProfile.ChargingProfileId != -1)
  1359. {
  1360. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1361. {
  1362. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1363. {
  1364. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1365. 0:
  1366. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1367. }
  1368. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1369. {
  1370. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1371. {
  1372. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1373. 0:
  1374. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1375. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1376. {
  1377. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1378. }
  1379. if(idxPeriod > 0)
  1380. {
  1381. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1382. {
  1383. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1384. }
  1385. }
  1386. }
  1387. }
  1388. }
  1389. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1390. {
  1391. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1392. {
  1393. defaultTxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.Duration:((defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1394. 0:
  1395. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1396. }
  1397. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1398. {
  1399. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1400. {
  1401. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1402. 0:
  1403. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1404. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1405. {
  1406. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1407. }
  1408. if(idxPeriod > 0)
  1409. {
  1410. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1411. {
  1412. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1413. }
  1414. }
  1415. }
  1416. }
  1417. }
  1418. else
  1419. {
  1420. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1421. {
  1422. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1423. {
  1424. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1425. 0:
  1426. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1427. }
  1428. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1429. {
  1430. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1431. {
  1432. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1433. 0:
  1434. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1435. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1436. {
  1437. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1438. }
  1439. if(idxPeriod > 0)
  1440. {
  1441. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1442. {
  1443. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1444. }
  1445. }
  1446. }
  1447. }
  1448. }
  1449. else
  1450. {
  1451. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1452. {
  1453. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1454. 0:
  1455. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1456. }
  1457. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1458. {
  1459. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1460. {
  1461. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1462. 0:
  1463. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1464. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1465. {
  1466. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1467. }
  1468. if(idxPeriod > 0)
  1469. {
  1470. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1471. {
  1472. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1473. }
  1474. }
  1475. }
  1476. }
  1477. }
  1478. }
  1479. /*
  1480. DEBUG_INFO("defaultTxProfile after align.\n");
  1481. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1482. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1483. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1484. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1485. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1486. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1487. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1488. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1489. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1490. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1491. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1492. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1493. {
  1494. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1495. {
  1496. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1497. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1498. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1499. }
  1500. }
  1501. DEBUG_INFO("------------------------------------\n");*/
  1502. }
  1503. if(maxProfile.ChargingProfileId != -1)
  1504. {
  1505. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1506. {
  1507. if(maxProfile.ChargingSchedule.Duration != -1)
  1508. {
  1509. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1510. 0:
  1511. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1512. }
  1513. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1514. {
  1515. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1516. {
  1517. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1518. 0:
  1519. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1520. if(idxPeriod > 0)
  1521. {
  1522. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1523. {
  1524. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1525. }
  1526. }
  1527. }
  1528. }
  1529. }
  1530. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1531. {
  1532. if(maxProfile.ChargingSchedule.Duration != -1)
  1533. {
  1534. maxProfile.ChargingSchedule.Duration = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.Duration:((maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1535. 0:
  1536. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1537. }
  1538. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1539. {
  1540. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1541. {
  1542. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = (strstr((char*)ShmOCPP16Data->StatusNotification[(connectorId==0?0:connectorId-1)].Status, "Charging")==NULL)?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod:((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1543. 0:
  1544. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1545. if(idxPeriod > 0)
  1546. {
  1547. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1548. {
  1549. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1550. }
  1551. }
  1552. }
  1553. }
  1554. }
  1555. else
  1556. {
  1557. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1558. {
  1559. if(maxProfile.ChargingSchedule.Duration != -1)
  1560. {
  1561. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1562. 0:
  1563. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1564. }
  1565. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1566. {
  1567. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1568. {
  1569. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1570. 0:
  1571. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1572. if(idxPeriod > 0)
  1573. {
  1574. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1575. {
  1576. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1577. }
  1578. }
  1579. }
  1580. }
  1581. }
  1582. else
  1583. {
  1584. if(maxProfile.ChargingSchedule.Duration != -1)
  1585. {
  1586. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1587. 0:
  1588. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1589. }
  1590. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1591. {
  1592. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1593. {
  1594. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1595. 0:
  1596. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1597. if(idxPeriod > 0)
  1598. {
  1599. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1600. {
  1601. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1602. }
  1603. }
  1604. }
  1605. }
  1606. }
  1607. }
  1608. /*
  1609. DEBUG_INFO("MaxProfile after align.\n");
  1610. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1611. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1612. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1613. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1614. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1615. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1616. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1617. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1618. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1619. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1620. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1621. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1622. {
  1623. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1624. {
  1625. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1626. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1627. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1628. }
  1629. }
  1630. DEBUG_INFO("------------------------------------\n");*/
  1631. }
  1632. /*
  1633. * Merge to conposite schedule
  1634. */
  1635. //DEBUG_INFO("====================================\n");
  1636. // Find each profile period quantity
  1637. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1638. {
  1639. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1640. limitMax = idx+1;
  1641. }
  1642. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1643. {
  1644. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1645. limitDef = idx+1;
  1646. }
  1647. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1648. {
  1649. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1650. limitTx = idx+1;
  1651. }
  1652. // TxProfile found, composite schedule based on it
  1653. if(txProfile.ChargingProfileId != -1)
  1654. {
  1655. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1656. {
  1657. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1658. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  1659. (txProfile.ChargingSchedule.Duration > 0))
  1660. {
  1661. if(maxProfile.ChargingProfileId != -1)
  1662. {
  1663. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1664. {
  1665. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  1666. {
  1667. if((maxProfile.ChargingSchedule.Duration > 0))
  1668. {
  1669. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1670. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1671. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1672. }
  1673. else
  1674. {
  1675. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1676. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1677. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  1678. }
  1679. }
  1680. if(idxMaxPeriod == (limitMax-1))
  1681. {
  1682. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1683. {
  1684. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1685. {
  1686. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1687. compositePeriodIdx++;
  1688. }
  1689. else
  1690. {
  1691. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1692. }
  1693. }
  1694. }
  1695. }
  1696. }
  1697. else
  1698. {
  1699. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1700. {
  1701. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1702. compositePeriodIdx++;
  1703. }
  1704. else
  1705. {
  1706. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1707. }
  1708. }
  1709. }
  1710. if(idxTxPeriod == (limitTx-1))
  1711. {
  1712. if(defaultTxProfile.ChargingProfileId != -1)
  1713. {
  1714. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1715. {
  1716. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  1717. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1718. (defaultTxProfile.ChargingSchedule.Duration>0))
  1719. {
  1720. if(maxProfile.ChargingProfileId != -1)
  1721. {
  1722. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1723. {
  1724. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1725. {
  1726. if((maxProfile.ChargingSchedule.Duration > 0))
  1727. {
  1728. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1729. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1730. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1731. }
  1732. else
  1733. {
  1734. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1735. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1736. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1737. }
  1738. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1739. {
  1740. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1741. {
  1742. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1743. compositePeriodIdx++;
  1744. }
  1745. else
  1746. {
  1747. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1748. }
  1749. }
  1750. break;
  1751. }
  1752. }
  1753. }
  1754. else
  1755. {
  1756. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1757. {
  1758. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1759. compositePeriodIdx++;
  1760. }
  1761. else
  1762. {
  1763. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1764. }
  1765. }
  1766. }
  1767. }
  1768. }
  1769. }
  1770. }
  1771. }
  1772. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  1773. else if(defaultTxProfile.ChargingProfileId != -1)
  1774. {
  1775. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1776. {
  1777. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  1778. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1779. (defaultTxProfile.ChargingSchedule.Duration > 0))
  1780. {
  1781. if(maxProfile.ChargingProfileId != -1)
  1782. {
  1783. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1784. {
  1785. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1786. {
  1787. if((maxProfile.ChargingSchedule.Duration > 0))
  1788. {
  1789. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1790. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1791. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  1792. }
  1793. else
  1794. {
  1795. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1796. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1797. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1798. }
  1799. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1800. {
  1801. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1802. {
  1803. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1804. compositePeriodIdx++;
  1805. }
  1806. else
  1807. {
  1808. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1809. }
  1810. }
  1811. break;
  1812. }
  1813. }
  1814. }
  1815. else
  1816. {
  1817. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1818. {
  1819. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1820. compositePeriodIdx++;
  1821. }
  1822. else
  1823. {
  1824. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1825. }
  1826. }
  1827. }
  1828. }
  1829. }
  1830. // Fill other period by MaxProfile
  1831. if(maxProfile.ChargingProfileId != -1)
  1832. {
  1833. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1834. {
  1835. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1836. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1837. (maxProfile.ChargingSchedule.Duration > 0))
  1838. {
  1839. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  1840. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1841. {
  1842. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  1843. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  1844. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1845. }
  1846. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1847. {
  1848. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  1849. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  1850. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1851. }
  1852. if(tmpPeriod.Limit != -1)
  1853. {
  1854. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1855. {
  1856. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1857. {
  1858. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1859. compositePeriodIdx++;
  1860. }
  1861. else
  1862. {
  1863. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1864. }
  1865. }
  1866. }
  1867. }
  1868. }
  1869. }
  1870. DEBUG_INFO("Composite schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1871. DEBUG_INFO("Composite schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1872. DEBUG_INFO("Composite rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1873. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1874. {
  1875. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1876. {
  1877. compositeProfile->ChargingProfileId = 1;
  1878. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1879. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1880. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1881. }
  1882. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1883. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1884. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1885. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1886. }
  1887. if(line)
  1888. free(line);
  1889. }
  1890. //==========================================
  1891. // Init all share memory
  1892. //==========================================
  1893. int InitShareMemory()
  1894. {
  1895. int result = PASS;
  1896. int MeterSMId;
  1897. //creat ShmSysConfigAndInfo
  1898. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1899. {
  1900. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  1901. result = FAIL;
  1902. }
  1903. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1904. {
  1905. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  1906. result = FAIL;
  1907. }
  1908. else
  1909. {}
  1910. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  1911. {
  1912. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  1913. result = FAIL;
  1914. }
  1915. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1916. {
  1917. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  1918. result = FAIL;
  1919. }
  1920. else
  1921. {}
  1922. //creat ShmPsuData
  1923. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  1924. {
  1925. DEBUG_ERROR("shmget ShmPsuData NG\n");
  1926. result = FAIL;
  1927. }
  1928. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1929. {
  1930. DEBUG_ERROR("shmat ShmPsuData NG\n");
  1931. result = FAIL;
  1932. }
  1933. else
  1934. {}
  1935. //creat ShmOCPP16Data
  1936. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  1937. {
  1938. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  1939. result = FAIL;
  1940. }
  1941. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1942. {
  1943. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  1944. result = FAIL;
  1945. }
  1946. else
  1947. {}
  1948. /****************************** For Initial Settings************************************************/
  1949. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  1950. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  1951. // allocate Configuration memory address
  1952. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  1953. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  1954. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  1955. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  1956. //offline MeterValue Interval
  1957. TempMeterValueInterval = 0;
  1958. return result;
  1959. }
  1960. int ProcessShareMemory()
  1961. {
  1962. if(InitShareMemory() == FAIL)
  1963. {
  1964. DEBUG_ERROR("InitShareMemory NG\n");
  1965. if(ShmStatusCodeData!=NULL)
  1966. {
  1967. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1968. }
  1969. sleep(5);
  1970. return FAIL;
  1971. }
  1972. return PASS;
  1973. }
  1974. //---------------------common routine---------------------------//
  1975. int isOFFline(void)
  1976. {
  1977. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  1978. {
  1979. if(TempMeterValueInterval >= 2 )
  1980. {
  1981. TempMeterValueInterval = 0;
  1982. return TRUE;
  1983. }
  1984. else
  1985. {
  1986. TempMeterValueInterval = TempMeterValueInterval+ 1;
  1987. return FALSE;
  1988. }
  1989. }
  1990. else
  1991. {
  1992. return FALSE;
  1993. }
  1994. }
  1995. //---------------------------------------------
  1996. // new:
  1997. // enum SYSTEM_STATUS
  1998. // {
  1999. // SYS_MODE_BOOTING = 0,
  2000. // SYS_MODE_IDLE = 1,
  2001. // SYS_MODE_AUTHORIZING = 2,
  2002. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  2003. // SYS_MODE_REASSIGN = 4,
  2004. // SYS_MODE_PREPARING = 5,
  2005. // SYS_MODE_PREPARE_FOR_EV = 6,
  2006. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  2007. // SYS_MODE_CHARGING = 8,
  2008. // SYS_MODE_TERMINATING = 9,
  2009. // SYS_MODE_COMPLETE = 10,
  2010. // SYS_MODE_ALARM = 11,
  2011. // SYS_MODE_FAULT = 12,
  2012. // SYS_MODE_RESERVATION = 13,
  2013. // SYS_MODE_BOOKING = 14,
  2014. // SYS_MODE_MAINTAIN = 15,
  2015. // SYS_MODE_DEBUG = 16,
  2016. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  2017. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  2018. // SYS_MODE_UPDATE = 19
  2019. // };
  2020. //
  2021. //
  2022. //-----------------------------------------
  2023. void CheckSystemValue(void)
  2024. {
  2025. uint8_t reqSampleMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2026. uint8_t reqClockAlignMeter[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY + AC_QUANTITY]={0};
  2027. char filenmae[100]={0};
  2028. char str[100]={0};
  2029. int tempIndex = 0;
  2030. //===============================
  2031. // send Heartbeat
  2032. //===============================
  2033. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2034. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2035. {
  2036. clientTime.Heartbeat=time((time_t*)NULL);
  2037. if(server_sign == TRUE)
  2038. {
  2039. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2040. }
  2041. else
  2042. {
  2043. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2044. }
  2045. }
  2046. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= HeartBeatWaitTime))
  2047. {
  2048. //parameter for test
  2049. sendHeartbeatRequest(0);
  2050. //==============================================
  2051. // Reset Waiting Time
  2052. //==============================================
  2053. clientTime.Heartbeat=time((time_t*)NULL);
  2054. HeartBeatWithNOResponse = HeartBeatWithNOResponse + 1;
  2055. }
  2056. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2057. {
  2058. //===============================
  2059. // CSU Trigger Reset Conf
  2060. //===============================
  2061. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2062. {
  2063. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2064. }
  2065. //===============================
  2066. // CSU Trigger Authorize Request
  2067. //===============================
  2068. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2069. {
  2070. sendAuthorizeRequest(0);
  2071. authorizeRetryTimes = authorizeRetryTimes + 1;
  2072. if(authorizeRetryTimes < 3)
  2073. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2074. }
  2075. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2076. {
  2077. authorizeRetryTimes = 0;
  2078. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  2079. server_sign = FALSE;
  2080. }
  2081. else if((server_sign == FALSE) && (strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0)&& (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1))
  2082. {
  2083. sendAuthorizeRequest(0);
  2084. }
  2085. //===============================
  2086. // CSU Trigger Smart Charging Profilw
  2087. //===============================
  2088. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2089. {
  2090. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index]);
  2091. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2092. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileConf = 1;
  2093. }
  2094. //==============================================
  2095. // Charger start transaction
  2096. //==============================================
  2097. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2098. {
  2099. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq =0;
  2100. sendStartTransactionRequest(gun_index);
  2101. clientTime.StartTransaction = time((time_t*)NULL);
  2102. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2103. }
  2104. //==============================================
  2105. // Charger stop transaction
  2106. //==============================================
  2107. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2108. {
  2109. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq =0;
  2110. sendStopTransactionRequest(gun_index);
  2111. clientTime.StopTransaction = time((time_t*)NULL);
  2112. }
  2113. //==============================================
  2114. // Charger status report
  2115. //==============================================
  2116. //--- Check Mode Change ---//
  2117. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2118. if(gunType[gun_index] == 'J')
  2119. {
  2120. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2121. {
  2122. tempIndex = ((gun_index==2) ? 1: 0);
  2123. }
  2124. else
  2125. {
  2126. tempIndex = gun_index;
  2127. }
  2128. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2129. {
  2130. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2131. {
  2132. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2133. {
  2134. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2135. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2136. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2137. statusModeChage[gun_index] = TRUE;
  2138. }
  2139. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2140. {
  2141. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2142. if((access(filenmae,F_OK))!=-1)
  2143. {
  2144. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2145. sprintf(str,"rm -f %s",filenmae);
  2146. system(str);
  2147. }
  2148. }
  2149. #if 1 // for TempStopTransaction
  2150. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2151. {
  2152. checkTempStopTransaction(gun_index);
  2153. }
  2154. #endif
  2155. }
  2156. }
  2157. }
  2158. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2159. {
  2160. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2161. {
  2162. tempIndex = ((gun_index==2) ? 1: 0);
  2163. }
  2164. else
  2165. {
  2166. tempIndex = gun_index;
  2167. }
  2168. for (int index = 0; index < CCS_QUANTITY; index++)
  2169. {
  2170. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2171. {
  2172. 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]*/ )
  2173. {
  2174. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2175. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2176. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2177. statusModeChage[gun_index] = TRUE;
  2178. }
  2179. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2180. {
  2181. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2182. if((access(filenmae,F_OK))!=-1)
  2183. {
  2184. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2185. sprintf(str,"rm -f %s",filenmae);
  2186. system(str);
  2187. }
  2188. }
  2189. #if 1 // for TempStopTransaction
  2190. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2191. {
  2192. checkTempStopTransaction(gun_index);
  2193. }
  2194. #endif
  2195. }
  2196. }
  2197. }
  2198. else if(gunType[gun_index] == 'G')
  2199. {
  2200. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2201. {
  2202. tempIndex = ((gun_index==2) ? 1: 0);
  2203. }
  2204. else
  2205. {
  2206. tempIndex = gun_index;
  2207. }
  2208. for (int index = 0; index < GB_QUANTITY; index++)
  2209. {
  2210. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2211. {
  2212. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2213. {
  2214. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2215. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2216. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2217. statusModeChage[gun_index] = TRUE;
  2218. }
  2219. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2220. {
  2221. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2222. if((access(filenmae,F_OK))!=-1)
  2223. {
  2224. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2225. sprintf(str,"rm -f %s",filenmae);
  2226. system(str);
  2227. }
  2228. }
  2229. #if 1 // for TempStopTransaction
  2230. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2231. {
  2232. checkTempStopTransaction(gun_index);
  2233. }
  2234. #endif
  2235. }
  2236. }
  2237. }
  2238. else
  2239. {
  2240. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2241. {
  2242. tempIndex = 2;
  2243. }
  2244. else
  2245. {
  2246. tempIndex = gun_index;
  2247. }
  2248. for (int index = 0; index < AC_QUANTITY; index++)
  2249. {
  2250. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2251. {
  2252. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2253. {
  2254. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2255. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2256. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2257. statusModeChage[gun_index] = TRUE;
  2258. }
  2259. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // complete
  2260. {
  2261. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2262. if((access(filenmae,F_OK))!=-1)
  2263. {
  2264. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2265. sprintf(str,"rm -f %s",filenmae);
  2266. system(str);
  2267. }
  2268. }
  2269. #if 1 // for TempStopTransaction
  2270. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2271. {
  2272. checkTempStopTransaction(gun_index);
  2273. }
  2274. #endif
  2275. }
  2276. }// END
  2277. }
  2278. if(isWebsocketSendable &&
  2279. (((statusModeChage[gun_index] == TRUE) || ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) || ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 10)))) )
  2280. {
  2281. if(SystemInitial > 0)
  2282. SystemInitial -= 1;
  2283. sendStatusNotificationRequest(gun_index);
  2284. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2285. statusModeChage[gun_index] = FALSE;
  2286. }
  2287. //==============================================
  2288. // Meter report
  2289. //==============================================
  2290. if(cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2291. {
  2292. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2293. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2294. }
  2295. if(/*(server_sign == TRUE) &&(isOFFline() == TRUE) ||*/
  2296. (((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1)) || ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE)))
  2297. {
  2298. //check Transaction active
  2299. if(gunType[gun_index] == 'J')
  2300. {
  2301. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2302. {
  2303. tempIndex = ((gun_index==2) ? 1: 0);
  2304. }
  2305. else
  2306. {
  2307. tempIndex = gun_index;
  2308. }
  2309. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2310. {
  2311. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2312. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2313. {
  2314. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2315. {
  2316. reqSampleMeter[gun_index] = 1;
  2317. }
  2318. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2319. {
  2320. reqClockAlignMeter[gun_index] = 1;
  2321. }
  2322. }
  2323. }// End for CHAdeMO
  2324. }
  2325. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2326. {
  2327. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2328. {
  2329. tempIndex = ((gun_index==2) ? 1: 0);
  2330. }
  2331. else
  2332. {
  2333. tempIndex = gun_index;
  2334. }
  2335. for (int index = 0; index < CCS_QUANTITY; index++)
  2336. {
  2337. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2338. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2339. {
  2340. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2341. {
  2342. reqSampleMeter[gun_index] = 1;
  2343. }
  2344. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2345. {
  2346. reqClockAlignMeter[gun_index] = 1;
  2347. }
  2348. }
  2349. } // End for CCS
  2350. }
  2351. else if(gunType[gun_index] == 'G')
  2352. {
  2353. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2354. {
  2355. tempIndex = ((gun_index==2) ? 1: 0);
  2356. }
  2357. else
  2358. {
  2359. tempIndex = gun_index;
  2360. }
  2361. for (int index = 0; index < GB_QUANTITY; index++)
  2362. {
  2363. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2364. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2365. {
  2366. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2367. {
  2368. reqSampleMeter[gun_index] = 1;
  2369. }
  2370. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2371. {
  2372. reqClockAlignMeter[gun_index] = 1;
  2373. }
  2374. }
  2375. }// End for GB
  2376. }
  2377. else
  2378. {
  2379. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2380. {
  2381. tempIndex = 2;
  2382. }
  2383. else
  2384. {
  2385. tempIndex = gun_index;
  2386. }
  2387. for (int index = 0; index < AC_QUANTITY; index++)
  2388. {
  2389. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2390. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2391. {
  2392. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2393. {
  2394. reqSampleMeter[gun_index] = 1;
  2395. }
  2396. else if((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0) && ((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0))
  2397. {
  2398. reqClockAlignMeter[gun_index] = 1;
  2399. }
  2400. }
  2401. }//End for AC
  2402. }
  2403. if(reqSampleMeter[gun_index] == 1)
  2404. {
  2405. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2406. storeTempStopTransaction(gun_index);
  2407. }
  2408. else if(reqClockAlignMeter[gun_index] == 1)
  2409. {
  2410. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2411. }
  2412. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2413. sleep(1);
  2414. }
  2415. //==============================================
  2416. // Check Connector reserved
  2417. //==============================================
  2418. //===============================
  2419. // Check if Reserve is expired
  2420. //===============================
  2421. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2422. {
  2423. double diff_t;
  2424. struct tm tp;
  2425. // current time
  2426. time_t t = time(NULL);
  2427. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2428. tp.tm_isdst = -1;
  2429. time_t utc = mktime(&tp);
  2430. diff_t = difftime(utc, t);
  2431. if(diff_t <= 0)
  2432. {
  2433. DEBUG_INFO("reserve expired.\n");
  2434. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2435. }
  2436. }//END OF Check if Reserve is expired
  2437. //==========================================
  2438. // csu trigger FirmwareStatusNotificationReq
  2439. //==========================================
  2440. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2441. {
  2442. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2443. }
  2444. //==========================================
  2445. // csu trigger CancelReservationConf
  2446. //==========================================
  2447. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2448. {
  2449. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2450. }
  2451. //==========================================
  2452. // csu trigger ChangeAvailabilityConf
  2453. //==========================================
  2454. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2455. {
  2456. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2457. }
  2458. //==========================================
  2459. // csu trigger UnlockConnectorConf
  2460. //==========================================
  2461. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2462. {
  2463. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2464. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2465. }
  2466. //==========================================
  2467. // csu trigger ReserveNowConf
  2468. //==========================================
  2469. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2470. {
  2471. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2472. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2473. }
  2474. //==========================================
  2475. // csu trigger DataTransferReq
  2476. //==========================================
  2477. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2478. {
  2479. sendDataTransferRequest(gun_index);
  2480. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2481. }
  2482. }
  2483. }
  2484. //==========================================
  2485. // send request routine
  2486. //==========================================
  2487. int sendAuthorizeRequest(int gun_index)
  2488. {
  2489. mtrace();
  2490. int result = FAIL;
  2491. char message[100]={0};
  2492. char guid[37];
  2493. char tempdata[65]={0};
  2494. DEBUG_INFO("sendAuthorizeRequest...\n");
  2495. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2496. //Local Authorize
  2497. if ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2498. {
  2499. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2500. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2501. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2502. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2503. result = PASS;
  2504. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2505. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2506. authorizeRetryTimes = 0;
  2507. return result;
  2508. }
  2509. else if(((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)&&(ShmOCPP16Data->OcppConnStatus == 0))||
  2510. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2511. {
  2512. OCPP_getIdTag((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2513. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2514. {
  2515. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2516. {
  2517. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2518. }
  2519. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2520. {
  2521. DEBUG_INFO("offline Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2522. }
  2523. DEBUG_INFO("offline Local Authorization Fail !!!!\n");
  2524. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2525. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2526. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2527. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2528. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2529. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2530. authorizeRetryTimes = 0;
  2531. return result;
  2532. }
  2533. else
  2534. {
  2535. DEBUG_INFO("offline Local Authorization get result !!!!\n");
  2536. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2537. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2538. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  2539. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  2540. else
  2541. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2542. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2543. result = PASS;
  2544. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2545. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2546. authorizeRetryTimes = 0;
  2547. return result;
  2548. }
  2549. }
  2550. //initailize struct Authorize
  2551. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2552. //get data from shared memory
  2553. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2554. random_uuid(guid);
  2555. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2556. LWS_Send(message);
  2557. sprintf(tempdata, "Authorize,%d", gun_index);
  2558. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2559. {
  2560. result = PASS;
  2561. DEBUG_INFO("Authorize mapItem pass\n");
  2562. }
  2563. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2564. return result;
  2565. }
  2566. int sendBootNotificationRequest(void)
  2567. {
  2568. mtrace();
  2569. int result = FAIL;
  2570. char message[500]={0}, payload[700]={0};
  2571. char guid[37]={0};
  2572. char tempdata[65]={0};
  2573. /*
  2574. int IsGunCharging = FALSE;
  2575. //check Transaction active
  2576. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2577. {
  2578. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2579. {
  2580. IsGunCharging = TRUE;
  2581. }
  2582. }
  2583. for (int index = 0; index < CCS_QUANTITY; index++)
  2584. {
  2585. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2586. {
  2587. IsGunCharging = TRUE;
  2588. }
  2589. }
  2590. for (int index = 0; index < GB_QUANTITY; index++)
  2591. {
  2592. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2593. {
  2594. IsGunCharging = TRUE;
  2595. }
  2596. }
  2597. for (int index = 0; index < AC_QUANTITY; index++)
  2598. {
  2599. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  2600. {
  2601. IsGunCharging = TRUE;
  2602. }
  2603. }
  2604. if(IsGunCharging == TRUE)
  2605. {
  2606. server_sign = TRUE;
  2607. return result;
  2608. }
  2609. */
  2610. // Fill BootNotification fields
  2611. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2612. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2613. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2614. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2615. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2616. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2617. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2618. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2619. ShmOCPP16Data->ChargeBoxId
  2620. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2621. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2622. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2623. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2624. ,ShmOCPP16Data->BootNotification.CpIccid
  2625. ,ShmOCPP16Data->BootNotification.CpImsi);
  2626. random_uuid(guid);
  2627. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2628. LWS_Send(message);
  2629. sprintf(tempdata, "BootNotification,0");
  2630. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid,mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  2631. {
  2632. result = PASS;
  2633. }
  2634. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  2635. strcpy(queuedata,message);
  2636. return result;
  2637. }
  2638. int sendDataTransferRequest(int gun_index)
  2639. {
  2640. mtrace();
  2641. char message[1000]={0};
  2642. char guid[37]={0};
  2643. char tempdata[65]={0};
  2644. int result = FAIL;
  2645. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  2646. random_uuid(guid);
  2647. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2648. MESSAGE_TYPE_CALL,
  2649. guid,
  2650. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2651. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2652. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2653. LWS_Send(message);
  2654. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2655. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2656. {
  2657. result = PASS;
  2658. DEBUG_INFO("DataTransfer mapItem pass\n");
  2659. }
  2660. return result;
  2661. }
  2662. int sendDiagnosticsStatusNotificationRequest(char *status)
  2663. {
  2664. mtrace();
  2665. int result = FAIL;
  2666. char message[110]={0};
  2667. char guid[37]={0};
  2668. char tempdata[65]={0};
  2669. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2670. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2671. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2672. random_uuid(guid);
  2673. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2674. LWS_SendNow(message);
  2675. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2676. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2677. {
  2678. result = PASS;
  2679. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2680. }
  2681. //#ifdef SystemLogMessage
  2682. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2683. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2684. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2685. //#endif
  2686. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2687. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2688. //record status
  2689. if(strcmp(status,"Idle")==0)
  2690. {
  2691. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2692. }
  2693. else if(strcmp(status,"Uploaded")==0)
  2694. {
  2695. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2696. }
  2697. else if(strcmp(status,"UploadFailed")==0)
  2698. {
  2699. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2700. }
  2701. else if(strcmp(status,"Uploading")==0)
  2702. {
  2703. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2704. }
  2705. return result;
  2706. }
  2707. int sendFirmwareStatusNotificationRequest(char *status)
  2708. {
  2709. mtrace();
  2710. int result = FAIL;
  2711. char message[110]={0};
  2712. char guid[37]={0};
  2713. char tempdata[65]={0};
  2714. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2715. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2716. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2717. random_uuid(guid);
  2718. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2719. LWS_SendNow(message);
  2720. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2721. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  2722. {
  2723. result = PASS;
  2724. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2725. }
  2726. //#ifdef SystemLogMessage
  2727. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2728. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2729. //#endif
  2730. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2731. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2732. //record status
  2733. if(strcmp(status,"Downloaded")==0)
  2734. {
  2735. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2736. }
  2737. else if(strcmp(status,"DownloadFailed")==0)
  2738. {
  2739. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  2740. }
  2741. else if(strcmp(status,"Downloading")==0)
  2742. {
  2743. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2744. }
  2745. else if(strcmp(status,"Idle")==0)
  2746. {
  2747. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2748. }
  2749. else if(strcmp(status,"InstallationFailed")==0)
  2750. {
  2751. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2752. }
  2753. else if(strcmp(status,"Installing")==0)
  2754. {
  2755. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2756. }
  2757. else if(strcmp(status,"Installed")==0)
  2758. {
  2759. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2760. }
  2761. return result;
  2762. }
  2763. int sendHeartbeatRequest(int gun_index)
  2764. {
  2765. mtrace();
  2766. int result = FAIL;
  2767. char message[80]={0};
  2768. char guid[37]={0};
  2769. char tempdata[65]={0};
  2770. random_uuid(guid);
  2771. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2772. , MESSAGE_TYPE_CALL
  2773. , guid );
  2774. LWS_Send(message);
  2775. sprintf(tempdata, "Heartbeat,%d", 0);
  2776. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  2777. {
  2778. result = PASS;
  2779. }
  2780. return result;
  2781. }
  2782. int sendStartTransactionRequest(int gun_index)
  2783. {
  2784. mtrace();
  2785. int result = FAIL;
  2786. char message[250]={0};
  2787. char guid[37]={0};
  2788. struct timeval tmnow;
  2789. struct tm *tm;
  2790. char buf[28];//, usec_buf[6];
  2791. char tempdata[65]={0};
  2792. int tempIndex = 0;
  2793. DEBUG_INFO("sendStartTransactionRequest...\n");
  2794. gettimeofday(&tmnow, NULL);
  2795. time_t t;
  2796. t = time(NULL);
  2797. /*UTC time and date*/
  2798. tm = gmtime(&t);
  2799. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2800. #if 0 // remove temporally
  2801. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2802. strcat(buf,".");
  2803. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2804. strcat(buf,usec_buf);
  2805. #endif
  2806. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  2807. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  2808. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2809. // clear StartTransaction Response
  2810. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  2811. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  2812. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  2813. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  2814. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2815. if(gunType[gun_index] == 'J')
  2816. {
  2817. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2818. {
  2819. tempIndex = ((gun_index==2) ? 1: 0);
  2820. }
  2821. else
  2822. {
  2823. tempIndex = gun_index;
  2824. }
  2825. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2826. {
  2827. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2828. {
  2829. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  2830. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  2831. }
  2832. }
  2833. }
  2834. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2835. {
  2836. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2837. {
  2838. tempIndex = ((gun_index==2) ? 1: 0);
  2839. }
  2840. else
  2841. {
  2842. tempIndex = gun_index;
  2843. }
  2844. for (int index = 0; index < CCS_QUANTITY; index++)
  2845. {
  2846. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2847. {
  2848. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  2849. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  2850. }
  2851. }
  2852. }
  2853. else if(gunType[gun_index] == 'G')
  2854. {
  2855. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2856. {
  2857. tempIndex = ((gun_index==2) ? 1: 0);
  2858. }
  2859. else
  2860. {
  2861. tempIndex = gun_index;
  2862. }
  2863. for (int index = 0; index < GB_QUANTITY; index++)
  2864. {
  2865. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2866. {
  2867. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  2868. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  2869. }
  2870. }
  2871. }
  2872. else
  2873. {
  2874. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2875. {
  2876. tempIndex = 2;
  2877. }
  2878. else
  2879. {
  2880. tempIndex = gun_index;
  2881. }
  2882. for (int index = 0; index < AC_QUANTITY; index++)
  2883. {
  2884. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2885. {
  2886. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  2887. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  2888. }
  2889. }
  2890. }
  2891. random_uuid(guid);
  2892. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  2893. {
  2894. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  2895. , gun_index +1
  2896. , MESSAGE_TYPE_CALL
  2897. , guid
  2898. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2899. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2900. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2901. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2902. }
  2903. else
  2904. {
  2905. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  2906. , gun_index +1
  2907. , MESSAGE_TYPE_CALL
  2908. , guid
  2909. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  2910. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  2911. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  2912. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  2913. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  2914. }
  2915. #if 1
  2916. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  2917. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  2918. {
  2919. result = PASS;
  2920. }
  2921. #endif
  2922. strcpy(queuedata, message);
  2923. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  2924. return result;
  2925. }
  2926. int sendStatusNotificationRequest(int gun_index)
  2927. {
  2928. mtrace();
  2929. int result = FAIL;
  2930. char message[600]={0};
  2931. char guid[37];
  2932. int currentStatus = 0;
  2933. struct timeval tmnow;
  2934. struct tm *tm;
  2935. char buf[28];//, usec_buf[6];
  2936. char tempdata[65]={0};
  2937. int tempIndex = 0;
  2938. gettimeofday(&tmnow, NULL);
  2939. time_t t;
  2940. t = time(NULL);
  2941. /*UTC time and date*/
  2942. tm = gmtime(&t);
  2943. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2944. #if 0 // remove temporally
  2945. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2946. strcat(buf,".");
  2947. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2948. strcat(buf,usec_buf);
  2949. #endif
  2950. printf("%s",buf);
  2951. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  2952. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  2953. // it's option
  2954. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  2955. /*
  2956. enum _SYSTEM_STATUS
  2957. {
  2958. S_BOOTING = 0,
  2959. S_IDLE, = 1
  2960. S_AUTHORIZING, =2
  2961. S_REASSIGN_CHECK, =3
  2962. S_REASSIGN, =4
  2963. S_PRECHARGE, =5
  2964. S_PREPARING_FOR_EV, =6
  2965. S_PREPARING_FOR_EVSE, =7
  2966. S_CHARGING, =8
  2967. S_TERMINATING, =9
  2968. S_COMPLETE, =10
  2969. S_ALARM, =11
  2970. S_FAULT =12
  2971. }
  2972. */
  2973. //check Transaction active
  2974. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2975. if(gunType[gun_index] == 'J')
  2976. {
  2977. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2978. {
  2979. tempIndex = ((gun_index==2) ? 1: 0);
  2980. }
  2981. else
  2982. {
  2983. tempIndex = gun_index;
  2984. }
  2985. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2986. {
  2987. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  2988. {
  2989. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  2990. {
  2991. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  2992. {
  2993. currentStatus = 1; //OCPP Status: Preparing
  2994. }
  2995. else
  2996. {
  2997. currentStatus = 0; //OCPP Status: Available
  2998. }
  2999. }
  3000. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3001. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3002. ) //S_PRECHARGE
  3003. {
  3004. currentStatus = 1; //OCPP Status: Preparing
  3005. }
  3006. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3007. {
  3008. currentStatus = 2; //OCPP Status: Charging
  3009. }
  3010. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3011. {
  3012. currentStatus = 5; //OCPP Status: Finishing
  3013. }
  3014. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3015. {
  3016. currentStatus = 4; //OCPP Status: SuspendedEV
  3017. }
  3018. 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
  3019. {
  3020. currentStatus = 7; //OCPP Status: Unavailable
  3021. }
  3022. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3023. {
  3024. currentStatus = 8; //OCPP Status: Faulted
  3025. }
  3026. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3027. {
  3028. currentStatus = 6; //OCPP Status: Reserved
  3029. }
  3030. } //end of the same index
  3031. }//end of for CHAdeMO_QUANTITY
  3032. }
  3033. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3034. {
  3035. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3036. {
  3037. tempIndex = ((gun_index==2) ? 1: 0);
  3038. }
  3039. else
  3040. {
  3041. tempIndex = gun_index;
  3042. }
  3043. for (int index = 0; index < CCS_QUANTITY; index++)
  3044. {
  3045. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3046. {
  3047. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3048. {
  3049. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3050. {
  3051. currentStatus = 1; //OCPP Status: Preparing
  3052. }
  3053. else
  3054. {
  3055. currentStatus = 0; //OCPP Status: Available
  3056. }
  3057. }
  3058. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3059. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3060. ) //S_PRECHARGE
  3061. {
  3062. currentStatus = 1; //OCPP Status: Preparing
  3063. }
  3064. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3065. {
  3066. currentStatus = 2; //OCPP Status: Charging
  3067. }
  3068. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3069. {
  3070. currentStatus = 5; //OCPP Status: Finishing
  3071. }
  3072. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3073. {
  3074. currentStatus = 4; //OCPP Status: SuspendedEV
  3075. }
  3076. 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
  3077. {
  3078. currentStatus = 7; //OCPP Status : Unavailable
  3079. }
  3080. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3081. {
  3082. currentStatus = 8; //OCPP Status: Faulted
  3083. }
  3084. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3085. {
  3086. currentStatus = 6; //OCPP Status: Reserved
  3087. }
  3088. } //end of the same index
  3089. } // end of for CCS_QUANTITY
  3090. }
  3091. else if(gunType[gun_index] == 'G')
  3092. {
  3093. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3094. {
  3095. tempIndex = ((gun_index==2) ? 1: 0);
  3096. }
  3097. else
  3098. {
  3099. tempIndex = gun_index;
  3100. }
  3101. for (int index = 0; index < GB_QUANTITY; index++)
  3102. {
  3103. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3104. {
  3105. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3106. {
  3107. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3108. {
  3109. currentStatus = 1; //OCPP Status: Preparing
  3110. }
  3111. else
  3112. {
  3113. currentStatus = 0; //OCPP Status: Available
  3114. }
  3115. }
  3116. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3117. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3118. ) //S_PRECHARGE
  3119. {
  3120. currentStatus = 1; //OCPP Status: Preparing
  3121. }
  3122. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3123. {
  3124. currentStatus = 2; //OCPP Status: Charging
  3125. }
  3126. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3127. {
  3128. currentStatus = 5; //OCPP Status: Finishing
  3129. }
  3130. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3131. {
  3132. currentStatus = 4; //OCPP Status: SuspendedEV
  3133. }
  3134. 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
  3135. {
  3136. currentStatus = 7; //OCPP Status: Unavailable
  3137. }
  3138. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3139. {
  3140. currentStatus = 8; //OCPP Status: Faulted
  3141. }
  3142. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3143. {
  3144. currentStatus = 6; //OCPP Status: Reserved
  3145. }
  3146. } //end of the same index
  3147. } // end of for GB_QUANTITY
  3148. }
  3149. else
  3150. {
  3151. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3152. {
  3153. tempIndex = 2;
  3154. }
  3155. else
  3156. {
  3157. tempIndex = gun_index;
  3158. }
  3159. for (int index = 0; index < AC_QUANTITY; index++)
  3160. {
  3161. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3162. {
  3163. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3164. {
  3165. 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))
  3166. {
  3167. currentStatus = 1; //OCPP Status: Preparing
  3168. }
  3169. else
  3170. {
  3171. currentStatus = 0; //OCPP Status: Available
  3172. }
  3173. }
  3174. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3175. {
  3176. currentStatus = 1; //OCPP Status: Preparing
  3177. }
  3178. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3179. {
  3180. currentStatus = 2; //OCPP Status: Charging
  3181. }
  3182. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3183. {
  3184. currentStatus = 5; //OCPP Status: Finishing
  3185. }
  3186. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3187. {
  3188. currentStatus = 4; //OCPP Status: SuspendedEV
  3189. }
  3190. 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
  3191. {
  3192. currentStatus = 7; //OCPP Status: Unavailable
  3193. }
  3194. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3195. {
  3196. currentStatus = 8; //OCPP Status: Faulted
  3197. }
  3198. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3199. {
  3200. currentStatus = 6; //OCPP Status: Reserved
  3201. }
  3202. }//end of the same index
  3203. }//end of for AC_QUANTITY
  3204. }
  3205. //it's option
  3206. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3207. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3208. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3209. random_uuid(guid);
  3210. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3211. , MESSAGE_TYPE_CALL
  3212. , guid
  3213. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3214. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3215. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3216. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3217. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3218. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3219. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3220. if((server_sign == TRUE))
  3221. {
  3222. LWS_Send(message);
  3223. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3224. if(hashmap_operation(0, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, guid, mapItem, tempdata/*(void**)(&mapItem)*//*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  3225. {
  3226. //DEBUG_ERROR("statusNotification mapitem pass");
  3227. result = PASS;
  3228. }
  3229. }
  3230. else
  3231. {
  3232. result = PASS;
  3233. }
  3234. return result;
  3235. }
  3236. int sendStopTransactionRequest(int gun_index)
  3237. {
  3238. mtrace();
  3239. int result = FAIL;
  3240. //char message[1500]={0};
  3241. char guid[37]={0};
  3242. char tempdata[65]={0};
  3243. int tempIndex = 0;
  3244. char TempStopTransaction[256];
  3245. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3246. //int idx_sample=0;
  3247. DEBUG_ERROR("sendStopTransactionRequest \n");
  3248. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3249. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3250. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3251. if(gunType[gun_index] == 'J')
  3252. {
  3253. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3254. {
  3255. tempIndex = ((gun_index==2) ? 1: 0);
  3256. }
  3257. else
  3258. {
  3259. tempIndex = gun_index;
  3260. }
  3261. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3262. {
  3263. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3264. {
  3265. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3266. }
  3267. }// END OF CHAdeMO_QUANTITY
  3268. }
  3269. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3270. {
  3271. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3272. {
  3273. tempIndex = ((gun_index==2) ? 1: 0);
  3274. }
  3275. else
  3276. {
  3277. tempIndex = gun_index;
  3278. }
  3279. for (int index = 0; index < CCS_QUANTITY; index++)
  3280. {
  3281. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3282. {
  3283. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3284. }
  3285. }// END OF CCS_QUANTITY
  3286. }
  3287. else if(gunType[gun_index] == 'G')
  3288. {
  3289. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3290. {
  3291. tempIndex = ((gun_index==2) ? 1: 0);
  3292. }
  3293. else
  3294. {
  3295. tempIndex = gun_index;
  3296. }
  3297. for (int index = 0; index < GB_QUANTITY; index++)
  3298. {
  3299. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3300. {
  3301. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3302. }
  3303. }// END OF GB_QUANTITY
  3304. }
  3305. else
  3306. {
  3307. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3308. {
  3309. tempIndex = 2;
  3310. }
  3311. else
  3312. {
  3313. tempIndex = gun_index;
  3314. }
  3315. for (int index = 0; index < AC_QUANTITY; index++)
  3316. {
  3317. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3318. {
  3319. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3320. }
  3321. }// END OF AC_QUANTITY
  3322. }
  3323. //====================================== Stop Transaction Time =====================================================
  3324. struct timeval tmnow;
  3325. struct tm *tm;
  3326. char buf[28];//, usec_buf[6];
  3327. gettimeofday(&tmnow, NULL);
  3328. time_t t;
  3329. t = time(NULL);
  3330. /*UTC time and date*/
  3331. tm = gmtime(&t);
  3332. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3333. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3334. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3335. random_uuid(guid);
  3336. /***********************************transactionData******************************************************/
  3337. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3338. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3339. //=================================
  3340. // Transaction_Begin
  3341. //=================================
  3342. //============================================ Energy.Active.Import.Interval ================================
  3343. //idx_sample=0;
  3344. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  3345. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3346. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3347. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  3348. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3349. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3350. {
  3351. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3352. }
  3353. else
  3354. {
  3355. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3356. }
  3357. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3358. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3359. //=================================
  3360. // Transaction_End
  3361. //=================================
  3362. // ================================= Current.Import L1 ===============================================
  3363. //idx_sample=1;
  3364. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3365. if(gunType[gun_index] == 'J')
  3366. {
  3367. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3368. {
  3369. tempIndex = ((gun_index==2) ? 1: 0);
  3370. }
  3371. else
  3372. {
  3373. tempIndex = gun_index;
  3374. }
  3375. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3376. {
  3377. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3378. {
  3379. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3380. }
  3381. }// End of for CHAdeMO_QUANTITY
  3382. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3383. }
  3384. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3385. {
  3386. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3387. {
  3388. tempIndex = ((gun_index==2) ? 1: 0);
  3389. }
  3390. else
  3391. {
  3392. tempIndex = gun_index;
  3393. }
  3394. for (int index = 0; index < CCS_QUANTITY; index++)
  3395. {
  3396. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3397. {
  3398. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3399. }
  3400. }// End of for CCS_QUANTITY
  3401. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3402. }
  3403. else if(gunType[gun_index] == 'G')
  3404. {
  3405. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3406. {
  3407. tempIndex = ((gun_index==2) ? 1: 0);
  3408. }
  3409. else
  3410. {
  3411. tempIndex = gun_index;
  3412. }
  3413. for (int index = 0; index < GB_QUANTITY; index++)
  3414. {
  3415. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3416. {
  3417. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3418. }
  3419. }// End of for GB_QUANTITY
  3420. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3421. }
  3422. else
  3423. {
  3424. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3425. {
  3426. tempIndex = 2;
  3427. }
  3428. else
  3429. {
  3430. tempIndex = gun_index;
  3431. }
  3432. for (int index = 0; index < AC_QUANTITY; index++)
  3433. {
  3434. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3435. {
  3436. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3437. }
  3438. }// End of for AC_QUANTITY
  3439. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3440. }
  3441. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3442. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3443. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3444. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3445. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3446. // ================================= Energy.Active.Import.Interval ==============================================
  3447. //idx_sample=2;
  3448. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3449. if(gunType[gun_index] == 'J')
  3450. {
  3451. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3452. {
  3453. tempIndex = ((gun_index==2) ? 1: 0);
  3454. }
  3455. else
  3456. {
  3457. tempIndex = gun_index;
  3458. }
  3459. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3460. {
  3461. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3462. {
  3463. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3464. }
  3465. }// END OF CHAdeMO_QUANTITY
  3466. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3467. }
  3468. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3469. {
  3470. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3471. {
  3472. tempIndex = ((gun_index==2) ? 1: 0);
  3473. }
  3474. else
  3475. {
  3476. tempIndex = gun_index;
  3477. }
  3478. for (int index = 0; index < CCS_QUANTITY; index++)
  3479. {
  3480. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3481. {
  3482. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3483. }
  3484. }// END OF CCS_QUANTITY
  3485. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3486. }
  3487. else if(gunType[gun_index] == 'G')
  3488. {
  3489. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3490. {
  3491. tempIndex = ((gun_index==2) ? 1: 0);
  3492. }
  3493. else
  3494. {
  3495. tempIndex = gun_index;
  3496. }
  3497. for (int index = 0; index < GB_QUANTITY; index++)
  3498. {
  3499. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3500. {
  3501. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3502. }
  3503. }// END OF GB_QUANTITY
  3504. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3505. }
  3506. else
  3507. {
  3508. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3509. {
  3510. tempIndex = 2;
  3511. }
  3512. else
  3513. {
  3514. tempIndex = gun_index;
  3515. }
  3516. for (int index = 0; index < AC_QUANTITY; index++)
  3517. {
  3518. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3519. {
  3520. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3521. }
  3522. }// END OF AC_QUANTITY
  3523. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3524. }
  3525. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3526. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3527. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3528. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3529. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3530. //=================================== Power.Active.Import ==================================================
  3531. //idx_sample=3;
  3532. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3533. if(gunType[gun_index] == 'J')
  3534. {
  3535. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3536. {
  3537. tempIndex = ((gun_index==2) ? 1: 0);
  3538. }
  3539. else
  3540. {
  3541. tempIndex = gun_index;
  3542. }
  3543. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3544. {
  3545. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3546. {
  3547. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3548. }
  3549. } // End for CHAdeMO_QUANTITY
  3550. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3551. }
  3552. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3553. {
  3554. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3555. {
  3556. tempIndex = ((gun_index==2) ? 1: 0);
  3557. }
  3558. else
  3559. {
  3560. tempIndex = gun_index;
  3561. }
  3562. for (int index = 0; index < CCS_QUANTITY; index++)
  3563. {
  3564. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3565. {
  3566. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3567. }
  3568. } // END for CCS_QUANTITY
  3569. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3570. }
  3571. else if(gunType[gun_index] == 'G')
  3572. {
  3573. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3574. {
  3575. tempIndex = ((gun_index==2) ? 1: 0);
  3576. }
  3577. else
  3578. {
  3579. tempIndex = gun_index;
  3580. }
  3581. for (int index = 0; index < GB_QUANTITY; index++)
  3582. {
  3583. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3584. {
  3585. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3586. }
  3587. }// END for GB_QUANTITY
  3588. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3589. }
  3590. else
  3591. {
  3592. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3593. {
  3594. tempIndex = 2;
  3595. }
  3596. else
  3597. {
  3598. tempIndex = gun_index;
  3599. }
  3600. for (int index = 0; index < AC_QUANTITY; index++)
  3601. {
  3602. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3603. {
  3604. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3605. }
  3606. } // END for AC_QUANTITY
  3607. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3608. }
  3609. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3610. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3611. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3612. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3613. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3614. //============================ Voltage L1 ====================================
  3615. //idx_sample=4;
  3616. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3617. if(gunType[gun_index] == 'J')
  3618. {
  3619. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3620. {
  3621. tempIndex = ((gun_index==2) ? 1: 0);
  3622. }
  3623. else
  3624. {
  3625. tempIndex = gun_index;
  3626. }
  3627. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3628. {
  3629. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3630. {
  3631. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3632. }
  3633. } // END OF FOR CHAdeMO_QUANTITY
  3634. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3635. }
  3636. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3637. {
  3638. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3639. {
  3640. tempIndex = ((gun_index==2) ? 1: 0);
  3641. }
  3642. else
  3643. {
  3644. tempIndex = gun_index;
  3645. }
  3646. for (int index = 0; index < CCS_QUANTITY; index++)
  3647. {
  3648. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3649. {
  3650. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3651. }
  3652. } // END OF FOR CCS_QUANTITY
  3653. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3654. }
  3655. else if(gunType[gun_index] == 'G')
  3656. {
  3657. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3658. {
  3659. tempIndex = ((gun_index==2) ? 1: 0);
  3660. }
  3661. else
  3662. {
  3663. tempIndex = gun_index;
  3664. }
  3665. for (int index = 0; index < GB_QUANTITY; index++)
  3666. {
  3667. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3668. {
  3669. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3670. }
  3671. } // END OF FOR GB_QUANTITY
  3672. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3673. }
  3674. else
  3675. {
  3676. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3677. {
  3678. tempIndex = 2;
  3679. }
  3680. else
  3681. {
  3682. tempIndex = gun_index;
  3683. }
  3684. for (int index = 0; index < AC_QUANTITY; index++)
  3685. {
  3686. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3687. {
  3688. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  3689. }
  3690. } // END OF FOR AC_QUANTITY
  3691. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3692. }
  3693. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3694. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3695. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3696. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3697. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3698. //====================== SoC ================================
  3699. //idx_sample=5;
  3700. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3701. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3702. {
  3703. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3704. {
  3705. tempIndex = ((gun_index==2) ? 1: 0);
  3706. }
  3707. else
  3708. {
  3709. tempIndex = gun_index;
  3710. }
  3711. if(gunType[gun_index] == 'J')
  3712. {
  3713. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3714. {
  3715. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3716. {
  3717. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3718. }
  3719. }
  3720. }
  3721. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3722. {
  3723. for (int index = 0; index < CCS_QUANTITY; index++)
  3724. {
  3725. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3726. {
  3727. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3728. }
  3729. }
  3730. }
  3731. else if(gunType[gun_index] == 'G')
  3732. {
  3733. for (int index = 0; index < GB_QUANTITY; index++)
  3734. {
  3735. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3736. {
  3737. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  3738. }
  3739. }
  3740. }
  3741. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3742. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  3743. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  3744. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  3745. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  3746. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  3747. } // END FOR DC CASE
  3748. // ================================= Current.Import L2 ===============================================
  3749. //idx_sample=6;
  3750. // AC 3 phse L2 current
  3751. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3752. {
  3753. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3754. {
  3755. tempIndex = 2;
  3756. }
  3757. else
  3758. {
  3759. tempIndex = gun_index;
  3760. }
  3761. for (int index = 0; index < AC_QUANTITY; index++)
  3762. {
  3763. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3764. {
  3765. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  3766. }
  3767. }// End of for AC_QUANTITY
  3768. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  3769. }
  3770. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3771. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  3772. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  3773. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  3774. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3775. // ================================= Current.Import L3 ===============================================
  3776. //idx_sample=7;
  3777. // AC 3 phse L3 current
  3778. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3779. {
  3780. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3781. {
  3782. tempIndex = 2;
  3783. }
  3784. else
  3785. {
  3786. tempIndex = gun_index;
  3787. }
  3788. for (int index = 0; index < AC_QUANTITY; index++)
  3789. {
  3790. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3791. {
  3792. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  3793. }
  3794. }// End of for AC_QUANTITY
  3795. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  3796. }
  3797. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3798. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  3799. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  3800. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  3801. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3802. //============================ Voltage L2 ====================================
  3803. //idx_sample=8;
  3804. // AC 3 phse L2 voltage
  3805. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3806. {
  3807. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3808. {
  3809. tempIndex = 2;
  3810. }
  3811. else
  3812. {
  3813. tempIndex = gun_index;
  3814. }
  3815. for (int index = 0; index < AC_QUANTITY; index++)
  3816. {
  3817. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3818. {
  3819. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  3820. }
  3821. } // END OF FOR AC_QUANTITY
  3822. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  3823. }
  3824. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3825. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  3826. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  3827. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  3828. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3829. //============================ Voltage L3 ====================================
  3830. //idx_sample=8;
  3831. // AC 3 phse L3 voltage
  3832. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3833. {
  3834. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3835. {
  3836. tempIndex = 2;
  3837. }
  3838. else
  3839. {
  3840. tempIndex = gun_index;
  3841. }
  3842. for (int index = 0; index < AC_QUANTITY; index++)
  3843. {
  3844. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3845. {
  3846. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  3847. }
  3848. } // END OF FOR AC_QUANTITY
  3849. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  3850. }
  3851. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3852. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  3853. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  3854. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  3855. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3856. //================================================ Message create ====================================================
  3857. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  3858. {
  3859. sprintf(queuedata,"%d,[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  3860. ,gun_index+1
  3861. ,MESSAGE_TYPE_CALL
  3862. ,guid
  3863. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3864. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3865. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3866. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3867. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3868. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3869. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3870. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3871. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3872. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3873. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3874. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3875. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3877. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3885. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3886. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3887. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3889. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3890. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3891. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3892. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3893. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3894. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3895. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3896. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3897. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3898. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3899. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3900. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3901. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3902. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3903. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3904. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  3905. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  3906. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  3907. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  3908. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  3909. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  3910. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  3911. );
  3912. }
  3913. else
  3914. {
  3915. if((ShmSysConfigAndInfo->SysConfig.ModelName[2]!='Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2]!='W'))
  3916. {
  3917. sprintf(queuedata,"%d,[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  3918. ,gun_index+1
  3919. ,MESSAGE_TYPE_CALL
  3920. ,guid
  3921. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3922. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3923. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3924. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3925. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3926. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3927. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3928. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3929. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3930. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3931. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3932. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3933. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3934. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3935. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3936. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3937. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3938. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3939. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3940. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3941. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3942. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3943. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3944. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3945. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3946. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3947. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3948. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3949. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3950. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  3951. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  3952. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  3953. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  3954. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  3955. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  3956. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  3957. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  3958. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  3959. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  3960. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  3961. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  3962. );
  3963. }
  3964. else
  3965. {
  3966. sprintf(queuedata,"%d,[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  3967. ,gun_index+1
  3968. ,MESSAGE_TYPE_CALL
  3969. ,guid
  3970. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  3971. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  3972. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  3973. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  3974. ,ShmOCPP16Data->StopTransaction[gun_index].StopReason
  3975. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  3976. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  3977. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  3978. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  3979. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  3980. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  3981. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  3982. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  3983. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  3984. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  3985. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  3986. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  3987. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  3988. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  3989. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  3990. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  3991. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  3992. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  3993. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  3994. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  3995. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  3996. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  3997. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  3998. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  3999. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  4000. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  4001. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  4002. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  4003. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  4004. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  4005. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  4006. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  4007. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  4008. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  4009. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  4010. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  4011. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  4012. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  4013. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  4014. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  4015. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  4016. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  4017. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  4018. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  4019. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  4020. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  4021. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  4022. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  4023. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  4024. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  4025. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  4026. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  4027. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  4028. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  4029. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  4030. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  4031. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  4032. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  4033. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  4034. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  4035. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  4036. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  4037. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  4038. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  4039. );
  4040. }
  4041. }
  4042. #if 1 // for TempStopTransaction
  4043. //Delete TempStopTransaction
  4044. if((access(TempStopTransaction,F_OK))!=-1)
  4045. {
  4046. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4047. }
  4048. #endif
  4049. #if 1
  4050. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4051. if(hashmap_operation(0, guid, tempdata) == 1)
  4052. {
  4053. result = PASS;
  4054. DEBUG_INFO("StopTransaction mapitem pass\n");
  4055. }
  4056. #endif
  4057. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4058. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4059. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4060. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4061. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4062. {
  4063. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4064. }
  4065. //for test
  4066. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4067. return result;
  4068. }
  4069. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4070. {
  4071. mtrace();
  4072. int result = FAIL;
  4073. char guid[37]={0};
  4074. char tempdata[65]={0};
  4075. int tempIndex = 0;
  4076. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4077. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4078. //set value
  4079. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4080. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) ? ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId : 0);
  4081. random_uuid(guid);
  4082. //UTC Date time
  4083. struct timeval tmnow;
  4084. struct tm *tm;
  4085. char buf[28];//, usec_buf[6];
  4086. gettimeofday(&tmnow, NULL);
  4087. time_t t;
  4088. t = time(NULL);
  4089. /*UTC time and date*/
  4090. tm = gmtime(&t);
  4091. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4092. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4093. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4094. //idx_sample=0;
  4095. //********************************(1)Current.Import L1************************************************/
  4096. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4097. if(gunType[gun_index] == 'J')
  4098. {
  4099. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4100. {
  4101. tempIndex = ((gun_index==2) ? 1: 0);
  4102. }
  4103. else
  4104. {
  4105. tempIndex = gun_index;
  4106. }
  4107. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4108. {
  4109. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4110. {
  4111. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4112. }
  4113. }
  4114. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4115. }
  4116. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4117. {
  4118. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4119. {
  4120. tempIndex = ((gun_index==2) ? 1: 0);
  4121. }
  4122. else
  4123. {
  4124. tempIndex = gun_index;
  4125. }
  4126. for (int index = 0; index < CCS_QUANTITY; index++)
  4127. {
  4128. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4129. {
  4130. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4131. }
  4132. }
  4133. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4134. }
  4135. else if(gunType[gun_index] == 'G')
  4136. {
  4137. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4138. {
  4139. tempIndex = ((gun_index==2) ? 1: 0);
  4140. }
  4141. else
  4142. {
  4143. tempIndex = gun_index;
  4144. }
  4145. for (int index = 0; index < GB_QUANTITY; index++)
  4146. {
  4147. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4148. {
  4149. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4150. }
  4151. }
  4152. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4153. }
  4154. else
  4155. {
  4156. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4157. {
  4158. tempIndex = 2;
  4159. }
  4160. else
  4161. {
  4162. tempIndex = gun_index;
  4163. }
  4164. for (int index = 0; index < AC_QUANTITY; index++)
  4165. {
  4166. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4167. {
  4168. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4169. }
  4170. }
  4171. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4172. }
  4173. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4174. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4175. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4176. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4177. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4178. //idx_sample=1;
  4179. //********************************(2)Energy.Active.Import.Register ************************************************/
  4180. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4181. if(gunType[gun_index] == 'J')
  4182. {
  4183. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4184. {
  4185. tempIndex = ((gun_index==2) ? 1: 0);
  4186. }
  4187. else
  4188. {
  4189. tempIndex = gun_index;
  4190. }
  4191. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4192. {
  4193. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4194. {
  4195. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4196. }
  4197. }
  4198. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4199. }
  4200. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4201. {
  4202. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4203. {
  4204. tempIndex = ((gun_index==2) ? 1: 0);
  4205. }
  4206. else
  4207. {
  4208. tempIndex = gun_index;
  4209. }
  4210. for (int index = 0; index < CCS_QUANTITY; index++)
  4211. {
  4212. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4213. {
  4214. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4215. }
  4216. }
  4217. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4218. }
  4219. else if(gunType[gun_index] == 'G')
  4220. {
  4221. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4222. {
  4223. tempIndex = ((gun_index==2) ? 1: 0);
  4224. }
  4225. else
  4226. {
  4227. tempIndex = gun_index;
  4228. }
  4229. for (int index = 0; index < GB_QUANTITY; index++)
  4230. {
  4231. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4232. {
  4233. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4234. }
  4235. }
  4236. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4237. }
  4238. else
  4239. {
  4240. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4241. {
  4242. tempIndex = 2;
  4243. }
  4244. else
  4245. {
  4246. tempIndex = gun_index;
  4247. }
  4248. for (int index = 0; index < AC_QUANTITY; index++)
  4249. {
  4250. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4251. {
  4252. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4253. }
  4254. }
  4255. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4256. }
  4257. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4258. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4259. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4260. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4261. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4262. //idx_sample=2;
  4263. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4264. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4265. if(gunType[gun_index] == 'J')
  4266. {
  4267. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4268. {
  4269. tempIndex = ((gun_index==2) ? 1: 0);
  4270. }
  4271. else
  4272. {
  4273. tempIndex = gun_index;
  4274. }
  4275. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4276. {
  4277. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4278. {
  4279. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4280. }
  4281. } // END OF FOR CHAdeMO_QUANTITY
  4282. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4283. }
  4284. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4285. {
  4286. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4287. {
  4288. tempIndex = ((gun_index==2) ? 1: 0);
  4289. }
  4290. else
  4291. {
  4292. tempIndex = gun_index;
  4293. }
  4294. for (int index = 0; index < CCS_QUANTITY; index++)
  4295. {
  4296. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4297. {
  4298. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4299. }
  4300. } // END OF CCS_QUANTITY
  4301. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4302. }
  4303. else if(gunType[gun_index] == 'G')
  4304. {
  4305. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4306. {
  4307. tempIndex = ((gun_index==2) ? 1: 0);
  4308. }
  4309. else
  4310. {
  4311. tempIndex = gun_index;
  4312. }
  4313. for (int index = 0; index < GB_QUANTITY; index++)
  4314. {
  4315. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4316. {
  4317. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4318. }
  4319. } // END OF GB_QUANTITY
  4320. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4321. }
  4322. else
  4323. {
  4324. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4325. {
  4326. tempIndex = 2;
  4327. }
  4328. else
  4329. {
  4330. tempIndex = gun_index;
  4331. }
  4332. for (int index = 0; index < AC_QUANTITY; index++)
  4333. {
  4334. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4335. {
  4336. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4337. }
  4338. }
  4339. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4340. }
  4341. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  4342. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4343. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4344. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4345. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4346. //idx_sample=3;
  4347. //********************************(4)Power.Active.Import************************************************/
  4348. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4349. if(gunType[gun_index] == 'J')
  4350. {
  4351. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4352. {
  4353. tempIndex = ((gun_index==2) ? 1: 0);
  4354. }
  4355. else
  4356. {
  4357. tempIndex = gun_index;
  4358. }
  4359. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4360. {
  4361. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4362. {
  4363. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4364. }
  4365. } // END OF FOR
  4366. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4367. }
  4368. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4369. {
  4370. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4371. {
  4372. tempIndex = ((gun_index==2) ? 1: 0);
  4373. }
  4374. else
  4375. {
  4376. tempIndex = gun_index;
  4377. }
  4378. for (int index = 0; index < CCS_QUANTITY; index++)
  4379. {
  4380. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4381. {
  4382. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4383. }
  4384. }
  4385. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4386. }
  4387. else if(gunType[gun_index] == 'G')
  4388. {
  4389. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4390. {
  4391. tempIndex = ((gun_index==2) ? 1: 0);
  4392. }
  4393. else
  4394. {
  4395. tempIndex = gun_index;
  4396. }
  4397. for (int index = 0; index < GB_QUANTITY; index++)
  4398. {
  4399. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4400. {
  4401. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4402. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4403. }
  4404. }
  4405. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4406. }
  4407. else
  4408. {
  4409. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4410. {
  4411. tempIndex = 2;
  4412. }
  4413. else
  4414. {
  4415. tempIndex = gun_index;
  4416. }
  4417. for (int index = 0; index < AC_QUANTITY; index++)
  4418. {
  4419. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4420. {
  4421. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4422. }
  4423. }
  4424. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4425. }
  4426. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  4427. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4428. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4429. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4430. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4431. //idx_sample=4;
  4432. //***********************************************(5)VOLTAGE L1******************************************************/
  4433. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4434. if(gunType[gun_index] == 'J')
  4435. {
  4436. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4437. {
  4438. tempIndex = ((gun_index==2) ? 1: 0);
  4439. }
  4440. else
  4441. {
  4442. tempIndex = gun_index;
  4443. }
  4444. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4445. {
  4446. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4447. {
  4448. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4449. }
  4450. }
  4451. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4452. }
  4453. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4454. {
  4455. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4456. {
  4457. tempIndex = ((gun_index==2) ? 1: 0);
  4458. }
  4459. else
  4460. {
  4461. tempIndex = gun_index;
  4462. }
  4463. for (int index = 0; index < CCS_QUANTITY; index++)
  4464. {
  4465. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4466. {
  4467. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4468. }
  4469. }
  4470. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4471. }
  4472. else if(gunType[gun_index] == 'G')
  4473. {
  4474. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4475. {
  4476. tempIndex = ((gun_index==2) ? 1: 0);
  4477. }
  4478. else
  4479. {
  4480. tempIndex = gun_index;
  4481. }
  4482. for (int index = 0; index < GB_QUANTITY; index++)
  4483. {
  4484. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4485. {
  4486. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4487. }
  4488. }
  4489. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4490. }
  4491. else
  4492. {
  4493. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4494. {
  4495. tempIndex = 2;
  4496. }
  4497. else
  4498. {
  4499. tempIndex = gun_index;
  4500. }
  4501. for (int index = 0; index < AC_QUANTITY; index++)
  4502. {
  4503. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4504. {
  4505. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4506. }
  4507. }
  4508. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4509. }
  4510. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  4511. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4512. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4513. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4514. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4515. //***********************************************(6)SOC******************************************************/
  4516. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4517. {
  4518. //idx_sample=5;
  4519. //sampledValue = NULL;
  4520. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4521. {
  4522. tempIndex = ((gun_index==2) ? 1: 0);
  4523. }
  4524. else
  4525. {
  4526. tempIndex = gun_index;
  4527. }
  4528. if(gunType[gun_index] == 'J')
  4529. {
  4530. //tempIndex = ((gun_index==2) ? 1: 0);
  4531. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4532. {
  4533. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4534. {
  4535. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4536. }
  4537. }
  4538. }
  4539. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4540. {
  4541. //tempIndex = ((gun_index==2) ? 1: 0);
  4542. for (int index = 0; index < CCS_QUANTITY; index++)
  4543. {
  4544. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4545. {
  4546. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4547. }
  4548. }
  4549. }
  4550. else if(gunType[gun_index] == 'G')
  4551. {
  4552. //tempIndex = ((gun_index==2) ? 1: 0);
  4553. for (int index = 0; index < GB_QUANTITY; index++)
  4554. {
  4555. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4556. {
  4557. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4558. }
  4559. }
  4560. }
  4561. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[ReadingContext_Sample_Periodic]);
  4562. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4563. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4564. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4565. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_Outlet]);
  4566. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4567. }
  4568. //********************************(7)Current.Import L2************************************************/
  4569. // Only for AC 3 phase
  4570. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4571. {
  4572. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4573. {
  4574. tempIndex = 2;
  4575. }
  4576. else
  4577. {
  4578. tempIndex = gun_index;
  4579. }
  4580. for (int index = 0; index < AC_QUANTITY; index++)
  4581. {
  4582. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4583. {
  4584. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  4585. }
  4586. }
  4587. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  4588. }
  4589. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  4590. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  4591. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  4592. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  4593. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4594. //********************************(8)Current.Import L3************************************************/
  4595. // Only for AC 3 phase
  4596. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4597. {
  4598. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4599. {
  4600. tempIndex = 2;
  4601. }
  4602. else
  4603. {
  4604. tempIndex = gun_index;
  4605. }
  4606. for (int index = 0; index < AC_QUANTITY; index++)
  4607. {
  4608. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4609. {
  4610. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  4611. }
  4612. }
  4613. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  4614. }
  4615. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  4616. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  4617. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  4618. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  4619. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4620. //***********************************************(9)VOLTAGE L2******************************************************/
  4621. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4622. {
  4623. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4624. {
  4625. tempIndex = 2;
  4626. }
  4627. else
  4628. {
  4629. tempIndex = gun_index;
  4630. }
  4631. for (int index = 0; index < AC_QUANTITY; index++)
  4632. {
  4633. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4634. {
  4635. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  4636. }
  4637. }
  4638. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  4639. }
  4640. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  4641. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  4642. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  4643. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  4644. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4645. //***********************************************(10)VOLTAGE L3******************************************************/
  4646. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4647. {
  4648. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4649. {
  4650. tempIndex = 2;
  4651. }
  4652. else
  4653. {
  4654. tempIndex = gun_index;
  4655. }
  4656. for (int index = 0; index < AC_QUANTITY; index++)
  4657. {
  4658. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4659. {
  4660. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  4661. }
  4662. }
  4663. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  4664. }
  4665. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  4666. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  4667. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  4668. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  4669. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4670. // Message create ====================================================================================================
  4671. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  4672. {
  4673. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  4674. ,gun_index + 1
  4675. ,MESSAGE_TYPE_CALL
  4676. ,guid
  4677. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4678. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4679. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4680. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4681. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4682. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4683. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4684. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4685. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4686. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4687. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4688. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4689. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4690. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4691. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4692. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4693. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4694. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4695. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4696. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4697. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4698. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4699. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4700. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4701. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4702. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4703. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4704. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4705. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4706. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4707. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4708. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4709. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4710. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4711. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4712. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4713. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4714. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4715. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value
  4716. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context
  4717. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format
  4718. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand
  4719. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase
  4720. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location
  4721. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit
  4722. );
  4723. }
  4724. else
  4725. {
  4726. if((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W'))
  4727. {
  4728. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  4729. ,gun_index + 1
  4730. ,MESSAGE_TYPE_CALL
  4731. ,guid
  4732. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4733. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4734. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4735. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4736. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4737. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4738. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4739. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4740. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4741. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4742. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4743. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4744. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4745. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4746. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4747. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4748. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4749. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4750. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4751. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4752. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4753. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4754. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4755. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4756. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4757. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4758. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4759. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4760. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4761. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4762. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4763. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4764. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4765. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4766. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4767. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4768. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4769. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4770. );
  4771. }
  4772. else
  4773. {
  4774. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",{\"connectorId\":%d,\"transactionId\":%d,\"meterValue\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  4775. ,gun_index + 1
  4776. ,MESSAGE_TYPE_CALL
  4777. ,guid
  4778. ,ShmOCPP16Data->MeterValues[gun_index].ConnectorId
  4779. ,ShmOCPP16Data->MeterValues[gun_index].TransactionId
  4780. ,(const char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp
  4781. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value
  4782. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context
  4783. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format
  4784. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand
  4785. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase
  4786. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location
  4787. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit
  4788. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value
  4789. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context
  4790. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format
  4791. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand
  4792. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase
  4793. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location
  4794. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit
  4795. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value
  4796. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context
  4797. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format
  4798. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand
  4799. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase
  4800. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location
  4801. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit
  4802. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value
  4803. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context
  4804. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format
  4805. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand
  4806. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase
  4807. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location
  4808. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit
  4809. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value
  4810. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context
  4811. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format
  4812. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand
  4813. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase
  4814. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location
  4815. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit
  4816. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value
  4817. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context
  4818. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format
  4819. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand
  4820. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase
  4821. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location
  4822. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit
  4823. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value
  4824. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context
  4825. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format
  4826. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand
  4827. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase
  4828. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location
  4829. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit
  4830. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value
  4831. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context
  4832. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format
  4833. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand
  4834. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase
  4835. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location
  4836. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit
  4837. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value
  4838. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context
  4839. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format
  4840. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand
  4841. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase
  4842. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location
  4843. ,ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit
  4844. );
  4845. }
  4846. }
  4847. // Put request guid to hash map
  4848. sprintf(tempdata, "MeterValues,%d", (gun_index));
  4849. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)//if(hashmap_operation(0,NULL/*hashMap*/, mapItem[0].key_string, mapItem[0].key_value/*mapItem*/, (void**)(&mapItem)/*(void**)(&mapItem)*/) == MAP_OK/*hashmap_put(hashMap, mapItem->key_string, mapItem) == MAP_OK*/)
  4850. {
  4851. result = PASS;
  4852. DEBUG_INFO("MeterValues mapitem pass\n");
  4853. }
  4854. if(dataType != ReadingContext_Trigger)
  4855. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4856. else
  4857. LWS_Send(queuedata +2);
  4858. return result;
  4859. }
  4860. //==========================================
  4861. // send confirm routine
  4862. //==========================================
  4863. int sendCancelReservationConfirmation(char *uuid,char *payload)
  4864. {
  4865. mtrace();
  4866. int result = FAIL;
  4867. char message[100]={0};
  4868. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  4869. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4870. LWS_Send(message);
  4871. result = TRUE;
  4872. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  4873. return result;
  4874. }
  4875. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  4876. {
  4877. mtrace();
  4878. int result = FAIL;
  4879. char message[100]={0};
  4880. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  4881. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4882. LWS_Send(message);
  4883. result = TRUE;
  4884. return result;
  4885. }
  4886. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  4887. {
  4888. mtrace();
  4889. int result = FAIL;
  4890. char message[100]={0};
  4891. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  4892. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4893. LWS_Send(message);
  4894. result = TRUE;
  4895. return result;
  4896. }
  4897. int sendClearCacheConfirmation(char *uuid,char *payload)
  4898. {
  4899. mtrace();
  4900. int result = FAIL;
  4901. char message[500]={0};
  4902. DEBUG_INFO("sendClearCacheConfirmation...\n");
  4903. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4904. LWS_Send(message);
  4905. return result;
  4906. }
  4907. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  4908. {
  4909. mtrace();
  4910. int result = FAIL;
  4911. char message[500]={0};
  4912. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  4913. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  4914. LWS_Send(message);
  4915. return result;
  4916. }
  4917. int sendDataTransferConfirmation(char *uuid,char *payload)
  4918. {
  4919. mtrace();
  4920. char statusStr[20]={0};
  4921. char dataStr[10]={0};
  4922. char sstr[20]={0};
  4923. int c = 0;
  4924. char *loc;
  4925. int result = FAIL;
  4926. DEBUG_INFO("sendDataTransferConfirmation...\n");
  4927. /**********************status**************************/
  4928. loc = strstr(payload, "status");
  4929. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4930. c = 0;
  4931. while (loc[3+strlen("status")+c] != '\"')
  4932. {
  4933. sstr[c] = loc[3+strlen("status")+c];
  4934. c++;
  4935. }
  4936. sstr[c] = '\0';
  4937. strcpy(statusStr, sstr);
  4938. /**********************data**************************/
  4939. loc = strstr(payload, "data");
  4940. memset(sstr ,0, ARRAY_SIZE(sstr) );
  4941. c = 0;
  4942. while (loc[3+strlen("data")+c] != '\"')
  4943. {
  4944. sstr[c] = loc[3+strlen("data")+c];
  4945. c++;
  4946. }
  4947. sstr[c] = '\0';
  4948. strcpy(dataStr, sstr);
  4949. return result;
  4950. }
  4951. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  4952. {
  4953. mtrace();
  4954. int result = FAIL;
  4955. char message[1000]={0};
  4956. int CompositeScheduleIndex = 0;
  4957. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  4958. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  4959. if(nPeriod == 0)
  4960. {
  4961. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  4962. {
  4963. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  4964. ,MESSAGE_TYPE_CALLRESULT
  4965. ,uuid
  4966. ,payload
  4967. ,connectorIdInt);
  4968. }
  4969. else
  4970. {
  4971. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  4972. ,MESSAGE_TYPE_CALLRESULT
  4973. ,uuid
  4974. ,payload
  4975. ,connectorIdInt
  4976. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4977. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4978. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4979. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  4980. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  4981. }
  4982. }
  4983. else
  4984. {
  4985. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  4986. ,MESSAGE_TYPE_CALLRESULT
  4987. ,uuid
  4988. ,payload
  4989. ,connectorIdInt
  4990. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4991. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  4992. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  4993. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  4994. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  4995. {
  4996. if (idx_sample == 0)
  4997. {
  4998. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  4999. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5000. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5001. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5002. }
  5003. else
  5004. {
  5005. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5006. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5007. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5008. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5009. }
  5010. }
  5011. sprintf(message + strlen(message), "]}}]");
  5012. }
  5013. LWS_Send(message);
  5014. result = TRUE;
  5015. return result;
  5016. }
  5017. int sendGetConfigurationConfirmation(char *uuid)
  5018. {
  5019. mtrace();
  5020. int result = FAIL;
  5021. int MaxKeySupported = 0;
  5022. int sentConfigurationNumber= 0;
  5023. int sentunConfigurationNumber= 0;
  5024. char message[4000]={0};
  5025. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5026. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5027. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5028. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5029. ,MESSAGE_TYPE_CALLRESULT
  5030. ,uuid );
  5031. //configuration key
  5032. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5033. {
  5034. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5035. {
  5036. if (sentConfigurationNumber == 0)
  5037. {
  5038. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5039. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5040. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5041. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5042. }
  5043. else
  5044. {
  5045. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5046. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5047. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5048. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5049. }
  5050. sentConfigurationNumber = sentConfigurationNumber + 1;
  5051. }
  5052. }
  5053. sprintf(message + strlen(message), "]");
  5054. if(UnknownKeynum != 0)
  5055. {
  5056. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5057. //unkown key
  5058. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5059. {
  5060. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5061. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5062. if(sentunConfigurationNumber == 0)
  5063. {
  5064. sprintf(message + strlen(message), "\"%s\""
  5065. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5066. }
  5067. else
  5068. {
  5069. sprintf(message + strlen(message), ",\"%s\""
  5070. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5071. }
  5072. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5073. }
  5074. sprintf(message + strlen(message), "]");
  5075. }
  5076. sprintf(message + strlen(message), "}]");
  5077. LWS_Send(message);
  5078. return result;
  5079. }
  5080. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5081. {
  5082. mtrace();
  5083. int result = FAIL;
  5084. char message[400]={0};
  5085. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5086. if(strcmp(payload,"")==0)
  5087. {
  5088. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5089. }
  5090. else
  5091. {
  5092. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5093. }
  5094. LWS_Send(message);
  5095. result = TRUE;
  5096. return result;
  5097. }
  5098. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5099. {
  5100. mtrace();
  5101. int result = FAIL;
  5102. char message[80]={0};
  5103. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5104. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5105. LWS_Send(message);
  5106. result = TRUE;
  5107. return result;
  5108. }
  5109. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5110. {
  5111. mtrace();
  5112. int result = FAIL;
  5113. char message[80]={0};
  5114. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5115. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5116. LWS_Send(message);
  5117. result = TRUE;
  5118. return result;
  5119. }
  5120. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5121. {
  5122. mtrace();
  5123. int result = FAIL;
  5124. char message[80]={0};
  5125. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5126. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5127. LWS_Send(message);
  5128. result = TRUE;
  5129. return result;
  5130. }
  5131. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5132. {
  5133. mtrace();
  5134. int result = FAIL;
  5135. char message[80]={0};
  5136. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5137. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5138. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5139. LWS_Send(message);
  5140. result = TRUE;
  5141. return result;
  5142. }
  5143. int sendResetConfirmation(char *uuid,char *payload)
  5144. {
  5145. mtrace();
  5146. int result = FAIL;
  5147. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5148. char message[80]={0};
  5149. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5150. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5151. LWS_Send(message);
  5152. result = TRUE;
  5153. return result;
  5154. }
  5155. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5156. {
  5157. mtrace();
  5158. int result = FAIL;
  5159. char message[500]={0};
  5160. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5161. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5162. LWS_Send(message);
  5163. result = TRUE;
  5164. return result;
  5165. }
  5166. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5167. {
  5168. mtrace();
  5169. int result = FAIL;
  5170. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5171. char message[80]={0};
  5172. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5173. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5174. LWS_Send(message);
  5175. result = TRUE;
  5176. return result;
  5177. }
  5178. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5179. {
  5180. mtrace();
  5181. int result = FAIL;
  5182. char message[80]={0};
  5183. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5184. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5185. LWS_Send(message);
  5186. result = TRUE;
  5187. return result;
  5188. }
  5189. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5190. {
  5191. mtrace();
  5192. int result = FAIL;
  5193. char message[80]={0};
  5194. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5195. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5196. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5197. LWS_Send(message);
  5198. result = TRUE;
  5199. return result;
  5200. }
  5201. int sendUpdateFirmwareConfirmation(char *uuid)
  5202. {
  5203. mtrace();
  5204. int result = FAIL;
  5205. char message[60]={0};
  5206. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5207. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5208. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5209. LWS_Send(message);
  5210. result = TRUE;
  5211. return result;
  5212. }
  5213. //==========================================
  5214. // send CallError routine
  5215. //==========================================
  5216. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5217. {
  5218. mtrace();
  5219. char message[220]={0};
  5220. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5221. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5222. LWS_Send(message);
  5223. }
  5224. //==========================================
  5225. // Handle server request routine Start
  5226. //==========================================
  5227. int handleCancelReservationRequest(char *uuid, char *payload)
  5228. {
  5229. mtrace();
  5230. int result = FAIL;
  5231. int gunNO = 0;
  5232. int reservationIdInt = -1;
  5233. char comfirmstr[20];
  5234. DEBUG_INFO("handleCancelReservationRequest...\n");
  5235. json_object *CancelReservation;
  5236. CancelReservation = json_tokener_parse(payload);
  5237. if(!is_error(CancelReservation))
  5238. {
  5239. // Required data
  5240. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  5241. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5242. }
  5243. json_object_put(CancelReservation);
  5244. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  5245. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5246. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5247. if(reservationIdInt != -1)
  5248. {
  5249. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5250. //check Transaction active
  5251. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5252. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5253. {
  5254. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5255. {
  5256. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5257. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5258. if(gunType[2] == 'J')
  5259. {
  5260. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5261. }
  5262. else
  5263. {
  5264. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5265. }
  5266. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5267. goto end;
  5268. }
  5269. }
  5270. for (int index = 0; index < CCS_QUANTITY; index++)
  5271. {
  5272. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5273. {
  5274. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5275. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5276. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  5277. {
  5278. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5279. }
  5280. else
  5281. {
  5282. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5283. }
  5284. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5285. goto end;
  5286. }
  5287. }
  5288. for (int index = 0; index < GB_QUANTITY; index++)
  5289. {
  5290. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5291. {
  5292. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5293. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5294. if(gunType[2] == 'G')
  5295. {
  5296. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5297. }
  5298. else
  5299. {
  5300. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5301. }
  5302. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5303. goto end;
  5304. }
  5305. }
  5306. for (int index = 0; index < AC_QUANTITY; index++)
  5307. {
  5308. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5309. {
  5310. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5311. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5312. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5313. {
  5314. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5315. }
  5316. else
  5317. {
  5318. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5319. }
  5320. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5321. goto end;
  5322. }
  5323. }
  5324. }
  5325. //The reservationId does NOT match the reservationId
  5326. sendCancelReservationConfirmation(uuid, comfirmstr);
  5327. end:
  5328. // Fill in ocpp packet uuid
  5329. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5330. return result;
  5331. }
  5332. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5333. {
  5334. mtrace();
  5335. int result = FAIL;
  5336. int gunIndex = 0;
  5337. char typeStr[16]={0};
  5338. char comfirmstr[20];
  5339. int specificId = FALSE;
  5340. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5341. json_object *ChangeAvailability;
  5342. ChangeAvailability = json_tokener_parse(payload);
  5343. if(!is_error(ChangeAvailability))
  5344. {
  5345. // Required data
  5346. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  5347. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5348. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  5349. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5350. }
  5351. json_object_put(ChangeAvailability);
  5352. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5353. {
  5354. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5355. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5356. }
  5357. else if(gunIndex == 0)
  5358. {
  5359. for(int i=0; i < gunTotalNumber; i++)
  5360. {
  5361. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5362. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5363. }
  5364. }
  5365. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5366. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5367. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  5368. {
  5369. specificId = TRUE;
  5370. }
  5371. if(specificId == FALSE)
  5372. goto end;
  5373. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5374. {
  5375. //----------------------gunIndex is 0 ------------------------------------------------//
  5376. if(gunIndex == 0)
  5377. {
  5378. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5379. {
  5380. for(int i=0; i < gunTotalNumber; i++)
  5381. {
  5382. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5383. {
  5384. if ((gunType[i] == 'J')&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5385. {
  5386. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5387. {
  5388. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5389. goto end;
  5390. }
  5391. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5392. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5393. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5394. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5395. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5396. {
  5397. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5398. goto end;
  5399. }
  5400. }
  5401. }//END FOR CHAdeMO_QUANTITY
  5402. for (int index = 0; index < CCS_QUANTITY; index++)
  5403. {
  5404. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5405. {
  5406. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5407. {
  5408. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5409. goto end;
  5410. }
  5411. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5412. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5413. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5414. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5415. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5416. {
  5417. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5418. goto end;
  5419. }
  5420. }
  5421. }//END FOR CCS_QUANTITY
  5422. for (int index = 0; index < GB_QUANTITY; index++)
  5423. {
  5424. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5425. {
  5426. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5427. {
  5428. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5429. goto end;
  5430. }
  5431. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5432. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5433. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5434. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5435. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5436. {
  5437. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5438. goto end;
  5439. }
  5440. }
  5441. }// END FOR GB_QUANTITY
  5442. for (int index = 0; index < AC_QUANTITY; index++)
  5443. {
  5444. if (((gunType[i] > '0')&&(gunType[i] <= '9'))&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5445. {
  5446. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5447. {
  5448. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5449. goto end;
  5450. }
  5451. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5452. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5453. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5454. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5455. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5456. {
  5457. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5458. goto end;
  5459. }
  5460. }
  5461. }//END FOR AC_QUANTITY
  5462. }// END FOR gunTotalNumber
  5463. }
  5464. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5465. {
  5466. for(int i=0; i < gunTotalNumber; i++)
  5467. {
  5468. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5469. {
  5470. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5471. goto end;
  5472. }
  5473. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5474. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5475. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5476. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5477. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5478. {
  5479. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5480. goto end;
  5481. }
  5482. }
  5483. }
  5484. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5485. goto end;
  5486. }
  5487. //----------------------gunIndex is not 0 ------------------------------------------------//
  5488. //check Transaction active
  5489. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5490. {
  5491. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J'))
  5492. {
  5493. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5494. {
  5495. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5496. goto end;
  5497. }
  5498. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5499. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5500. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5501. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5502. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5503. {
  5504. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5505. goto end;
  5506. }
  5507. else
  5508. {
  5509. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5510. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5511. goto end;
  5512. }
  5513. }
  5514. }//END FOR CHAdeMO_QUANTITY
  5515. for (int index = 0; index < CCS_QUANTITY; index++)
  5516. {
  5517. if ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E')))
  5518. {
  5519. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5520. {
  5521. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5522. goto end;
  5523. }
  5524. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5525. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5526. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5527. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5528. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5529. {
  5530. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5531. goto end;
  5532. }
  5533. else
  5534. {
  5535. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5536. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5537. goto end;
  5538. }
  5539. }
  5540. }//END FOR CCS_QUANTITY
  5541. for (int index = 0; index < GB_QUANTITY; index++)
  5542. {
  5543. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))
  5544. {
  5545. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5546. {
  5547. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5548. goto end;
  5549. }
  5550. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5551. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5552. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5553. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5554. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5555. {
  5556. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5557. goto end;
  5558. }
  5559. else
  5560. {
  5561. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5562. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5563. goto end;
  5564. }
  5565. }
  5566. }// END FOR GB_QUANTITY
  5567. for (int index = 0; index < AC_QUANTITY; index++)
  5568. {
  5569. if ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))
  5570. {
  5571. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5572. {
  5573. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5574. goto end;
  5575. }
  5576. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5577. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5578. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5579. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5580. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5581. {
  5582. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5583. goto end;
  5584. }
  5585. else
  5586. {
  5587. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5588. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5589. goto end;
  5590. }
  5591. }
  5592. }//END FOR AC_QUANTITY
  5593. }//END FOR AvailabilityTypeStr[Inoperative]
  5594. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5595. {
  5596. //----------------------gunIndex is 0 ------------------------------------------------//
  5597. if(gunIndex == 0)
  5598. {
  5599. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5600. {
  5601. for(int i=0; i < gunTotalNumber; i++)
  5602. {
  5603. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5604. {
  5605. if ((gunType[i] == 'J' )&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J')) ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5606. {
  5607. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5608. goto end;
  5609. }
  5610. }//END FOR CHAdeMO_QUANTITY
  5611. for (int index = 0; index < CCS_QUANTITY; index++)
  5612. {
  5613. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(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
  5614. {
  5615. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5616. goto end;
  5617. }
  5618. }//END FOR CCS_QUANTITY
  5619. for (int index = 0; index < GB_QUANTITY; index++)
  5620. {
  5621. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5622. {
  5623. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5624. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5625. goto end;
  5626. }
  5627. }// END FOR GB_QUANTITY
  5628. for (int index = 0; index < AC_QUANTITY; index++)
  5629. {
  5630. if (((gunType[i] > '0')&&(gunType[i] <= '9')) &&(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
  5631. {
  5632. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5633. goto end;
  5634. }
  5635. }//END FOR CHAdeMO_QUANTITY
  5636. }// END FOR gunTotalNumber
  5637. }
  5638. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5639. {
  5640. for(int i=0; i < gunTotalNumber; i++)
  5641. {
  5642. for (int index = 0; index < AC_QUANTITY; index++)
  5643. {
  5644. if (((gunType[i] > '0')&&(gunType[i] <= '9')) &&(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
  5645. {
  5646. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5647. goto end;
  5648. }
  5649. }//END FOR CHAdeMO_QUANTITY
  5650. } // END FOR gunTotalNumber
  5651. }
  5652. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5653. goto end;
  5654. }
  5655. //----------------------gunIndex is not 0 ------------------------------------------------//
  5656. //check Transaction active
  5657. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5658. {
  5659. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'J') ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5660. {
  5661. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5662. goto end;
  5663. }
  5664. }//END FOR CHAdeMO_QUANTITY
  5665. for (int index = 0; index < CCS_QUANTITY; index++)
  5666. {
  5667. if ((((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5668. {
  5669. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5670. goto end;
  5671. }
  5672. }//END FOR CCS_QUANTITY
  5673. for (int index = 0; index < GB_QUANTITY; index++)
  5674. {
  5675. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5676. {
  5677. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5678. goto end;
  5679. }
  5680. }// END FOR GB_QUANTITY
  5681. for (int index = 0; index < AC_QUANTITY; index++)
  5682. {
  5683. if (((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5684. {
  5685. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5686. goto end;
  5687. }
  5688. }//END FOR AC_QUANTITY
  5689. }//END FOR AvailabilityTypeStr[Operative]
  5690. end:
  5691. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5692. {
  5693. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5694. }
  5695. else
  5696. {
  5697. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5698. }
  5699. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5700. {
  5701. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5702. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5703. }
  5704. else if(gunIndex == 0)
  5705. {
  5706. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5707. {
  5708. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5709. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5710. }
  5711. }
  5712. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5713. return result;
  5714. }
  5715. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5716. {
  5717. mtrace();
  5718. int result = FAIL;
  5719. char keystr[40]={0};
  5720. char valuestr[100]={0};
  5721. char comfirmstr[20]={0};
  5722. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5723. json_object *ChangeConfiguration;
  5724. ChangeConfiguration = json_tokener_parse(payload);
  5725. if(!is_error(ChangeConfiguration))
  5726. {
  5727. // Required data
  5728. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  5729. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5730. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  5731. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5732. }
  5733. json_object_put(ChangeConfiguration);
  5734. if((uuid==NULL) || (payload ==NULL) )
  5735. {
  5736. DEBUG_ERROR("Payload is null\n");
  5737. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5738. }
  5739. else
  5740. {
  5741. int status = setKeyValue(keystr, valuestr);
  5742. switch(status)
  5743. {
  5744. case ConfigurationStatus_Accepted:
  5745. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5746. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5747. StoreConfigurationTable();
  5748. break;
  5749. case RebootRequired:
  5750. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5751. StoreConfigurationTable();
  5752. break;
  5753. case NotSupported:
  5754. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5755. break;
  5756. case ConfigurationStatus_Rejected:
  5757. default:
  5758. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5759. break;
  5760. }
  5761. }
  5762. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5763. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5764. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5765. {
  5766. ChageWebSocketPingInterval(atoi(valuestr));
  5767. }
  5768. if((strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5769. {
  5770. ShmSysConfigAndInfo->SysInfo.InternetConn = 0;
  5771. }
  5772. return result;
  5773. }
  5774. int handleClearCacheRequest(char *uuid, char *payload)
  5775. {
  5776. mtrace();
  5777. int result = FAIL;
  5778. char comfirmstr[20];
  5779. int fd;
  5780. char rmFileCmd[100]={0};
  5781. struct stat stats;
  5782. DEBUG_INFO("handleClearCacheRequest...\n");
  5783. stat("/Storage/OCPP", &stats);
  5784. // Check for directory existence
  5785. if (S_ISDIR(stats.st_mode) == 1)
  5786. {}
  5787. else
  5788. {
  5789. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  5790. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  5791. system(rmFileCmd);
  5792. }
  5793. memset(rmFileCmd, 0, ARRAY_SIZE(rmFileCmd));
  5794. if((access(AuthorizationCache_JSON,F_OK))!=-1)
  5795. {
  5796. DEBUG_INFO("AuthorizationCache file exist.\n");
  5797. }
  5798. else
  5799. {
  5800. DEBUG_INFO("AuthorizationCache file not exist\n");
  5801. FILE *log = fopen(AuthorizationCache_JSON, "w+");
  5802. if(log == NULL)
  5803. {
  5804. DEBUG_INFO("AuthorizationCache file is NULL\n");
  5805. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5806. goto end;
  5807. }
  5808. else
  5809. {
  5810. fclose(log);
  5811. }
  5812. }
  5813. if((fd = open(AuthorizationCache_JSON,O_RDWR)) < 0)
  5814. {
  5815. DEBUG_INFO("open AuthorizationCache file failed\n");
  5816. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5817. }
  5818. else
  5819. {
  5820. DEBUG_INFO("open AuthorizationCache file successful\n");
  5821. ftruncate(fd,0);
  5822. lseek(fd,0,SEEK_SET);
  5823. close(fd);
  5824. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  5825. }
  5826. end:
  5827. sendClearCacheConfirmation(uuid, comfirmstr);
  5828. return result;
  5829. }
  5830. int handleClearChargingProfileRequest(char *uuid, char *payload)
  5831. {
  5832. mtrace();
  5833. int result = FAIL;
  5834. int resultRename;
  5835. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  5836. char chargingProfilePurposeStr[26]={0};
  5837. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  5838. char tempchargingProfilePurposeStr[26]={0};
  5839. char sstr[160]={0};
  5840. char str[100]={0};
  5841. int c = 0;
  5842. char *loc;
  5843. char fname[200]={0};
  5844. char comfirmstr[20]={0};
  5845. char word[1600]={0};
  5846. int clearflag = FALSE;
  5847. int chargingProfileIdIsNULL = FALSE;
  5848. int connectorIsNULL = FALSE;
  5849. int chargingProfilePurposeIsNULL = FALSE;
  5850. int stackLevelIsNULL = FALSE;
  5851. //int GotoEnd = FALSE;
  5852. FILE *fptr1, *fptr2;
  5853. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  5854. int n_chargingProfile=0;
  5855. int isEmptyFile = FALSE;
  5856. char sLineWord[1600]={0};
  5857. char chargingProfiles[10][100]={0};
  5858. int ChargeProfileCount = 0;
  5859. int ch;
  5860. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  5861. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  5862. json_object *ClearChargingProfile;
  5863. ClearChargingProfile = json_tokener_parse(payload);
  5864. if(!is_error(ClearChargingProfile))
  5865. {
  5866. // Optional data
  5867. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  5868. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  5869. else
  5870. chargingProfileIdIsNULL = TRUE;
  5871. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  5872. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  5873. else
  5874. connectorIsNULL = TRUE;
  5875. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  5876. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  5877. else
  5878. chargingProfilePurposeIsNULL = TRUE;
  5879. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  5880. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  5881. else
  5882. stackLevelIsNULL = TRUE;
  5883. }
  5884. json_object_put(ClearChargingProfile);
  5885. if(connectorIsNULL == FALSE)
  5886. {
  5887. switch(connectorIdInt)
  5888. {
  5889. case 0:
  5890. if(chargingProfilePurposeIsNULL == TRUE)
  5891. {
  5892. int l = 0;
  5893. strcpy(fname, ChargePointMaxProfile_JSON);
  5894. if((access(fname,F_OK))!=-1)
  5895. {
  5896. strcpy(chargingProfiles[l], fname);
  5897. l = l + 1;
  5898. }
  5899. strcpy(fname, TxDefaultProfile_0_JSON);
  5900. if((access(fname,F_OK))!=-1)
  5901. {
  5902. strcpy(chargingProfiles[l], fname);
  5903. l = l + 1;
  5904. }
  5905. ChargeProfileCount = l;
  5906. }
  5907. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  5908. {
  5909. strcpy(fname, ChargePointMaxProfile_JSON);
  5910. if((access(fname,F_OK))!=-1)
  5911. {
  5912. strcpy(chargingProfiles[0], fname);
  5913. ChargeProfileCount = 1;
  5914. }
  5915. }
  5916. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5917. {
  5918. strcpy(fname, TxDefaultProfile_0_JSON);
  5919. if((access(fname,F_OK))!=-1)
  5920. {
  5921. strcpy(chargingProfiles[0], fname);
  5922. ChargeProfileCount = 1;
  5923. }
  5924. }
  5925. break;
  5926. default:
  5927. if(chargingProfilePurposeIsNULL == TRUE)
  5928. {
  5929. int m = 0;
  5930. memset(fname, 0, ARRAY_SIZE(fname));
  5931. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5932. if((access(fname,F_OK))!=-1)
  5933. {
  5934. strcpy(chargingProfiles[m], fname);
  5935. m = m + 1;
  5936. }
  5937. memset(fname, 0, ARRAY_SIZE(fname));
  5938. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5939. if((access(fname,F_OK))!=-1)
  5940. {
  5941. strcpy(chargingProfiles[m], fname);
  5942. m = m + 1;
  5943. }
  5944. ChargeProfileCount = m;
  5945. }
  5946. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5947. {
  5948. //strcpy(fname, TxDefaultProfile_1_JSON);
  5949. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5950. if((access(fname,F_OK))!=-1)
  5951. {
  5952. strcpy(chargingProfiles[0], fname);
  5953. ChargeProfileCount = 1;
  5954. }
  5955. }
  5956. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  5957. {
  5958. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5959. if((access(fname,F_OK))!=-1)
  5960. {
  5961. strcpy(chargingProfiles[0], fname);
  5962. ChargeProfileCount = 1;
  5963. }
  5964. //strcpy(fname, TxProfile_1_JSON);
  5965. }
  5966. //strcpy(fname, ChargePointMaxProfile_JSON );
  5967. break;
  5968. }
  5969. }
  5970. else // Check all Charging Profiles
  5971. {
  5972. int i = 0;
  5973. char fnametemp[200]={0};
  5974. ChargeProfileCount = 0;
  5975. //Check ChargePointMaxProfile.json exit
  5976. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  5977. {
  5978. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  5979. i = i + 1;
  5980. }
  5981. //Check TxDefaultProfile_0.json exit
  5982. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  5983. {
  5984. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  5985. i = i + 1;
  5986. }
  5987. //Check TxDefaultProfile_%d.json
  5988. for(int j=1; j <= gunTotalNumber; j++)
  5989. {
  5990. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5991. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  5992. if((access(fnametemp,F_OK))!=-1)
  5993. {
  5994. strcpy(chargingProfiles[i], fnametemp);
  5995. i = i + 1;
  5996. }
  5997. }
  5998. //Check TxProfile_%d.json
  5999. for(int j=1; j <= gunTotalNumber; j++)
  6000. {
  6001. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6002. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  6003. if((access(fnametemp,F_OK))!=-1)
  6004. {
  6005. strcpy(chargingProfiles[i], fnametemp);
  6006. i = i + 1;
  6007. }
  6008. }
  6009. ChargeProfileCount = i;
  6010. }// End connectorIsNULL is TRUE
  6011. if(ChargeProfileCount == 0)
  6012. {
  6013. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6014. goto end;
  6015. }
  6016. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6017. {
  6018. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6019. goto end;
  6020. }
  6021. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6022. {
  6023. memset(str, 0, ARRAY_SIZE(str));
  6024. // clear temp file
  6025. sprintf(str,"rm -f %s",temp);
  6026. system(str);
  6027. for(int k=0; k < ChargeProfileCount; k++)
  6028. {
  6029. memset(str, 0, ARRAY_SIZE(str));
  6030. //clear file in C
  6031. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6032. system(str);
  6033. }
  6034. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6035. goto end;
  6036. }
  6037. else if(connectorIsNULL == TRUE)
  6038. {
  6039. for(int k=0; k < ChargeProfileCount; k++)
  6040. {
  6041. fptr1 = fopen(chargingProfiles[k], "r");
  6042. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6043. //Check Charging Profile Count
  6044. while(fscanf(fptr1, "%s", word) != EOF)
  6045. {
  6046. //DEBUG_INFO("word=%s\n",word);
  6047. if(strstr(word, "chargingProfileId")!= NULL)
  6048. {
  6049. //DEBUG_INFO("test chargingProfileId \n");
  6050. n_chargingProfile = n_chargingProfile + 1;
  6051. //DEBUG_INFO("chargingProfileId Found\n");
  6052. }
  6053. }
  6054. rewind(fptr1);
  6055. //search Charging Profile Element
  6056. //int i= 0;
  6057. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6058. {
  6059. //------------------------tempconnectorIdInt------------------------//
  6060. loc = strstr(sLineWord, "connectorId");
  6061. c = 0;
  6062. memset(sstr ,0, sizeof(sstr) );
  6063. while (loc[strlen("connectorId")+2+c] != ',')
  6064. {
  6065. sstr[c] = loc[strlen("connectorId")+2+c];
  6066. c++;
  6067. }
  6068. sstr[c] = '\0';
  6069. tempconnectorIdInt = atoi(sstr);
  6070. printf("file's gun number is %d\n", tempconnectorIdInt);
  6071. //--------------------------chargingProfileId--------------------//
  6072. c = 0;
  6073. loc = strstr(sLineWord, "chargingProfileId");
  6074. memset(sstr ,0, ARRAY_SIZE(sstr));
  6075. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6076. {
  6077. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6078. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6079. c++;
  6080. }
  6081. sstr[c] = '\0';
  6082. tempchargingProfileIdInt = atoi(sstr);
  6083. //stackLevel
  6084. c = 0;
  6085. loc = strstr(sLineWord, "stackLevel");
  6086. memset(sstr ,0, ARRAY_SIZE(sstr));
  6087. while (loc[strlen("stackLevel")+2+c] != ',')
  6088. {
  6089. sstr[c] = loc[strlen("stackLevel")+2+c];
  6090. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6091. c++;
  6092. }
  6093. sstr[c] = '\0';
  6094. tempstackLevelInt = atoi(sstr);
  6095. c = 0;
  6096. loc = strstr(sLineWord, "chargingProfilePurpose");
  6097. memset(sstr ,0, ARRAY_SIZE(sstr));
  6098. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6099. {
  6100. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6101. c++;
  6102. }
  6103. sstr[c] = '\0';
  6104. strcpy(tempchargingProfilePurposeStr, sstr);
  6105. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6106. {
  6107. //------- not write to fptr2-------//
  6108. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6109. //clearflag = TRUE;
  6110. }
  6111. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6112. {
  6113. //------- not write to fptr2-------//
  6114. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6115. }
  6116. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6117. {
  6118. //------- not write to fptr2-------//
  6119. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6120. }
  6121. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  6122. {
  6123. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6124. }
  6125. else
  6126. {
  6127. fprintf(fptr2, sLineWord);//writing data into file
  6128. }
  6129. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6130. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6131. if(clearflag == TRUE)
  6132. {
  6133. fclose(fptr1);
  6134. fclose(fptr2);
  6135. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6136. system(str);
  6137. // clear temp file
  6138. sprintf(str,"rm -f %s",temp);
  6139. system(str);
  6140. }
  6141. else
  6142. {
  6143. fclose(fptr1);
  6144. fclose(fptr2);
  6145. memset(str, 0, ARRAY_SIZE(str));
  6146. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6147. system(str);
  6148. resultRename = rename(temp, chargingProfiles[k]);
  6149. if(resultRename == 0)
  6150. {
  6151. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  6152. }
  6153. else
  6154. {
  6155. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  6156. }
  6157. if(comfirmstr[0]== 0)
  6158. {
  6159. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6160. }
  6161. //Check chargingProfile is empty file
  6162. /*------ Read the file ----------------*/
  6163. fptr1=fopen(chargingProfiles[k],"r");
  6164. ch=fgetc(fptr1);
  6165. rewind(fptr1);
  6166. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6167. if(ch!=EOF)
  6168. {
  6169. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6170. {
  6171. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6172. if(sLineWord[0]=='\0')
  6173. {
  6174. isEmptyFile = TRUE;
  6175. break;
  6176. }
  6177. else
  6178. {
  6179. isEmptyFile = FALSE;
  6180. break;
  6181. }
  6182. }
  6183. }
  6184. else
  6185. isEmptyFile = TRUE;
  6186. fclose(fptr1);
  6187. if(isEmptyFile == TRUE)
  6188. {
  6189. memset(str, 0, ARRAY_SIZE(str));
  6190. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6191. system(str);
  6192. }
  6193. }
  6194. }// End of while(int k=0; k < ChargePointCount; k++)
  6195. }
  6196. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6197. {
  6198. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6199. for(int k=0; k < ChargeProfileCount; k++)
  6200. {
  6201. fptr1 = fopen(chargingProfiles[k], "r");
  6202. fptr2 = fopen(temp, "w+");
  6203. //Check Charging Profile Count
  6204. while(fscanf(fptr1, "%s", word) != EOF)
  6205. {
  6206. //DEBUG_INFO("word=%s\n",word);
  6207. if(strstr(word, "chargingProfileId")!= NULL)
  6208. {
  6209. n_chargingProfile = n_chargingProfile + 1;
  6210. }
  6211. }
  6212. rewind(fptr1);
  6213. //search Charging Profile Element
  6214. //int i= 0;
  6215. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6216. {
  6217. //*************************tempconnectorIdInt*********************************/
  6218. loc = strstr(sLineWord, "connectorId");
  6219. c = 0;
  6220. memset(sstr ,0, ARRAY_SIZE(sstr));
  6221. while (loc[strlen("connectorId")+2+c] != ',')
  6222. {
  6223. sstr[c] = loc[strlen("connectorId")+2+c];
  6224. c++;
  6225. }
  6226. sstr[c] = '\0';
  6227. tempconnectorIdInt = atoi(sstr);
  6228. //chargingProfileId
  6229. c = 0;
  6230. loc = strstr(sLineWord, "chargingProfileId");
  6231. memset(sstr ,0, ARRAY_SIZE(sstr));
  6232. while (loc[strlen("chargingProfileId")+2+c] != ',')
  6233. {
  6234. sstr[c] = loc[strlen("chargingProfileId")+2+c];
  6235. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6236. c++;
  6237. }
  6238. sstr[c] = '\0';
  6239. tempchargingProfileIdInt = atoi(sstr);
  6240. //stackLevel
  6241. c = 0;
  6242. loc = strstr(sLineWord, "stackLevel");
  6243. memset(sstr ,0, ARRAY_SIZE(sstr));
  6244. while (loc[strlen("stackLevel")+2+c] != ',')
  6245. {
  6246. sstr[c] = loc[strlen("stackLevel")+2+c];
  6247. //printf("i=%d sstr=%c\n",c, sstr[c]);
  6248. c++;
  6249. }
  6250. sstr[c] = '\0';
  6251. tempstackLevelInt = atoi(sstr);
  6252. c = 0;
  6253. loc = strstr(sLineWord, "chargingProfilePurpose");
  6254. memset(sstr ,0, ARRAY_SIZE(sstr));
  6255. while (loc[3+strlen("chargingProfilePurpose")+c] != '\"')
  6256. {
  6257. sstr[c] = loc[3+strlen("chargingProfilePurpose")+c];
  6258. c++;
  6259. }
  6260. sstr[c] = '\0';
  6261. strcpy(tempchargingProfilePurposeStr, sstr);
  6262. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6263. {
  6264. //------- not write to fptr2-------//
  6265. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6266. //clearflag = TRUE;
  6267. }
  6268. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6269. {
  6270. //------- not write to fptr2-------//
  6271. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6272. }
  6273. else if(stackLevelIsNULL == TRUE)
  6274. {
  6275. //Clear Whole File
  6276. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6277. clearflag = TRUE;
  6278. break;
  6279. }
  6280. else
  6281. {
  6282. fprintf(fptr2, sLineWord);//writing data into file
  6283. }
  6284. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6285. }
  6286. if(clearflag == TRUE)
  6287. {
  6288. fclose(fptr1);
  6289. fclose(fptr2);
  6290. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6291. system(str);
  6292. // clear temp file
  6293. sprintf(str,"rm -f %s",temp);
  6294. system(str);
  6295. }
  6296. else
  6297. {
  6298. fclose(fptr1);
  6299. fclose(fptr2);
  6300. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6301. system(str);
  6302. resultRename = rename(temp, chargingProfiles[k]);
  6303. if(resultRename == 0)
  6304. {
  6305. DEBUG_INFO("File ChargingProfile renamed successfully");
  6306. }
  6307. else
  6308. {
  6309. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6310. }
  6311. if(comfirmstr[0]== 0)
  6312. {
  6313. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6314. }
  6315. //Check chargingProfile is empty file
  6316. /*------ Read the file ----------------*/
  6317. fptr1=fopen(chargingProfiles[k],"r");
  6318. ch=fgetc(fptr1);
  6319. rewind(fptr1);
  6320. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6321. if(ch!=EOF)
  6322. {
  6323. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6324. {
  6325. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6326. if(sLineWord[0]=='\0')
  6327. {
  6328. isEmptyFile = TRUE;
  6329. break;
  6330. }
  6331. else
  6332. {
  6333. isEmptyFile = FALSE;
  6334. break;
  6335. }
  6336. }
  6337. }
  6338. else
  6339. isEmptyFile = TRUE;
  6340. fclose(fptr1);
  6341. if(isEmptyFile == TRUE)
  6342. {
  6343. memset(str, 0, ARRAY_SIZE(str));
  6344. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6345. system(str);
  6346. }
  6347. /*------- End of reading ---------------*/
  6348. }
  6349. } // while(int k=0; k < ChargeProfileCount; k++)
  6350. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6351. end:
  6352. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6353. return result;
  6354. }
  6355. void createFirmwareVersionByDataTransfer(void)
  6356. {
  6357. json_object *FirmwareDataTransfer = json_object_new_object();
  6358. // AC & DC model
  6359. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6360. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6361. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6362. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6363. // DC model
  6364. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6365. {
  6366. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6367. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6368. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6369. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6370. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6371. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6372. }
  6373. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6374. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  6375. {
  6376. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6377. }
  6378. // 4G model
  6379. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  6380. {
  6381. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6382. }
  6383. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6384. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6385. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string(FirmwareDataTransfer));
  6386. }
  6387. int handleDataTransferRequest(char *uuid, char *payload)
  6388. {
  6389. mtrace();
  6390. json_object *response = json_object_new_object();
  6391. int result = FAIL;
  6392. char tempvendorId[255]={0};
  6393. char tempmessageId[50]={0};
  6394. char tempdata[512]={0};
  6395. char message[2048]={0};
  6396. DEBUG_INFO("handleDataTransferRequest...\n");
  6397. if((uuid != NULL) && (payload != NULL))
  6398. {
  6399. json_object *DataTransfer;
  6400. DataTransfer = json_tokener_parse(payload);
  6401. if(!is_error(DataTransfer))
  6402. {
  6403. // Required data
  6404. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  6405. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6406. // Optional data
  6407. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6408. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6409. if(json_object_object_get(DataTransfer, "data") != NULL)
  6410. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6411. result = PASS;
  6412. }
  6413. json_object_put(DataTransfer);
  6414. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6415. {
  6416. // Send all moudle firmware version on EVSE
  6417. system("/usr/bin/run_tmate_restart.sh");
  6418. createFirmwareVersionByDataTransfer();
  6419. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6420. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6421. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6422. }
  6423. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6424. {
  6425. json_object *data;
  6426. data = json_tokener_parse(tempdata);
  6427. if(!is_error(data))
  6428. {
  6429. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6430. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6431. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6432. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6433. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6434. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6435. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6436. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6437. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6438. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6439. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6440. }
  6441. else
  6442. {
  6443. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6444. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6445. }
  6446. json_object_put(data);
  6447. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6448. }
  6449. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  6450. {
  6451. json_object *data;
  6452. data = json_tokener_parse(tempdata);
  6453. if(!is_error(data))
  6454. {
  6455. if(json_object_object_get(data, "idToken") != NULL)
  6456. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  6457. if(json_object_object_get(data, "price") != NULL)
  6458. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  6459. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6460. }
  6461. else
  6462. {
  6463. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6464. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6465. }
  6466. json_object_put(data);
  6467. }
  6468. else if(strstr(tempmessageId, "RunningCost") != NULL)
  6469. {
  6470. json_object *data;
  6471. data = json_tokener_parse(tempdata);
  6472. if(!is_error(data))
  6473. {
  6474. if(json_object_object_get(data, "txId") != NULL)
  6475. if(json_object_object_get(data, "description") != NULL)
  6476. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6477. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6478. }
  6479. else
  6480. {
  6481. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6482. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6483. }
  6484. json_object_put(data);
  6485. }
  6486. else if(strstr(tempmessageId, "FinalCost") != NULL)
  6487. {
  6488. json_object *data;
  6489. data = json_tokener_parse(tempdata);
  6490. if(!is_error(data))
  6491. {
  6492. if(json_object_object_get(data, "txId") != NULL)
  6493. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  6494. if(json_object_object_get(data, "description") != NULL)
  6495. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6496. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6497. }
  6498. else
  6499. {
  6500. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6501. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6502. }
  6503. json_object_put(data);
  6504. }
  6505. else
  6506. {
  6507. // Can not find valid message id
  6508. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6509. }
  6510. }
  6511. else
  6512. {
  6513. // Payload is null
  6514. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6515. }
  6516. LWS_Send(message);
  6517. return result;
  6518. }
  6519. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6520. {
  6521. mtrace();
  6522. int result = FAIL;
  6523. int connectorIdInt, durationInt;
  6524. char chargingRateUnitStr[4]={0};
  6525. char comfirmstr[20];
  6526. int confirmPeriods = 0;
  6527. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6528. json_object *GetCompositeSchedule;
  6529. GetCompositeSchedule = json_tokener_parse(payload);
  6530. if(!is_error(GetCompositeSchedule))
  6531. {
  6532. // Required data
  6533. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  6534. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6535. else
  6536. connectorIdInt = -1;
  6537. if(json_object_object_get(GetCompositeSchedule, "duration"))
  6538. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6539. else
  6540. durationInt = 86400;
  6541. // Optional data
  6542. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6543. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6544. }
  6545. json_object_put(GetCompositeSchedule);
  6546. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6547. if((connectorIdInt == 0) ||
  6548. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6549. {
  6550. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6551. struct StructChargingProfile tmpProfile[1];
  6552. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6553. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6554. {
  6555. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6556. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6557. }
  6558. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6559. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6560. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6561. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6562. {
  6563. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6564. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6565. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6566. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6567. {
  6568. confirmPeriods = idx;
  6569. break;
  6570. }
  6571. }
  6572. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6573. }
  6574. else
  6575. {
  6576. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6577. }
  6578. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6579. return result;
  6580. }
  6581. int handleGetConfigurationRequest(char *uuid, char *payload)
  6582. {
  6583. mtrace();
  6584. int result = FAIL;
  6585. int MaxKeySupported = 0;
  6586. int n_keys = 0;
  6587. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  6588. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6589. json_object *GetConfiguration;
  6590. GetConfiguration = json_tokener_parse(payload);
  6591. if(!is_error(GetConfiguration))
  6592. {
  6593. // Optional data
  6594. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6595. {
  6596. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6597. {
  6598. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6599. n_keys = idx + 1;
  6600. }
  6601. }
  6602. }
  6603. json_object_put(GetConfiguration);
  6604. UnknownKeynum = 0;
  6605. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6606. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6607. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6608. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6609. if(n_keys != 0)
  6610. {
  6611. for(int i=0;i<n_keys;i++)
  6612. {
  6613. getKeyValue(requestKey[i]);
  6614. }
  6615. }
  6616. else
  6617. {
  6618. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6619. getKeyValue("");
  6620. }
  6621. processUnkownKey();
  6622. sendGetConfigurationConfirmation(uuid);
  6623. return result;
  6624. }
  6625. static char fnamePlusPath[100]={0};
  6626. static char fnamePWithNoPath[60]={0};
  6627. void checkUploadLog(void)
  6628. {
  6629. FILE *fp;
  6630. /* Open the command for reading. */
  6631. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6632. if (fp == NULL) {
  6633. printf("Failed to run command\n" );
  6634. exit(1);
  6635. }
  6636. int ftppathlen = 0;
  6637. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6638. int i = 0;
  6639. /* Read the output a line at a time - output it. */
  6640. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6641. if(i==0)
  6642. {
  6643. ftppathlen = strlen(fnamePlusPath);
  6644. printf("%s\n", fnamePlusPath);
  6645. fnamePlusPath[ftppathlen]='\0';
  6646. break;
  6647. }
  6648. i= i+1;
  6649. }
  6650. /* close */
  6651. pclose(fp);
  6652. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6653. {
  6654. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6655. {
  6656. fnamePlusPath[k]='\0';
  6657. }
  6658. }
  6659. i=1;
  6660. //char fname[60]={0};
  6661. while(i < ftppathlen)
  6662. {
  6663. int len=ftppathlen-i;
  6664. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6665. {
  6666. printf("compare '/' all right\n");
  6667. break;
  6668. }
  6669. i=i+1;
  6670. }
  6671. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6672. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6673. fnamePWithNoPath[i+1] = '\0';
  6674. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6675. {
  6676. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6677. {
  6678. fnamePWithNoPath[j]='\0';
  6679. }
  6680. }
  6681. FILE* fp1 = fopen(fnamePlusPath, "r");
  6682. if (fp1)
  6683. {
  6684. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6685. // file exists
  6686. fclose(fp1);
  6687. }
  6688. else
  6689. {
  6690. // file doesn't exist
  6691. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6692. }
  6693. }
  6694. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6695. {
  6696. mtrace();
  6697. int result = FAIL;
  6698. char cmdBuf[512];
  6699. char fName[258];
  6700. time_t CurrentTime;
  6701. struct tm *tm;
  6702. system("/usr/bin/run_tmate_restart.sh");
  6703. pthread_t th_Status;
  6704. CurrentTime = time(NULL);
  6705. tm = localtime(&CurrentTime);
  6706. 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);
  6707. sendGetDiagnosticsConfirmation(uuid, fName);
  6708. system("exec /root/logPackTools 'log' 6");
  6709. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", fName);
  6710. system(cmdBuf);
  6711. checkUploadLog();
  6712. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6713. return result;
  6714. }
  6715. void* GetDiagnosticsProcess(void* data)
  6716. {
  6717. pthread_detach(pthread_self());
  6718. mtrace();
  6719. int retriesInt=0, retryIntervalInt=0;
  6720. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6721. char protocol[10]={0}, user[50]={0},password[50]={0},host[50]={0}, path[50]={0}, ftppath[60]={0},host1[50]={0},path1[50]={0};
  6722. int port=0;
  6723. int isSuccess = FALSE;
  6724. char ftpbuf[200]={0};
  6725. json_object *GetDiagnostics;
  6726. DEBUG_INFO("GetDiagnosticsProcess...\n");
  6727. GetDiagnostics = json_tokener_parse(data);
  6728. if(!is_error(GetDiagnostics))
  6729. {
  6730. // Required data
  6731. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  6732. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  6733. // Optional data
  6734. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  6735. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  6736. else
  6737. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6738. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  6739. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  6740. else
  6741. retryIntervalInt = 30;
  6742. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  6743. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  6744. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  6745. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  6746. }
  6747. json_object_put(GetDiagnostics);
  6748. //****************location*******************/
  6749. if(strcmp(locationstr,"")==0)
  6750. {
  6751. DEBUG_INFO("location is <Empty>!\n");
  6752. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6753. goto end;
  6754. }
  6755. memset(protocol, 0, ARRAY_SIZE(protocol));
  6756. memset(user, 0, ARRAY_SIZE(user) );
  6757. memset(password, 0, ARRAY_SIZE(password));
  6758. memset(host, 0, ARRAY_SIZE(host));
  6759. memset(path, 0, ARRAY_SIZE(path));
  6760. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  6761. memset(host1, 0, ARRAY_SIZE(host1));
  6762. memset(path1, 0, ARRAY_SIZE(path1));
  6763. /*location: ftp://user:password@host:port/path*/
  6764. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6765. if((access(fnamePlusPath,F_OK))!=-1)
  6766. {
  6767. DEBUG_INFO("fnamePlusPath exist.\n");
  6768. }
  6769. else
  6770. {
  6771. DEBUG_INFO("fnamePlusPath not exist!\n");
  6772. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6773. goto end;
  6774. }
  6775. if(strchr(locationstr,'@')==NULL)
  6776. {
  6777. sscanf(locationstr,
  6778. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6779. protocol, host, &port, path);
  6780. strcpy(user,"anonymous");
  6781. strcpy(password,"");
  6782. }
  6783. else
  6784. {
  6785. //DEBUG_INFO("pch=%s\n", pch);
  6786. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6787. protocol, user, password, host, &port, path);
  6788. }
  6789. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6790. {
  6791. DEBUG_INFO("protocol is not ftp/http ! \n");
  6792. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6793. goto end;
  6794. }
  6795. if(strncmp(locationstr,"http", 4) == 0)
  6796. {
  6797. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6798. sprintf(ftppath,"/%s", path);
  6799. do
  6800. {
  6801. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6802. sleep(3);
  6803. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6804. if(!isSuccess)
  6805. {
  6806. DEBUG_INFO("Diagnostics fail.\n");
  6807. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6808. sleep(retryIntervalInt);
  6809. }
  6810. else
  6811. {
  6812. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6813. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6814. }
  6815. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6816. }
  6817. else
  6818. {
  6819. sscanf(host,"%[^/]%s",host1, path1);
  6820. sprintf(ftppath,"%s", path1);
  6821. int ftppathlen=strlen(ftppath);
  6822. int i=1;
  6823. char filenametemp[50];
  6824. while(i < ftppathlen)
  6825. {
  6826. int len=ftppathlen-i;
  6827. if(ftppath[len]== 47) // '/' ascll code: 47
  6828. {
  6829. DEBUG_INFO("find '/' all right\n");
  6830. break;
  6831. }
  6832. i=i+1;
  6833. }
  6834. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  6835. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6836. filenametemp[i+1] = 0;
  6837. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  6838. if(port == 0)
  6839. port = 21;
  6840. do
  6841. {
  6842. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6843. sleep(3);
  6844. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6845. if(!isSuccess)
  6846. {
  6847. DEBUG_INFO("Diagnostics fail.\n");
  6848. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6849. sleep(retryIntervalInt);
  6850. }
  6851. else
  6852. {
  6853. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6854. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6855. }
  6856. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6857. }
  6858. end:
  6859. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  6860. pthread_exit(NULL);
  6861. }
  6862. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6863. {
  6864. mtrace();
  6865. int result = FAIL;
  6866. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6867. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6868. {
  6869. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6870. localversion = -1;
  6871. }
  6872. else
  6873. {
  6874. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6875. OCPP_getListVerion();
  6876. }
  6877. //from db.OCPP_getListVerion
  6878. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6879. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6880. sendGetLocalListVersionConfirmation(uuid,"");
  6881. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6882. return result;
  6883. }
  6884. int handleRemoteStartRequest(char *uuid, char *payload)
  6885. {
  6886. mtrace();
  6887. int result = FAIL;
  6888. int connectorIdInt=0;
  6889. int tempIndex = 0;
  6890. int connectorIdIsNULL, chargingProfileIsNULL;
  6891. char comfirmstr[20]={0};
  6892. char cmdBuf[512];
  6893. json_object *RemoteStartTransaction;
  6894. FILE *fp;
  6895. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6896. if(server_pending == TRUE)
  6897. {
  6898. return 0;
  6899. }
  6900. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  6901. RemoteStartTransaction = json_tokener_parse(payload);
  6902. if(!is_error(RemoteStartTransaction))
  6903. {
  6904. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  6905. {
  6906. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  6907. if(connectorIdInt <= gunTotalNumber)
  6908. {
  6909. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  6910. // Required data
  6911. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  6912. // Optional data
  6913. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  6914. {
  6915. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  6916. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  6917. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  6918. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  6919. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  6920. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  6921. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  6922. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  6923. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  6924. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  6925. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  6926. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  6927. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  6928. {
  6929. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit , "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingRateUnit")));
  6930. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  6931. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration"));
  6932. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  6933. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate"));
  6934. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  6935. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule, "%s", json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule")));
  6936. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  6937. {
  6938. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  6939. {
  6940. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.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(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  6941. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = json_object_get_double(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  6942. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  6943. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 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(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  6944. }
  6945. }
  6946. }
  6947. }
  6948. else
  6949. chargingProfileIsNULL = TRUE;
  6950. }
  6951. }
  6952. else
  6953. connectorIdIsNULL = TRUE;
  6954. }
  6955. else
  6956. connectorIdIsNULL = TRUE;
  6957. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6958. {
  6959. DEBUG_WARN("Connector id is NULL\n.");
  6960. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6961. goto end;
  6962. }
  6963. /*
  6964. enum _SYSTEM_STATUS
  6965. {
  6966. S_BOOTING = 0,
  6967. S_IDLE, = 1
  6968. S_AUTHORIZING, = 2
  6969. S_REASSIGN_CHECK, = 3
  6970. S_REASSIGN, = 4
  6971. S_PRECHARGE, = 5
  6972. S_PREPARING_FOR_EV, = 6
  6973. S_PREPARING_FOR_EVSE, = 7
  6974. S_CHARGING, = 8
  6975. S_TERMINATING, = 9
  6976. S_COMPLETE, = 10
  6977. S_ALARM, = 11
  6978. S_FAULT = 12
  6979. }
  6980. */
  6981. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  6982. {
  6983. //check Transaction active
  6984. if(gunType[connectorIdInt -1] == 'J')
  6985. {
  6986. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6987. {
  6988. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  6989. }
  6990. else
  6991. {
  6992. tempIndex = connectorIdInt -1;
  6993. }
  6994. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6995. {
  6996. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  6997. {
  6998. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  6999. {
  7000. //Reserved
  7001. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7002. }
  7003. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  7004. {
  7005. //Reserved
  7006. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7007. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7008. goto end;
  7009. }
  7010. else
  7011. {
  7012. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7013. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7014. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7015. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7016. {
  7017. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  7018. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7019. goto end;
  7020. }
  7021. }//END FOR ELSE
  7022. }
  7023. }// END FOR CHAdeMO_QUANTITY
  7024. }
  7025. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7026. {
  7027. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7028. {
  7029. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7030. }
  7031. else
  7032. {
  7033. tempIndex = connectorIdInt -1;
  7034. }
  7035. for (int index = 0; index < CCS_QUANTITY; index++)
  7036. {
  7037. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7038. {
  7039. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  7040. {
  7041. //Reserved
  7042. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7043. }
  7044. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  7045. {
  7046. //Reserved
  7047. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7048. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7049. goto end;
  7050. }
  7051. else
  7052. {
  7053. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7054. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7055. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7056. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7057. {
  7058. DEBUG_WARN("CCS connector not allow start\n.");
  7059. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7060. goto end;
  7061. }
  7062. }// END FOR ELSE
  7063. }
  7064. }// END FOR CCS_QUANTITY
  7065. }
  7066. else if(gunType[connectorIdInt -1] == 'G')
  7067. {
  7068. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7069. {
  7070. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7071. }
  7072. else
  7073. {
  7074. tempIndex = connectorIdInt -1;
  7075. }
  7076. for (int index = 0; index < GB_QUANTITY; index++)
  7077. {
  7078. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7079. {
  7080. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  7081. {
  7082. //Reserved
  7083. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7084. }
  7085. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  7086. {
  7087. //Reserved
  7088. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7089. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7090. goto end;
  7091. }
  7092. else
  7093. {
  7094. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7095. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7096. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7097. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7098. {
  7099. DEBUG_WARN("GB connector not allow start\n.");
  7100. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7101. goto end;
  7102. }
  7103. }// END FOR ELSE
  7104. }
  7105. } // END FOR GB_QUANTITY
  7106. }
  7107. else
  7108. {
  7109. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7110. {
  7111. tempIndex = 2;
  7112. }
  7113. else
  7114. {
  7115. tempIndex = connectorIdInt -1;
  7116. }
  7117. for (int index = 0; index < AC_QUANTITY; index++)
  7118. {
  7119. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7120. {
  7121. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  7122. {
  7123. //Reserved
  7124. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7125. }
  7126. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  7127. {
  7128. //Reserved
  7129. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7130. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7131. goto end;
  7132. }
  7133. else
  7134. {
  7135. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7136. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7137. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7138. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7139. {
  7140. DEBUG_WARN("AC connector not allow start\n.");
  7141. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7142. goto end;
  7143. }
  7144. }//END FOR ELSE
  7145. }
  7146. }// END FOR AC_QUANTITY
  7147. }
  7148. if(chargingProfileIsNULL == FALSE)
  7149. {
  7150. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7151. {
  7152. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7153. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7154. //memset idTag
  7155. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7156. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7157. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7158. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7159. // Save profile to file
  7160. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7161. system(cmdBuf);
  7162. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7163. fp = fopen(cmdBuf, "w");
  7164. fprintf(fp, "{\"connectorId\":%d,\"csChargingProfiles\":%s}\n", connectorIdInt, json_object_to_json_string(json_object_object_get(RemoteStartTransaction, "chargingProfile")));
  7165. fclose(fp);
  7166. }
  7167. else
  7168. {
  7169. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  7170. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7171. }
  7172. }
  7173. else
  7174. {
  7175. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7176. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7177. //memset idTag
  7178. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7179. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7180. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7181. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7182. }
  7183. }
  7184. else
  7185. {
  7186. DEBUG_WARN("Connector id over\n.");
  7187. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7188. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7189. }
  7190. end:
  7191. json_object_put(RemoteStartTransaction);
  7192. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  7193. {
  7194. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7195. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7196. }
  7197. //OCPP send RemoteStartConfirmation by first.
  7198. sendRemoteStartConfirmation(uuid, comfirmstr);
  7199. return result;
  7200. }
  7201. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7202. {
  7203. mtrace();
  7204. int result = FAIL;
  7205. int match = FALSE;
  7206. int GunNO = 0;
  7207. int tempIndex = 0;
  7208. int transactionIdInt=0;
  7209. int transactionIdIsNULL= TRUE;
  7210. char comfirmstr[20];
  7211. json_object *RemoteStopTransaction;
  7212. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7213. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7214. if(server_pending == TRUE)
  7215. {
  7216. return 0;
  7217. }
  7218. RemoteStopTransaction = json_tokener_parse(payload);
  7219. if(!is_error(RemoteStopTransaction))
  7220. {
  7221. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  7222. {
  7223. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  7224. transactionIdIsNULL = FALSE;
  7225. }
  7226. }
  7227. json_object_put(RemoteStopTransaction);
  7228. if(transactionIdIsNULL == FALSE)
  7229. {
  7230. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7231. {
  7232. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7233. {
  7234. //check Transaction active
  7235. if(gunType[gun_index] == 'J')
  7236. {
  7237. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7238. {
  7239. tempIndex = ((gun_index==2) ? 1: 0);
  7240. }
  7241. else
  7242. {
  7243. tempIndex = gun_index;
  7244. }
  7245. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7246. {
  7247. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7248. {
  7249. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7250. {
  7251. match = TRUE;
  7252. GunNO = gun_index;
  7253. }
  7254. }
  7255. }// END FOR CHAdeMO_QUANTITY
  7256. }
  7257. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7258. {
  7259. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7260. {
  7261. tempIndex = ((gun_index==2) ? 1: 0);
  7262. }
  7263. else
  7264. {
  7265. tempIndex = gun_index;
  7266. }
  7267. for (int index = 0; index < CCS_QUANTITY; index++)
  7268. {
  7269. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7270. {
  7271. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7272. {
  7273. match = TRUE;
  7274. GunNO = gun_index;
  7275. }
  7276. }
  7277. }// END FOR CCS_QUANTITY
  7278. }
  7279. else if(gunType[gun_index] == 'G')
  7280. {
  7281. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7282. {
  7283. tempIndex = ((gun_index==2) ? 1: 0);
  7284. }
  7285. else
  7286. {
  7287. tempIndex = gun_index;
  7288. }
  7289. for (int index = 0; index < GB_QUANTITY; index++)
  7290. {
  7291. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7292. {
  7293. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7294. {
  7295. match = TRUE;
  7296. GunNO = gun_index;
  7297. }
  7298. }
  7299. }// END FOR GB_QUANTITY
  7300. }
  7301. else
  7302. {
  7303. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7304. {
  7305. tempIndex = 2;
  7306. }
  7307. else
  7308. {
  7309. tempIndex = gun_index;
  7310. }
  7311. for (int index = 0; index < AC_QUANTITY; index++)
  7312. {
  7313. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7314. {
  7315. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7316. {
  7317. match = TRUE;
  7318. GunNO = gun_index;
  7319. }
  7320. }
  7321. }// END FOR CHAdeMO_QUANTITY
  7322. } // END FOR AC ELSE
  7323. }// CHECK IF ResponseTransactionId == transactionIdInt
  7324. }//END FOR
  7325. if( match == TRUE)
  7326. {
  7327. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7328. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7329. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7330. }
  7331. else
  7332. {
  7333. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7334. }
  7335. }
  7336. else
  7337. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7338. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7339. return result;
  7340. }
  7341. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7342. {
  7343. mtrace();
  7344. int result = FAIL;
  7345. int connectorIdInt=0, reservationIdInt=0;
  7346. int tempIndex = 0;
  7347. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7348. char comfirmstr[20]={0};
  7349. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7350. int c = 0;
  7351. char *loc;
  7352. //char *ptr;
  7353. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7354. strcpy(sstrtemp, stringtrimspace(payload));
  7355. //***(1)connectorId ****/
  7356. c=0;
  7357. loc = strstr(sstrtemp, "connectorId");
  7358. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7359. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7360. {
  7361. sstr[c] = loc[strlen("connectorId")+2+c];
  7362. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7363. c++;
  7364. }
  7365. sstr[c] = '\0';
  7366. connectorIdInt = atoi(sstr);
  7367. //***(2)expiryDate ****/
  7368. loc = strstr(sstrtemp, "expiryDate");
  7369. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7370. c = 0;
  7371. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7372. {
  7373. sstr[c] = loc[3+strlen("expiryDate")+c];
  7374. c++;
  7375. }
  7376. sstr[c] = '\0';
  7377. strcpy(expiryDatestr, sstr);
  7378. //***(3)idTag ****/
  7379. loc = strstr(sstrtemp, "idTag");
  7380. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7381. c = 0;
  7382. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7383. {
  7384. sstr[c] = loc[3+strlen("idTag")+c];
  7385. c++;
  7386. }
  7387. sstr[c] = '\0';
  7388. strcpy(idTagstr, sstr);
  7389. //***(4)parentIdTag ****/
  7390. loc = strstr(sstrtemp, "parentIdTag");
  7391. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7392. c = 0;
  7393. if(loc == NULL)
  7394. {
  7395. strcpy(parentIdTagstr, "");
  7396. }
  7397. else
  7398. {
  7399. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7400. {
  7401. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7402. c++;
  7403. }
  7404. sstr[c] = '\0';
  7405. strcpy(parentIdTagstr, sstr);
  7406. }
  7407. //***(5)reservationId ****/
  7408. c=0;
  7409. loc = strstr(sstrtemp, "reservationId");
  7410. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7411. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7412. {
  7413. sstr[c] = loc[strlen("reservationId")+2+c];
  7414. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7415. c++;
  7416. }
  7417. sstr[c] = '\0';
  7418. reservationIdInt = atoi(sstr);
  7419. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7420. /*
  7421. enum SYSTEM_STATUS
  7422. {
  7423. SYS_MODE_BOOTING = 0,
  7424. SYS_MODE_IDLE = 1,
  7425. SYS_MODE_AUTHORIZING = 2,
  7426. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7427. SYS_MODE_REASSIGN = 4,
  7428. SYS_MODE_PREPARING = 5,
  7429. SYS_MODE_PREPARE_FOR_EV = 6,
  7430. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7431. SYS_MODE_CHARGING = 8,
  7432. SYS_MODE_TERMINATING = 9,
  7433. SYS_MODE_COMPLETE = 10,
  7434. SYS_MODE_ALARM = 11,
  7435. SYS_MODE_FAULT = 12,
  7436. SYS_MODE_RESERVATION = 13,
  7437. SYS_MODE_BOOKING = 14,
  7438. SYS_MODE_MAINTAIN = 15,
  7439. SYS_MODE_DEBUG = 16,
  7440. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7441. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7442. SYS_MODE_UPDATE = 19
  7443. };
  7444. */
  7445. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7446. {
  7447. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7448. goto end;
  7449. }
  7450. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7451. {
  7452. //check Transaction active
  7453. if(gunType[connectorIdInt -1] == 'J')
  7454. {
  7455. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7456. {
  7457. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7458. }
  7459. else
  7460. {
  7461. tempIndex = connectorIdInt -1;
  7462. }
  7463. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7464. {
  7465. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7466. {
  7467. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7468. {
  7469. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7470. {
  7471. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7472. {
  7473. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7474. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7475. }
  7476. 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'))
  7477. {
  7478. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7479. }
  7480. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7481. {
  7482. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7483. }
  7484. else
  7485. {
  7486. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7487. }
  7488. }
  7489. 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
  7490. {
  7491. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7492. }
  7493. }
  7494. else
  7495. {
  7496. //replace reservation
  7497. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7498. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7499. }
  7500. }
  7501. } // END FOR CHAdeMO_QUANTITY
  7502. }
  7503. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7504. {
  7505. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7506. {
  7507. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7508. }
  7509. else
  7510. {
  7511. tempIndex = connectorIdInt -1;
  7512. }
  7513. for (int index = 0; index < CCS_QUANTITY; index++)
  7514. {
  7515. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7516. {
  7517. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7518. {
  7519. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7520. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7521. {
  7522. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7523. {
  7524. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7525. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7526. }
  7527. 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'))
  7528. {
  7529. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7530. }
  7531. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7532. {
  7533. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7534. }
  7535. else
  7536. {
  7537. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7538. }
  7539. }
  7540. 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
  7541. {
  7542. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7543. }
  7544. }
  7545. else
  7546. {
  7547. //replace reservation
  7548. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7549. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7550. }
  7551. }
  7552. } // END FOR CCS_QUANTITY
  7553. }
  7554. else if(gunType[connectorIdInt -1] == 'G')
  7555. {
  7556. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7557. {
  7558. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7559. }
  7560. else
  7561. {
  7562. tempIndex = connectorIdInt -1;
  7563. }
  7564. for (int index = 0; index < GB_QUANTITY; index++)
  7565. {
  7566. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7567. {
  7568. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7569. {
  7570. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7571. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7572. {
  7573. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7574. {
  7575. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7576. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7577. }
  7578. 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'))
  7579. {
  7580. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7581. }
  7582. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7583. {
  7584. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7585. }
  7586. else
  7587. {
  7588. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7589. }
  7590. }
  7591. 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
  7592. {
  7593. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7594. }
  7595. }
  7596. else
  7597. {
  7598. //replace reservation
  7599. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7600. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7601. }
  7602. }
  7603. }// END FOR GB_QUANTITY
  7604. }
  7605. else
  7606. {
  7607. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7608. {
  7609. tempIndex = 2;
  7610. }
  7611. else
  7612. {
  7613. tempIndex = (connectorIdInt -1);
  7614. }
  7615. for (int index = 0; index < AC_QUANTITY; index++)
  7616. {
  7617. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7618. {
  7619. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7620. {
  7621. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7622. {
  7623. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7624. {
  7625. 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))
  7626. {
  7627. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7628. }
  7629. else
  7630. {
  7631. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7632. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7633. }
  7634. }
  7635. 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'))
  7636. {
  7637. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7638. }
  7639. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7640. {
  7641. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7642. }
  7643. else
  7644. {
  7645. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7646. }
  7647. }
  7648. 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
  7649. {
  7650. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7651. }
  7652. }
  7653. else
  7654. {
  7655. //replace reservation
  7656. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7657. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7658. }
  7659. }
  7660. } // END FOR AC_QUANTITY
  7661. }
  7662. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7663. }
  7664. else if(connectorIdInt == 0)
  7665. {
  7666. //check Transaction active
  7667. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7668. {
  7669. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7670. {
  7671. 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'))
  7672. {
  7673. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7674. goto end;
  7675. }
  7676. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7677. {
  7678. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7679. goto end;
  7680. }
  7681. 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
  7682. {
  7683. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7684. goto end;
  7685. }
  7686. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7687. {
  7688. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7689. goto end;
  7690. }
  7691. }
  7692. }// END FOR CHAdeMO_QUANTITY
  7693. for (int index = 0; index < CCS_QUANTITY; index++)
  7694. {
  7695. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7696. {
  7697. 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'))
  7698. {
  7699. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7700. goto end;
  7701. }
  7702. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7703. {
  7704. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7705. goto end;
  7706. }
  7707. 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
  7708. {
  7709. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7710. goto end;
  7711. }
  7712. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7713. {
  7714. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7715. goto end;
  7716. }
  7717. }
  7718. } // END FOR CCS_QUANTITY
  7719. for (int index = 0; index < GB_QUANTITY; index++)
  7720. {
  7721. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7722. {
  7723. 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'))
  7724. {
  7725. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7726. goto end;
  7727. }
  7728. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7729. {
  7730. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7731. goto end;
  7732. }
  7733. 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
  7734. {
  7735. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7736. goto end;
  7737. }
  7738. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7739. {
  7740. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7741. goto end;
  7742. }
  7743. }
  7744. } // END FOR GB_QUANTITY
  7745. for (int index = 0; index < AC_QUANTITY; index++)
  7746. {
  7747. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7748. {
  7749. 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'))
  7750. {
  7751. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7752. goto end;
  7753. }
  7754. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7755. {
  7756. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7757. goto end;
  7758. }
  7759. 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
  7760. {
  7761. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7762. goto end;
  7763. }
  7764. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7765. {
  7766. 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))
  7767. {
  7768. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7769. goto end;
  7770. }
  7771. }
  7772. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7773. {
  7774. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7775. goto end;
  7776. }
  7777. }
  7778. }// END FOR AC_QUANTITY
  7779. //The connectorId is 0
  7780. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7781. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7782. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7783. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7784. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7785. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7786. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7787. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7788. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7789. result = TRUE;
  7790. return result;
  7791. }
  7792. else
  7793. {
  7794. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7795. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7796. }
  7797. if(strcmp(comfirmstr,"Accepted") == 0)
  7798. {
  7799. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7800. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7801. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7802. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7803. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7804. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7805. result = TRUE;
  7806. return result;
  7807. }
  7808. end:
  7809. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7810. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7811. return result;
  7812. }
  7813. int handleResetRequest(char *uuid, char *payload)
  7814. {
  7815. mtrace();
  7816. int result = FAIL;
  7817. char sstr[10]={0},sstrtemp[30]={ 0 };
  7818. char typestr[10]={0};
  7819. char comfirmstr[20]={0};
  7820. int c = 0;
  7821. char *loc;
  7822. DEBUG_INFO("handleResetRequest...\n");
  7823. strcpy(sstrtemp, stringtrimspace(payload));
  7824. loc = strstr(sstrtemp, "type");
  7825. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7826. c = 0;
  7827. while (loc[3+strlen("type")+c] != '\"')
  7828. {
  7829. sstr[c] = loc[3+strlen("type")+c];
  7830. c++;
  7831. }
  7832. sstr[c] = '\0';
  7833. strcpy(typestr,sstr);
  7834. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7835. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  7836. {
  7837. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7838. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7839. result = TRUE;
  7840. return result;
  7841. }
  7842. else
  7843. {
  7844. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7845. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7846. goto errorend;
  7847. }
  7848. errorend:
  7849. sendResetConfirmation(uuid, comfirmstr);
  7850. return result;
  7851. }
  7852. int handleSendLocalListRequest(char *uuid, char *payload)
  7853. {
  7854. mtrace();
  7855. int result = FAIL;
  7856. int listVersionInt;
  7857. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7858. char listsearch[]="listVersion";
  7859. char updateTypesearch[]="updateType";
  7860. char localAuthorizationListsearch[]="localAuthorizationList";
  7861. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  7862. char CardList[500][160]={0};
  7863. char updateTypestr[15]={0};
  7864. char idTagstr[20]={0};
  7865. char parentIdTag[20]={0};
  7866. char expiryDate[30]={0};
  7867. char idTagstatus[16]={0};
  7868. int c = 0;
  7869. int i = 0;
  7870. char *delim1 = "}";
  7871. char * pch;
  7872. char *loc;
  7873. //char *ptr;
  7874. char comfirmstr[20];
  7875. //int n_localAuthorizations = 0;
  7876. int checkState_Faulted = FALSE;
  7877. DEBUG_INFO("handleSendLocalListRequest...\n");
  7878. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7879. {
  7880. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7881. goto end;
  7882. }
  7883. //check Charge Point state
  7884. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7885. {
  7886. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7887. {
  7888. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7889. }
  7890. }
  7891. for (int index = 0; index < CCS_QUANTITY; index++)
  7892. {
  7893. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7894. {
  7895. checkState_Faulted = TRUE; //OCPP Status
  7896. }
  7897. }
  7898. for (int index = 0; index < GB_QUANTITY; index++)
  7899. {
  7900. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7901. {
  7902. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7903. }
  7904. }
  7905. //check Charge Point state
  7906. for (int index = 0; index < AC_QUANTITY; index++)
  7907. {
  7908. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7909. {
  7910. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7911. }
  7912. }
  7913. if(checkState_Faulted == TRUE)
  7914. {
  7915. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7916. goto end;
  7917. }
  7918. //Filter payload space
  7919. strcpy(sstrtemp, stringtrimspace(payload));
  7920. //listVersion
  7921. c = 0;
  7922. loc = strstr(sstrtemp, listsearch);
  7923. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7924. {
  7925. sstr[c] = loc[strlen("listVersion")+2+c];
  7926. c++;
  7927. }
  7928. sstr[c] = '\0';
  7929. listVersionInt = atoi(sstr);
  7930. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7931. //updateType
  7932. loc = strstr(sstrtemp, updateTypesearch);
  7933. c = 0;
  7934. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7935. {
  7936. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7937. c++;
  7938. }
  7939. sstr[c] = '\0';
  7940. strcpy(updateTypestr, sstr);
  7941. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7942. //localAuthorizationList
  7943. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7944. loc = strstr(sstrtemp, localAuthorizationListsearch);
  7945. if(loc != NULL) // localAuthorizationList is not NULL
  7946. {
  7947. //Check UpdateType
  7948. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7949. {
  7950. //Local list full update
  7951. printf("Local list full update.\n");
  7952. OCPP_getListVerion();
  7953. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7954. {
  7955. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7956. goto end;
  7957. }
  7958. OCPP_cleanLocalList();
  7959. }
  7960. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7961. {
  7962. //Local list different update
  7963. printf("Local list different update.\n");
  7964. OCPP_getListVerion();
  7965. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7966. {
  7967. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7968. goto end;
  7969. }
  7970. }
  7971. else
  7972. {
  7973. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7974. goto end;
  7975. }
  7976. c = 0;
  7977. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7978. {
  7979. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7980. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7981. c++;
  7982. }
  7983. sstr[c] = '\0';
  7984. //DEBUG_INFO("sstr=%s\n", sstr);
  7985. //parsing strings to words
  7986. i = 0;
  7987. pch = strtok(sstr,delim1);
  7988. while (pch != NULL)
  7989. {
  7990. strcpy(CardList[i], pch);
  7991. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7992. pch = strtok (NULL, delim1);
  7993. i = i + 1;
  7994. }
  7995. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7996. //local Authorizations List Numbers
  7997. //n_localAuthorizations = i;
  7998. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7999. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8000. c= 0;
  8001. while(c < i) // i is CardList Number
  8002. {
  8003. //Search "IdToken"
  8004. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8005. loc = strstr(CardList[c], "idTag");
  8006. int j = 0;
  8007. while (loc[3+strlen("idTag")+j] != '\"')
  8008. {
  8009. sstr[j] = loc[3+strlen("idTag")+j];
  8010. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8011. j++;
  8012. }
  8013. sstr[j] = '\0';
  8014. strcpy(idTagstr, sstr);
  8015. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8016. //Search "expiryDate"
  8017. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8018. loc = strstr(CardList[c], "expiryDate");
  8019. j = 0;
  8020. if(loc != NULL)
  8021. {
  8022. while (loc[3+strlen("expiryDate")+j] != '\"')
  8023. {
  8024. sstr[j] = loc[3+strlen("expiryDate")+j];
  8025. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8026. j++;
  8027. }
  8028. sstr[j] = '\0';
  8029. strcpy(expiryDate, sstr);
  8030. }
  8031. else
  8032. {
  8033. strcpy(expiryDate, "");
  8034. }
  8035. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8036. //Search "parentIdTag"
  8037. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8038. loc = strstr(CardList[c], "parentIdTag");
  8039. j = 0;
  8040. if(loc != NULL)
  8041. {
  8042. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8043. {
  8044. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8045. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8046. j++;
  8047. }
  8048. sstr[j] = '\0';
  8049. strcpy(parentIdTag, sstr);
  8050. }
  8051. else
  8052. {
  8053. strcpy(parentIdTag, "");
  8054. }
  8055. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8056. //Search "status"
  8057. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8058. loc = strstr(CardList[c], "status");
  8059. j = 0;
  8060. while (loc[3+strlen("status")+j] != '\"')
  8061. {
  8062. sstr[j] = loc[3+strlen("status")+j];
  8063. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8064. j++;
  8065. }
  8066. sstr[j] = '\0';
  8067. strcpy(idTagstatus, sstr);
  8068. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8069. OCPP_getIdTag(idTagstr);
  8070. //OCPP_getIdTag("test"); For Test
  8071. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8072. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8073. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8074. {
  8075. //Local list full update
  8076. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8077. // update list
  8078. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8079. //DEBUG_INFO("Local list full update. 1\n");
  8080. //OCPP_get_TableAuthlocalAllData();
  8081. //DEBUG_INFO("Local list full update. 2\n");
  8082. }
  8083. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8084. {
  8085. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8086. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8087. }
  8088. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8089. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8090. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8091. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8092. c++;
  8093. }
  8094. }
  8095. else
  8096. {
  8097. //Check UpdateType
  8098. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8099. {
  8100. //Local list full update
  8101. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8102. OCPP_cleanLocalList();
  8103. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8104. goto end;
  8105. }
  8106. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8107. {
  8108. //Local list different update
  8109. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8110. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8111. goto end;
  8112. }
  8113. }
  8114. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8115. end:
  8116. sendSendLocalListConfirmation(uuid, comfirmstr);
  8117. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8118. return result;
  8119. }
  8120. #define MAX 200
  8121. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8122. {
  8123. mtrace();
  8124. int result = FAIL;
  8125. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8126. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8127. char chargingProfilePurposeStr[30]={0};
  8128. char chargingProfileKindStr[16]={0};
  8129. char recurrencyKindStr[10]={0};
  8130. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8131. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8132. int chargingSchedulePeriodCount = 0;
  8133. char comfirmstr[20]={0};
  8134. int meet= FALSE;
  8135. FILE *fptr1;
  8136. char filename[MAX]={0};
  8137. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8138. char rmFileCmd[50]={0};
  8139. char tempchargingProfilePurposeStr[30]={0};
  8140. char word[1600]={0};
  8141. int n_chargingProfile = 0;
  8142. json_object *SetChargingProfile;
  8143. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8144. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8145. SetChargingProfile = json_tokener_parse(payload);
  8146. if(!is_error(SetChargingProfile))
  8147. {
  8148. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  8149. {
  8150. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  8151. if(connectorIdInt == 0)
  8152. {
  8153. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  8154. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8155. }
  8156. else
  8157. {
  8158. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  8159. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  8160. }
  8161. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  8162. }
  8163. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  8164. {
  8165. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  8166. {
  8167. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  8168. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8169. {
  8170. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8171. }
  8172. else
  8173. {
  8174. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8175. }
  8176. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  8177. }
  8178. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  8179. {
  8180. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  8181. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8182. {
  8183. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8184. }
  8185. else
  8186. {
  8187. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8188. }
  8189. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  8190. }
  8191. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8192. {
  8193. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  8194. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8195. {
  8196. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8197. }
  8198. else
  8199. {
  8200. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8201. }
  8202. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  8203. }
  8204. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  8205. {
  8206. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  8207. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8208. {
  8209. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8210. }
  8211. else
  8212. {
  8213. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8214. }
  8215. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  8216. }
  8217. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  8218. {
  8219. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  8220. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8221. {
  8222. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8223. }
  8224. else
  8225. {
  8226. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8227. }
  8228. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  8229. }
  8230. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  8231. {
  8232. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  8233. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8234. {
  8235. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8236. }
  8237. else
  8238. {
  8239. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8240. }
  8241. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  8242. }
  8243. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  8244. {
  8245. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  8246. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8247. {
  8248. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8249. }
  8250. else
  8251. {
  8252. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8253. }
  8254. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  8255. }
  8256. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  8257. {
  8258. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  8259. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8260. {
  8261. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8262. }
  8263. else
  8264. {
  8265. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8266. }
  8267. //DEBUG_INFO("validToStr: %s\n", validToStr);
  8268. }
  8269. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  8270. {
  8271. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  8272. {
  8273. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  8274. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8275. {
  8276. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8277. }
  8278. else
  8279. {
  8280. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8281. }
  8282. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  8283. }
  8284. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  8285. {
  8286. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  8287. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8288. {
  8289. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8290. }
  8291. else
  8292. {
  8293. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8294. }
  8295. //DEBUG_INFO("durationInt: %d\n", durationInt);
  8296. }
  8297. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  8298. {
  8299. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  8300. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8301. {
  8302. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8303. }
  8304. else
  8305. {
  8306. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8307. }
  8308. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  8309. }
  8310. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  8311. {
  8312. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  8313. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8314. {
  8315. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8316. }
  8317. else
  8318. {
  8319. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8320. }
  8321. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  8322. }
  8323. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8324. {
  8325. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  8326. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  8327. if(chargingSchedulePeriodCount <= 10)
  8328. {
  8329. for(int idxPeriod=0;idxPeriod<json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));idxPeriod++)
  8330. {
  8331. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod") != NULL)
  8332. {
  8333. startPeriodInt[idxPeriod] = 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(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "startPeriod"));
  8334. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8335. {
  8336. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8337. }
  8338. else
  8339. {
  8340. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8341. }
  8342. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  8343. }
  8344. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit") != NULL)
  8345. {
  8346. limitflaot[idxPeriod] = 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(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "limit"));
  8347. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8348. {
  8349. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8350. }
  8351. else
  8352. {
  8353. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8354. }
  8355. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  8356. }
  8357. if(json_object_object_get(json_object_array_get_idx(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases") != NULL)
  8358. {
  8359. numberPhasesInt[idxPeriod] = 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(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"), idxPeriod), "numberPhases"));
  8360. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8361. {
  8362. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8363. }
  8364. else
  8365. {
  8366. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8367. }
  8368. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  8369. }
  8370. }
  8371. }
  8372. }
  8373. }
  8374. }
  8375. }
  8376. json_object_put(SetChargingProfile);
  8377. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8378. {
  8379. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8380. goto end;
  8381. }
  8382. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8383. {
  8384. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8385. if(connectorIdInt != 0)
  8386. {
  8387. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8388. goto end;
  8389. }
  8390. strcpy(filename, ChargePointMaxProfile_JSON );
  8391. fptr1 = fopen(filename, "r");
  8392. if (!fptr1)
  8393. {
  8394. //file not exist
  8395. DEBUG_INFO("Unable to open the input file!!\n");
  8396. fptr1 = fopen(filename, "w+");
  8397. }
  8398. else
  8399. {
  8400. //Check Charging Profile Count
  8401. while(fscanf(fptr1, "%s", word) != EOF)
  8402. {
  8403. //DEBUG_INFO("word=%s\n",word);
  8404. if(strstr(word, "chargingProfileId")!= NULL)
  8405. {
  8406. //DEBUG_INFO("test chargingProfileId \n");
  8407. n_chargingProfile = n_chargingProfile + 1;
  8408. //DEBUG_INFO("chargingProfileId Found\n");
  8409. }
  8410. }
  8411. }
  8412. fclose(fptr1);
  8413. }
  8414. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8415. {
  8416. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8417. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8418. {
  8419. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8420. goto end;
  8421. }
  8422. memset(filename, 0, ARRAY_SIZE(filename));
  8423. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8424. fptr1 = fopen(filename, "r");
  8425. if (!fptr1)
  8426. {
  8427. //file not exist
  8428. //DEBUG_INFO("Unable to open the input file!!\n");
  8429. fptr1 = fopen(filename, "w+");
  8430. }
  8431. else
  8432. {
  8433. //Check Charging Profile Count
  8434. while(fscanf(fptr1, "%s", word) != EOF)
  8435. {
  8436. //DEBUG_INFO("word=%s\n",word);
  8437. if(strstr(word, "chargingProfileId")!= NULL)
  8438. {
  8439. //DEBUG_INFO("test chargingProfileId \n");
  8440. n_chargingProfile = n_chargingProfile + 1;
  8441. //DEBUG_INFO("chargingProfileId Found\n");
  8442. }
  8443. }
  8444. }
  8445. fclose(fptr1);
  8446. }
  8447. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8448. {
  8449. //printf("set chargingProfile 1-4\n");
  8450. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8451. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8452. if(connectorIdInt == 0)
  8453. {
  8454. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8455. goto end;
  8456. }
  8457. int tempIndex = 0;
  8458. //check Transaction active
  8459. if(gunType[connectorIdInt -1] == 'J')
  8460. {
  8461. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8462. {
  8463. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8464. }
  8465. else
  8466. {
  8467. tempIndex = connectorIdInt -1;
  8468. }
  8469. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8470. {
  8471. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8472. {
  8473. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8474. {
  8475. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8476. {
  8477. meet = TRUE;
  8478. break;
  8479. }
  8480. }
  8481. }
  8482. }
  8483. }
  8484. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8485. {
  8486. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8487. {
  8488. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8489. }
  8490. else
  8491. {
  8492. tempIndex = connectorIdInt -1;
  8493. }
  8494. for (int index = 0; index < CCS_QUANTITY; index++)
  8495. {
  8496. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8497. {
  8498. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8499. {
  8500. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8501. {
  8502. meet = TRUE;
  8503. break;
  8504. }
  8505. }
  8506. }
  8507. }
  8508. }
  8509. else if(gunType[connectorIdInt -1] == 'G')
  8510. {
  8511. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8512. {
  8513. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8514. }
  8515. else
  8516. {
  8517. tempIndex = connectorIdInt -1;
  8518. }
  8519. for (int index = 0; index < GB_QUANTITY; index++)
  8520. {
  8521. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8522. {
  8523. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8524. {
  8525. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8526. {
  8527. meet = TRUE;
  8528. break;
  8529. }
  8530. }
  8531. }
  8532. }
  8533. }
  8534. else
  8535. {
  8536. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8537. {
  8538. tempIndex = 2;
  8539. }
  8540. else
  8541. {
  8542. tempIndex = (connectorIdInt -1);
  8543. }
  8544. for (int index = 0; index < AC_QUANTITY; index++)
  8545. {
  8546. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8547. {
  8548. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8549. {
  8550. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8551. {
  8552. meet = TRUE;
  8553. break;
  8554. }
  8555. }
  8556. }
  8557. }
  8558. }
  8559. //check Transaction active
  8560. if(meet == FALSE)
  8561. {
  8562. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8563. goto end;
  8564. }
  8565. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8566. {
  8567. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8568. goto end;
  8569. }
  8570. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8571. fptr1 = fopen(filename, "r");
  8572. if (!fptr1)
  8573. {
  8574. //file not exist
  8575. DEBUG_INFO("Unable to open the input file!!\n");
  8576. fptr1 = fopen(filename, "w+");
  8577. }
  8578. else
  8579. {
  8580. //Check Charging Profile Count
  8581. while(fscanf(fptr1, "%s", word) != EOF)
  8582. {
  8583. //DEBUG_INFO("word=%s\n",word);
  8584. if(strstr(word, "chargingProfileId")!= NULL)
  8585. {
  8586. //DEBUG_INFO("test chargingProfileId \n");
  8587. n_chargingProfile = n_chargingProfile + 1;
  8588. //DEBUG_INFO("chargingProfileId Found\n");
  8589. }
  8590. }
  8591. }
  8592. fclose(fptr1);
  8593. }
  8594. // Check ChargeProfileMaxStackLevel
  8595. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8596. {
  8597. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8598. goto end;
  8599. }
  8600. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8601. {
  8602. int i = 0;
  8603. char fnametemp[200]={0};
  8604. n_chargingProfile = 0;
  8605. //Check ChargePointMaxProfile.json exit
  8606. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8607. {
  8608. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8609. //Check Charging Profile Count
  8610. while(fscanf(fptr1, "%s", word) != EOF)
  8611. {
  8612. //DEBUG_INFO("word=%s\n",word);
  8613. if(strstr(word, "chargingProfileId")!= NULL)
  8614. {
  8615. //DEBUG_INFO("test chargingProfileId \n");
  8616. n_chargingProfile = n_chargingProfile + 1;
  8617. i = i + 1;
  8618. //DEBUG_INFO("chargingProfileId Found\n");
  8619. }
  8620. memset(word, 0, ARRAY_SIZE(word));
  8621. }
  8622. fclose(fptr1);
  8623. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8624. }
  8625. //Check TxDefaultProfile_0.json exit
  8626. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8627. {
  8628. i = 0;
  8629. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8630. //Check Charging Profile Count
  8631. while(fscanf(fptr1, "%s", word) != EOF)
  8632. {
  8633. //DEBUG_INFO("word=%s\n",word);
  8634. if(strstr(word, "chargingProfileId")!= NULL)
  8635. {
  8636. //DEBUG_INFO("test chargingProfileId \n");
  8637. n_chargingProfile = n_chargingProfile + 1;
  8638. i = i + 1;
  8639. //DEBUG_INFO("chargingProfileId Found\n");
  8640. }
  8641. memset(word, 0, ARRAY_SIZE(word));
  8642. }
  8643. fclose(fptr1);
  8644. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8645. }
  8646. //Check TxDefaultProfile_%d.json
  8647. for(int j=1; j <= gunTotalNumber; j++)
  8648. {
  8649. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8650. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8651. if((access(fnametemp,F_OK))!=-1)
  8652. {
  8653. i = 0;
  8654. fptr1 = fopen(fnametemp, "r");
  8655. //Check Charging Profile Count
  8656. while(fscanf(fptr1, "%s", word) != EOF)
  8657. {
  8658. //DEBUG_INFO("word=%s\n",word);
  8659. if(strstr(word, "chargingProfileId")!= NULL)
  8660. {
  8661. //DEBUG_INFO("test chargingProfileId \n");
  8662. n_chargingProfile = n_chargingProfile + 1;
  8663. i = i + 1;
  8664. //DEBUG_INFO("chargingProfileId Found\n");
  8665. }
  8666. memset(word, 0, ARRAY_SIZE(word));
  8667. }
  8668. fclose(fptr1);
  8669. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8670. }
  8671. }
  8672. //Check TxProfile_%d.json
  8673. for(int j=1; j <= gunTotalNumber; j++)
  8674. {
  8675. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8676. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8677. if((access(fnametemp,F_OK))!=-1)
  8678. {
  8679. i = 0;
  8680. fptr1 = fopen(fnametemp, "r");
  8681. //Check Charging Profile Count
  8682. while(fscanf(fptr1, "%s", word) != EOF)
  8683. {
  8684. //DEBUG_INFO("word=%s\n",word);
  8685. if(strstr(word, "chargingProfileId")!= NULL)
  8686. {
  8687. //DEBUG_INFO("test chargingProfileId \n");
  8688. n_chargingProfile = n_chargingProfile + 1;
  8689. i = i + 1;
  8690. //DEBUG_INFO("chargingProfileId Found\n");
  8691. }
  8692. memset(word, 0, ARRAY_SIZE(word));
  8693. }
  8694. fclose(fptr1);
  8695. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8696. }
  8697. }
  8698. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8699. {
  8700. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8701. goto end;
  8702. }
  8703. }
  8704. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8705. //**********************************Write to File********************************************************/
  8706. FILE *infile;
  8707. FILE *outfile;
  8708. infile = fopen (filename, "r");
  8709. outfile = fopen (tempfile, "w");
  8710. int d =0;
  8711. d = fgetc(infile);
  8712. rewind(infile);
  8713. if(d == EOF)
  8714. {
  8715. // Profile is empty
  8716. fprintf(outfile,"%s\n",payload);
  8717. fclose(infile);
  8718. fclose(outfile);
  8719. sprintf(rmFileCmd,"rm -f %s",filename);
  8720. system(rmFileCmd);
  8721. rename(tempfile, filename);
  8722. }
  8723. else
  8724. {
  8725. // Profile is not empty
  8726. char buf[2048]={0};
  8727. int ChargingProfileAdded = FALSE;
  8728. while (fgets(buf, sizeof(buf), infile) != NULL)
  8729. {
  8730. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8731. json_object *tmpChargingProfile;
  8732. tmpChargingProfile = json_tokener_parse(buf);
  8733. if(!is_error(SetChargingProfile))
  8734. {
  8735. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  8736. {
  8737. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  8738. }
  8739. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  8740. {
  8741. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  8742. {
  8743. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  8744. }
  8745. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  8746. {
  8747. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  8748. }
  8749. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8750. {
  8751. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  8752. }
  8753. }
  8754. }
  8755. json_object_put(tmpChargingProfile);
  8756. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  8757. {
  8758. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8759. {
  8760. //DEBUG_INFO("update set chargingProfile to file -0\n");
  8761. if(ChargingProfileAdded == FALSE)
  8762. {
  8763. fprintf(outfile,"%s\n",payload);
  8764. ChargingProfileAdded = TRUE;
  8765. }
  8766. }
  8767. else
  8768. {
  8769. if(tempstackLevelInt < stackLevelInt)
  8770. {
  8771. if(ChargingProfileAdded == FALSE)
  8772. {
  8773. fprintf(outfile,"%s\n",buf);
  8774. fprintf(outfile,"%s\n",payload);
  8775. ChargingProfileAdded = TRUE;
  8776. }
  8777. else
  8778. {
  8779. fprintf(outfile,"%s\n",buf);
  8780. }
  8781. }
  8782. else
  8783. {
  8784. if(ChargingProfileAdded == FALSE)
  8785. {
  8786. fprintf(outfile,"%s\n",buf);
  8787. fprintf(outfile,"%s\n",payload);
  8788. ChargingProfileAdded = TRUE;
  8789. }
  8790. else
  8791. {
  8792. fprintf(outfile,"%s\n",buf);
  8793. }
  8794. }
  8795. }
  8796. }
  8797. else
  8798. {
  8799. if(tempchargingProfileIdInt < chargingProfileIdInt)
  8800. {
  8801. if(ChargingProfileAdded == FALSE)
  8802. {
  8803. fprintf(outfile,"%s\n",buf);
  8804. fprintf(outfile,"%s\n",payload);
  8805. ChargingProfileAdded = TRUE;
  8806. }
  8807. else
  8808. {
  8809. fprintf(outfile,"%s\n",buf);
  8810. }
  8811. }
  8812. else if(tempstackLevelInt < stackLevelInt)
  8813. {
  8814. if(ChargingProfileAdded == FALSE)
  8815. {
  8816. fprintf(outfile,"%s\n",buf);
  8817. fprintf(outfile,"%s\n",payload);
  8818. ChargingProfileAdded = TRUE;
  8819. }
  8820. else
  8821. {
  8822. fprintf(outfile,"%s\n",buf);
  8823. }
  8824. }
  8825. else
  8826. {
  8827. if(ChargingProfileAdded == FALSE)
  8828. {
  8829. fprintf(outfile,"%s\n",buf);
  8830. fprintf(outfile,"%s\n",payload);
  8831. ChargingProfileAdded = TRUE;
  8832. }
  8833. else
  8834. {
  8835. fprintf(outfile,"%s\n",buf);
  8836. }
  8837. }
  8838. }
  8839. } // end of while loop
  8840. fclose(infile);
  8841. fclose(outfile);
  8842. sprintf(rmFileCmd,"rm -f %s",filename);
  8843. system(rmFileCmd);
  8844. rename(tempfile, filename);
  8845. }
  8846. sleep(1);
  8847. result = TRUE;
  8848. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8849. end:
  8850. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  8851. return result;
  8852. }
  8853. int handleTriggerMessageRequest(char *uuid, char *payload)
  8854. {
  8855. mtrace();
  8856. int result = FAIL;
  8857. int connectorIdIsNULL = FALSE;
  8858. int connectorIdInt =0;
  8859. char sstr[40]={0},sstrtemp[100]={ 0 };
  8860. char requestedMessagestr[40]={0};
  8861. char comfirmstr[20]={0};
  8862. int c = 0;
  8863. char *loc;
  8864. DEBUG_INFO("handleTriggerMessageRequest\n");
  8865. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  8866. strcpy(sstrtemp, stringtrimspace(payload));
  8867. c = 0;
  8868. loc = strstr(sstrtemp, "requestedMessage");
  8869. while (loc[3+strlen("requestedMessage")+c] != '\"')
  8870. {
  8871. sstr[c] = loc[3+strlen("requestedMessage")+c];
  8872. c++;
  8873. }
  8874. sstr[c] = '\0';
  8875. strcpy(requestedMessagestr, sstr);
  8876. c = 0;
  8877. loc = strstr(sstrtemp, "connectorId");
  8878. if(loc == NULL)
  8879. {
  8880. connectorIdIsNULL = TRUE;
  8881. }
  8882. else
  8883. {
  8884. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8885. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  8886. {
  8887. sstr[c] = loc[strlen("connectorId")+2+c];
  8888. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8889. c++;
  8890. }
  8891. sstr[c] = '\0';
  8892. connectorIdInt = atoi(sstr);
  8893. }
  8894. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  8895. {
  8896. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  8897. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  8898. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  8899. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  8900. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  8901. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  8902. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  8903. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  8904. {
  8905. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  8906. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8907. return TRUE;
  8908. }
  8909. else
  8910. {
  8911. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8912. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8913. }
  8914. }
  8915. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  8916. {
  8917. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  8918. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8919. return TRUE;
  8920. }
  8921. //==========================
  8922. // Trigger message
  8923. //==========================
  8924. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  8925. {
  8926. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  8927. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  8928. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  8929. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  8930. {
  8931. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  8932. }
  8933. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  8934. }
  8935. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  8936. {
  8937. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  8938. }
  8939. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  8940. {
  8941. //sendBootNotificationRequest();
  8942. server_sign = FALSE;
  8943. }
  8944. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  8945. {
  8946. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  8947. }
  8948. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  8949. {
  8950. if(connectorIdIsNULL == FALSE)
  8951. {
  8952. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8953. {
  8954. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  8955. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  8956. }
  8957. }
  8958. else
  8959. {
  8960. for(int idx=0;idx< gunTotalNumber;idx++)
  8961. {
  8962. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  8963. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  8964. }
  8965. }
  8966. }
  8967. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8968. {
  8969. if(connectorIdIsNULL == FALSE)
  8970. {
  8971. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8972. {
  8973. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  8974. }
  8975. }
  8976. else
  8977. {
  8978. for(int idx=0;idx< gunTotalNumber;idx++)
  8979. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  8980. }
  8981. }
  8982. return result;
  8983. }
  8984. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8985. {
  8986. mtrace();
  8987. int result = FAIL;
  8988. int connectorIdInt =0;
  8989. char comfirmstr[20]={0};
  8990. int tempIndex = 0;
  8991. json_object *UnlockConnector;
  8992. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8993. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8994. UnlockConnector = json_tokener_parse(payload);
  8995. if(!is_error(UnlockConnector))
  8996. {
  8997. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  8998. {
  8999. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  9000. }
  9001. }
  9002. json_object_put(UnlockConnector);
  9003. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  9004. if(gunTotalNumber == 0)
  9005. {
  9006. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9007. goto end;
  9008. }
  9009. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9010. {
  9011. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9012. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9013. goto end;
  9014. }
  9015. else
  9016. {
  9017. //check Transaction active
  9018. if(gunType[connectorIdInt-1] == 'J')
  9019. {
  9020. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9021. {
  9022. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9023. }
  9024. else
  9025. {
  9026. tempIndex = connectorIdInt -1;
  9027. }
  9028. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9029. {
  9030. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9031. {
  9032. //stop Transaction
  9033. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9034. }
  9035. }
  9036. }
  9037. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9038. {
  9039. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9040. {
  9041. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9042. }
  9043. else
  9044. {
  9045. tempIndex = connectorIdInt -1;
  9046. }
  9047. for (int index = 0; index < CCS_QUANTITY; index++)
  9048. {
  9049. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9050. {
  9051. //stop Transaction
  9052. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9053. }
  9054. }
  9055. }
  9056. else if(gunType[connectorIdInt-1] == 'G')
  9057. {
  9058. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9059. {
  9060. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9061. }
  9062. else
  9063. {
  9064. tempIndex = connectorIdInt -1;
  9065. }
  9066. for (int index = 0; index < GB_QUANTITY; index++)
  9067. {
  9068. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9069. {
  9070. //stop Transaction
  9071. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9072. }
  9073. }
  9074. }
  9075. else
  9076. {
  9077. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9078. {
  9079. tempIndex = 2;
  9080. }
  9081. else
  9082. {
  9083. tempIndex = connectorIdInt-1;
  9084. }
  9085. for (int index = 0; index < AC_QUANTITY; index++)
  9086. {
  9087. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9088. {
  9089. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9090. }
  9091. }
  9092. }
  9093. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9094. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9095. result = TRUE;
  9096. return result;
  9097. }
  9098. end:
  9099. //json_object_put(obj); --- remove temporally
  9100. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9101. return result;
  9102. }
  9103. static char UpdateFirmwarepayloadData[300]={0};
  9104. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9105. {
  9106. mtrace();
  9107. int result = FAIL;
  9108. pthread_t t;
  9109. sendUpdateFirmwareConfirmation(uuid);
  9110. memset(UpdateFirmwarepayloadData, 0, 300);
  9111. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9112. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9113. ////pthread_join(t, NULL); //
  9114. //pthread_detach(t);
  9115. //sendUpdateFirmwareConfirmation(uuid);
  9116. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9117. return result;
  9118. }
  9119. void *UpdateFirmwareProcess(void *data)
  9120. {
  9121. pthread_detach(pthread_self());
  9122. mtrace();
  9123. int retriesInt =0, retryIntervalInt=0;
  9124. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9125. int port=0;
  9126. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9127. int isSuccess = 0;
  9128. char ftpbuf[200];
  9129. char temp[100];
  9130. char * pch;
  9131. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9132. json_object *UpdateFirmware;
  9133. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  9134. if(!is_error(UpdateFirmware))
  9135. {
  9136. // Required data
  9137. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  9138. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  9139. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  9140. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  9141. // Optional data
  9142. if(json_object_object_get(UpdateFirmware, "retries"))
  9143. {
  9144. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  9145. }
  9146. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  9147. {
  9148. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  9149. }
  9150. }
  9151. json_object_put(UpdateFirmware);
  9152. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9153. memset(path, 0, ARRAY_SIZE(path));
  9154. system("rm -f /mnt/*");
  9155. if(strncmp(locationstr,"http", 4) == 0)
  9156. {
  9157. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9158. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9159. // protocol, user, password, host, path);
  9160. sprintf(ftppath,"/%s", path);
  9161. DEBUG_INFO("locationstr: %s\n", locationstr);
  9162. DEBUG_INFO("protocol: %s\n",protocol);
  9163. DEBUG_INFO("host: %s\n",host);
  9164. DEBUG_INFO("path: %s\n",path);
  9165. DEBUG_INFO("ftppath: %s\n",ftppath);
  9166. int ftppathlen=strlen(ftppath);
  9167. int i=1;
  9168. char filenametemp[50];
  9169. while(i < ftppathlen)
  9170. {
  9171. int len=ftppathlen-i;
  9172. if(ftppath[len]== 47) // '/' ascll code: 47
  9173. {
  9174. DEBUG_INFO("compare '/' all right\n");
  9175. break;
  9176. }
  9177. i=i+1;
  9178. }
  9179. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9180. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9181. filenametemp[i+1] = 0;
  9182. do
  9183. {
  9184. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9185. sleep(3);
  9186. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9187. if(!isSuccess)
  9188. {
  9189. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9190. sleep(retryIntervalInt);
  9191. }
  9192. else
  9193. {
  9194. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9195. }
  9196. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9197. }
  9198. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9199. {
  9200. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9201. memset(temp, 0, ARRAY_SIZE(temp));
  9202. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9203. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9204. int ftppathlen=strlen(ftpbuf);
  9205. int i=1;
  9206. char filenametemp[50];
  9207. while(i < ftppathlen)
  9208. {
  9209. int len=ftppathlen-i;
  9210. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9211. {
  9212. DEBUG_INFO(" compare '/' all right\n");
  9213. break;
  9214. }
  9215. i=i+1;
  9216. }
  9217. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9218. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9219. filenametemp[i+1] = 0;
  9220. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9221. pch=strchr(temp,'@');
  9222. if(pch==NULL)
  9223. {
  9224. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9225. protocol, host, &port, path);
  9226. strcpy(user,"anonymous");
  9227. strcpy(password,"");
  9228. }
  9229. else
  9230. {
  9231. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9232. protocol, user, password, host, &port, path);
  9233. }
  9234. sscanf(host,"%[^/]%s",host1, path1);
  9235. sprintf(ftppath,"%s", path1);
  9236. //DEBUG_INFO("protocol =%s\n",protocol);
  9237. //DEBUG_INFO("user =%s\n",user);
  9238. //DEBUG_INFO("password =%s\n",password);
  9239. //DEBUG_INFO("host1 =%s\n",host1);
  9240. //DEBUG_INFO("port =%d\n",port);
  9241. //DEBUG_INFO("path1 =%s\n",path1);
  9242. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9243. //ftpFile(host, user, password, port, ftppath, fname);
  9244. //download firmware pthred
  9245. if(port == 0)
  9246. {
  9247. port = 21;
  9248. }
  9249. do
  9250. {
  9251. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9252. sleep(3);
  9253. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9254. if(!isSuccess)
  9255. {
  9256. //BulldogUtil.sleepMs(interval*1000);
  9257. DEBUG_INFO("Update firmware request and download file fail.\n");
  9258. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9259. sleep(retryIntervalInt);
  9260. }
  9261. else
  9262. {
  9263. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9264. }
  9265. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9266. }
  9267. else
  9268. {
  9269. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9270. }
  9271. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9272. pthread_exit(NULL);
  9273. }
  9274. //==========================================
  9275. // Handle server response routine
  9276. //==========================================
  9277. void handleAuthorizeResponse(char *payload, int gun_index)
  9278. {
  9279. mtrace();
  9280. char expiryDatestr[30]={0};
  9281. char parentIdTagstr[20]={0};
  9282. char statusstr[20]={0};
  9283. char expiryDatestrtemp[30]={0};
  9284. char parentIdTagstrtemp[20]={0};
  9285. char IdTagstrtemp[20]={0};
  9286. char statusstrtemp[20]={0};
  9287. int expiryDateISNULL=FALSE;
  9288. int parentIdTagISNULL=FALSE;
  9289. char sstr[160]={0};
  9290. char* filename = AuthorizationCache_JSON;
  9291. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9292. char *loc;
  9293. int resultRename=0;
  9294. int responseIdTagInfoAsZero= 0;
  9295. char rmFileCmd[50]={0};
  9296. DEBUG_INFO("handleAuthorizeResponse...\n");
  9297. json_object *Authorize;
  9298. Authorize = json_tokener_parse(payload);
  9299. if(!is_error(Authorize))
  9300. {
  9301. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9302. {
  9303. // Required data
  9304. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9305. // Optional data
  9306. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9307. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9308. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9309. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9310. }
  9311. }
  9312. json_object_put(Authorize);
  9313. if(expiryDateISNULL == FALSE)
  9314. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9315. if(parentIdTagISNULL == FALSE)
  9316. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9317. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9318. //Update idTag information to authorization cache if supproted
  9319. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9320. {
  9321. if((access(filename,F_OK))!=-1)
  9322. {
  9323. printf("AuthorizationCache exist.\n");
  9324. }
  9325. else
  9326. {
  9327. printf("AuthorizationCache not exist\n");
  9328. FILE *log = fopen(filename, "w+");
  9329. if(log == NULL)
  9330. {
  9331. printf("log is NULL\n");
  9332. goto out;
  9333. }
  9334. else
  9335. {
  9336. fclose(log);
  9337. }
  9338. }
  9339. FILE *infile;
  9340. FILE *outfile;
  9341. // open file for writing
  9342. infile = fopen (filename, "r");
  9343. outfile = fopen (tempfile, "w");
  9344. int c;
  9345. c = fgetc(infile);
  9346. //DEBUG_INFO("c:%d\n",c);
  9347. rewind(infile);
  9348. if(c == EOF)
  9349. {
  9350. DEBUG_INFO("Orignal File is NULL\n");
  9351. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9352. {
  9353. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9354. }
  9355. else
  9356. {
  9357. strcpy(expiryDatestrtemp, "");
  9358. }
  9359. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9360. {
  9361. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9362. }
  9363. else
  9364. {
  9365. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9366. }
  9367. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9368. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9369. fclose(infile);
  9370. fclose(outfile);
  9371. sprintf(rmFileCmd,"rm -f %s",filename);
  9372. system(rmFileCmd);
  9373. resultRename = rename(tempfile, filename);
  9374. if(resultRename == 0)
  9375. {
  9376. printf("File renamed successfully");
  9377. }
  9378. else
  9379. {
  9380. printf("Error: unable to rename the file");
  9381. }
  9382. }
  9383. else
  9384. {
  9385. char buf[160]={0};
  9386. while (fgets(buf, ARRAY_SIZE(buf), infile) != NULL)
  9387. {
  9388. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9389. memset(expiryDatestr, 0, ARRAY_SIZE(expiryDatestrtemp));
  9390. memset(parentIdTagstr,0, ARRAY_SIZE(parentIdTagstrtemp));
  9391. memset(statusstr, 0, ARRAY_SIZE(statusstrtemp));
  9392. memset(IdTagstrtemp, 0, ARRAY_SIZE(IdTagstrtemp));
  9393. memset(expiryDatestrtemp, 0, ARRAY_SIZE(expiryDatestrtemp));
  9394. memset(parentIdTagstrtemp, 0, ARRAY_SIZE(parentIdTagstrtemp));
  9395. memset(statusstrtemp, 0, ARRAY_SIZE(statusstrtemp));
  9396. //------------------IdTag-----------------------
  9397. loc = strstr(buf, "idTag");
  9398. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9399. c = 0;
  9400. while (loc[3+strlen("idTag")+c] != '\"')
  9401. {
  9402. sstr[c] = loc[3+strlen("idTag")+c];
  9403. c++;
  9404. }
  9405. sstr[c] = '\0';
  9406. strcpy(IdTagstrtemp,sstr);
  9407. //*********************expiryDate***************/
  9408. loc = strstr(buf, "expiryDate");
  9409. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9410. c = 0;
  9411. while (loc[3+strlen("expiryDate")+c] != '\"')
  9412. {
  9413. sstr[c] = loc[3+strlen("expiryDate")+c];
  9414. c++;
  9415. }
  9416. sstr[c] = '\0';
  9417. strcpy(expiryDatestr,sstr);
  9418. //*********************parentIdTag***************/
  9419. loc = strstr(buf, "parentIdTag");
  9420. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9421. c = 0;
  9422. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9423. {
  9424. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9425. c++;
  9426. }
  9427. sstr[c] = '\0';
  9428. strcpy(parentIdTagstr,sstr);
  9429. //*********************status***************/
  9430. loc = strstr(buf, "status");
  9431. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9432. c = 0;
  9433. while (loc[3+strlen("status")+c] != '\"')
  9434. {
  9435. sstr[c] = loc[3+strlen("status")+c];
  9436. c++;
  9437. }
  9438. sstr[c] = '\0';
  9439. strcpy(statusstr,sstr);
  9440. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9441. {
  9442. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9443. responseIdTagInfoAsZero = 1;
  9444. }
  9445. else
  9446. {
  9447. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9448. }
  9449. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9450. {
  9451. //modify item
  9452. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9453. {
  9454. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9455. }
  9456. else
  9457. {
  9458. strcpy(expiryDatestrtemp, "");
  9459. }
  9460. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9461. {
  9462. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9463. }
  9464. else
  9465. {
  9466. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9467. }
  9468. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9469. }
  9470. else
  9471. {
  9472. //wrie original item
  9473. strcpy(expiryDatestrtemp, expiryDatestr);
  9474. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9475. strcpy(statusstrtemp, statusstr);
  9476. }
  9477. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9478. }
  9479. fclose(infile);
  9480. fclose(outfile);
  9481. sprintf(rmFileCmd,"rm -f %s",filename);
  9482. system(rmFileCmd);
  9483. resultRename = rename(tempfile, filename);
  9484. if(resultRename == 0)
  9485. {
  9486. DEBUG_INFO("File renamed successfully");
  9487. }
  9488. else
  9489. {
  9490. DEBUG_INFO("Error: unable to rename the file");
  9491. }
  9492. }
  9493. }
  9494. out:
  9495. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9496. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9497. authorizeRetryTimes = 0;
  9498. }
  9499. char * strtrimc( char * s )
  9500. {
  9501. char * p1 = s;
  9502. char * p2 = s;
  9503. while(*p1 != '\0')
  9504. {
  9505. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9506. {
  9507. if(*p1 != ',')
  9508. {
  9509. p1 ++;
  9510. }
  9511. else
  9512. {
  9513. break;
  9514. }
  9515. }
  9516. if(*p1 != ',')
  9517. {
  9518. * p2 ++ = *p1 ++;
  9519. //printf("p2=%s\n",p2);
  9520. }
  9521. else
  9522. {
  9523. break;
  9524. }
  9525. }
  9526. *p2 = '\0';
  9527. return (s);
  9528. }
  9529. void handleBootNotificationResponse(char *payload, int gun_index)
  9530. {
  9531. mtrace();
  9532. char statusStr[12]={0};
  9533. char currentTimeStr[30]={0};
  9534. int intervalInt = 0;
  9535. struct tm tp;
  9536. char buf[28]={0};
  9537. char timebuf[50]={0};
  9538. DEBUG_INFO("handleBootNotificationResponse...\n");
  9539. json_object *BootNotification;
  9540. BootNotification = json_tokener_parse(payload);
  9541. if(!is_error(BootNotification))
  9542. {
  9543. // Required data
  9544. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9545. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9546. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9547. }
  9548. json_object_put(BootNotification);
  9549. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9550. BootNotificationInterval = intervalInt;
  9551. HeartBeatWaitTime = intervalInt;
  9552. //write back to ShmOCPP16Data->BootNotification
  9553. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9554. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9555. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9556. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9557. {
  9558. server_sign = TRUE;
  9559. server_pending =FALSE;
  9560. }
  9561. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9562. {
  9563. server_pending = TRUE;
  9564. }
  9565. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9566. tp.tm_isdst = -1;
  9567. //time_t utc = mktime(&tp);
  9568. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9569. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9570. sprintf(timebuf,"date -s '%s'",buf);
  9571. system(timebuf);
  9572. srand(time(NULL));
  9573. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  9574. //==============================================
  9575. // RTC sync
  9576. //==============================================
  9577. system("/sbin/hwclock -w --systohc");
  9578. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9579. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9580. }
  9581. void handleDataTransferResponse(char *payload, int gun_index)
  9582. {
  9583. char sstr[160]={0};//sstr[200]={ 0 };
  9584. int c = 0;
  9585. char *loc;
  9586. DEBUG_INFO("handleDataTransferResponse ...\n");
  9587. loc = strstr(payload, "status");
  9588. printf("loc=%s\n",loc);
  9589. c = 0;
  9590. while (loc[3+strlen("status")+c] != '\"')
  9591. {
  9592. sstr[c] = loc[3+strlen("status")+c];
  9593. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9594. c++;
  9595. }
  9596. sstr[c] = '\0';
  9597. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9598. }
  9599. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9600. {
  9601. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9602. //struct json_object *obj;
  9603. // obj = json_tokener_parse(payload);
  9604. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9605. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9606. //No fields are defined.
  9607. }
  9608. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9609. {
  9610. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9611. //struct json_object *obj;
  9612. // obj = json_tokener_parse(payload);
  9613. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9614. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9615. //No fields are defined.
  9616. }
  9617. void handleHeartbeatResponse(char *payload, int gun_index)
  9618. {
  9619. mtrace();
  9620. struct tm tp;
  9621. char buf[28]={0};
  9622. char timebuf[50]={0};
  9623. DEBUG_INFO("handleHeartbeatResponse...\n");
  9624. json_object *Heartbeat;
  9625. Heartbeat = json_tokener_parse(payload);
  9626. if(!is_error(Heartbeat))
  9627. {
  9628. // Required data
  9629. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  9630. }
  9631. json_object_put(Heartbeat);
  9632. if(FirstHeartBeat == 0)
  9633. {
  9634. FirstHeartBeat = 1;
  9635. DEBUG_INFO("FirstHeartBeat \n");
  9636. }
  9637. HeartBeatWithNOResponse = 0;
  9638. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9639. tp.tm_isdst = -1;
  9640. //time_t utc = mktime(&tp);
  9641. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9642. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9643. sprintf(timebuf,"date -s '%s'",buf);
  9644. system(timebuf);
  9645. //==============================================
  9646. // RTC sync
  9647. //==============================================
  9648. system("/sbin/hwclock -w --systohc");
  9649. }
  9650. void handleMeterValuesResponse(char *payload, int gun_index)
  9651. {
  9652. mtrace();
  9653. DEBUG_INFO("handleMeterValuesResponse...\n");
  9654. }
  9655. void handleStartTransactionResponse(char *payload, int gun_index)
  9656. {
  9657. mtrace();
  9658. //int transactionIdInt = 0;
  9659. FILE *outfile;
  9660. char data[100]={0};
  9661. DEBUG_INFO("handleStartTransactionResponse...\n");
  9662. json_object *StartTransaction;
  9663. StartTransaction = json_tokener_parse(payload);
  9664. if(!is_error(StartTransaction))
  9665. {
  9666. // Required data
  9667. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  9668. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  9669. // Optional data
  9670. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  9671. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  9672. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9673. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  9674. }
  9675. json_object_put(StartTransaction);
  9676. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9677. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9678. //-----------Start : write to the Queue TransactionId file -----------------//
  9679. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9680. {}
  9681. else
  9682. {
  9683. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9684. if(log == NULL)
  9685. {
  9686. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9687. return ;
  9688. }
  9689. else
  9690. {
  9691. fclose(log);
  9692. }
  9693. }
  9694. // open file for writing
  9695. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  9696. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  9697. {
  9698. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9699. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9700. fputs(data, outfile);
  9701. fclose (outfile);
  9702. }
  9703. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9704. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9705. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9706. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9707. }
  9708. void handleStatusNotificationResponse(char *payload, int gun_index)
  9709. {
  9710. mtrace();
  9711. DEBUG_INFO("handleStatusNotificationResponse...\n");
  9712. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9713. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9714. }
  9715. void handleStopTransactionnResponse(char *payload, int gun_index)
  9716. {
  9717. mtrace();
  9718. DEBUG_INFO("handleStopTransactionnResponse...\n");
  9719. json_object *StopTransaction;
  9720. StopTransaction = json_tokener_parse(payload);
  9721. if(!is_error(StopTransaction))
  9722. {
  9723. // Optional data
  9724. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  9725. {
  9726. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  9727. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  9728. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  9729. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9730. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  9731. }
  9732. }
  9733. json_object_put(StopTransaction);
  9734. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  9735. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  9736. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9737. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9738. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9739. }
  9740. //==========================================
  9741. // Handle Error routine
  9742. //==========================================
  9743. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9744. {
  9745. mtrace();
  9746. #ifdef SystemLogMessage
  9747. DEBUG_INFO("errorCode: %s\n", errorCode);
  9748. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9749. DEBUG_INFO("errorDetails: %s\n", payload);
  9750. #endif
  9751. }
  9752. //===============================================
  9753. // Common routine
  9754. //===============================================
  9755. int initialConfigurationTable(void)
  9756. {
  9757. //clock_t start_t, end_t, total_t;
  9758. FILE *fp;
  9759. FILE *outfile;
  9760. char str[200]={0};
  9761. char sstr[100]={0};
  9762. int c = 0;
  9763. char *loc;
  9764. DEBUG_INFO("initialConfigurationTable...\n");
  9765. //start_t = clock();
  9766. //printf("Starting of the program, start_t = %ld\n", start_t);
  9767. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  9768. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  9769. {
  9770. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  9771. if(outfile == NULL)
  9772. {
  9773. DEBUG_INFO("Error opening file\n");
  9774. return FALSE;
  9775. }
  9776. /*Core Profile*/
  9777. //AllowOfflineTxForUnknownId
  9778. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9779. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9780. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  9781. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  9782. //AuthorizationCacheEnabled
  9783. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9784. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9785. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9786. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  9787. //AuthorizeRemoteTxRequests
  9788. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9790. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  9791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  9792. //BlinkRepeat
  9793. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9794. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9796. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  9797. //ClockAlignedDataInterval
  9798. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9799. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9801. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  9802. //ConnectionTimeOut
  9803. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9804. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9805. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9806. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  9807. //GetConfigurationMaxKeys
  9808. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9809. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "44" );
  9811. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  9812. // HeartbeatInterval
  9813. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9815. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  9816. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  9817. // LightIntensity
  9818. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9819. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9820. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9821. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  9822. // LocalAuthorizeOffline
  9823. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  9824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9825. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9826. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  9827. // LocalPreAuthorize
  9828. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9829. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9831. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  9832. // MaxEnergyOnInvalidId
  9833. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9834. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9835. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9836. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9837. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  9838. // MeterValuesAlignedData
  9839. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  9840. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9841. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  9843. else
  9844. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  9845. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  9846. // MeterValuesAlignedDataMaxLength
  9847. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9849. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9850. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  9851. else
  9852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9853. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  9854. // MeterValuesSampledData
  9855. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  9856. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9857. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  9859. else
  9860. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  9861. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  9862. // MeterValuesSampledDataMaxLength
  9863. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9865. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9866. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  9867. else
  9868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9869. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  9870. // MeterValueSampleInterval
  9871. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  9874. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  9875. // MinimumStatusDuration
  9876. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  9879. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  9880. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  9881. // NumberOfConnectors
  9882. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9884. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9885. {
  9886. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9887. }
  9888. else
  9889. {
  9890. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9891. }
  9892. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9893. // ResetRetries
  9894. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9895. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9896. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9897. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  9898. // ConnectorPhaseRotation
  9899. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9900. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9901. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9902. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  9903. // ConnectorPhaseRotationMaxLength
  9904. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9905. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9906. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9907. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  9908. // StopTransactionOnEVSideDisconnect
  9909. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9910. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9912. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  9913. // StopTransactionOnInvalidId
  9914. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  9915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9916. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9917. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  9918. // StopTxnAlignedData
  9919. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  9920. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9922. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  9923. // StopTxnAlignedDataMaxLength
  9924. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9925. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9926. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9927. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  9928. // StopTxnSampledData
  9929. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  9930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9931. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9932. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  9933. else
  9934. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  9935. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  9936. // StopTxnSampledDataMaxLength
  9937. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9938. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9939. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9940. {
  9941. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  9942. }
  9943. else
  9944. {
  9945. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  9946. }
  9947. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  9948. // SupportedFeatureProfiles
  9949. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9952. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  9953. // SupportedFeatureProfilesMaxLength
  9954. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9955. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9957. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  9958. // TransactionMessageAttempts
  9959. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9960. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9961. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9962. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9963. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9964. // TransactionMessageRetryInterval
  9965. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9967. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9968. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9969. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9970. // UnlockConnectorOnEVSideDisconnect
  9971. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9974. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  9975. // WebSocketPingInterval
  9976. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9977. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9979. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  9980. // QueueOffLineStartTransactionMessage
  9981. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  9982. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  9983. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  9984. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  9985. // AuthorizationKey
  9986. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  9987. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  9988. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "" );
  9989. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  9990. // SecurityProfile
  9991. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  9992. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  9993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "0" );
  9994. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  9995. // DefaultPrice
  9996. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  9997. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  9998. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  9999. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  10000. // CustomDisplayCostAndPrice
  10001. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  10002. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  10003. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  10004. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  10005. // CustomIdleFeeAfterStop
  10006. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  10007. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  10008. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  10009. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  10010. //* Local Auth List Management Profile*/
  10011. #if 0
  10012. //For OCTT Test Case
  10013. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10016. #endif
  10017. #if 1
  10018. //LocalAuthListEnabled
  10019. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10022. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10023. #endif
  10024. //LocalAuthListMaxLength
  10025. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10026. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10027. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10028. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10029. //SendLocalListMaxLength
  10030. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10031. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10032. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10033. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10034. //ReserveConnectorZeroSupported
  10035. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10037. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10038. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10039. //* Smart Charging Profile */
  10040. //ChargeProfileMaxStackLevel
  10041. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10042. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10043. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10044. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10045. // ChargingScheduleAllowedChargingRateUnit
  10046. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10047. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10048. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10049. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10050. // ChargingScheduleMaxPeriods
  10051. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10052. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10053. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10054. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10055. // ConnectorSwitch3to1PhaseSupported
  10056. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10057. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10058. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10059. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10060. // MaxChargingProfilesInstalled
  10061. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10062. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10063. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "5" );
  10064. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10065. fclose(outfile);
  10066. }
  10067. else
  10068. {
  10069. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10070. char keystr[60]={0};
  10071. char readonlystr[10]={0};
  10072. char valuestr[100]={0};
  10073. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10074. if(fp == NULL) {
  10075. DEBUG_INFO("Error opening file");
  10076. return FALSE;
  10077. }
  10078. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10079. {
  10080. //DEBUG_INFO("Get Configuration \n");
  10081. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10082. //*************************key*********************************/
  10083. loc = strstr(str, "key");
  10084. c = 0;
  10085. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10086. while (loc[strlen("key")+3+c] != '\"')
  10087. {
  10088. sstr[c] = loc[strlen("key")+3+c];
  10089. c++;
  10090. }
  10091. sstr[c] = '\0';
  10092. strcpy(keystr,sstr);
  10093. //*************************readonly*********************************/
  10094. loc = strstr(str, "readonly");
  10095. c = 0;
  10096. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10097. while (loc[strlen("readonly")+2+c] != ',')
  10098. {
  10099. sstr[c] = loc[strlen("readonly")+2+c];
  10100. c++;
  10101. }
  10102. sstr[c] = '\0';
  10103. strcpy(readonlystr,sstr);
  10104. //*************************value*********************************/
  10105. loc = strstr(str, "value");
  10106. c = 0;
  10107. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10108. while (loc[strlen("value")+3+c] != '\"')
  10109. {
  10110. sstr[c] = loc[strlen("value")+3+c];
  10111. c++;
  10112. }
  10113. sstr[c] = '\0';
  10114. strcpy(valuestr,sstr);
  10115. // DEBUG_INFO("keystr=%s\n",keystr);
  10116. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10117. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10118. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10119. {
  10120. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10121. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10122. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10123. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10124. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10125. }
  10126. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10127. {
  10128. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10129. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10130. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10131. }
  10132. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10133. {
  10134. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10135. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10136. }
  10137. if(strcmp(keystr, "BlinkRepeat") == 0)
  10138. {
  10139. //Charger.BlinkRepeat = Integer.parseInt(value);
  10140. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10141. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10142. }
  10143. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10144. {
  10145. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10146. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10147. }
  10148. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10149. {
  10150. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10151. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10152. }
  10153. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10154. {
  10155. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10156. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  10157. }
  10158. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10159. {
  10160. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10161. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10162. HeartBeatWaitTime = atoi(valuestr);
  10163. }
  10164. if(strcmp(keystr, "LightIntensity") == 0)
  10165. {
  10166. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10167. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10168. }
  10169. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10170. {
  10171. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10172. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10173. }
  10174. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10175. {
  10176. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10177. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10178. }
  10179. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10180. {
  10181. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10182. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10183. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10184. }
  10185. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10186. {
  10187. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10188. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10189. }
  10190. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10191. {
  10192. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10193. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10194. }
  10195. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10196. {
  10197. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10198. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10199. }
  10200. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10201. {
  10202. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10204. }
  10205. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10206. {
  10207. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10208. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10209. }
  10210. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10211. {
  10212. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10213. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10214. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10215. }
  10216. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10217. {
  10218. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10219. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10220. }
  10221. if(strcmp(keystr, "ResetRetries") == 0)
  10222. {
  10223. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10224. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10225. }
  10226. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10227. {
  10228. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10229. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10230. }
  10231. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10232. {
  10233. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10234. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10235. }
  10236. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10237. {
  10238. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10239. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10240. }
  10241. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10242. {
  10243. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10244. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10245. }
  10246. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10247. {
  10248. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10249. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10250. }
  10251. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10252. {
  10253. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10254. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10255. }
  10256. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10257. {
  10258. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10259. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10260. }
  10261. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10262. {
  10263. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10264. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10265. }
  10266. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10267. {
  10268. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10269. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10270. }
  10271. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10272. {
  10273. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10274. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10275. }
  10276. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10277. {
  10278. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10279. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10280. TransactionMessageAttemptsValue = atoi(valuestr);
  10281. }
  10282. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10283. {
  10284. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10285. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10286. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10287. }
  10288. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10289. {
  10290. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10291. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10292. }
  10293. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10294. {
  10295. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10296. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10297. }
  10298. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10299. {
  10300. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10301. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10302. }
  10303. if(strcmp(keystr, "AuthorizationKey") == 0)
  10304. {
  10305. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10306. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  10307. }
  10308. if(strcmp(keystr, "SecurityProfile") == 0)
  10309. {
  10310. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10311. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  10312. }
  10313. if(strcmp(keystr, "DefaultPrice") == 0)
  10314. {
  10315. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10316. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  10317. }
  10318. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  10319. {
  10320. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10321. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  10322. }
  10323. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  10324. {
  10325. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10326. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  10327. }
  10328. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10329. {
  10330. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10331. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10332. }
  10333. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10334. {
  10335. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10336. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10337. }
  10338. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10339. {
  10340. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10341. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10342. }
  10343. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10344. {
  10345. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10346. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10347. }
  10348. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10349. {
  10350. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10351. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10352. }
  10353. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10354. {
  10355. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10356. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10357. }
  10358. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10359. {
  10360. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10361. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10362. }
  10363. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10364. {
  10365. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10366. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10367. }
  10368. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10369. {
  10370. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10371. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10372. }
  10373. }
  10374. fclose(fp);
  10375. }
  10376. return 0;
  10377. }
  10378. void StoreConfigurationTable(void)
  10379. {
  10380. FILE *outfile;
  10381. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10382. if(outfile == NULL)
  10383. {
  10384. DEBUG_INFO("Error opening file");
  10385. return ;
  10386. }
  10387. /*Core Profile*/
  10388. //AllowOfflineTxForUnknownId
  10389. /*
  10390. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10391. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10392. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10394. */
  10395. //DEBUG_INFO("data=%s\n",data);
  10396. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10397. //AuthorizationCacheEnabled
  10398. /*
  10399. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10402. */
  10403. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10404. //AuthorizeRemoteTxRequests
  10405. /*
  10406. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10409. */
  10410. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10411. //BlinkRepeat
  10412. /*
  10413. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10416. */
  10417. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10418. //ClockAlignedDataInterval
  10419. /*
  10420. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10423. */
  10424. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10425. //ConnectionTimeOut
  10426. /*
  10427. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10428. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10430. */
  10431. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10432. //GetConfigurationMaxKeys
  10433. /*
  10434. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10435. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10436. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10437. */
  10438. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10439. // HeartbeatInterval
  10440. /*
  10441. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10442. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10444. */
  10445. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10446. // LightIntensity
  10447. /*
  10448. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10449. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10450. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10451. */
  10452. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10453. // LocalAuthorizeOffline
  10454. /*
  10455. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10456. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10457. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10458. */
  10459. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10460. // LocalPreAuthorize
  10461. /*
  10462. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10463. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10464. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10465. */
  10466. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10467. // MaxEnergyOnInvalidId
  10468. /*
  10469. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10470. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10471. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10472. */
  10473. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10474. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10475. // MeterValuesAlignedData
  10476. /*
  10477. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10479. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10480. */
  10481. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10482. // MeterValuesAlignedDataMaxLength
  10483. /*
  10484. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10485. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10486. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10487. */
  10488. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10489. // MeterValuesSampledData
  10490. /*
  10491. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10492. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10493. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10494. */
  10495. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10496. // MeterValuesSampledDataMaxLength
  10497. /*
  10498. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10499. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10500. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10501. */
  10502. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10503. // MeterValueSampleInterval
  10504. /*
  10505. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10506. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10508. */
  10509. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10510. // MinimumStatusDuration
  10511. /*
  10512. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10513. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10514. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10515. */
  10516. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10517. // NumberOfConnectors
  10518. /*
  10519. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10520. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10521. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10522. {
  10523. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10524. }
  10525. else
  10526. {
  10527. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10528. }
  10529. */
  10530. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10531. // ResetRetries
  10532. /*
  10533. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10534. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10536. */
  10537. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10538. // ConnectorPhaseRotation
  10539. /*
  10540. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10543. */
  10544. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10545. // ConnectorPhaseRotationMaxLength
  10546. /*
  10547. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10550. */
  10551. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10552. // StopTransactionOnEVSideDisconnect
  10553. /*
  10554. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10555. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10557. */
  10558. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10559. // StopTransactionOnInvalidId
  10560. /*
  10561. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10564. */
  10565. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10566. // StopTxnAlignedData
  10567. /*
  10568. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10571. */
  10572. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10573. // StopTxnAlignedDataMaxLength
  10574. /*
  10575. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10578. */
  10579. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10580. // StopTxnSampledData
  10581. /*
  10582. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10585. */
  10586. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10587. // StopTxnSampledDataMaxLength
  10588. /*
  10589. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10592. */
  10593. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10594. // SupportedFeatureProfiles
  10595. /*
  10596. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10599. */
  10600. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10601. // SupportedFeatureProfilesMaxLength
  10602. /*
  10603. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10606. */
  10607. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10608. // TransactionMessageAttempts
  10609. /*
  10610. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10613. */
  10614. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10615. // TransactionMessageRetryInterval
  10616. /*
  10617. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10620. */
  10621. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10622. // UnlockConnectorOnEVSideDisconnect
  10623. /*
  10624. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10627. */
  10628. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10629. // WebSocketPingInterval
  10630. /*
  10631. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10634. */
  10635. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10636. // QueueOffLineStartTransactionMessage
  10637. /*
  10638. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  10639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10641. */
  10642. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10643. // AuthorizationKey
  10644. /*
  10645. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  10648. */
  10649. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10650. // SecurityProfile
  10651. /*
  10652. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  10655. */
  10656. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10657. // DefaultPrice
  10658. /*
  10659. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  10660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  10661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  10662. */
  10663. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  10664. // CustomDisplayCostAndPrice
  10665. /*
  10666. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  10667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  10668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  10669. */
  10670. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  10671. // CustomIdleFeeAfterStop
  10672. /*
  10673. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  10674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  10675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  10676. */
  10677. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  10678. //* Local Auth List Management Profile*/
  10679. //LocalAuthListEnabled
  10680. /*
  10681. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10684. */
  10685. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10686. //LocalAuthListMaxLength
  10687. /*
  10688. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10691. */
  10692. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10693. //SendLocalListMaxLength
  10694. /*
  10695. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10698. */
  10699. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10700. //ReserveConnectorZeroSupported
  10701. /*
  10702. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10704. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10705. */
  10706. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10707. //* Smart Charging Profile */
  10708. //ChargeProfileMaxStackLevel
  10709. /*
  10710. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10711. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10712. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10713. */
  10714. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10715. // ChargingScheduleAllowedChargingRateUnit
  10716. /*
  10717. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10718. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10719. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10720. */
  10721. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10722. // ChargingScheduleMaxPeriods
  10723. /*
  10724. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10725. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10726. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10727. */
  10728. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10729. // ConnectorSwitch3to1PhaseSupported
  10730. /*
  10731. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10732. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10733. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10734. */
  10735. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10736. // MaxChargingProfilesInstalled
  10737. /*
  10738. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10739. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10740. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10741. */
  10742. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10743. fclose(outfile);
  10744. }
  10745. void getKeyValue(char *keyReq)
  10746. {
  10747. int isEmpty = FALSE;
  10748. int isKnowKey = FALSE;
  10749. DEBUG_INFO("keyReq = %s\n", keyReq);
  10750. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10751. isEmpty = TRUE;
  10752. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10753. {
  10754. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10755. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10756. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10757. {
  10758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10759. }
  10760. else
  10761. {
  10762. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10763. }
  10764. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10765. isKnowKey = TRUE;
  10766. }
  10767. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10768. {
  10769. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10770. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10771. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10772. {
  10773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10774. }
  10775. else
  10776. {
  10777. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10778. }
  10779. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10780. isKnowKey = TRUE;
  10781. }
  10782. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10783. {
  10784. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10785. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10786. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10787. {
  10788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10789. }
  10790. else
  10791. {
  10792. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10793. }
  10794. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10795. isKnowKey = TRUE;
  10796. }
  10797. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10798. {
  10799. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10800. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  10801. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10802. {
  10803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  10804. }
  10805. else
  10806. {
  10807. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  10808. }
  10809. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  10810. isKnowKey = TRUE;
  10811. }
  10812. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  10813. {
  10814. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  10815. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  10816. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10817. {
  10818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  10819. }
  10820. else
  10821. {
  10822. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  10823. }
  10824. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  10825. isKnowKey = TRUE;
  10826. }
  10827. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  10828. {
  10829. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  10830. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  10831. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10832. {
  10833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  10834. }
  10835. else
  10836. {
  10837. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  10838. }
  10839. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  10840. isKnowKey = TRUE;
  10841. }
  10842. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  10843. {
  10844. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  10845. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  10846. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10847. {
  10848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  10849. }
  10850. else
  10851. {
  10852. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  10853. }
  10854. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  10855. isKnowKey = TRUE;
  10856. }
  10857. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  10858. {
  10859. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  10860. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  10861. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10862. {
  10863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  10864. }
  10865. else
  10866. {
  10867. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  10868. }
  10869. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  10870. isKnowKey = TRUE;
  10871. }
  10872. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  10873. {
  10874. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  10875. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  10876. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10877. {
  10878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  10879. }
  10880. else
  10881. {
  10882. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  10883. }
  10884. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  10885. isKnowKey = TRUE;
  10886. }
  10887. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  10888. {
  10889. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  10890. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  10891. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10892. {
  10893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  10894. }
  10895. else
  10896. {
  10897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  10898. }
  10899. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  10900. isKnowKey = TRUE;
  10901. }
  10902. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  10903. {
  10904. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  10905. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  10906. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10907. {
  10908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  10909. }
  10910. else
  10911. {
  10912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  10913. }
  10914. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  10915. isKnowKey = TRUE;
  10916. }
  10917. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  10918. {
  10919. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  10920. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  10921. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10922. {
  10923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10924. }
  10925. else
  10926. {
  10927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10928. }
  10929. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  10930. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  10931. isKnowKey = TRUE;
  10932. }
  10933. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  10934. {
  10935. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  10936. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  10937. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10938. {
  10939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10940. }
  10941. else
  10942. {
  10943. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10944. }
  10945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  10946. isKnowKey = TRUE;
  10947. }
  10948. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  10949. {
  10950. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  10951. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  10952. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10953. {
  10954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10955. }
  10956. else
  10957. {
  10958. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10959. }
  10960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  10961. isKnowKey = TRUE;
  10962. }
  10963. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  10964. {
  10965. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  10966. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  10967. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10968. {
  10969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  10970. }
  10971. else
  10972. {
  10973. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  10974. }
  10975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  10976. isKnowKey = TRUE;
  10977. }
  10978. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  10979. {
  10980. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  10981. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  10982. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10983. {
  10984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10985. }
  10986. else
  10987. {
  10988. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10989. }
  10990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  10991. isKnowKey = TRUE;
  10992. }
  10993. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  10994. {
  10995. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  10996. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  10997. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10998. {
  10999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11000. }
  11001. else
  11002. {
  11003. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11004. }
  11005. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11006. isKnowKey = TRUE;
  11007. }
  11008. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11009. {
  11010. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11011. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11012. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11013. {
  11014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11015. }
  11016. else
  11017. {
  11018. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11019. }
  11020. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11021. isKnowKey = TRUE;
  11022. }
  11023. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11024. {
  11025. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11026. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11027. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11028. {
  11029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11030. }
  11031. else
  11032. {
  11033. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11034. }
  11035. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11036. isKnowKey = TRUE;
  11037. }
  11038. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11039. {
  11040. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11041. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11042. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11043. {
  11044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11045. }
  11046. else
  11047. {
  11048. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11049. }
  11050. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11051. isKnowKey = TRUE;
  11052. }
  11053. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11054. {
  11055. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11056. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11057. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11058. {
  11059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11060. }
  11061. else
  11062. {
  11063. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11064. }
  11065. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11066. isKnowKey = TRUE;
  11067. }
  11068. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11069. {
  11070. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11071. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11072. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11073. {
  11074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11075. }
  11076. else
  11077. {
  11078. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11079. }
  11080. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11081. isKnowKey = TRUE;
  11082. }
  11083. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11084. {
  11085. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11086. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11087. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11088. {
  11089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11090. }
  11091. else
  11092. {
  11093. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11094. }
  11095. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11096. isKnowKey = TRUE;
  11097. }
  11098. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11099. {
  11100. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11101. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11102. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11103. {
  11104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11105. }
  11106. else
  11107. {
  11108. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11109. }
  11110. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11111. isKnowKey = TRUE;
  11112. }
  11113. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11114. {
  11115. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11116. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11117. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11118. {
  11119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11120. }
  11121. else
  11122. {
  11123. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11124. }
  11125. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11126. isKnowKey = TRUE;
  11127. }
  11128. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11129. {
  11130. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11131. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11132. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11133. {
  11134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11135. }
  11136. else
  11137. {
  11138. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11139. }
  11140. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11141. isKnowKey = TRUE;
  11142. }
  11143. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11144. {
  11145. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11146. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11147. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11148. {
  11149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11150. }
  11151. else
  11152. {
  11153. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11154. }
  11155. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11156. isKnowKey = TRUE;
  11157. }
  11158. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11159. {
  11160. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11161. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11162. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11163. {
  11164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11165. }
  11166. else
  11167. {
  11168. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11169. }
  11170. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11171. isKnowKey = TRUE;
  11172. }
  11173. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11174. {
  11175. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11176. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11177. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11178. {
  11179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11180. }
  11181. else
  11182. {
  11183. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11184. }
  11185. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11186. isKnowKey = TRUE;
  11187. }
  11188. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11189. {
  11190. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11191. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11192. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11193. {
  11194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11195. }
  11196. else
  11197. {
  11198. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11199. }
  11200. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11201. isKnowKey = TRUE;
  11202. }
  11203. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11204. {
  11205. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11206. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11207. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11208. {
  11209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11210. }
  11211. else
  11212. {
  11213. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11214. }
  11215. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11216. isKnowKey = TRUE;
  11217. }
  11218. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11219. {
  11220. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11221. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11222. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11223. {
  11224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11225. }
  11226. else
  11227. {
  11228. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11229. }
  11230. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11231. isKnowKey = TRUE;
  11232. }
  11233. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11234. {
  11235. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11236. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11237. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11238. {
  11239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11240. }
  11241. else
  11242. {
  11243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11244. }
  11245. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11246. isKnowKey = TRUE;
  11247. }
  11248. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11249. {
  11250. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11251. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11252. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11253. {
  11254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11255. }
  11256. else
  11257. {
  11258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11259. }
  11260. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11261. isKnowKey = TRUE;
  11262. }
  11263. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11264. {
  11265. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11266. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11267. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11268. {
  11269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11270. }
  11271. else
  11272. {
  11273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11274. }
  11275. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11276. isKnowKey = TRUE;
  11277. }
  11278. /*
  11279. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  11280. {
  11281. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  11282. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  11283. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  11284. {
  11285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  11286. }
  11287. else
  11288. {
  11289. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  11290. }
  11291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  11292. isKnowKey = TRUE;
  11293. }*/
  11294. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  11295. {
  11296. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  11297. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  11298. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  11299. {
  11300. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  11301. }
  11302. else
  11303. {
  11304. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  11305. }
  11306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  11307. isKnowKey = TRUE;
  11308. }
  11309. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  11310. {
  11311. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  11312. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  11313. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  11314. {
  11315. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  11316. }
  11317. else
  11318. {
  11319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  11320. }
  11321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  11322. isKnowKey = TRUE;
  11323. }
  11324. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  11325. {
  11326. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  11327. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  11328. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  11329. {
  11330. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  11331. }
  11332. else
  11333. {
  11334. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  11335. }
  11336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  11337. isKnowKey = TRUE;
  11338. }
  11339. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  11340. {
  11341. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  11342. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  11343. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  11344. {
  11345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  11346. }
  11347. else
  11348. {
  11349. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  11350. }
  11351. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  11352. isKnowKey = TRUE;
  11353. }
  11354. #if 1
  11355. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11356. {
  11357. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11358. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11359. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11360. {
  11361. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11362. }
  11363. else
  11364. {
  11365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11366. }
  11367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11368. isKnowKey = TRUE;
  11369. }
  11370. #endif
  11371. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11372. {
  11373. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11374. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11375. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11376. {
  11377. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11378. }
  11379. else
  11380. {
  11381. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11382. }
  11383. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11384. isKnowKey = TRUE;
  11385. }
  11386. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11387. {
  11388. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11389. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11390. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11391. {
  11392. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11393. }
  11394. else
  11395. {
  11396. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11397. }
  11398. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11399. isKnowKey = TRUE;
  11400. }
  11401. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11402. {
  11403. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11404. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11405. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11406. {
  11407. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11408. }
  11409. else
  11410. {
  11411. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11412. }
  11413. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11414. isKnowKey = TRUE;
  11415. }
  11416. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11417. {
  11418. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11419. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11420. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11421. {
  11422. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11423. }
  11424. else
  11425. {
  11426. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11427. }
  11428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11429. isKnowKey = TRUE;
  11430. }
  11431. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11432. {
  11433. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11434. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11435. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11436. {
  11437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11438. }
  11439. else
  11440. {
  11441. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11442. }
  11443. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11444. isKnowKey = TRUE;
  11445. }
  11446. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11447. {
  11448. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11449. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11450. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11451. {
  11452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11453. }
  11454. else
  11455. {
  11456. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11457. }
  11458. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11459. isKnowKey = TRUE;
  11460. }
  11461. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11462. {
  11463. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11464. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11465. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11466. {
  11467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11468. }
  11469. else
  11470. {
  11471. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11472. }
  11473. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11474. isKnowKey = TRUE;
  11475. }
  11476. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11477. {
  11478. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11479. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11480. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11481. {
  11482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11483. }
  11484. else
  11485. {
  11486. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11487. }
  11488. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11489. isKnowKey = TRUE;
  11490. }
  11491. //=========================================================
  11492. if(!isEmpty && !isKnowKey)
  11493. {
  11494. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11495. strcpy(unknownkey[UnknownKeynum], keyReq);
  11496. UnknownKeynum = UnknownKeynum + 1;
  11497. }
  11498. }
  11499. void processUnkownKey(void)
  11500. {
  11501. DEBUG_INFO("processUnkownKey...\n");
  11502. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11503. for(int index=0; index < UnknownKeynum; index++)
  11504. {
  11505. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11506. {
  11507. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11508. }
  11509. }
  11510. }
  11511. int setKeyValue(char *key, char *value)
  11512. {
  11513. int isSuccess = NotSupported;
  11514. int check_ascii=0;
  11515. char str[10]={0};
  11516. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11517. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11518. {
  11519. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11520. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11521. {
  11522. strcpy(str, (const char*)value);
  11523. for(int i = 0; str[i]; i++){
  11524. str[i] = tolower(str[i]);
  11525. }
  11526. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11527. isSuccess = ConfigurationStatus_Accepted;
  11528. }
  11529. else
  11530. {
  11531. isSuccess = ConfigurationStatus_Rejected;
  11532. }
  11533. }
  11534. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11535. {
  11536. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11537. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11538. {
  11539. strcpy(str, (const char*)value);
  11540. for(int i = 0; str[i]; i++){
  11541. str[i] = tolower(str[i]);
  11542. }
  11543. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11544. isSuccess = ConfigurationStatus_Accepted;
  11545. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11546. }
  11547. else
  11548. {
  11549. isSuccess = ConfigurationStatus_Rejected;
  11550. }
  11551. }
  11552. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11553. {
  11554. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11555. {
  11556. strcpy(str, (const char*)value);
  11557. for(int i = 0; str[i]; i++)
  11558. {
  11559. str[i] = tolower(str[i]);
  11560. }
  11561. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11562. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11563. isSuccess = ConfigurationStatus_Accepted;
  11564. }
  11565. else
  11566. {
  11567. isSuccess = ConfigurationStatus_Rejected;
  11568. }
  11569. }
  11570. if(strcmp(key, "BlinkRepeat") == 0)
  11571. {
  11572. //Charger.BlinkRepeat = Integer.parseInt(value);
  11573. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11574. {
  11575. check_ascii = value[0];
  11576. if( (check_ascii < 48) || (check_ascii > 57) )
  11577. {
  11578. isSuccess = ConfigurationStatus_Rejected;
  11579. }
  11580. else
  11581. {
  11582. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11583. isSuccess = ConfigurationStatus_Accepted;
  11584. }
  11585. }
  11586. else
  11587. {
  11588. isSuccess = ConfigurationStatus_Rejected;
  11589. }
  11590. }
  11591. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11592. {
  11593. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11594. {
  11595. check_ascii = value[0];
  11596. if( (check_ascii < 48) || (check_ascii > 57) )
  11597. {
  11598. isSuccess = ConfigurationStatus_Rejected;
  11599. }
  11600. else
  11601. {
  11602. if((atoi(value) == 0) || (atoi(value) >= 10))
  11603. {
  11604. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11605. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11606. isSuccess = ConfigurationStatus_Accepted;
  11607. }
  11608. else
  11609. isSuccess = ConfigurationStatus_Rejected;
  11610. }
  11611. }
  11612. else
  11613. {
  11614. isSuccess = ConfigurationStatus_Rejected;
  11615. }
  11616. }
  11617. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11618. {
  11619. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11620. {
  11621. check_ascii = value[0];
  11622. if( (check_ascii < 48) || (check_ascii > 57) )
  11623. {
  11624. isSuccess = ConfigurationStatus_Rejected;
  11625. }
  11626. else
  11627. {
  11628. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11629. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11630. isSuccess = ConfigurationStatus_Accepted;
  11631. }
  11632. }
  11633. else
  11634. {
  11635. isSuccess = ConfigurationStatus_Rejected;
  11636. }
  11637. }
  11638. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11639. {
  11640. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11641. {
  11642. check_ascii = value[0];
  11643. if( (check_ascii < 48) || (check_ascii > 57) )
  11644. {
  11645. isSuccess = ConfigurationStatus_Rejected;
  11646. }
  11647. else
  11648. {
  11649. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11650. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11651. isSuccess = ConfigurationStatus_Accepted;
  11652. }
  11653. }
  11654. else
  11655. {
  11656. isSuccess = ConfigurationStatus_Rejected;
  11657. }
  11658. }
  11659. if(strcmp(key, "HeartbeatInterval") == 0)
  11660. {
  11661. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11662. {
  11663. check_ascii = value[0];
  11664. if( (check_ascii < 48) || (check_ascii > 57) )
  11665. {
  11666. isSuccess = ConfigurationStatus_Rejected;
  11667. }
  11668. else
  11669. {
  11670. if((atoi(value) == 0) || (atoi(value) >= 10))
  11671. {
  11672. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11673. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11674. HeartBeatWaitTime = atoi(value);
  11675. isSuccess = ConfigurationStatus_Accepted;
  11676. }
  11677. else
  11678. {
  11679. isSuccess = ConfigurationStatus_Rejected;
  11680. }
  11681. }
  11682. }
  11683. else
  11684. {
  11685. isSuccess = ConfigurationStatus_Rejected;
  11686. }
  11687. }
  11688. if(strcmp(key, "LightIntensity") == 0)
  11689. {
  11690. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11691. {
  11692. check_ascii = value[0];
  11693. if( (check_ascii < 48) || (check_ascii > 57) )
  11694. {
  11695. isSuccess = ConfigurationStatus_Rejected;
  11696. }
  11697. else
  11698. {
  11699. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11700. isSuccess = ConfigurationStatus_Accepted;
  11701. }
  11702. }
  11703. else
  11704. {
  11705. isSuccess = ConfigurationStatus_Rejected;
  11706. }
  11707. }
  11708. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11709. {
  11710. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11711. {
  11712. strcpy(str, (const char*)value);
  11713. for(int i = 0; str[i]; i++)
  11714. {
  11715. str[i] = tolower(str[i]);
  11716. }
  11717. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11718. isSuccess = ConfigurationStatus_Accepted;
  11719. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11720. }
  11721. else
  11722. {
  11723. isSuccess = ConfigurationStatus_Rejected;
  11724. }
  11725. }
  11726. if(strcmp(key, "LocalPreAuthorize") == 0)
  11727. {
  11728. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11729. {
  11730. strcpy(str, (const char*)value);
  11731. for(int i = 0; str[i]; i++)
  11732. {
  11733. str[i] = tolower(str[i]);
  11734. }
  11735. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11736. isSuccess = ConfigurationStatus_Accepted;
  11737. }
  11738. else
  11739. {
  11740. isSuccess = ConfigurationStatus_Rejected;
  11741. }
  11742. }
  11743. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11744. {
  11745. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11746. {
  11747. check_ascii = value[0];
  11748. if( (check_ascii < 48) || (check_ascii > 57) )
  11749. {
  11750. isSuccess = ConfigurationStatus_Rejected;
  11751. }
  11752. else
  11753. {
  11754. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11755. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11756. isSuccess = ConfigurationStatus_Accepted;
  11757. }
  11758. }
  11759. else
  11760. {
  11761. isSuccess = ConfigurationStatus_Rejected;
  11762. }
  11763. }
  11764. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11765. {
  11766. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11767. {
  11768. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11769. isSuccess = ConfigurationStatus_Accepted;
  11770. }
  11771. else
  11772. {
  11773. isSuccess = ConfigurationStatus_Rejected;
  11774. }
  11775. }
  11776. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11777. {
  11778. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11779. {
  11780. check_ascii = value[0];
  11781. if( (check_ascii < 48) || (check_ascii > 57) )
  11782. {
  11783. isSuccess = ConfigurationStatus_Rejected;
  11784. }
  11785. else
  11786. {
  11787. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11788. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11789. isSuccess = ConfigurationStatus_Accepted;
  11790. }
  11791. }
  11792. else
  11793. {
  11794. isSuccess = ConfigurationStatus_Rejected;
  11795. }
  11796. }
  11797. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11798. {
  11799. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11800. {
  11801. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11802. isSuccess = ConfigurationStatus_Accepted;
  11803. }
  11804. else
  11805. {
  11806. isSuccess = ConfigurationStatus_Rejected;
  11807. }
  11808. }
  11809. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11810. {
  11811. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11812. {
  11813. check_ascii = value[0];
  11814. if( (check_ascii < 48) || (check_ascii > 57) )
  11815. {
  11816. isSuccess = ConfigurationStatus_Rejected;
  11817. }
  11818. else
  11819. {
  11820. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11821. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11822. isSuccess = ConfigurationStatus_Accepted;
  11823. }
  11824. }
  11825. else
  11826. {
  11827. isSuccess = ConfigurationStatus_Rejected;
  11828. }
  11829. }
  11830. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11831. {
  11832. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11833. {
  11834. check_ascii = value[0];
  11835. if( (check_ascii < 48) || (check_ascii > 57) )
  11836. {
  11837. isSuccess = ConfigurationStatus_Rejected;
  11838. }
  11839. else
  11840. {
  11841. if((atoi(value) == 0) || (atoi(value) >= 10))
  11842. {
  11843. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11844. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  11845. isSuccess = ConfigurationStatus_Accepted;
  11846. }
  11847. else
  11848. {
  11849. isSuccess = ConfigurationStatus_Rejected;
  11850. }
  11851. }
  11852. }
  11853. else
  11854. {
  11855. isSuccess = ConfigurationStatus_Rejected;
  11856. }
  11857. }
  11858. if(strcmp(key, "MinimumStatusDuration") == 0)
  11859. {
  11860. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11861. {
  11862. check_ascii = value[0];
  11863. if( (check_ascii < 48) || (check_ascii > 57) )
  11864. {
  11865. isSuccess = ConfigurationStatus_Rejected;
  11866. }
  11867. else
  11868. {
  11869. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  11870. {
  11871. isSuccess = ConfigurationStatus_Rejected;
  11872. }
  11873. else
  11874. {
  11875. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  11876. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  11877. server_cycle_Status = atoi(value); //StatusNotification Cycle
  11878. isSuccess = ConfigurationStatus_Accepted;
  11879. }
  11880. }
  11881. }
  11882. else
  11883. {
  11884. isSuccess = ConfigurationStatus_Rejected;
  11885. }
  11886. }
  11887. if(strcmp(key, "NumberOfConnectors") == 0)
  11888. {
  11889. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11890. {
  11891. check_ascii = value[0];
  11892. if( (check_ascii < 48) || (check_ascii > 57) )
  11893. {
  11894. isSuccess = ConfigurationStatus_Rejected;
  11895. }
  11896. else
  11897. {
  11898. //Charger.ResetRetries = Integer.parseInt(value);
  11899. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  11900. isSuccess = ConfigurationStatus_Accepted;
  11901. }
  11902. }
  11903. else
  11904. {
  11905. isSuccess = ConfigurationStatus_Rejected;
  11906. }
  11907. }
  11908. if(strcmp(key, "ResetRetries") == 0)
  11909. {
  11910. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11911. {
  11912. check_ascii = value[0];
  11913. if( (check_ascii < 48) || (check_ascii > 57) )
  11914. {
  11915. isSuccess = ConfigurationStatus_Rejected;
  11916. }
  11917. else
  11918. {
  11919. //Charger.ResetRetries = Integer.parseInt(value);
  11920. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  11921. isSuccess = ConfigurationStatus_Accepted;
  11922. }
  11923. }
  11924. else
  11925. {
  11926. isSuccess = ConfigurationStatus_Rejected;
  11927. }
  11928. }
  11929. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  11930. {
  11931. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11932. {
  11933. strcpy(str, (const char*)value);
  11934. for(int i = 0; str[i]; i++)
  11935. {
  11936. str[i] = tolower(str[i]);
  11937. }
  11938. if(strcmp(str, "notapplicable")== 0)
  11939. {
  11940. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  11941. isSuccess = ConfigurationStatus_Accepted;
  11942. }
  11943. else if(strcmp(str, "unknown")== 0)
  11944. {
  11945. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  11946. isSuccess = ConfigurationStatus_Accepted;
  11947. }
  11948. else if(strcmp(str, "rst")== 0)
  11949. {
  11950. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  11951. isSuccess = ConfigurationStatus_Accepted;
  11952. }
  11953. else if(strcmp(str, "rts")== 0)
  11954. {
  11955. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  11956. isSuccess = ConfigurationStatus_Accepted;
  11957. }
  11958. else if(strcmp(str, "srt")== 0)
  11959. {
  11960. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  11961. isSuccess = ConfigurationStatus_Accepted;
  11962. }
  11963. else if(strcmp(str, "str")== 0)
  11964. {
  11965. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  11966. isSuccess = ConfigurationStatus_Accepted;
  11967. }
  11968. else if(strcmp(str, "trs")== 0)
  11969. {
  11970. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  11971. isSuccess = ConfigurationStatus_Accepted;
  11972. }
  11973. else if(strcmp(str, "tsr")== 0)
  11974. {
  11975. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  11976. isSuccess = ConfigurationStatus_Accepted;
  11977. }
  11978. else
  11979. {
  11980. isSuccess = ConfigurationStatus_Rejected;
  11981. }
  11982. }
  11983. else
  11984. {
  11985. isSuccess = ConfigurationStatus_Rejected;
  11986. }
  11987. }
  11988. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  11989. {
  11990. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11991. {
  11992. check_ascii = value[0];
  11993. if( (check_ascii < 48) || (check_ascii > 57) )
  11994. {
  11995. isSuccess = ConfigurationStatus_Rejected;
  11996. }
  11997. else
  11998. {
  11999. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12000. isSuccess = ConfigurationStatus_Accepted;
  12001. }
  12002. }
  12003. else
  12004. {
  12005. isSuccess = ConfigurationStatus_Rejected;
  12006. }
  12007. }
  12008. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12009. {
  12010. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12011. {
  12012. strcpy(str, (const char*)value);
  12013. for(int i = 0; str[i]; i++)
  12014. {
  12015. str[i] = tolower(str[i]);
  12016. }
  12017. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12018. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12019. isSuccess = ConfigurationStatus_Accepted;
  12020. }
  12021. else
  12022. {
  12023. isSuccess = ConfigurationStatus_Rejected;
  12024. }
  12025. }
  12026. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12027. {
  12028. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12029. {
  12030. strcpy(str, (const char*)value);
  12031. for(int i = 0; str[i]; i++)
  12032. {
  12033. str[i] = tolower(str[i]);
  12034. }
  12035. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12036. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12037. isSuccess = ConfigurationStatus_Accepted;
  12038. }
  12039. else
  12040. {
  12041. isSuccess = ConfigurationStatus_Rejected;
  12042. }
  12043. }
  12044. if(strcmp(key, "StopTxnAlignedData") == 0)
  12045. {
  12046. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12047. {
  12048. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12049. isSuccess = ConfigurationStatus_Accepted;
  12050. }
  12051. else
  12052. {
  12053. isSuccess = ConfigurationStatus_Rejected;
  12054. }
  12055. }
  12056. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12057. {
  12058. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12059. {
  12060. check_ascii = value[0];
  12061. if( (check_ascii < 48) || (check_ascii > 57) )
  12062. {
  12063. isSuccess = ConfigurationStatus_Rejected;
  12064. }
  12065. else
  12066. {
  12067. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12068. isSuccess = ConfigurationStatus_Accepted;
  12069. }
  12070. }
  12071. else
  12072. {
  12073. isSuccess = ConfigurationStatus_Rejected;
  12074. }
  12075. }
  12076. if(strcmp(key, "StopTxnSampledData") == 0)
  12077. {
  12078. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12079. {
  12080. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12081. isSuccess = ConfigurationStatus_Accepted;
  12082. }
  12083. else
  12084. {
  12085. isSuccess = ConfigurationStatus_Rejected;
  12086. }
  12087. }
  12088. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12089. {
  12090. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12091. {
  12092. check_ascii = value[0];
  12093. if( (check_ascii < 48) || (check_ascii > 57) )
  12094. {
  12095. isSuccess = ConfigurationStatus_Rejected;
  12096. }
  12097. else
  12098. {
  12099. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12100. isSuccess = ConfigurationStatus_Accepted;
  12101. }
  12102. }
  12103. else
  12104. {
  12105. isSuccess = ConfigurationStatus_Rejected;
  12106. }
  12107. }
  12108. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12109. {
  12110. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12111. {
  12112. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12113. isSuccess = ConfigurationStatus_Accepted;
  12114. }
  12115. else
  12116. {
  12117. isSuccess = ConfigurationStatus_Rejected;
  12118. }
  12119. }
  12120. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12121. {
  12122. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12123. {
  12124. check_ascii = value[0];
  12125. if( (check_ascii < 48) || (check_ascii > 57) )
  12126. {
  12127. isSuccess = ConfigurationStatus_Rejected;
  12128. }
  12129. else
  12130. {
  12131. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12132. isSuccess = ConfigurationStatus_Accepted;
  12133. }
  12134. }
  12135. else
  12136. {
  12137. isSuccess = ConfigurationStatus_Rejected;
  12138. }
  12139. }
  12140. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12141. {
  12142. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12143. {
  12144. check_ascii = value[0];
  12145. if( (check_ascii < 48) || (check_ascii > 57) )
  12146. {
  12147. isSuccess = ConfigurationStatus_Rejected;
  12148. }
  12149. else
  12150. {
  12151. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12152. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12153. TransactionMessageAttemptsValue = atoi(value);
  12154. isSuccess = ConfigurationStatus_Accepted;
  12155. }
  12156. }
  12157. else
  12158. {
  12159. isSuccess = ConfigurationStatus_Rejected;
  12160. }
  12161. }
  12162. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12163. {
  12164. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12165. {
  12166. check_ascii = value[0];
  12167. if( (check_ascii < 48) || (check_ascii > 57) )
  12168. {
  12169. isSuccess = ConfigurationStatus_Rejected;
  12170. }
  12171. else
  12172. {
  12173. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12174. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12175. TransactionMessageRetryIntervalValue = atoi(value);
  12176. isSuccess = ConfigurationStatus_Accepted;
  12177. }
  12178. }
  12179. else
  12180. {
  12181. isSuccess = ConfigurationStatus_Rejected;
  12182. }
  12183. }
  12184. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12185. {
  12186. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12187. {
  12188. strcpy(str, (const char*)value);
  12189. for(int i = 0; str[i]; i++)
  12190. {
  12191. str[i] = tolower(str[i]);
  12192. }
  12193. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12194. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12195. isSuccess = ConfigurationStatus_Accepted;
  12196. }
  12197. else
  12198. {
  12199. isSuccess = ConfigurationStatus_Rejected;
  12200. }
  12201. }
  12202. if(strcmp(key, "WebSocketPingInterval") == 0)
  12203. {
  12204. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12205. {
  12206. check_ascii = value[0];
  12207. if( (check_ascii < 48) || (check_ascii > 57) )
  12208. {
  12209. isSuccess = ConfigurationStatus_Rejected;
  12210. }
  12211. else
  12212. {
  12213. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12214. isSuccess = ConfigurationStatus_Accepted;
  12215. }
  12216. }
  12217. else
  12218. {
  12219. isSuccess = ConfigurationStatus_Rejected;
  12220. }
  12221. }
  12222. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12223. {
  12224. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12225. {
  12226. strcpy(str, (const char*)value);
  12227. for(int i = 0; str[i]; i++)
  12228. {
  12229. str[i] = tolower(str[i]);
  12230. }
  12231. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12232. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12233. isSuccess = ConfigurationStatus_Accepted;
  12234. }
  12235. else
  12236. {
  12237. isSuccess = ConfigurationStatus_Rejected;
  12238. }
  12239. }
  12240. if(strcmp(key, "AuthorizationKey") == 0)
  12241. {
  12242. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  12243. {
  12244. strcpy(str, (const char*)value);
  12245. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  12246. isSuccess = ConfigurationStatus_Accepted;
  12247. }
  12248. else
  12249. {
  12250. isSuccess = ConfigurationStatus_Rejected;
  12251. }
  12252. }
  12253. if(strcmp(key, "SecurityProfile") == 0)
  12254. {
  12255. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12256. {
  12257. check_ascii = value[0];
  12258. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  12259. {
  12260. isSuccess = ConfigurationStatus_Rejected;
  12261. }
  12262. else if(check_ascii == 0x33)
  12263. {
  12264. isSuccess = NotSupported;
  12265. }
  12266. else
  12267. {
  12268. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  12269. {
  12270. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  12271. isSuccess = ConfigurationStatus_Accepted;
  12272. }
  12273. else
  12274. isSuccess = ConfigurationStatus_Rejected;
  12275. }
  12276. }
  12277. else
  12278. {
  12279. isSuccess = ConfigurationStatus_Rejected;
  12280. }
  12281. }
  12282. if(strcmp(key, "DefaultPrice") == 0)
  12283. {
  12284. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  12285. {
  12286. strcpy(str, (const char*)value);
  12287. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  12288. isSuccess = ConfigurationStatus_Accepted;
  12289. }
  12290. else
  12291. {
  12292. isSuccess = ConfigurationStatus_Rejected;
  12293. }
  12294. }
  12295. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  12296. {
  12297. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12298. {
  12299. strcpy(str, (const char*)value);
  12300. for(int i = 0; str[i]; i++)
  12301. {
  12302. str[i] = tolower(str[i]);
  12303. }
  12304. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12305. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12306. isSuccess = ConfigurationStatus_Accepted;
  12307. }
  12308. else
  12309. {
  12310. isSuccess = ConfigurationStatus_Rejected;
  12311. }
  12312. }
  12313. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  12314. {
  12315. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12316. {
  12317. strcpy(str, (const char*)value);
  12318. for(int i = 0; str[i]; i++)
  12319. {
  12320. str[i] = tolower(str[i]);
  12321. }
  12322. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12323. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12324. isSuccess = ConfigurationStatus_Accepted;
  12325. }
  12326. else
  12327. {
  12328. isSuccess = ConfigurationStatus_Rejected;
  12329. }
  12330. }
  12331. #if 0
  12332. //For OCPP Test Case
  12333. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12334. {
  12335. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12336. {
  12337. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12338. isSuccess = ConfigurationStatus_Accepted;
  12339. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12340. }
  12341. else
  12342. {
  12343. isSuccess = ConfigurationStatus_Rejected;
  12344. }
  12345. }
  12346. #endif
  12347. #if 1
  12348. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12349. {
  12350. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12351. {
  12352. strcpy(str, (const char*)value);
  12353. for(int i = 0; str[i]; i++)
  12354. {
  12355. str[i] = tolower(str[i]);
  12356. }
  12357. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12358. isSuccess = ConfigurationStatus_Accepted;
  12359. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12360. }
  12361. else
  12362. {
  12363. isSuccess = ConfigurationStatus_Rejected;
  12364. }
  12365. }
  12366. #endif
  12367. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12368. {
  12369. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12370. {
  12371. check_ascii = value[0];
  12372. if( (check_ascii < 48) || (check_ascii > 57) )
  12373. {
  12374. isSuccess = ConfigurationStatus_Rejected;
  12375. }
  12376. else
  12377. {
  12378. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12379. isSuccess = ConfigurationStatus_Accepted;
  12380. }
  12381. }
  12382. else
  12383. {
  12384. isSuccess = ConfigurationStatus_Rejected;
  12385. }
  12386. }
  12387. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12388. {
  12389. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12390. {
  12391. check_ascii = value[0];
  12392. if( (check_ascii < 48) || (check_ascii > 57) )
  12393. {
  12394. isSuccess = ConfigurationStatus_Rejected;
  12395. }
  12396. else
  12397. {
  12398. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12399. isSuccess = ConfigurationStatus_Accepted;
  12400. }
  12401. }
  12402. else
  12403. {
  12404. isSuccess = ConfigurationStatus_Rejected;
  12405. }
  12406. }
  12407. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12408. {
  12409. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12410. {
  12411. strcpy(str, (const char*)value);
  12412. for(int i = 0; str[i]; i++)
  12413. {
  12414. str[i] = tolower(str[i]);
  12415. }
  12416. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12417. isSuccess = ConfigurationStatus_Accepted;
  12418. }
  12419. else
  12420. {
  12421. isSuccess = ConfigurationStatus_Rejected;
  12422. }
  12423. }
  12424. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12425. {
  12426. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12427. {
  12428. check_ascii = value[0];
  12429. if( (check_ascii < 48) || (check_ascii > 57) )
  12430. {
  12431. isSuccess = ConfigurationStatus_Rejected;
  12432. }
  12433. else
  12434. {
  12435. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12436. isSuccess = ConfigurationStatus_Accepted;
  12437. }
  12438. }
  12439. else
  12440. {
  12441. isSuccess = ConfigurationStatus_Rejected;
  12442. }
  12443. }
  12444. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12445. {
  12446. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12447. {
  12448. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12449. isSuccess = ConfigurationStatus_Accepted;
  12450. }
  12451. else
  12452. {
  12453. isSuccess = ConfigurationStatus_Rejected;
  12454. }
  12455. }
  12456. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12457. {
  12458. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12459. {
  12460. check_ascii = value[0];
  12461. if( (check_ascii < 48) || (check_ascii > 57) )
  12462. {
  12463. isSuccess = ConfigurationStatus_Rejected;
  12464. }
  12465. else
  12466. {
  12467. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12468. isSuccess = ConfigurationStatus_Accepted;
  12469. }
  12470. }
  12471. else
  12472. {
  12473. isSuccess = ConfigurationStatus_Rejected;
  12474. }
  12475. }
  12476. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12477. {
  12478. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12479. {
  12480. strcpy(str, (const char*)value);
  12481. for(int i = 0; str[i]; i++)
  12482. {
  12483. str[i] = tolower(str[i]);
  12484. }
  12485. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12486. isSuccess = ConfigurationStatus_Accepted;
  12487. }
  12488. else
  12489. {
  12490. isSuccess = ConfigurationStatus_Rejected;
  12491. }
  12492. }
  12493. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12494. {
  12495. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12496. {
  12497. check_ascii = value[0];
  12498. if( (check_ascii < 48) || (check_ascii > 57) )
  12499. {
  12500. isSuccess = ConfigurationStatus_Rejected;
  12501. }
  12502. else
  12503. {
  12504. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12505. isSuccess = ConfigurationStatus_Accepted;
  12506. }
  12507. }
  12508. else
  12509. {
  12510. isSuccess = ConfigurationStatus_Rejected;
  12511. }
  12512. }
  12513. return isSuccess;
  12514. }
  12515. int TransactionMessageAttemptsGet(void)
  12516. {
  12517. return TransactionMessageAttemptsValue;
  12518. }
  12519. int FirstHeartBeatResponse(void)
  12520. {
  12521. return FirstHeartBeat;
  12522. }
  12523. int TransactionMessageRetryIntervalGet(void)
  12524. {
  12525. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12526. }
  12527. int ReadHttpStatus(int sock)
  12528. {
  12529. //char c;
  12530. char buff[1024]="",*ptr=buff+1;
  12531. int bytes_received, status;
  12532. DEBUG_INFO("Begin Response ..\n");
  12533. while((bytes_received = recv(sock, ptr, 1, 0))){
  12534. if(bytes_received==-1){
  12535. perror("ReadHttpStatus");
  12536. exit(1);
  12537. }
  12538. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12539. ptr++;
  12540. }
  12541. *ptr=0;
  12542. ptr=buff+1;
  12543. sscanf(ptr,"%*s %d ", &status);
  12544. DEBUG_INFO("%s\n",ptr);
  12545. DEBUG_INFO("status=%d\n",status);
  12546. DEBUG_INFO("End Response ..\n");
  12547. return (bytes_received>0)?status:0;
  12548. }
  12549. //the only filed that it parsed is 'Content-Length'
  12550. int ParseHeader(int sock)
  12551. {
  12552. //char c;
  12553. char buff[1024]="",*ptr=buff+4;
  12554. int bytes_received;
  12555. DEBUG_INFO("Begin HEADER ..\n");
  12556. while((bytes_received = recv(sock, ptr, 1, 0))){
  12557. if(bytes_received==-1){
  12558. perror("Parse Header");
  12559. exit(1);
  12560. }
  12561. if(
  12562. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12563. (ptr[-1]=='\r') && (*ptr=='\n' )
  12564. ) break;
  12565. ptr++;
  12566. }
  12567. *ptr=0;
  12568. ptr=buff+4;
  12569. //printf("%s",ptr);
  12570. if(bytes_received){
  12571. ptr=strstr(ptr,"Content-Length:");
  12572. if(ptr){
  12573. sscanf(ptr,"%*s %d",&bytes_received);
  12574. }else
  12575. bytes_received=-1; //unknown size
  12576. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12577. }
  12578. DEBUG_INFO("End HEADER ..\n");
  12579. return bytes_received ;
  12580. }
  12581. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12582. {
  12583. char rmFileCmd[100]={0};
  12584. char FilePath[100]={0};
  12585. char ftpbuf[200];
  12586. int systemresult;
  12587. //DEBUG_INFO("filename=%s\n",filename);
  12588. //DEBUG_INFO("url=%s\n",url);
  12589. sprintf(FilePath,"/mnt/%s",filename);
  12590. if((access(FilePath,F_OK))!=-1)
  12591. {
  12592. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12593. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12594. system(rmFileCmd);
  12595. }
  12596. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12597. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  12598. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12599. systemresult = system(ftpbuf);
  12600. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12601. if(systemresult != 0)
  12602. {
  12603. DEBUG_INFO("http DownLoad error!\n");
  12604. return FALSE;
  12605. }
  12606. return TRUE;
  12607. }
  12608. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12609. {
  12610. char rmFileCmd[100]={0};
  12611. char FilePath[100]={0};
  12612. char ftpbuf[200];
  12613. int systemresult;
  12614. //char temp[100];
  12615. sprintf(FilePath,"/mnt/%s",filename);
  12616. if((access(FilePath,F_OK))!=-1)
  12617. {
  12618. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12619. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12620. system(rmFileCmd);
  12621. }
  12622. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12623. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  12624. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12625. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12626. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12627. systemresult = system(ftpbuf);
  12628. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12629. if(systemresult != 0)
  12630. {
  12631. printf("wget error!\n");
  12632. return FALSE;
  12633. }
  12634. return TRUE;
  12635. }
  12636. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12637. {
  12638. char rmFileCmd[100]={0};
  12639. char FilePath[100]={0};
  12640. char ftpbuf[200];
  12641. int systemresult;
  12642. //DEBUG_INFO("filename=%s\n",filename);
  12643. //DEBUG_INFO("url=%s\n",url);
  12644. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12645. if((access(FilePath,F_OK))!=-1)
  12646. {
  12647. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12648. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12649. system(rmFileCmd);
  12650. }
  12651. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12652. if(fp == NULL)
  12653. {
  12654. DEBUG_INFO("log is NULL\n");
  12655. return FALSE;
  12656. }
  12657. else
  12658. {
  12659. fprintf(fp, "%s\n", url);
  12660. fprintf(fp, "%s\n", filename);
  12661. fclose(fp);
  12662. }
  12663. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12664. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12665. systemresult = system(ftpbuf);
  12666. DEBUG_INFO("systemresult = %d\n",systemresult);
  12667. if(systemresult != 0)
  12668. {
  12669. DEBUG_INFO("http upload error!\n");
  12670. return FALSE;
  12671. }
  12672. return TRUE;
  12673. }
  12674. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12675. {
  12676. struct hostent* server;
  12677. char *IPbuffer;
  12678. char ftpbuf[200];
  12679. int systemresult;
  12680. // To retrieve host information
  12681. server = gethostbyname(location);
  12682. // To convert an Internet network
  12683. // address into ASCII string
  12684. IPbuffer = inet_ntoa(*((struct in_addr*)
  12685. server->h_addr_list[0]));
  12686. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12687. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12688. /* format : ftpput -u username -p passwd IP target source*/
  12689. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12690. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12691. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12692. systemresult = system(ftpbuf);
  12693. DEBUG_INFO("systemresult=%d\n",systemresult);
  12694. if(systemresult != 0)
  12695. {
  12696. DEBUG_INFO("ftpput error!\n");
  12697. return FALSE;
  12698. }
  12699. return TRUE;
  12700. }
  12701. /**
  12702. * Place the contents of the specified file into a memory buffer
  12703. *
  12704. * @param[in] filename The path and name of the file to read
  12705. * @param[out] filebuffer A pointer to the contents in memory
  12706. * @return status 0 success, 1 on failure
  12707. */
  12708. int get_file_contents(const char* filename, char** outbuffer) {
  12709. FILE* file = NULL;
  12710. long filesize;
  12711. const int blocksize = 1;
  12712. size_t readsize;
  12713. char* filebuffer;
  12714. // Open the file
  12715. file = fopen(filename, "r");
  12716. if (NULL == file)
  12717. {
  12718. printf("'%s' not opened\n", filename);
  12719. exit(EXIT_FAILURE);
  12720. }
  12721. // Determine the file size
  12722. fseek(file, 0, SEEK_END);
  12723. filesize = ftell(file);
  12724. rewind (file);
  12725. // Allocate memory for the file contents
  12726. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12727. *outbuffer = filebuffer;
  12728. if (filebuffer == NULL)
  12729. {
  12730. fputs ("malloc out-of-memory", stderr);
  12731. exit(EXIT_FAILURE);
  12732. }
  12733. // Read in the file
  12734. readsize = fread(filebuffer, blocksize, filesize, file);
  12735. if (readsize != filesize)
  12736. {
  12737. fputs ("didn't read file completely",stderr);
  12738. exit(EXIT_FAILURE);
  12739. }
  12740. // Clean exit
  12741. fclose(file);
  12742. return EXIT_SUCCESS;
  12743. }
  12744. static int selectSqlCount = 0;
  12745. static int callback(void *data, int argc, char **argv, char **azColName){
  12746. int i;
  12747. //printf("%s: ", (const char*)data);
  12748. selectSqlCount = argc;
  12749. for(i = 0; i<argc; i++){
  12750. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12751. }
  12752. //printf("\n");
  12753. return 0;
  12754. }
  12755. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12756. //int i;
  12757. //printf("%s:\n", (const char*)data);
  12758. localversion = argv[5] ? atoi(argv[5]) : 0;
  12759. //printf("localversion=%d\n", localversion);
  12760. return 0;
  12761. }
  12762. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12763. //int i;
  12764. //printf("%s:\n", (const char*)data);
  12765. //idTag
  12766. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12767. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12768. //parentIdTag
  12769. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12770. //expir_date
  12771. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12772. //status
  12773. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12774. //version
  12775. idTagQuery.listVersionInt = atoi(argv[5]);
  12776. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12777. return 0;
  12778. }
  12779. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  12780. {
  12781. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12782. // printf("localversion=%d\n", localversion);
  12783. return 0;
  12784. }
  12785. //=========================================
  12786. // Sqlite3 related function
  12787. //=========================================
  12788. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12789. {
  12790. for (int i = 0; i < n_columns; i++)
  12791. {
  12792. DEBUG_INFO("%s\t", col_values[i]);
  12793. }
  12794. DEBUG_INFO("\n");
  12795. return 0;
  12796. }
  12797. void OCPP_getListVerion()
  12798. {
  12799. int rc = 0;
  12800. // const char* data = "Callback function called";
  12801. char sql[100];
  12802. char zErrMsg[100];
  12803. memset(sql, 0, 100);
  12804. memset(zErrMsg, 0, 100);
  12805. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12806. /* Execute SQL statement */
  12807. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12808. if( rc != SQLITE_OK )
  12809. {
  12810. DEBUG_INFO("SQL error: %s", zErrMsg);
  12811. }
  12812. }
  12813. void OCPP_getIdTag(char idTag[])
  12814. {
  12815. int rc = 0;
  12816. // const char* data = "Callback function called";
  12817. char sql[100];
  12818. char zErrMsg[100];
  12819. memset(sql, 0, 100);
  12820. memset(zErrMsg, 0, 100);
  12821. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  12822. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12823. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12824. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12825. /* Execute SQL statement */
  12826. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12827. if( rc != SQLITE_OK )
  12828. {
  12829. DEBUG_INFO("SQL error: %s", zErrMsg);
  12830. }
  12831. //return ver;
  12832. }
  12833. void OCPP_get_TableAuthlocalAllData(void)
  12834. {
  12835. int rc = 0;
  12836. char sql[100];
  12837. char zErrMsg[100];
  12838. memset(sql, 0, 100);
  12839. memset(zErrMsg, 0, 100);
  12840. sprintf(sql,"select * from ocpp_auth_local ");
  12841. /* Execute SQL statement */
  12842. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12843. if( rc != SQLITE_OK )
  12844. {
  12845. DEBUG_INFO("SQL error: %s", zErrMsg);
  12846. }
  12847. //return ver;
  12848. }
  12849. int OCPP_cleanLocalList()
  12850. {
  12851. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12852. char *errMsg = 0;
  12853. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12854. if (SQLITE_OK != rc)
  12855. {
  12856. DEBUG_INFO("%s\n",errMsg);
  12857. return FALSE;
  12858. }
  12859. return TRUE;
  12860. }
  12861. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12862. {
  12863. int isSuccess = FALSE;
  12864. int ret = 0;
  12865. //const char* data = "Callback function called";
  12866. char sql[300];
  12867. char zErrMsg[200];
  12868. memset(sql, 0, 300);
  12869. memset(zErrMsg, 0, 200);
  12870. sprintf(sql,"insert or replace into ocpp_auth_local (idtag, parent_idtag, expir_date, status, version) " "VALUES ('%s', '%s', '%s', '%s', %d ); ""SELECT * from ocpp_auth_local", idTag, parentTage, expiryDate, status, version);
  12871. //* Execute SQL statement */
  12872. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12873. if( ret != SQLITE_OK )
  12874. {
  12875. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12876. return isSuccess;
  12877. }
  12878. memset(sql, 0, 300);
  12879. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  12880. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  12881. if( ret != SQLITE_OK )
  12882. {
  12883. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12884. return isSuccess;
  12885. }
  12886. isSuccess = TRUE;
  12887. return isSuccess;
  12888. }
  12889. void OCPP_deleteIdTag(char idTag[])
  12890. {
  12891. //int ver = 0;
  12892. //int isSuccess = FALSE;
  12893. int rc = 0;
  12894. char sql[100];
  12895. char zErrMsg[100];
  12896. memset(sql, 0, 100);
  12897. memset(zErrMsg, 0, 100);
  12898. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  12899. //* Execute SQL statement */
  12900. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12901. if( rc != SQLITE_OK )
  12902. {
  12903. DEBUG_INFO("SQL error: %s", zErrMsg);
  12904. }
  12905. }
  12906. int GetOcppServerURL()
  12907. {
  12908. int result = FALSE;
  12909. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  12910. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  12911. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  12912. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12913. {
  12914. #if 1
  12915. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12916. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12917. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12918. #endif
  12919. result = TRUE;
  12920. goto End;
  12921. }
  12922. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12923. {
  12924. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12925. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12926. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12927. result = TRUE;
  12928. goto End;
  12929. }
  12930. else
  12931. {
  12932. strcpy(OcppHost,"");
  12933. }
  12934. End:
  12935. return result;
  12936. }
  12937. int GetOcppPath()
  12938. {
  12939. int result = FALSE;
  12940. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12941. {
  12942. if(OcppTempPath == NULL)
  12943. {
  12944. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12945. }
  12946. else
  12947. {
  12948. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12949. }
  12950. result = TRUE;
  12951. goto End;
  12952. }
  12953. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12954. {
  12955. if(OcppTempPath == NULL)
  12956. {
  12957. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12958. }
  12959. else
  12960. {
  12961. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12962. }
  12963. result = TRUE;
  12964. goto End;
  12965. }
  12966. else
  12967. {
  12968. strcpy(OcppPath,"");
  12969. }
  12970. End:
  12971. return result;
  12972. }
  12973. int GetOcppPort()
  12974. {
  12975. return OcppPort;
  12976. }
  12977. int GetOcppConnStatus(void)
  12978. {
  12979. return ShmOCPP16Data->OcppConnStatus;
  12980. }
  12981. void SetOcppConnStatus(uint8_t status)
  12982. {
  12983. ShmOCPP16Data->OcppConnStatus = status;
  12984. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12985. }
  12986. int GetHeartBeatWithNOResponse(void)
  12987. {
  12988. return HeartBeatWithNOResponse;
  12989. }
  12990. void SetHeartBeatWithNOResponse(void)
  12991. {
  12992. HeartBeatWithNOResponse = 0;
  12993. }
  12994. void GetStartTransactionIdTag(int gun_index)
  12995. {
  12996. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  12997. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  12998. }
  12999. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13000. {
  13001. char ch;
  13002. FILE *fptr1;
  13003. int temptransactionId;
  13004. char str[100]={0};
  13005. temptransactionId = 0;
  13006. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  13007. {
  13008. DEBUG_INFO("IdTag is empty.\n");
  13009. return temptransactionId;
  13010. }
  13011. /*------ Read the file ----------------*/
  13012. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13013. if (!fptr1)
  13014. {
  13015. DEBUG_INFO("QueueTransactionId file open error.\n");
  13016. //printf(" File not found or unable to open the input file!!\n");
  13017. return temptransactionId;
  13018. }
  13019. ch=fgetc(fptr1);
  13020. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13021. rewind(fptr1);
  13022. if(ch!=EOF)
  13023. {
  13024. // printf("%c",ch);
  13025. while (fgets(str, 100, fptr1) != NULL)
  13026. {
  13027. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13028. if(str[0]=='\0')
  13029. {
  13030. break;
  13031. }
  13032. char *revbuf[8] = {0}; //存放分割後的子字串
  13033. int num = 0;//分割後子字串的個數
  13034. DEBUG_INFO("str: %s\n", str);
  13035. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  13036. DEBUG_INFO("revbuf[0]: %s\n", revbuf[0]);
  13037. DEBUG_INFO("revbuf[1]: %s\n", revbuf[1]);
  13038. DEBUG_INFO("revbuf[2]: %s\n", revbuf[2]);
  13039. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13040. {
  13041. if(isStopTransaction)
  13042. {
  13043. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13044. {
  13045. temptransactionId = atoi(revbuf[2]);
  13046. break;
  13047. }
  13048. }
  13049. else
  13050. {
  13051. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13052. {
  13053. temptransactionId = atoi(revbuf[2]);
  13054. break;
  13055. }
  13056. }
  13057. }
  13058. }
  13059. }
  13060. else
  13061. DEBUG_INFO("EOF\n");
  13062. fclose(fptr1);
  13063. /*------- End of reading ---------------*/
  13064. return temptransactionId;
  13065. }
  13066. void SetTransactionIdZero(int transactionId)
  13067. {
  13068. char ch;
  13069. FILE *fptr1, *fptr2;
  13070. int temptransactionId = 0;
  13071. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13072. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13073. if (!fptr1)
  13074. {
  13075. //printf(" File not found or unable to open the input file!!\n");
  13076. return ;
  13077. }
  13078. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13079. if (!fptr2)
  13080. {
  13081. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13082. fclose(fptr1);
  13083. return ;
  13084. }
  13085. ch=fgetc(fptr1);
  13086. rewind(fptr1);
  13087. if(ch!=EOF)
  13088. {
  13089. // copy all contents to the temporary file except the specific line
  13090. while (fgets(str, 100, fptr1) != NULL)
  13091. {
  13092. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13093. if(str[0]=='\0')
  13094. {
  13095. break;
  13096. }
  13097. char *revbuf[8] = {0};
  13098. int num = 0;
  13099. strcpy(strtemp, str);
  13100. splitstring(str,",",revbuf,&num);
  13101. if(revbuf[2][0] != '\0')
  13102. {
  13103. temptransactionId = atoi(revbuf[2]);
  13104. if(transactionId != temptransactionId)
  13105. {
  13106. fprintf(fptr2, "%s\n", strtemp);
  13107. }
  13108. }
  13109. }
  13110. }
  13111. fclose(fptr1);
  13112. fclose(fptr2);
  13113. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13114. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13115. /*------ Read the file ----------------*/
  13116. }
  13117. int InternetDisconnect(void)
  13118. {
  13119. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13120. }
  13121. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13122. void storeTempStopTransaction(int gun_index)
  13123. {
  13124. char guid[37]={0};
  13125. int tempIndex = 0;
  13126. char TempStopTransaction[256];
  13127. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  13128. DEBUG_INFO("storeTempStopTransaction...\n");
  13129. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13130. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13131. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13132. if(gunType[gun_index] == 'J')
  13133. {
  13134. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13135. {
  13136. tempIndex = ((gun_index==2) ? 1: 0);
  13137. }
  13138. else
  13139. {
  13140. tempIndex = gun_index;
  13141. }
  13142. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13143. {
  13144. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13145. {
  13146. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13147. }
  13148. }// END OF CHAdeMO_QUANTITY
  13149. }
  13150. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13151. {
  13152. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13153. {
  13154. tempIndex = ((gun_index==2) ? 1: 0);
  13155. }
  13156. else
  13157. {
  13158. tempIndex = gun_index;
  13159. }
  13160. for (int index = 0; index < CCS_QUANTITY; index++)
  13161. {
  13162. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13163. {
  13164. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13165. }
  13166. }// END OF CCS_QUANTITY
  13167. }
  13168. else if(gunType[gun_index] == 'G')
  13169. {
  13170. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13171. {
  13172. tempIndex = ((gun_index==2) ? 1: 0);
  13173. }
  13174. else
  13175. {
  13176. tempIndex = gun_index;
  13177. }
  13178. for (int index = 0; index < GB_QUANTITY; index++)
  13179. {
  13180. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13181. {
  13182. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13183. }
  13184. }// END OF GB_QUANTITY
  13185. }
  13186. else
  13187. {
  13188. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13189. {
  13190. tempIndex = 2;
  13191. }
  13192. else
  13193. {
  13194. tempIndex = gun_index;
  13195. }
  13196. for (int index = 0; index < AC_QUANTITY; index++)
  13197. {
  13198. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13199. {
  13200. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13201. }
  13202. }// END OF AC_QUANTITY
  13203. }
  13204. //Stop Transaction Time
  13205. struct timeval tmnow;
  13206. struct tm *tm;
  13207. char buf[28];//, usec_buf[6];
  13208. gettimeofday(&tmnow, NULL);
  13209. time_t t;
  13210. t = time(NULL);
  13211. /*UTC time and date*/
  13212. tm = gmtime(&t);
  13213. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13214. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13215. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13216. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13217. random_uuid(guid);
  13218. /***********************************transactionData******************************************************/
  13219. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13220. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13221. //=================================
  13222. //1. Transaction_Begin
  13223. //=================================
  13224. //============================== Energy.Active.Import.Interval ===========================================
  13225. //idx_sample=0;
  13226. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  13227. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13228. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13229. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand,MeasurandStr[Energy_Active_Import_Interval]);//MeasurandStr[Energy_Active_Export_Interval/*Energy_Reactive_Export_Register*/]);
  13230. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13231. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13232. {
  13233. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13234. }
  13235. else
  13236. {
  13237. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13238. }
  13239. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13240. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13241. //=================================
  13242. //2. Transaction_End
  13243. //=================================
  13244. //2.1====================================== Current.Import L1 ==============================================
  13245. //idx_sample=1;
  13246. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13247. if(gunType[gun_index] == 'J')
  13248. {
  13249. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13250. {
  13251. tempIndex = ((gun_index==2) ? 1: 0);
  13252. }
  13253. else
  13254. {
  13255. tempIndex = gun_index;
  13256. }
  13257. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13258. {
  13259. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13260. {
  13261. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13262. }
  13263. }// End of for CHAdeMO_QUANTITY
  13264. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13265. }
  13266. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13267. {
  13268. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13269. {
  13270. tempIndex = ((gun_index==2) ? 1: 0);
  13271. }
  13272. else
  13273. {
  13274. tempIndex = gun_index;
  13275. }
  13276. for (int index = 0; index < CCS_QUANTITY; index++)
  13277. {
  13278. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13279. {
  13280. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13281. }
  13282. }// End of for CCS_QUANTITY
  13283. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13284. }
  13285. else if(gunType[gun_index] == 'G')
  13286. {
  13287. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13288. {
  13289. tempIndex = ((gun_index==2) ? 1: 0);
  13290. }
  13291. else
  13292. {
  13293. tempIndex = gun_index;
  13294. }
  13295. for (int index = 0; index < GB_QUANTITY; index++)
  13296. {
  13297. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13298. {
  13299. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13300. }
  13301. }// End of for GB_QUANTITY
  13302. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13303. }
  13304. else
  13305. {
  13306. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13307. {
  13308. tempIndex = 2;
  13309. }
  13310. else
  13311. {
  13312. tempIndex = gun_index;
  13313. }
  13314. for (int index = 0; index < AC_QUANTITY; index++)
  13315. {
  13316. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13317. {
  13318. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13319. }
  13320. }// End of for AC_QUANTITY
  13321. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13322. }
  13323. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13324. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13325. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13326. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13327. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13328. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13329. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13330. //idx_sample=2;
  13331. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13332. if(gunType[gun_index] == 'J')
  13333. {
  13334. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13335. {
  13336. tempIndex = ((gun_index==2) ? 1: 0);
  13337. }
  13338. else
  13339. {
  13340. tempIndex = gun_index;
  13341. }
  13342. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13343. {
  13344. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13345. {
  13346. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13347. }
  13348. }// END OF CHAdeMO_QUANTITY
  13349. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13350. }
  13351. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13352. {
  13353. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13354. {
  13355. tempIndex = ((gun_index==2) ? 1: 0);
  13356. }
  13357. else
  13358. {
  13359. tempIndex = gun_index;
  13360. }
  13361. for (int index = 0; index < CCS_QUANTITY; index++)
  13362. {
  13363. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13364. {
  13365. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13366. }
  13367. }// END OF CCS_QUANTITY
  13368. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13369. }
  13370. else if(gunType[gun_index] == 'G')
  13371. {
  13372. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13373. {
  13374. tempIndex = ((gun_index==2) ? 1: 0);
  13375. }
  13376. else
  13377. {
  13378. tempIndex = gun_index;
  13379. }
  13380. for (int index = 0; index < GB_QUANTITY; index++)
  13381. {
  13382. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13383. {
  13384. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13385. }
  13386. }// END OF GB_QUANTITY
  13387. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13388. }
  13389. else
  13390. {
  13391. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13392. {
  13393. tempIndex = 2;
  13394. }
  13395. else
  13396. {
  13397. tempIndex = gun_index;
  13398. }
  13399. for (int index = 0; index < AC_QUANTITY; index++)
  13400. {
  13401. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13402. {
  13403. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13404. }
  13405. }// END OF AC_QUANTITY
  13406. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13407. }
  13408. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13409. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13410. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13411. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13412. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13413. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13414. //2.3====================================== Power.Active.Import =========================================
  13415. //idx_sample=3;
  13416. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13417. if(gunType[gun_index] == 'J')
  13418. {
  13419. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13420. {
  13421. tempIndex = ((gun_index==2) ? 1: 0);
  13422. }
  13423. else
  13424. {
  13425. tempIndex = gun_index;
  13426. }
  13427. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13428. {
  13429. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13430. {
  13431. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13432. }
  13433. } // End for CHAdeMO_QUANTITY
  13434. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13435. }
  13436. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13437. {
  13438. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13439. {
  13440. tempIndex = ((gun_index==2) ? 1: 0);
  13441. }
  13442. else
  13443. {
  13444. tempIndex = gun_index;
  13445. }
  13446. for (int index = 0; index < CCS_QUANTITY; index++)
  13447. {
  13448. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13449. {
  13450. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13451. }
  13452. } // END for CCS_QUANTITY
  13453. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13454. }
  13455. else if(gunType[gun_index] == 'G')
  13456. {
  13457. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13458. {
  13459. tempIndex = ((gun_index==2) ? 1: 0);
  13460. }
  13461. else
  13462. {
  13463. tempIndex = gun_index;
  13464. }
  13465. for (int index = 0; index < GB_QUANTITY; index++)
  13466. {
  13467. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13468. {
  13469. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13470. }
  13471. }// END for GB_QUANTITY
  13472. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13473. }
  13474. else
  13475. {
  13476. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13477. {
  13478. tempIndex = 2;
  13479. }
  13480. else
  13481. {
  13482. tempIndex = gun_index;
  13483. }
  13484. for (int index = 0; index < AC_QUANTITY; index++)
  13485. {
  13486. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13487. {
  13488. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13489. }
  13490. } // END for AC_QUANTITY
  13491. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13492. }
  13493. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13494. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13495. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13496. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13497. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13498. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13499. //2.4====================================== Voltage L1 ====================================================
  13500. //idx_sample=4;
  13501. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13502. if(gunType[gun_index] == 'J')
  13503. {
  13504. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13505. {
  13506. tempIndex = ((gun_index==2) ? 1: 0);
  13507. }
  13508. else
  13509. {
  13510. tempIndex = gun_index;
  13511. }
  13512. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13513. {
  13514. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13515. {
  13516. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13517. }
  13518. } // END OF FOR CHAdeMO_QUANTITY
  13519. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13520. }
  13521. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13522. {
  13523. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13524. {
  13525. tempIndex = ((gun_index==2) ? 1: 0);
  13526. }
  13527. else
  13528. {
  13529. tempIndex = gun_index;
  13530. }
  13531. for (int index = 0; index < CCS_QUANTITY; index++)
  13532. {
  13533. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13534. {
  13535. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13536. }
  13537. } // END OF FOR CCS_QUANTITY
  13538. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13539. }
  13540. else if(gunType[gun_index] == 'G')
  13541. {
  13542. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13543. {
  13544. tempIndex = ((gun_index==2) ? 1: 0);
  13545. }
  13546. else
  13547. {
  13548. tempIndex = gun_index;
  13549. }
  13550. for (int index = 0; index < GB_QUANTITY; index++)
  13551. {
  13552. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13553. {
  13554. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13555. }
  13556. } // END OF FOR GB_QUANTITY
  13557. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13558. }
  13559. else
  13560. {
  13561. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13562. {
  13563. tempIndex = 2;
  13564. }
  13565. else
  13566. {
  13567. tempIndex = gun_index;
  13568. }
  13569. for (int index = 0; index < AC_QUANTITY; index++)
  13570. {
  13571. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13572. {
  13573. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  13574. }
  13575. } // END OF FOR AC_QUANTITY
  13576. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13577. }
  13578. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13579. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13580. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13581. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13582. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13583. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13584. //2.5============================================== SoC =========================================================
  13585. //idx_sample=5;
  13586. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13587. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13588. {
  13589. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13590. {
  13591. tempIndex = ((gun_index==2) ? 1: 0);
  13592. }
  13593. else
  13594. {
  13595. tempIndex = gun_index;
  13596. }
  13597. if(gunType[gun_index] == 'J')
  13598. {
  13599. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13600. {
  13601. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13602. {
  13603. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13604. }
  13605. }
  13606. }
  13607. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13608. {
  13609. for (int index = 0; index < CCS_QUANTITY; index++)
  13610. {
  13611. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13612. {
  13613. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13614. }
  13615. }
  13616. }
  13617. else if(gunType[gun_index] == 'G')
  13618. {
  13619. for (int index = 0; index < GB_QUANTITY; index++)
  13620. {
  13621. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13622. {
  13623. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13624. }
  13625. }
  13626. }
  13627. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13628. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13629. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13630. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13631. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  13632. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13633. } // END FOR DC CASE
  13634. //2.6====================================== Current.Import L2 ==============================================
  13635. // idx_sample=6;
  13636. // AC 3 phase L2 current
  13637. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13638. {
  13639. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13640. {
  13641. tempIndex = 2;
  13642. }
  13643. else
  13644. {
  13645. tempIndex = gun_index;
  13646. }
  13647. for (int index = 0; index < AC_QUANTITY; index++)
  13648. {
  13649. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13650. {
  13651. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  13652. }
  13653. }// End of for AC_QUANTITY
  13654. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  13655. }
  13656. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13657. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  13658. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  13659. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  13660. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13661. //2.7====================================== Current.Import L3 ==============================================
  13662. // idx_sample=7;
  13663. // AC 3 phase L3 current
  13664. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13665. {
  13666. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13667. {
  13668. tempIndex = 2;
  13669. }
  13670. else
  13671. {
  13672. tempIndex = gun_index;
  13673. }
  13674. for (int index = 0; index < AC_QUANTITY; index++)
  13675. {
  13676. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13677. {
  13678. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  13679. }
  13680. }// End of for AC_QUANTITY
  13681. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  13682. }
  13683. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13684. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  13685. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  13686. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  13687. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13688. //2.9====================================== Voltage L2 ====================================================
  13689. //idx_sample=8;
  13690. // AC 3 phase L2 volatge
  13691. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13692. {
  13693. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13694. {
  13695. tempIndex = 2;
  13696. }
  13697. else
  13698. {
  13699. tempIndex = gun_index;
  13700. }
  13701. for (int index = 0; index < AC_QUANTITY; index++)
  13702. {
  13703. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13704. {
  13705. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  13706. }
  13707. } // END OF FOR AC_QUANTITY
  13708. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  13709. }
  13710. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13711. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  13712. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  13713. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  13714. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13715. //2.10====================================== Voltage L3 ====================================================
  13716. //idx_sample=9;
  13717. // AC 3 phase L3 volatge
  13718. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13719. {
  13720. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13721. {
  13722. tempIndex = 2;
  13723. }
  13724. else
  13725. {
  13726. tempIndex = gun_index;
  13727. }
  13728. for (int index = 0; index < AC_QUANTITY; index++)
  13729. {
  13730. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13731. {
  13732. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3 );//AcChargingVoltage is 0~6553.5 volt for AC EVSE
  13733. }
  13734. } // END OF FOR AC_QUANTITY
  13735. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  13736. }
  13737. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13738. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  13739. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  13740. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  13741. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13742. //======================================== Message create ==============================================
  13743. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13744. {
  13745. sprintf(queuedata,"%d,[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  13746. ,gun_index+1
  13747. ,MESSAGE_TYPE_CALL
  13748. ,guid
  13749. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13750. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13751. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13752. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13753. ,"PowerLoss"
  13754. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13755. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13756. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13757. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13758. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13759. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13760. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13761. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13762. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13763. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13764. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13765. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13766. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13767. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13768. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13769. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13770. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13771. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13772. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13773. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13774. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13775. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13776. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13777. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13778. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13779. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13780. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13781. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13782. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13783. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13784. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13785. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13786. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13787. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13788. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13789. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13790. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  13791. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  13792. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  13793. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  13794. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  13795. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  13796. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  13797. );
  13798. }
  13799. else
  13800. {
  13801. if(((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W')))
  13802. {
  13803. sprintf(queuedata,"%d,[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  13804. ,gun_index+1
  13805. ,MESSAGE_TYPE_CALL
  13806. ,guid
  13807. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13808. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13809. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13810. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13811. ,"PowerLoss"
  13812. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13813. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13814. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13815. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13816. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13817. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13818. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13819. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13820. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13821. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13822. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13823. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13824. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13825. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13826. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13827. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13828. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13829. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13830. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13831. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13832. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13833. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13834. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13835. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13836. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13837. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13838. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13839. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13840. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13841. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13842. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13843. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13844. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13845. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13846. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13847. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13848. );
  13849. }
  13850. else
  13851. {
  13852. sprintf(queuedata,"%d,[%d,\"%s\",\"StopTransaction\",{\"idTag\":\"%s\",\"meterStop\":%d,\"timestamp\":\"%s\",\"transactionId\":%d,\"reason\":\"%s\",\"transactionData\":[{\"timestamp\":\"%s\",\"sampledValue\":[{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"},{\"value\":\"%s\",\"context\":\"%s\",\"format\":\"%s\",\"measurand\":\"%s\",\"phase\":\"%s\",\"location\":\"%s\",\"unit\":\"%s\"}]}]}]"
  13853. ,gun_index+1
  13854. ,MESSAGE_TYPE_CALL
  13855. ,guid
  13856. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13857. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13858. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13859. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13860. ,"PowerLoss"
  13861. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13862. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13863. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13864. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13865. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13866. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13867. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13868. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13869. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13870. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13871. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13872. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13873. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13874. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13875. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13877. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13883. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13884. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13885. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13886. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13887. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13888. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13889. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13890. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13891. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13892. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13893. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13894. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13895. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13896. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13897. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  13898. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  13899. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  13900. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  13901. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  13902. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  13903. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  13904. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  13905. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  13906. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  13907. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  13908. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  13909. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  13910. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  13911. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  13912. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  13913. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  13914. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  13915. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  13916. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  13917. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  13918. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  13919. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  13920. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  13921. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  13922. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  13923. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  13924. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  13925. );
  13926. }
  13927. }
  13928. // Check File "TempStopTransaction" Exist
  13929. if((access(TempStopTransaction,F_OK))!=-1)
  13930. {
  13931. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  13932. fclose(fopen(TempStopTransaction, "w"));
  13933. }
  13934. else
  13935. {
  13936. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  13937. FILE *log = fopen(TempStopTransaction, "w+");
  13938. if(log == NULL)
  13939. {
  13940. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  13941. return ;
  13942. }
  13943. else
  13944. {
  13945. fclose(log);
  13946. }
  13947. }
  13948. //Add TempStopTransaction | Update TempStopTransaction
  13949. // open file for writing
  13950. FILE *outfile;
  13951. outfile = fopen (TempStopTransaction, "a");
  13952. //DEBUG_INFO("data = %s\n", queuedata);
  13953. fputs(queuedata, outfile);
  13954. fputs("\n", outfile);
  13955. fclose (outfile);
  13956. }
  13957. void checkTempStopTransaction(int gun_index)
  13958. {
  13959. FILE *fptr1;
  13960. char ch;
  13961. char str[QUEUE_MESSAGE_LENGTH]={0};
  13962. char guid[37]={0};
  13963. char tempdata[65]={0};
  13964. char connectorStr[2]={0};
  13965. char TempStopTransaction[256];
  13966. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  13967. fptr1 = fopen(TempStopTransaction, "r");
  13968. //TempStopTransaction格式: 槍號,StopTransaction封包
  13969. if (!fptr1)
  13970. {
  13971. //printf(" File not found or unable to open the input file!!\n");
  13972. return ;
  13973. }
  13974. ch=fgetc(fptr1);
  13975. //printf(" Now the content of the file %s is : \n",fname);
  13976. rewind(fptr1);
  13977. if(ch!=EOF)
  13978. {
  13979. // copy all contents to the temporary file except the specific line
  13980. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  13981. {
  13982. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13983. if(str[0]=='\0')
  13984. {
  13985. break;
  13986. }
  13987. //TempStopTransaction格式: 槍號,StopTransaction封包
  13988. strncpy(connectorStr, str, 1);
  13989. if(atoi(connectorStr) != (gun_index+1))
  13990. {
  13991. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  13992. fclose(fptr1);
  13993. return ;
  13994. }
  13995. //random_uuid(guid);
  13996. strncpy(guid, str+6, 36); //copy guid
  13997. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  13998. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  13999. {
  14000. DEBUG_INFO("StopTransaction mapitem pass\n");
  14001. }
  14002. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14003. memset(str,0,ARRAY_SIZE(str));
  14004. }
  14005. }
  14006. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14007. fclose(fptr1);
  14008. remove(TempStopTransaction); // remove the original file
  14009. }
  14010. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14011. {
  14012. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14013. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14014. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14015. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14016. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14017. }
  14018. int GetWebSocketPingInterval(void)
  14019. {
  14020. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14021. }
  14022. int GetServerSign(void)
  14023. {
  14024. return server_sign;
  14025. }
  14026. uint8_t GetOcppSecurityProfile()
  14027. {
  14028. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14029. }
  14030. void GetOcppChargerBoxId(uint8_t *data)
  14031. {
  14032. sprintf((char*)data, "%s", ShmOCPP16Data->ChargeBoxId);
  14033. }
  14034. void GetOcppSecurityPassword(uint8_t *data)
  14035. {
  14036. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14037. }
  14038. void SetServerSign(int value)
  14039. {
  14040. server_sign = value;
  14041. }
  14042. int GetBootNotificationInterval(void)
  14043. {
  14044. return BootNotificationInterval;
  14045. }
  14046. int GetInternetConn(void)
  14047. {
  14048. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14049. }
  14050. void InitialSystemValue(void)
  14051. {
  14052. int connectorIndex = 0;
  14053. //int valueASCII = 0;
  14054. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14055. gunTotalNumber=0;
  14056. SystemInitial = 0;
  14057. localversion=0;
  14058. BootNotificationInterval = 0;
  14059. authorizeRetryTimes = 0;
  14060. GunStatusInterval = 10;
  14061. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14062. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14063. //Hear Beat
  14064. HeartBeatWithNOResponse = 0;
  14065. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14066. FirstHeartBeat = 0;
  14067. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14068. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14069. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14070. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14071. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14072. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14073. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14074. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14075. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14076. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14077. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14078. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14079. memset(gunType, 0, ARRAY_SIZE(gunType));
  14080. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14081. {
  14082. //check connector / socket type (index: 8, 9, 10)
  14083. for(int index=7; index <10 ; index++)
  14084. {
  14085. if(index != 8)
  14086. {
  14087. // DC Connector
  14088. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  14089. {
  14090. SystemInitial = SystemInitial + 1;
  14091. gunTotalNumber = gunTotalNumber + 1;
  14092. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14093. connectorIndex = connectorIndex + 1;
  14094. }
  14095. }
  14096. else
  14097. {
  14098. // AC Connector
  14099. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14100. {
  14101. SystemInitial = SystemInitial + 1;
  14102. gunTotalNumber = gunTotalNumber + 1;
  14103. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14104. connectorIndex = connectorIndex + 1;
  14105. }
  14106. }
  14107. }
  14108. //DEBUG_INFO("DC ...\n");
  14109. }
  14110. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14111. {
  14112. //check connector / socket type (index: 8, 9, 10)
  14113. for(int index=7; index <10 ; index++)
  14114. {
  14115. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14116. {
  14117. SystemInitial = SystemInitial + 1;
  14118. gunTotalNumber = gunTotalNumber + 1;
  14119. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14120. connectorIndex = connectorIndex + 1;
  14121. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14122. }
  14123. }
  14124. }
  14125. //Status && ConnectorPlugIn Setting
  14126. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14127. {
  14128. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14129. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14130. }
  14131. for (int index = 0; index < CCS_QUANTITY; index++)
  14132. {
  14133. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14134. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14135. }
  14136. for (int index = 0; index < GB_QUANTITY; index++)
  14137. {
  14138. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14139. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14140. }
  14141. for (int index = 0; index < AC_QUANTITY; index++)
  14142. {
  14143. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14144. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14145. }
  14146. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14147. {
  14148. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14149. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14150. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14151. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14152. }
  14153. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14154. clientTime.Heartbeat=time((time_t*)NULL);
  14155. sleep(1);
  14156. }
  14157. void LWS_Send(char * str)
  14158. {
  14159. //=====================================================
  14160. // Check InternetConn 0: disconnected, 1: connected
  14161. //====================================================
  14162. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14163. {
  14164. DEBUG_INFO("offline now !!!\n");
  14165. return;
  14166. }
  14167. pthread_mutex_lock(&lock_send);
  14168. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14169. sprintf((char *)SendBuffer, "%s", str);
  14170. SendBufLen = strlen(str);
  14171. pthread_mutex_unlock(&lock_send);
  14172. lws_callback_on_writable(wsi_client);
  14173. //lws_service(context, 0);
  14174. //sleep(1);
  14175. }
  14176. void LWS_SendNow(char * str)
  14177. {
  14178. //=====================================================
  14179. // Check InternetConn 0: disconnected, 1: connected
  14180. //====================================================
  14181. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14182. {
  14183. DEBUG_INFO("offline now !!!\n");
  14184. return;
  14185. }
  14186. pthread_mutex_lock(&lock_send);
  14187. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14188. sprintf((char *)SendBuffer, "%s", str);
  14189. SendBufLen = strlen(str);
  14190. pthread_mutex_unlock(&lock_send);
  14191. lws_callback_on_writable(wsi_client);
  14192. lws_service(context, 0);
  14193. //sleep(1);
  14194. }