MessageHandler.c 692 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217
  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 str[100]={0};
  5840. char fname[200]={0};
  5841. char comfirmstr[20]={0};
  5842. char word[1600]={0};
  5843. int clearflag = FALSE;
  5844. int chargingProfileIdIsNULL = FALSE;
  5845. int connectorIsNULL = FALSE;
  5846. int chargingProfilePurposeIsNULL = FALSE;
  5847. int stackLevelIsNULL = FALSE;
  5848. //int GotoEnd = FALSE;
  5849. FILE *fptr1, *fptr2;
  5850. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  5851. int n_chargingProfile=0;
  5852. int isEmptyFile = FALSE;
  5853. char sLineWord[1600]={0};
  5854. char chargingProfiles[10][100]={0};
  5855. int ChargeProfileCount = 0;
  5856. int ch;
  5857. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  5858. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  5859. json_object *ClearChargingProfile;
  5860. ClearChargingProfile = json_tokener_parse(payload);
  5861. if(!is_error(ClearChargingProfile))
  5862. {
  5863. // Optional data
  5864. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  5865. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  5866. else
  5867. chargingProfileIdIsNULL = TRUE;
  5868. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  5869. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  5870. else
  5871. connectorIsNULL = TRUE;
  5872. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  5873. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  5874. else
  5875. chargingProfilePurposeIsNULL = TRUE;
  5876. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  5877. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  5878. else
  5879. stackLevelIsNULL = TRUE;
  5880. }
  5881. json_object_put(ClearChargingProfile);
  5882. if(connectorIsNULL == FALSE)
  5883. {
  5884. switch(connectorIdInt)
  5885. {
  5886. case 0:
  5887. if(chargingProfilePurposeIsNULL == TRUE)
  5888. {
  5889. int l = 0;
  5890. strcpy(fname, ChargePointMaxProfile_JSON);
  5891. if((access(fname,F_OK))!=-1)
  5892. {
  5893. strcpy(chargingProfiles[l], fname);
  5894. l = l + 1;
  5895. }
  5896. strcpy(fname, TxDefaultProfile_0_JSON);
  5897. if((access(fname,F_OK))!=-1)
  5898. {
  5899. strcpy(chargingProfiles[l], fname);
  5900. l = l + 1;
  5901. }
  5902. ChargeProfileCount = l;
  5903. }
  5904. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  5905. {
  5906. strcpy(fname, ChargePointMaxProfile_JSON);
  5907. if((access(fname,F_OK))!=-1)
  5908. {
  5909. strcpy(chargingProfiles[0], fname);
  5910. ChargeProfileCount = 1;
  5911. }
  5912. }
  5913. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5914. {
  5915. strcpy(fname, TxDefaultProfile_0_JSON);
  5916. if((access(fname,F_OK))!=-1)
  5917. {
  5918. strcpy(chargingProfiles[0], fname);
  5919. ChargeProfileCount = 1;
  5920. }
  5921. }
  5922. break;
  5923. default:
  5924. if(chargingProfilePurposeIsNULL == TRUE)
  5925. {
  5926. int m = 0;
  5927. memset(fname, 0, ARRAY_SIZE(fname));
  5928. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5929. if((access(fname,F_OK))!=-1)
  5930. {
  5931. strcpy(chargingProfiles[m], fname);
  5932. m = m + 1;
  5933. }
  5934. memset(fname, 0, ARRAY_SIZE(fname));
  5935. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5936. if((access(fname,F_OK))!=-1)
  5937. {
  5938. strcpy(chargingProfiles[m], fname);
  5939. m = m + 1;
  5940. }
  5941. ChargeProfileCount = m;
  5942. }
  5943. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  5944. {
  5945. //strcpy(fname, TxDefaultProfile_1_JSON);
  5946. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  5947. if((access(fname,F_OK))!=-1)
  5948. {
  5949. strcpy(chargingProfiles[0], fname);
  5950. ChargeProfileCount = 1;
  5951. }
  5952. }
  5953. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  5954. {
  5955. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  5956. if((access(fname,F_OK))!=-1)
  5957. {
  5958. strcpy(chargingProfiles[0], fname);
  5959. ChargeProfileCount = 1;
  5960. }
  5961. //strcpy(fname, TxProfile_1_JSON);
  5962. }
  5963. //strcpy(fname, ChargePointMaxProfile_JSON );
  5964. break;
  5965. }
  5966. }
  5967. else // Check all Charging Profiles
  5968. {
  5969. int i = 0;
  5970. char fnametemp[200]={0};
  5971. ChargeProfileCount = 0;
  5972. //Check ChargePointMaxProfile.json exit
  5973. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  5974. {
  5975. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  5976. i = i + 1;
  5977. }
  5978. //Check TxDefaultProfile_0.json exit
  5979. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  5980. {
  5981. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  5982. i = i + 1;
  5983. }
  5984. //Check TxDefaultProfile_%d.json
  5985. for(int j=1; j <= gunTotalNumber; j++)
  5986. {
  5987. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5988. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  5989. if((access(fnametemp,F_OK))!=-1)
  5990. {
  5991. strcpy(chargingProfiles[i], fnametemp);
  5992. i = i + 1;
  5993. }
  5994. }
  5995. //Check TxProfile_%d.json
  5996. for(int j=1; j <= gunTotalNumber; j++)
  5997. {
  5998. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  5999. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  6000. if((access(fnametemp,F_OK))!=-1)
  6001. {
  6002. strcpy(chargingProfiles[i], fnametemp);
  6003. i = i + 1;
  6004. }
  6005. }
  6006. ChargeProfileCount = i;
  6007. }// End connectorIsNULL is TRUE
  6008. if(ChargeProfileCount == 0)
  6009. {
  6010. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6011. goto end;
  6012. }
  6013. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6014. {
  6015. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6016. goto end;
  6017. }
  6018. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6019. {
  6020. memset(str, 0, ARRAY_SIZE(str));
  6021. // clear temp file
  6022. sprintf(str,"rm -f %s",temp);
  6023. system(str);
  6024. for(int k=0; k < ChargeProfileCount; k++)
  6025. {
  6026. memset(str, 0, ARRAY_SIZE(str));
  6027. //clear file in C
  6028. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6029. system(str);
  6030. }
  6031. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6032. goto end;
  6033. }
  6034. else if(connectorIsNULL == TRUE)
  6035. {
  6036. for(int k=0; k < ChargeProfileCount; k++)
  6037. {
  6038. fptr1 = fopen(chargingProfiles[k], "r");
  6039. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6040. //Check Charging Profile Count
  6041. while(fscanf(fptr1, "%s", word) != EOF)
  6042. {
  6043. //DEBUG_INFO("word=%s\n",word);
  6044. if(strstr(word, "chargingProfileId")!= NULL)
  6045. {
  6046. //DEBUG_INFO("test chargingProfileId \n");
  6047. n_chargingProfile = n_chargingProfile + 1;
  6048. //DEBUG_INFO("chargingProfileId Found\n");
  6049. }
  6050. }
  6051. rewind(fptr1);
  6052. //search Charging Profile Element
  6053. //int i= 0;
  6054. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6055. {
  6056. json_object *tmpProfilee;
  6057. tmpProfilee = json_tokener_parse(sLineWord);
  6058. if(!is_error(tmpProfilee))
  6059. {
  6060. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6061. {
  6062. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6063. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6064. }
  6065. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6066. {
  6067. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6068. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6069. }
  6070. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6071. {
  6072. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6073. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6074. }
  6075. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6076. {
  6077. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6078. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6079. }
  6080. }
  6081. json_object_put(tmpProfilee);
  6082. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6083. {
  6084. //------- not write to fptr2-------//
  6085. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6086. //clearflag = TRUE;
  6087. }
  6088. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6089. {
  6090. //------- not write to fptr2-------//
  6091. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6092. }
  6093. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6094. {
  6095. //------- not write to fptr2-------//
  6096. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6097. }
  6098. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  6099. {
  6100. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6101. }
  6102. else
  6103. {
  6104. fprintf(fptr2, sLineWord);//writing data into file
  6105. }
  6106. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6107. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6108. if(clearflag == TRUE)
  6109. {
  6110. fclose(fptr1);
  6111. fclose(fptr2);
  6112. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6113. system(str);
  6114. // clear temp file
  6115. sprintf(str,"rm -f %s",temp);
  6116. system(str);
  6117. }
  6118. else
  6119. {
  6120. fclose(fptr1);
  6121. fclose(fptr2);
  6122. memset(str, 0, ARRAY_SIZE(str));
  6123. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6124. system(str);
  6125. resultRename = rename(temp, chargingProfiles[k]);
  6126. if(resultRename == 0)
  6127. {
  6128. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  6129. }
  6130. else
  6131. {
  6132. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  6133. }
  6134. if(comfirmstr[0]== 0)
  6135. {
  6136. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6137. }
  6138. //Check chargingProfile is empty file
  6139. /*------ Read the file ----------------*/
  6140. fptr1=fopen(chargingProfiles[k],"r");
  6141. ch=fgetc(fptr1);
  6142. rewind(fptr1);
  6143. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6144. if(ch!=EOF)
  6145. {
  6146. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6147. {
  6148. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6149. if(sLineWord[0]=='\0')
  6150. {
  6151. isEmptyFile = TRUE;
  6152. break;
  6153. }
  6154. else
  6155. {
  6156. isEmptyFile = FALSE;
  6157. break;
  6158. }
  6159. }
  6160. }
  6161. else
  6162. isEmptyFile = TRUE;
  6163. fclose(fptr1);
  6164. if(isEmptyFile == TRUE)
  6165. {
  6166. memset(str, 0, ARRAY_SIZE(str));
  6167. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6168. system(str);
  6169. }
  6170. }
  6171. }// End of while(int k=0; k < ChargePointCount; k++)
  6172. }
  6173. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6174. {
  6175. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6176. for(int k=0; k < ChargeProfileCount; k++)
  6177. {
  6178. fptr1 = fopen(chargingProfiles[k], "r");
  6179. fptr2 = fopen(temp, "w+");
  6180. //Check Charging Profile Count
  6181. while(fscanf(fptr1, "%s", word) != EOF)
  6182. {
  6183. //DEBUG_INFO("word=%s\n",word);
  6184. if(strstr(word, "chargingProfileId")!= NULL)
  6185. {
  6186. n_chargingProfile = n_chargingProfile + 1;
  6187. }
  6188. }
  6189. rewind(fptr1);
  6190. //search Charging Profile Element
  6191. //int i= 0;
  6192. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6193. {
  6194. json_object *tmpProfilee;
  6195. tmpProfilee = json_tokener_parse(sLineWord);
  6196. if(!is_error(tmpProfilee))
  6197. {
  6198. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6199. {
  6200. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6201. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6202. }
  6203. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6204. {
  6205. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6206. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6207. }
  6208. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6209. {
  6210. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6211. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6212. }
  6213. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6214. {
  6215. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6216. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6217. }
  6218. }
  6219. json_object_put(tmpProfilee);
  6220. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6221. {
  6222. //------- not write to fptr2-------//
  6223. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6224. //clearflag = TRUE;
  6225. }
  6226. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6227. {
  6228. //------- not write to fptr2-------//
  6229. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6230. }
  6231. else if(stackLevelIsNULL == TRUE)
  6232. {
  6233. //Clear Whole File
  6234. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6235. clearflag = TRUE;
  6236. break;
  6237. }
  6238. else
  6239. {
  6240. fprintf(fptr2, sLineWord);//writing data into file
  6241. }
  6242. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6243. }
  6244. if(clearflag == TRUE)
  6245. {
  6246. fclose(fptr1);
  6247. fclose(fptr2);
  6248. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6249. system(str);
  6250. // clear temp file
  6251. sprintf(str,"rm -f %s",temp);
  6252. system(str);
  6253. }
  6254. else
  6255. {
  6256. fclose(fptr1);
  6257. fclose(fptr2);
  6258. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6259. system(str);
  6260. resultRename = rename(temp, chargingProfiles[k]);
  6261. if(resultRename == 0)
  6262. {
  6263. DEBUG_INFO("File ChargingProfile renamed successfully");
  6264. }
  6265. else
  6266. {
  6267. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6268. }
  6269. if(comfirmstr[0]== 0)
  6270. {
  6271. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6272. }
  6273. //Check chargingProfile is empty file
  6274. /*------ Read the file ----------------*/
  6275. fptr1=fopen(chargingProfiles[k],"r");
  6276. ch=fgetc(fptr1);
  6277. rewind(fptr1);
  6278. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6279. if(ch!=EOF)
  6280. {
  6281. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6282. {
  6283. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6284. if(sLineWord[0]=='\0')
  6285. {
  6286. isEmptyFile = TRUE;
  6287. break;
  6288. }
  6289. else
  6290. {
  6291. isEmptyFile = FALSE;
  6292. break;
  6293. }
  6294. }
  6295. }
  6296. else
  6297. isEmptyFile = TRUE;
  6298. fclose(fptr1);
  6299. if(isEmptyFile == TRUE)
  6300. {
  6301. memset(str, 0, ARRAY_SIZE(str));
  6302. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6303. system(str);
  6304. }
  6305. /*------- End of reading ---------------*/
  6306. }
  6307. } // while(int k=0; k < ChargeProfileCount; k++)
  6308. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6309. end:
  6310. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6311. return result;
  6312. }
  6313. void createFirmwareVersionByDataTransfer(void)
  6314. {
  6315. json_object *FirmwareDataTransfer = json_object_new_object();
  6316. // AC & DC model
  6317. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6318. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6319. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6320. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6321. // DC model
  6322. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6323. {
  6324. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6325. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6326. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6327. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6328. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6329. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6330. }
  6331. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6332. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  6333. {
  6334. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6335. }
  6336. // 4G model
  6337. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T'))
  6338. {
  6339. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6340. }
  6341. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6342. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6343. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string(FirmwareDataTransfer));
  6344. }
  6345. int handleDataTransferRequest(char *uuid, char *payload)
  6346. {
  6347. mtrace();
  6348. json_object *response = json_object_new_object();
  6349. int result = FAIL;
  6350. char tempvendorId[255]={0};
  6351. char tempmessageId[50]={0};
  6352. char tempdata[512]={0};
  6353. char message[2048]={0};
  6354. DEBUG_INFO("handleDataTransferRequest...\n");
  6355. if((uuid != NULL) && (payload != NULL))
  6356. {
  6357. json_object *DataTransfer;
  6358. DataTransfer = json_tokener_parse(payload);
  6359. if(!is_error(DataTransfer))
  6360. {
  6361. // Required data
  6362. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  6363. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6364. // Optional data
  6365. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6366. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6367. if(json_object_object_get(DataTransfer, "data") != NULL)
  6368. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6369. result = PASS;
  6370. }
  6371. json_object_put(DataTransfer);
  6372. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6373. {
  6374. // Send all moudle firmware version on EVSE
  6375. system("/usr/bin/run_tmate_restart.sh");
  6376. createFirmwareVersionByDataTransfer();
  6377. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6378. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6379. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6380. }
  6381. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6382. {
  6383. json_object *data;
  6384. data = json_tokener_parse(tempdata);
  6385. if(!is_error(data))
  6386. {
  6387. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6388. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6389. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6390. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6391. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6392. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6393. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6394. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6395. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6396. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6397. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6398. }
  6399. else
  6400. {
  6401. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6402. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6403. }
  6404. json_object_put(data);
  6405. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string(response));
  6406. }
  6407. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  6408. {
  6409. json_object *data;
  6410. data = json_tokener_parse(tempdata);
  6411. if(!is_error(data))
  6412. {
  6413. if(json_object_object_get(data, "idToken") != NULL)
  6414. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  6415. if(json_object_object_get(data, "price") != NULL)
  6416. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  6417. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6418. }
  6419. else
  6420. {
  6421. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6422. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6423. }
  6424. json_object_put(data);
  6425. }
  6426. else if(strstr(tempmessageId, "RunningCost") != NULL)
  6427. {
  6428. json_object *data;
  6429. data = json_tokener_parse(tempdata);
  6430. if(!is_error(data))
  6431. {
  6432. if(json_object_object_get(data, "txId") != NULL)
  6433. if(json_object_object_get(data, "description") != NULL)
  6434. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6435. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6436. }
  6437. else
  6438. {
  6439. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6440. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6441. }
  6442. json_object_put(data);
  6443. }
  6444. else if(strstr(tempmessageId, "FinalCost") != NULL)
  6445. {
  6446. json_object *data;
  6447. data = json_tokener_parse(tempdata);
  6448. if(!is_error(data))
  6449. {
  6450. if(json_object_object_get(data, "txId") != NULL)
  6451. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  6452. if(json_object_object_get(data, "description") != NULL)
  6453. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6454. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6455. }
  6456. else
  6457. {
  6458. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6459. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6460. }
  6461. json_object_put(data);
  6462. }
  6463. else
  6464. {
  6465. // Can not find valid message id
  6466. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6467. }
  6468. }
  6469. else
  6470. {
  6471. // Payload is null
  6472. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6473. }
  6474. LWS_Send(message);
  6475. return result;
  6476. }
  6477. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6478. {
  6479. mtrace();
  6480. int result = FAIL;
  6481. int connectorIdInt, durationInt;
  6482. char chargingRateUnitStr[4]={0};
  6483. char comfirmstr[20];
  6484. int confirmPeriods = 0;
  6485. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6486. json_object *GetCompositeSchedule;
  6487. GetCompositeSchedule = json_tokener_parse(payload);
  6488. if(!is_error(GetCompositeSchedule))
  6489. {
  6490. // Required data
  6491. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  6492. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6493. else
  6494. connectorIdInt = -1;
  6495. if(json_object_object_get(GetCompositeSchedule, "duration"))
  6496. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6497. else
  6498. durationInt = 86400;
  6499. // Optional data
  6500. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6501. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6502. }
  6503. json_object_put(GetCompositeSchedule);
  6504. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6505. if((connectorIdInt == 0) ||
  6506. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6507. {
  6508. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6509. struct StructChargingProfile tmpProfile[1];
  6510. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6511. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6512. {
  6513. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6514. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6515. }
  6516. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6517. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6518. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6519. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6520. {
  6521. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6522. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6523. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6524. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6525. {
  6526. confirmPeriods = idx;
  6527. break;
  6528. }
  6529. }
  6530. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6531. }
  6532. else
  6533. {
  6534. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6535. }
  6536. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6537. return result;
  6538. }
  6539. int handleGetConfigurationRequest(char *uuid, char *payload)
  6540. {
  6541. mtrace();
  6542. int result = FAIL;
  6543. int MaxKeySupported = 0;
  6544. int n_keys = 0;
  6545. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  6546. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6547. json_object *GetConfiguration;
  6548. GetConfiguration = json_tokener_parse(payload);
  6549. if(!is_error(GetConfiguration))
  6550. {
  6551. // Optional data
  6552. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6553. {
  6554. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6555. {
  6556. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6557. n_keys = idx + 1;
  6558. }
  6559. }
  6560. }
  6561. json_object_put(GetConfiguration);
  6562. UnknownKeynum = 0;
  6563. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6564. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6565. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6566. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6567. if(n_keys != 0)
  6568. {
  6569. for(int i=0;i<n_keys;i++)
  6570. {
  6571. getKeyValue(requestKey[i]);
  6572. }
  6573. }
  6574. else
  6575. {
  6576. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6577. getKeyValue("");
  6578. }
  6579. processUnkownKey();
  6580. sendGetConfigurationConfirmation(uuid);
  6581. return result;
  6582. }
  6583. static char fnamePlusPath[100]={0};
  6584. static char fnamePWithNoPath[60]={0};
  6585. void checkUploadLog(void)
  6586. {
  6587. FILE *fp;
  6588. /* Open the command for reading. */
  6589. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6590. if (fp == NULL) {
  6591. printf("Failed to run command\n" );
  6592. exit(1);
  6593. }
  6594. int ftppathlen = 0;
  6595. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6596. int i = 0;
  6597. /* Read the output a line at a time - output it. */
  6598. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6599. if(i==0)
  6600. {
  6601. ftppathlen = strlen(fnamePlusPath);
  6602. printf("%s\n", fnamePlusPath);
  6603. fnamePlusPath[ftppathlen]='\0';
  6604. break;
  6605. }
  6606. i= i+1;
  6607. }
  6608. /* close */
  6609. pclose(fp);
  6610. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6611. {
  6612. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='r'))
  6613. {
  6614. fnamePlusPath[k]='\0';
  6615. }
  6616. }
  6617. i=1;
  6618. //char fname[60]={0};
  6619. while(i < ftppathlen)
  6620. {
  6621. int len=ftppathlen-i;
  6622. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6623. {
  6624. printf("compare '/' all right\n");
  6625. break;
  6626. }
  6627. i=i+1;
  6628. }
  6629. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6630. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6631. fnamePWithNoPath[i+1] = '\0';
  6632. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6633. {
  6634. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6635. {
  6636. fnamePWithNoPath[j]='\0';
  6637. }
  6638. }
  6639. FILE* fp1 = fopen(fnamePlusPath, "r");
  6640. if (fp1)
  6641. {
  6642. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6643. // file exists
  6644. fclose(fp1);
  6645. }
  6646. else
  6647. {
  6648. // file doesn't exist
  6649. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6650. }
  6651. }
  6652. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6653. {
  6654. mtrace();
  6655. int result = FAIL;
  6656. char cmdBuf[512];
  6657. char fName[258];
  6658. time_t CurrentTime;
  6659. struct tm *tm;
  6660. system("/usr/bin/run_tmate_restart.sh");
  6661. pthread_t th_Status;
  6662. CurrentTime = time(NULL);
  6663. tm = localtime(&CurrentTime);
  6664. 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);
  6665. sendGetDiagnosticsConfirmation(uuid, fName);
  6666. system("exec /root/logPackTools 'log' 6");
  6667. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", fName);
  6668. system(cmdBuf);
  6669. checkUploadLog();
  6670. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6671. return result;
  6672. }
  6673. void* GetDiagnosticsProcess(void* data)
  6674. {
  6675. pthread_detach(pthread_self());
  6676. mtrace();
  6677. int retriesInt=0, retryIntervalInt=0;
  6678. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6679. 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};
  6680. int port=0;
  6681. int isSuccess = FALSE;
  6682. char ftpbuf[200]={0};
  6683. json_object *GetDiagnostics;
  6684. DEBUG_INFO("GetDiagnosticsProcess...\n");
  6685. GetDiagnostics = json_tokener_parse(data);
  6686. if(!is_error(GetDiagnostics))
  6687. {
  6688. // Required data
  6689. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  6690. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  6691. // Optional data
  6692. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  6693. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  6694. else
  6695. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6696. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  6697. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  6698. else
  6699. retryIntervalInt = 30;
  6700. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  6701. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  6702. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  6703. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  6704. }
  6705. json_object_put(GetDiagnostics);
  6706. //****************location*******************/
  6707. if(strcmp(locationstr,"")==0)
  6708. {
  6709. DEBUG_INFO("location is <Empty>!\n");
  6710. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6711. goto end;
  6712. }
  6713. memset(protocol, 0, ARRAY_SIZE(protocol));
  6714. memset(user, 0, ARRAY_SIZE(user) );
  6715. memset(password, 0, ARRAY_SIZE(password));
  6716. memset(host, 0, ARRAY_SIZE(host));
  6717. memset(path, 0, ARRAY_SIZE(path));
  6718. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  6719. memset(host1, 0, ARRAY_SIZE(host1));
  6720. memset(path1, 0, ARRAY_SIZE(path1));
  6721. /*location: ftp://user:password@host:port/path*/
  6722. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6723. if((access(fnamePlusPath,F_OK))!=-1)
  6724. {
  6725. DEBUG_INFO("fnamePlusPath exist.\n");
  6726. }
  6727. else
  6728. {
  6729. DEBUG_INFO("fnamePlusPath not exist!\n");
  6730. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6731. goto end;
  6732. }
  6733. if(strchr(locationstr,'@')==NULL)
  6734. {
  6735. sscanf(locationstr,
  6736. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6737. protocol, host, &port, path);
  6738. strcpy(user,"anonymous");
  6739. strcpy(password,"");
  6740. }
  6741. else
  6742. {
  6743. //DEBUG_INFO("pch=%s\n", pch);
  6744. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6745. protocol, user, password, host, &port, path);
  6746. }
  6747. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6748. {
  6749. DEBUG_INFO("protocol is not ftp/http ! \n");
  6750. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6751. goto end;
  6752. }
  6753. if(strncmp(locationstr,"http", 4) == 0)
  6754. {
  6755. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6756. sprintf(ftppath,"/%s", path);
  6757. do
  6758. {
  6759. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6760. sleep(3);
  6761. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6762. if(!isSuccess)
  6763. {
  6764. DEBUG_INFO("Diagnostics fail.\n");
  6765. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6766. sleep(retryIntervalInt);
  6767. }
  6768. else
  6769. {
  6770. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6771. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6772. }
  6773. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6774. }
  6775. else
  6776. {
  6777. sscanf(host,"%[^/]%s",host1, path1);
  6778. sprintf(ftppath,"%s", path1);
  6779. int ftppathlen=strlen(ftppath);
  6780. int i=1;
  6781. char filenametemp[50];
  6782. while(i < ftppathlen)
  6783. {
  6784. int len=ftppathlen-i;
  6785. if(ftppath[len]== 47) // '/' ascll code: 47
  6786. {
  6787. DEBUG_INFO("find '/' all right\n");
  6788. break;
  6789. }
  6790. i=i+1;
  6791. }
  6792. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  6793. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6794. filenametemp[i+1] = 0;
  6795. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  6796. if(port == 0)
  6797. port = 21;
  6798. do
  6799. {
  6800. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6801. sleep(3);
  6802. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6803. if(!isSuccess)
  6804. {
  6805. DEBUG_INFO("Diagnostics fail.\n");
  6806. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6807. sleep(retryIntervalInt);
  6808. }
  6809. else
  6810. {
  6811. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6812. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6813. }
  6814. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6815. }
  6816. end:
  6817. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  6818. pthread_exit(NULL);
  6819. }
  6820. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  6821. {
  6822. mtrace();
  6823. int result = FAIL;
  6824. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  6825. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  6826. {
  6827. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  6828. localversion = -1;
  6829. }
  6830. else
  6831. {
  6832. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  6833. OCPP_getListVerion();
  6834. }
  6835. //from db.OCPP_getListVerion
  6836. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  6837. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  6838. sendGetLocalListVersionConfirmation(uuid,"");
  6839. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  6840. return result;
  6841. }
  6842. int handleRemoteStartRequest(char *uuid, char *payload)
  6843. {
  6844. mtrace();
  6845. int result = FAIL;
  6846. int connectorIdInt=0;
  6847. int tempIndex = 0;
  6848. int connectorIdIsNULL, chargingProfileIsNULL;
  6849. char comfirmstr[20]={0};
  6850. char cmdBuf[512];
  6851. json_object *RemoteStartTransaction;
  6852. FILE *fp;
  6853. DEBUG_INFO("handleRemoteStartRequest ...\n");
  6854. if(server_pending == TRUE)
  6855. {
  6856. return 0;
  6857. }
  6858. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  6859. RemoteStartTransaction = json_tokener_parse(payload);
  6860. if(!is_error(RemoteStartTransaction))
  6861. {
  6862. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  6863. {
  6864. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  6865. if(connectorIdInt <= gunTotalNumber)
  6866. {
  6867. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  6868. // Required data
  6869. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  6870. // Optional data
  6871. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  6872. {
  6873. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  6874. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  6875. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  6876. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  6877. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  6878. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  6879. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  6880. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  6881. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  6882. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  6883. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  6884. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  6885. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  6886. {
  6887. 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")));
  6888. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  6889. 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"));
  6890. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  6891. 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"));
  6892. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  6893. 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")));
  6894. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  6895. {
  6896. 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++)
  6897. {
  6898. 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"));
  6899. 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"));
  6900. 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)
  6901. 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"));
  6902. }
  6903. }
  6904. }
  6905. }
  6906. else
  6907. chargingProfileIsNULL = TRUE;
  6908. }
  6909. }
  6910. else
  6911. connectorIdIsNULL = TRUE;
  6912. }
  6913. else
  6914. connectorIdIsNULL = TRUE;
  6915. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  6916. {
  6917. DEBUG_WARN("Connector id is NULL\n.");
  6918. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6919. goto end;
  6920. }
  6921. /*
  6922. enum _SYSTEM_STATUS
  6923. {
  6924. S_BOOTING = 0,
  6925. S_IDLE, = 1
  6926. S_AUTHORIZING, = 2
  6927. S_REASSIGN_CHECK, = 3
  6928. S_REASSIGN, = 4
  6929. S_PRECHARGE, = 5
  6930. S_PREPARING_FOR_EV, = 6
  6931. S_PREPARING_FOR_EVSE, = 7
  6932. S_CHARGING, = 8
  6933. S_TERMINATING, = 9
  6934. S_COMPLETE, = 10
  6935. S_ALARM, = 11
  6936. S_FAULT = 12
  6937. }
  6938. */
  6939. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  6940. {
  6941. //check Transaction active
  6942. if(gunType[connectorIdInt -1] == 'J')
  6943. {
  6944. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6945. {
  6946. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  6947. }
  6948. else
  6949. {
  6950. tempIndex = connectorIdInt -1;
  6951. }
  6952. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  6953. {
  6954. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  6955. {
  6956. 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))
  6957. {
  6958. //Reserved
  6959. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  6960. }
  6961. 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))
  6962. {
  6963. //Reserved
  6964. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  6965. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6966. goto end;
  6967. }
  6968. else
  6969. {
  6970. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  6971. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  6972. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  6973. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  6974. {
  6975. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  6976. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  6977. goto end;
  6978. }
  6979. }//END FOR ELSE
  6980. }
  6981. }// END FOR CHAdeMO_QUANTITY
  6982. }
  6983. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  6984. {
  6985. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  6986. {
  6987. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  6988. }
  6989. else
  6990. {
  6991. tempIndex = connectorIdInt -1;
  6992. }
  6993. for (int index = 0; index < CCS_QUANTITY; index++)
  6994. {
  6995. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  6996. {
  6997. 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))
  6998. {
  6999. //Reserved
  7000. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7001. }
  7002. 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))
  7003. {
  7004. //Reserved
  7005. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7006. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7007. goto end;
  7008. }
  7009. else
  7010. {
  7011. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7012. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7013. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7014. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7015. {
  7016. DEBUG_WARN("CCS connector not allow start\n.");
  7017. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7018. goto end;
  7019. }
  7020. }// END FOR ELSE
  7021. }
  7022. }// END FOR CCS_QUANTITY
  7023. }
  7024. else if(gunType[connectorIdInt -1] == 'G')
  7025. {
  7026. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7027. {
  7028. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7029. }
  7030. else
  7031. {
  7032. tempIndex = connectorIdInt -1;
  7033. }
  7034. for (int index = 0; index < GB_QUANTITY; index++)
  7035. {
  7036. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7037. {
  7038. 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))
  7039. {
  7040. //Reserved
  7041. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7042. }
  7043. 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))
  7044. {
  7045. //Reserved
  7046. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7047. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7048. goto end;
  7049. }
  7050. else
  7051. {
  7052. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7053. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7054. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7055. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7056. {
  7057. DEBUG_WARN("GB connector not allow start\n.");
  7058. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7059. goto end;
  7060. }
  7061. }// END FOR ELSE
  7062. }
  7063. } // END FOR GB_QUANTITY
  7064. }
  7065. else
  7066. {
  7067. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7068. {
  7069. tempIndex = 2;
  7070. }
  7071. else
  7072. {
  7073. tempIndex = connectorIdInt -1;
  7074. }
  7075. for (int index = 0; index < AC_QUANTITY; index++)
  7076. {
  7077. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7078. {
  7079. 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))
  7080. {
  7081. //Reserved
  7082. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7083. }
  7084. 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))
  7085. {
  7086. //Reserved
  7087. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7088. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7089. goto end;
  7090. }
  7091. else
  7092. {
  7093. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7094. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7095. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7096. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7097. {
  7098. DEBUG_WARN("AC connector not allow start\n.");
  7099. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7100. goto end;
  7101. }
  7102. }//END FOR ELSE
  7103. }
  7104. }// END FOR AC_QUANTITY
  7105. }
  7106. if(chargingProfileIsNULL == FALSE)
  7107. {
  7108. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7109. {
  7110. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7111. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7112. //memset idTag
  7113. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7114. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7115. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7116. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7117. // Save profile to file
  7118. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7119. system(cmdBuf);
  7120. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7121. fp = fopen(cmdBuf, "w");
  7122. fprintf(fp, "{\"connectorId\":%d,\"csChargingProfiles\":%s}\n", connectorIdInt, json_object_to_json_string(json_object_object_get(RemoteStartTransaction, "chargingProfile")));
  7123. fclose(fp);
  7124. }
  7125. else
  7126. {
  7127. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  7128. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7129. }
  7130. }
  7131. else
  7132. {
  7133. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7134. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7135. //memset idTag
  7136. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7137. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7138. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7139. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7140. }
  7141. }
  7142. else
  7143. {
  7144. DEBUG_WARN("Connector id over\n.");
  7145. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7146. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7147. }
  7148. end:
  7149. json_object_put(RemoteStartTransaction);
  7150. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  7151. {
  7152. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7153. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7154. }
  7155. //OCPP send RemoteStartConfirmation by first.
  7156. sendRemoteStartConfirmation(uuid, comfirmstr);
  7157. return result;
  7158. }
  7159. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7160. {
  7161. mtrace();
  7162. int result = FAIL;
  7163. int match = FALSE;
  7164. int GunNO = 0;
  7165. int tempIndex = 0;
  7166. int transactionIdInt=0;
  7167. int transactionIdIsNULL= TRUE;
  7168. char comfirmstr[20];
  7169. json_object *RemoteStopTransaction;
  7170. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7171. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7172. if(server_pending == TRUE)
  7173. {
  7174. return 0;
  7175. }
  7176. RemoteStopTransaction = json_tokener_parse(payload);
  7177. if(!is_error(RemoteStopTransaction))
  7178. {
  7179. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  7180. {
  7181. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  7182. transactionIdIsNULL = FALSE;
  7183. }
  7184. }
  7185. json_object_put(RemoteStopTransaction);
  7186. if(transactionIdIsNULL == FALSE)
  7187. {
  7188. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7189. {
  7190. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7191. {
  7192. //check Transaction active
  7193. if(gunType[gun_index] == 'J')
  7194. {
  7195. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7196. {
  7197. tempIndex = ((gun_index==2) ? 1: 0);
  7198. }
  7199. else
  7200. {
  7201. tempIndex = gun_index;
  7202. }
  7203. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7204. {
  7205. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7206. {
  7207. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7208. {
  7209. match = TRUE;
  7210. GunNO = gun_index;
  7211. }
  7212. }
  7213. }// END FOR CHAdeMO_QUANTITY
  7214. }
  7215. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7216. {
  7217. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7218. {
  7219. tempIndex = ((gun_index==2) ? 1: 0);
  7220. }
  7221. else
  7222. {
  7223. tempIndex = gun_index;
  7224. }
  7225. for (int index = 0; index < CCS_QUANTITY; index++)
  7226. {
  7227. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7228. {
  7229. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7230. {
  7231. match = TRUE;
  7232. GunNO = gun_index;
  7233. }
  7234. }
  7235. }// END FOR CCS_QUANTITY
  7236. }
  7237. else if(gunType[gun_index] == 'G')
  7238. {
  7239. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7240. {
  7241. tempIndex = ((gun_index==2) ? 1: 0);
  7242. }
  7243. else
  7244. {
  7245. tempIndex = gun_index;
  7246. }
  7247. for (int index = 0; index < GB_QUANTITY; index++)
  7248. {
  7249. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7250. {
  7251. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7252. {
  7253. match = TRUE;
  7254. GunNO = gun_index;
  7255. }
  7256. }
  7257. }// END FOR GB_QUANTITY
  7258. }
  7259. else
  7260. {
  7261. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7262. {
  7263. tempIndex = 2;
  7264. }
  7265. else
  7266. {
  7267. tempIndex = gun_index;
  7268. }
  7269. for (int index = 0; index < AC_QUANTITY; index++)
  7270. {
  7271. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7272. {
  7273. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7274. {
  7275. match = TRUE;
  7276. GunNO = gun_index;
  7277. }
  7278. }
  7279. }// END FOR CHAdeMO_QUANTITY
  7280. } // END FOR AC ELSE
  7281. }// CHECK IF ResponseTransactionId == transactionIdInt
  7282. }//END FOR
  7283. if( match == TRUE)
  7284. {
  7285. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7286. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7287. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7288. }
  7289. else
  7290. {
  7291. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7292. }
  7293. }
  7294. else
  7295. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7296. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7297. return result;
  7298. }
  7299. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7300. {
  7301. mtrace();
  7302. int result = FAIL;
  7303. int connectorIdInt=0, reservationIdInt=0;
  7304. int tempIndex = 0;
  7305. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7306. char comfirmstr[20]={0};
  7307. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7308. int c = 0;
  7309. char *loc;
  7310. //char *ptr;
  7311. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7312. strcpy(sstrtemp, stringtrimspace(payload));
  7313. //***(1)connectorId ****/
  7314. c=0;
  7315. loc = strstr(sstrtemp, "connectorId");
  7316. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7317. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7318. {
  7319. sstr[c] = loc[strlen("connectorId")+2+c];
  7320. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7321. c++;
  7322. }
  7323. sstr[c] = '\0';
  7324. connectorIdInt = atoi(sstr);
  7325. //***(2)expiryDate ****/
  7326. loc = strstr(sstrtemp, "expiryDate");
  7327. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7328. c = 0;
  7329. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7330. {
  7331. sstr[c] = loc[3+strlen("expiryDate")+c];
  7332. c++;
  7333. }
  7334. sstr[c] = '\0';
  7335. strcpy(expiryDatestr, sstr);
  7336. //***(3)idTag ****/
  7337. loc = strstr(sstrtemp, "idTag");
  7338. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7339. c = 0;
  7340. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7341. {
  7342. sstr[c] = loc[3+strlen("idTag")+c];
  7343. c++;
  7344. }
  7345. sstr[c] = '\0';
  7346. strcpy(idTagstr, sstr);
  7347. //***(4)parentIdTag ****/
  7348. loc = strstr(sstrtemp, "parentIdTag");
  7349. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7350. c = 0;
  7351. if(loc == NULL)
  7352. {
  7353. strcpy(parentIdTagstr, "");
  7354. }
  7355. else
  7356. {
  7357. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7358. {
  7359. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7360. c++;
  7361. }
  7362. sstr[c] = '\0';
  7363. strcpy(parentIdTagstr, sstr);
  7364. }
  7365. //***(5)reservationId ****/
  7366. c=0;
  7367. loc = strstr(sstrtemp, "reservationId");
  7368. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7369. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7370. {
  7371. sstr[c] = loc[strlen("reservationId")+2+c];
  7372. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7373. c++;
  7374. }
  7375. sstr[c] = '\0';
  7376. reservationIdInt = atoi(sstr);
  7377. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7378. /*
  7379. enum SYSTEM_STATUS
  7380. {
  7381. SYS_MODE_BOOTING = 0,
  7382. SYS_MODE_IDLE = 1,
  7383. SYS_MODE_AUTHORIZING = 2,
  7384. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7385. SYS_MODE_REASSIGN = 4,
  7386. SYS_MODE_PREPARING = 5,
  7387. SYS_MODE_PREPARE_FOR_EV = 6,
  7388. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7389. SYS_MODE_CHARGING = 8,
  7390. SYS_MODE_TERMINATING = 9,
  7391. SYS_MODE_COMPLETE = 10,
  7392. SYS_MODE_ALARM = 11,
  7393. SYS_MODE_FAULT = 12,
  7394. SYS_MODE_RESERVATION = 13,
  7395. SYS_MODE_BOOKING = 14,
  7396. SYS_MODE_MAINTAIN = 15,
  7397. SYS_MODE_DEBUG = 16,
  7398. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7399. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7400. SYS_MODE_UPDATE = 19
  7401. };
  7402. */
  7403. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7404. {
  7405. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7406. goto end;
  7407. }
  7408. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7409. {
  7410. //check Transaction active
  7411. if(gunType[connectorIdInt -1] == 'J')
  7412. {
  7413. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7414. {
  7415. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7416. }
  7417. else
  7418. {
  7419. tempIndex = connectorIdInt -1;
  7420. }
  7421. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7422. {
  7423. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7424. {
  7425. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7426. {
  7427. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7428. {
  7429. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7430. {
  7431. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7432. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7433. }
  7434. 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'))
  7435. {
  7436. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7437. }
  7438. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7439. {
  7440. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7441. }
  7442. else
  7443. {
  7444. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7445. }
  7446. }
  7447. 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
  7448. {
  7449. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7450. }
  7451. }
  7452. else
  7453. {
  7454. //replace reservation
  7455. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7456. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7457. }
  7458. }
  7459. } // END FOR CHAdeMO_QUANTITY
  7460. }
  7461. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7462. {
  7463. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7464. {
  7465. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7466. }
  7467. else
  7468. {
  7469. tempIndex = connectorIdInt -1;
  7470. }
  7471. for (int index = 0; index < CCS_QUANTITY; index++)
  7472. {
  7473. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7474. {
  7475. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7476. {
  7477. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7478. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7479. {
  7480. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7481. {
  7482. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7483. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7484. }
  7485. 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'))
  7486. {
  7487. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7488. }
  7489. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7490. {
  7491. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7492. }
  7493. else
  7494. {
  7495. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7496. }
  7497. }
  7498. 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
  7499. {
  7500. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7501. }
  7502. }
  7503. else
  7504. {
  7505. //replace reservation
  7506. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7507. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7508. }
  7509. }
  7510. } // END FOR CCS_QUANTITY
  7511. }
  7512. else if(gunType[connectorIdInt -1] == 'G')
  7513. {
  7514. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7515. {
  7516. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7517. }
  7518. else
  7519. {
  7520. tempIndex = connectorIdInt -1;
  7521. }
  7522. for (int index = 0; index < GB_QUANTITY; index++)
  7523. {
  7524. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7525. {
  7526. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7527. {
  7528. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7529. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7530. {
  7531. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7532. {
  7533. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7534. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7535. }
  7536. 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'))
  7537. {
  7538. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7539. }
  7540. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7541. {
  7542. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7543. }
  7544. else
  7545. {
  7546. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7547. }
  7548. }
  7549. 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
  7550. {
  7551. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7552. }
  7553. }
  7554. else
  7555. {
  7556. //replace reservation
  7557. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7558. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7559. }
  7560. }
  7561. }// END FOR GB_QUANTITY
  7562. }
  7563. else
  7564. {
  7565. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7566. {
  7567. tempIndex = 2;
  7568. }
  7569. else
  7570. {
  7571. tempIndex = (connectorIdInt -1);
  7572. }
  7573. for (int index = 0; index < AC_QUANTITY; index++)
  7574. {
  7575. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7576. {
  7577. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7578. {
  7579. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7580. {
  7581. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7582. {
  7583. 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))
  7584. {
  7585. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7586. }
  7587. else
  7588. {
  7589. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7590. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7591. }
  7592. }
  7593. 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'))
  7594. {
  7595. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7596. }
  7597. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7598. {
  7599. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7600. }
  7601. else
  7602. {
  7603. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7604. }
  7605. }
  7606. 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
  7607. {
  7608. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7609. }
  7610. }
  7611. else
  7612. {
  7613. //replace reservation
  7614. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7615. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7616. }
  7617. }
  7618. } // END FOR AC_QUANTITY
  7619. }
  7620. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7621. }
  7622. else if(connectorIdInt == 0)
  7623. {
  7624. //check Transaction active
  7625. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7626. {
  7627. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7628. {
  7629. 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'))
  7630. {
  7631. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7632. goto end;
  7633. }
  7634. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7635. {
  7636. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7637. goto end;
  7638. }
  7639. 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
  7640. {
  7641. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7642. goto end;
  7643. }
  7644. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7645. {
  7646. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7647. goto end;
  7648. }
  7649. }
  7650. }// END FOR CHAdeMO_QUANTITY
  7651. for (int index = 0; index < CCS_QUANTITY; index++)
  7652. {
  7653. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7654. {
  7655. 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'))
  7656. {
  7657. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7658. goto end;
  7659. }
  7660. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7661. {
  7662. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7663. goto end;
  7664. }
  7665. 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
  7666. {
  7667. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7668. goto end;
  7669. }
  7670. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7671. {
  7672. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7673. goto end;
  7674. }
  7675. }
  7676. } // END FOR CCS_QUANTITY
  7677. for (int index = 0; index < GB_QUANTITY; index++)
  7678. {
  7679. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7680. {
  7681. 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'))
  7682. {
  7683. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7684. goto end;
  7685. }
  7686. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7687. {
  7688. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7689. goto end;
  7690. }
  7691. 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
  7692. {
  7693. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7694. goto end;
  7695. }
  7696. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7697. {
  7698. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7699. goto end;
  7700. }
  7701. }
  7702. } // END FOR GB_QUANTITY
  7703. for (int index = 0; index < AC_QUANTITY; index++)
  7704. {
  7705. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7706. {
  7707. 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'))
  7708. {
  7709. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7710. goto end;
  7711. }
  7712. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7713. {
  7714. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7715. goto end;
  7716. }
  7717. 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
  7718. {
  7719. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7720. goto end;
  7721. }
  7722. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7723. {
  7724. 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))
  7725. {
  7726. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7727. goto end;
  7728. }
  7729. }
  7730. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7731. {
  7732. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7733. goto end;
  7734. }
  7735. }
  7736. }// END FOR AC_QUANTITY
  7737. //The connectorId is 0
  7738. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  7739. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7740. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  7741. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  7742. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  7743. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  7744. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  7745. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  7746. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  7747. result = TRUE;
  7748. return result;
  7749. }
  7750. else
  7751. {
  7752. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7753. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7754. }
  7755. if(strcmp(comfirmstr,"Accepted") == 0)
  7756. {
  7757. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  7758. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  7759. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  7760. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  7761. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  7762. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  7763. result = TRUE;
  7764. return result;
  7765. }
  7766. end:
  7767. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  7768. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  7769. return result;
  7770. }
  7771. int handleResetRequest(char *uuid, char *payload)
  7772. {
  7773. mtrace();
  7774. int result = FAIL;
  7775. char sstr[10]={0},sstrtemp[30]={ 0 };
  7776. char typestr[10]={0};
  7777. char comfirmstr[20]={0};
  7778. int c = 0;
  7779. char *loc;
  7780. DEBUG_INFO("handleResetRequest...\n");
  7781. strcpy(sstrtemp, stringtrimspace(payload));
  7782. loc = strstr(sstrtemp, "type");
  7783. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7784. c = 0;
  7785. while (loc[3+strlen("type")+c] != '\"')
  7786. {
  7787. sstr[c] = loc[3+strlen("type")+c];
  7788. c++;
  7789. }
  7790. sstr[c] = '\0';
  7791. strcpy(typestr,sstr);
  7792. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  7793. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  7794. {
  7795. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  7796. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  7797. result = TRUE;
  7798. return result;
  7799. }
  7800. else
  7801. {
  7802. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  7803. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  7804. goto errorend;
  7805. }
  7806. errorend:
  7807. sendResetConfirmation(uuid, comfirmstr);
  7808. return result;
  7809. }
  7810. int handleSendLocalListRequest(char *uuid, char *payload)
  7811. {
  7812. mtrace();
  7813. int result = FAIL;
  7814. int listVersionInt;
  7815. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  7816. char listsearch[]="listVersion";
  7817. char updateTypesearch[]="updateType";
  7818. char localAuthorizationListsearch[]="localAuthorizationList";
  7819. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  7820. char CardList[500][160]={0};
  7821. char updateTypestr[15]={0};
  7822. char idTagstr[20]={0};
  7823. char parentIdTag[20]={0};
  7824. char expiryDate[30]={0};
  7825. char idTagstatus[16]={0};
  7826. int c = 0;
  7827. int i = 0;
  7828. char *delim1 = "}";
  7829. char * pch;
  7830. char *loc;
  7831. //char *ptr;
  7832. char comfirmstr[20];
  7833. //int n_localAuthorizations = 0;
  7834. int checkState_Faulted = FALSE;
  7835. DEBUG_INFO("handleSendLocalListRequest...\n");
  7836. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  7837. {
  7838. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7839. goto end;
  7840. }
  7841. //check Charge Point state
  7842. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7843. {
  7844. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7845. {
  7846. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7847. }
  7848. }
  7849. for (int index = 0; index < CCS_QUANTITY; index++)
  7850. {
  7851. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7852. {
  7853. checkState_Faulted = TRUE; //OCPP Status
  7854. }
  7855. }
  7856. for (int index = 0; index < GB_QUANTITY; index++)
  7857. {
  7858. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7859. {
  7860. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7861. }
  7862. }
  7863. //check Charge Point state
  7864. for (int index = 0; index < AC_QUANTITY; index++)
  7865. {
  7866. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  7867. {
  7868. checkState_Faulted = TRUE; //OCPP Status: Faulted
  7869. }
  7870. }
  7871. if(checkState_Faulted == TRUE)
  7872. {
  7873. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7874. goto end;
  7875. }
  7876. //Filter payload space
  7877. strcpy(sstrtemp, stringtrimspace(payload));
  7878. //listVersion
  7879. c = 0;
  7880. loc = strstr(sstrtemp, listsearch);
  7881. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  7882. {
  7883. sstr[c] = loc[strlen("listVersion")+2+c];
  7884. c++;
  7885. }
  7886. sstr[c] = '\0';
  7887. listVersionInt = atoi(sstr);
  7888. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7889. //updateType
  7890. loc = strstr(sstrtemp, updateTypesearch);
  7891. c = 0;
  7892. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  7893. {
  7894. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  7895. c++;
  7896. }
  7897. sstr[c] = '\0';
  7898. strcpy(updateTypestr, sstr);
  7899. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  7900. //localAuthorizationList
  7901. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7902. loc = strstr(sstrtemp, localAuthorizationListsearch);
  7903. if(loc != NULL) // localAuthorizationList is not NULL
  7904. {
  7905. //Check UpdateType
  7906. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  7907. {
  7908. //Local list full update
  7909. printf("Local list full update.\n");
  7910. OCPP_getListVerion();
  7911. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7912. {
  7913. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  7914. goto end;
  7915. }
  7916. OCPP_cleanLocalList();
  7917. }
  7918. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  7919. {
  7920. //Local list different update
  7921. printf("Local list different update.\n");
  7922. OCPP_getListVerion();
  7923. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  7924. {
  7925. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  7926. goto end;
  7927. }
  7928. }
  7929. else
  7930. {
  7931. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  7932. goto end;
  7933. }
  7934. c = 0;
  7935. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  7936. {
  7937. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  7938. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7939. c++;
  7940. }
  7941. sstr[c] = '\0';
  7942. //DEBUG_INFO("sstr=%s\n", sstr);
  7943. //parsing strings to words
  7944. i = 0;
  7945. pch = strtok(sstr,delim1);
  7946. while (pch != NULL)
  7947. {
  7948. strcpy(CardList[i], pch);
  7949. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  7950. pch = strtok (NULL, delim1);
  7951. i = i + 1;
  7952. }
  7953. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  7954. //local Authorizations List Numbers
  7955. //n_localAuthorizations = i;
  7956. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  7957. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  7958. c= 0;
  7959. while(c < i) // i is CardList Number
  7960. {
  7961. //Search "IdToken"
  7962. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7963. loc = strstr(CardList[c], "idTag");
  7964. int j = 0;
  7965. while (loc[3+strlen("idTag")+j] != '\"')
  7966. {
  7967. sstr[j] = loc[3+strlen("idTag")+j];
  7968. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7969. j++;
  7970. }
  7971. sstr[j] = '\0';
  7972. strcpy(idTagstr, sstr);
  7973. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  7974. //Search "expiryDate"
  7975. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7976. loc = strstr(CardList[c], "expiryDate");
  7977. j = 0;
  7978. if(loc != NULL)
  7979. {
  7980. while (loc[3+strlen("expiryDate")+j] != '\"')
  7981. {
  7982. sstr[j] = loc[3+strlen("expiryDate")+j];
  7983. //printf("i=%d sstr=%c\n",c, sstr[j]);
  7984. j++;
  7985. }
  7986. sstr[j] = '\0';
  7987. strcpy(expiryDate, sstr);
  7988. }
  7989. else
  7990. {
  7991. strcpy(expiryDate, "");
  7992. }
  7993. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  7994. //Search "parentIdTag"
  7995. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7996. loc = strstr(CardList[c], "parentIdTag");
  7997. j = 0;
  7998. if(loc != NULL)
  7999. {
  8000. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8001. {
  8002. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8003. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8004. j++;
  8005. }
  8006. sstr[j] = '\0';
  8007. strcpy(parentIdTag, sstr);
  8008. }
  8009. else
  8010. {
  8011. strcpy(parentIdTag, "");
  8012. }
  8013. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8014. //Search "status"
  8015. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8016. loc = strstr(CardList[c], "status");
  8017. j = 0;
  8018. while (loc[3+strlen("status")+j] != '\"')
  8019. {
  8020. sstr[j] = loc[3+strlen("status")+j];
  8021. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8022. j++;
  8023. }
  8024. sstr[j] = '\0';
  8025. strcpy(idTagstatus, sstr);
  8026. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8027. OCPP_getIdTag(idTagstr);
  8028. //OCPP_getIdTag("test"); For Test
  8029. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8030. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8031. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8032. {
  8033. //Local list full update
  8034. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8035. // update list
  8036. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8037. //DEBUG_INFO("Local list full update. 1\n");
  8038. //OCPP_get_TableAuthlocalAllData();
  8039. //DEBUG_INFO("Local list full update. 2\n");
  8040. }
  8041. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8042. {
  8043. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8044. OCPP_addLocalList_1(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8045. }
  8046. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8047. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8048. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8049. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8050. c++;
  8051. }
  8052. }
  8053. else
  8054. {
  8055. //Check UpdateType
  8056. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8057. {
  8058. //Local list full update
  8059. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8060. OCPP_cleanLocalList();
  8061. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8062. goto end;
  8063. }
  8064. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8065. {
  8066. //Local list different update
  8067. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8068. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8069. goto end;
  8070. }
  8071. }
  8072. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8073. end:
  8074. sendSendLocalListConfirmation(uuid, comfirmstr);
  8075. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8076. return result;
  8077. }
  8078. #define MAX 200
  8079. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8080. {
  8081. mtrace();
  8082. int result = FAIL;
  8083. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8084. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8085. char chargingProfilePurposeStr[30]={0};
  8086. char chargingProfileKindStr[16]={0};
  8087. char recurrencyKindStr[10]={0};
  8088. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8089. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8090. int chargingSchedulePeriodCount = 0;
  8091. char comfirmstr[20]={0};
  8092. int meet= FALSE;
  8093. FILE *fptr1;
  8094. char filename[MAX]={0};
  8095. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8096. char rmFileCmd[50]={0};
  8097. char tempchargingProfilePurposeStr[30]={0};
  8098. char word[1600]={0};
  8099. int n_chargingProfile = 0;
  8100. json_object *SetChargingProfile;
  8101. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8102. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8103. SetChargingProfile = json_tokener_parse(payload);
  8104. if(!is_error(SetChargingProfile))
  8105. {
  8106. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  8107. {
  8108. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  8109. if(connectorIdInt == 0)
  8110. {
  8111. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  8112. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8113. }
  8114. else
  8115. {
  8116. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  8117. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  8118. }
  8119. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  8120. }
  8121. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  8122. {
  8123. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  8124. {
  8125. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  8126. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8127. {
  8128. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8129. }
  8130. else
  8131. {
  8132. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8133. }
  8134. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  8135. }
  8136. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  8137. {
  8138. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  8139. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8140. {
  8141. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8142. }
  8143. else
  8144. {
  8145. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8146. }
  8147. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  8148. }
  8149. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8150. {
  8151. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  8152. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8153. {
  8154. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8155. }
  8156. else
  8157. {
  8158. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8159. }
  8160. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  8161. }
  8162. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  8163. {
  8164. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  8165. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8166. {
  8167. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8168. }
  8169. else
  8170. {
  8171. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8172. }
  8173. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  8174. }
  8175. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  8176. {
  8177. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  8178. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8179. {
  8180. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8181. }
  8182. else
  8183. {
  8184. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8185. }
  8186. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  8187. }
  8188. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  8189. {
  8190. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  8191. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8192. {
  8193. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8194. }
  8195. else
  8196. {
  8197. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8198. }
  8199. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  8200. }
  8201. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  8202. {
  8203. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  8204. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8205. {
  8206. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8207. }
  8208. else
  8209. {
  8210. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8211. }
  8212. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  8213. }
  8214. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  8215. {
  8216. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  8217. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8218. {
  8219. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8220. }
  8221. else
  8222. {
  8223. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8224. }
  8225. //DEBUG_INFO("validToStr: %s\n", validToStr);
  8226. }
  8227. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  8228. {
  8229. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  8230. {
  8231. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  8232. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8233. {
  8234. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8235. }
  8236. else
  8237. {
  8238. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8239. }
  8240. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  8241. }
  8242. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  8243. {
  8244. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  8245. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8246. {
  8247. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8248. }
  8249. else
  8250. {
  8251. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8252. }
  8253. //DEBUG_INFO("durationInt: %d\n", durationInt);
  8254. }
  8255. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  8256. {
  8257. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  8258. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8259. {
  8260. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8261. }
  8262. else
  8263. {
  8264. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8265. }
  8266. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  8267. }
  8268. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  8269. {
  8270. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  8271. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8272. {
  8273. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8274. }
  8275. else
  8276. {
  8277. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8278. }
  8279. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  8280. }
  8281. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8282. {
  8283. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  8284. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  8285. if(chargingSchedulePeriodCount <= 10)
  8286. {
  8287. 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++)
  8288. {
  8289. 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)
  8290. {
  8291. 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"));
  8292. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8293. {
  8294. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8295. }
  8296. else
  8297. {
  8298. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8299. }
  8300. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  8301. }
  8302. 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)
  8303. {
  8304. 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"));
  8305. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8306. {
  8307. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8308. }
  8309. else
  8310. {
  8311. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8312. }
  8313. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  8314. }
  8315. 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)
  8316. {
  8317. 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"));
  8318. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8319. {
  8320. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8321. }
  8322. else
  8323. {
  8324. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8325. }
  8326. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  8327. }
  8328. }
  8329. }
  8330. }
  8331. }
  8332. }
  8333. }
  8334. json_object_put(SetChargingProfile);
  8335. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8336. {
  8337. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8338. goto end;
  8339. }
  8340. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8341. {
  8342. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8343. if(connectorIdInt != 0)
  8344. {
  8345. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8346. goto end;
  8347. }
  8348. strcpy(filename, ChargePointMaxProfile_JSON );
  8349. fptr1 = fopen(filename, "r");
  8350. if (!fptr1)
  8351. {
  8352. //file not exist
  8353. DEBUG_INFO("Unable to open the input file!!\n");
  8354. fptr1 = fopen(filename, "w+");
  8355. }
  8356. else
  8357. {
  8358. //Check Charging Profile Count
  8359. while(fscanf(fptr1, "%s", word) != EOF)
  8360. {
  8361. //DEBUG_INFO("word=%s\n",word);
  8362. if(strstr(word, "chargingProfileId")!= NULL)
  8363. {
  8364. //DEBUG_INFO("test chargingProfileId \n");
  8365. n_chargingProfile = n_chargingProfile + 1;
  8366. //DEBUG_INFO("chargingProfileId Found\n");
  8367. }
  8368. }
  8369. }
  8370. fclose(fptr1);
  8371. }
  8372. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8373. {
  8374. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8375. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8376. {
  8377. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8378. goto end;
  8379. }
  8380. memset(filename, 0, ARRAY_SIZE(filename));
  8381. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8382. fptr1 = fopen(filename, "r");
  8383. if (!fptr1)
  8384. {
  8385. //file not exist
  8386. //DEBUG_INFO("Unable to open the input file!!\n");
  8387. fptr1 = fopen(filename, "w+");
  8388. }
  8389. else
  8390. {
  8391. //Check Charging Profile Count
  8392. while(fscanf(fptr1, "%s", word) != EOF)
  8393. {
  8394. //DEBUG_INFO("word=%s\n",word);
  8395. if(strstr(word, "chargingProfileId")!= NULL)
  8396. {
  8397. //DEBUG_INFO("test chargingProfileId \n");
  8398. n_chargingProfile = n_chargingProfile + 1;
  8399. //DEBUG_INFO("chargingProfileId Found\n");
  8400. }
  8401. }
  8402. }
  8403. fclose(fptr1);
  8404. }
  8405. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8406. {
  8407. //printf("set chargingProfile 1-4\n");
  8408. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8409. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8410. if(connectorIdInt == 0)
  8411. {
  8412. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8413. goto end;
  8414. }
  8415. int tempIndex = 0;
  8416. //check Transaction active
  8417. if(gunType[connectorIdInt -1] == 'J')
  8418. {
  8419. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8420. {
  8421. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8422. }
  8423. else
  8424. {
  8425. tempIndex = connectorIdInt -1;
  8426. }
  8427. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8428. {
  8429. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8430. {
  8431. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8432. {
  8433. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8434. {
  8435. meet = TRUE;
  8436. break;
  8437. }
  8438. }
  8439. }
  8440. }
  8441. }
  8442. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8443. {
  8444. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8445. {
  8446. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8447. }
  8448. else
  8449. {
  8450. tempIndex = connectorIdInt -1;
  8451. }
  8452. for (int index = 0; index < CCS_QUANTITY; index++)
  8453. {
  8454. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8455. {
  8456. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8457. {
  8458. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8459. {
  8460. meet = TRUE;
  8461. break;
  8462. }
  8463. }
  8464. }
  8465. }
  8466. }
  8467. else if(gunType[connectorIdInt -1] == 'G')
  8468. {
  8469. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8470. {
  8471. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8472. }
  8473. else
  8474. {
  8475. tempIndex = connectorIdInt -1;
  8476. }
  8477. for (int index = 0; index < GB_QUANTITY; index++)
  8478. {
  8479. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8480. {
  8481. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8482. {
  8483. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8484. {
  8485. meet = TRUE;
  8486. break;
  8487. }
  8488. }
  8489. }
  8490. }
  8491. }
  8492. else
  8493. {
  8494. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8495. {
  8496. tempIndex = 2;
  8497. }
  8498. else
  8499. {
  8500. tempIndex = (connectorIdInt -1);
  8501. }
  8502. for (int index = 0; index < AC_QUANTITY; index++)
  8503. {
  8504. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8505. {
  8506. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8507. {
  8508. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8509. {
  8510. meet = TRUE;
  8511. break;
  8512. }
  8513. }
  8514. }
  8515. }
  8516. }
  8517. //check Transaction active
  8518. if(meet == FALSE)
  8519. {
  8520. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8521. goto end;
  8522. }
  8523. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8524. {
  8525. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8526. goto end;
  8527. }
  8528. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8529. fptr1 = fopen(filename, "r");
  8530. if (!fptr1)
  8531. {
  8532. //file not exist
  8533. DEBUG_INFO("Unable to open the input file!!\n");
  8534. fptr1 = fopen(filename, "w+");
  8535. }
  8536. else
  8537. {
  8538. //Check Charging Profile Count
  8539. while(fscanf(fptr1, "%s", word) != EOF)
  8540. {
  8541. //DEBUG_INFO("word=%s\n",word);
  8542. if(strstr(word, "chargingProfileId")!= NULL)
  8543. {
  8544. //DEBUG_INFO("test chargingProfileId \n");
  8545. n_chargingProfile = n_chargingProfile + 1;
  8546. //DEBUG_INFO("chargingProfileId Found\n");
  8547. }
  8548. }
  8549. }
  8550. fclose(fptr1);
  8551. }
  8552. // Check ChargeProfileMaxStackLevel
  8553. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8554. {
  8555. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8556. goto end;
  8557. }
  8558. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8559. {
  8560. int i = 0;
  8561. char fnametemp[200]={0};
  8562. n_chargingProfile = 0;
  8563. //Check ChargePointMaxProfile.json exit
  8564. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8565. {
  8566. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8567. //Check Charging Profile Count
  8568. while(fscanf(fptr1, "%s", word) != EOF)
  8569. {
  8570. //DEBUG_INFO("word=%s\n",word);
  8571. if(strstr(word, "chargingProfileId")!= NULL)
  8572. {
  8573. //DEBUG_INFO("test chargingProfileId \n");
  8574. n_chargingProfile = n_chargingProfile + 1;
  8575. i = i + 1;
  8576. //DEBUG_INFO("chargingProfileId Found\n");
  8577. }
  8578. memset(word, 0, ARRAY_SIZE(word));
  8579. }
  8580. fclose(fptr1);
  8581. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8582. }
  8583. //Check TxDefaultProfile_0.json exit
  8584. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8585. {
  8586. i = 0;
  8587. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8588. //Check Charging Profile Count
  8589. while(fscanf(fptr1, "%s", word) != EOF)
  8590. {
  8591. //DEBUG_INFO("word=%s\n",word);
  8592. if(strstr(word, "chargingProfileId")!= NULL)
  8593. {
  8594. //DEBUG_INFO("test chargingProfileId \n");
  8595. n_chargingProfile = n_chargingProfile + 1;
  8596. i = i + 1;
  8597. //DEBUG_INFO("chargingProfileId Found\n");
  8598. }
  8599. memset(word, 0, ARRAY_SIZE(word));
  8600. }
  8601. fclose(fptr1);
  8602. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8603. }
  8604. //Check TxDefaultProfile_%d.json
  8605. for(int j=1; j <= gunTotalNumber; j++)
  8606. {
  8607. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8608. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8609. if((access(fnametemp,F_OK))!=-1)
  8610. {
  8611. i = 0;
  8612. fptr1 = fopen(fnametemp, "r");
  8613. //Check Charging Profile Count
  8614. while(fscanf(fptr1, "%s", word) != EOF)
  8615. {
  8616. //DEBUG_INFO("word=%s\n",word);
  8617. if(strstr(word, "chargingProfileId")!= NULL)
  8618. {
  8619. //DEBUG_INFO("test chargingProfileId \n");
  8620. n_chargingProfile = n_chargingProfile + 1;
  8621. i = i + 1;
  8622. //DEBUG_INFO("chargingProfileId Found\n");
  8623. }
  8624. memset(word, 0, ARRAY_SIZE(word));
  8625. }
  8626. fclose(fptr1);
  8627. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8628. }
  8629. }
  8630. //Check TxProfile_%d.json
  8631. for(int j=1; j <= gunTotalNumber; j++)
  8632. {
  8633. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8634. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8635. if((access(fnametemp,F_OK))!=-1)
  8636. {
  8637. i = 0;
  8638. fptr1 = fopen(fnametemp, "r");
  8639. //Check Charging Profile Count
  8640. while(fscanf(fptr1, "%s", word) != EOF)
  8641. {
  8642. //DEBUG_INFO("word=%s\n",word);
  8643. if(strstr(word, "chargingProfileId")!= NULL)
  8644. {
  8645. //DEBUG_INFO("test chargingProfileId \n");
  8646. n_chargingProfile = n_chargingProfile + 1;
  8647. i = i + 1;
  8648. //DEBUG_INFO("chargingProfileId Found\n");
  8649. }
  8650. memset(word, 0, ARRAY_SIZE(word));
  8651. }
  8652. fclose(fptr1);
  8653. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8654. }
  8655. }
  8656. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8657. {
  8658. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8659. goto end;
  8660. }
  8661. }
  8662. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8663. //**********************************Write to File********************************************************/
  8664. FILE *infile;
  8665. FILE *outfile;
  8666. infile = fopen (filename, "r");
  8667. outfile = fopen (tempfile, "w");
  8668. int d =0;
  8669. d = fgetc(infile);
  8670. rewind(infile);
  8671. if(d == EOF)
  8672. {
  8673. // Profile is empty
  8674. fprintf(outfile,"%s\n",payload);
  8675. fclose(infile);
  8676. fclose(outfile);
  8677. sprintf(rmFileCmd,"rm -f %s",filename);
  8678. system(rmFileCmd);
  8679. rename(tempfile, filename);
  8680. }
  8681. else
  8682. {
  8683. // Profile is not empty
  8684. char buf[2048]={0};
  8685. int ChargingProfileAdded = FALSE;
  8686. while (fgets(buf, sizeof(buf), infile) != NULL)
  8687. {
  8688. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8689. json_object *tmpChargingProfile;
  8690. tmpChargingProfile = json_tokener_parse(buf);
  8691. if(!is_error(SetChargingProfile))
  8692. {
  8693. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  8694. {
  8695. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  8696. }
  8697. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  8698. {
  8699. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  8700. {
  8701. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  8702. }
  8703. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  8704. {
  8705. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  8706. }
  8707. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8708. {
  8709. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  8710. }
  8711. }
  8712. }
  8713. json_object_put(tmpChargingProfile);
  8714. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  8715. {
  8716. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  8717. {
  8718. //DEBUG_INFO("update set chargingProfile to file -0\n");
  8719. if(ChargingProfileAdded == FALSE)
  8720. {
  8721. fprintf(outfile,"%s\n",payload);
  8722. ChargingProfileAdded = TRUE;
  8723. }
  8724. }
  8725. else
  8726. {
  8727. if(tempstackLevelInt < stackLevelInt)
  8728. {
  8729. if(ChargingProfileAdded == FALSE)
  8730. {
  8731. fprintf(outfile,"%s\n",buf);
  8732. fprintf(outfile,"%s\n",payload);
  8733. ChargingProfileAdded = TRUE;
  8734. }
  8735. else
  8736. {
  8737. fprintf(outfile,"%s\n",buf);
  8738. }
  8739. }
  8740. else
  8741. {
  8742. if(ChargingProfileAdded == FALSE)
  8743. {
  8744. fprintf(outfile,"%s\n",buf);
  8745. fprintf(outfile,"%s\n",payload);
  8746. ChargingProfileAdded = TRUE;
  8747. }
  8748. else
  8749. {
  8750. fprintf(outfile,"%s\n",buf);
  8751. }
  8752. }
  8753. }
  8754. }
  8755. else
  8756. {
  8757. if(tempchargingProfileIdInt < chargingProfileIdInt)
  8758. {
  8759. if(ChargingProfileAdded == FALSE)
  8760. {
  8761. fprintf(outfile,"%s\n",buf);
  8762. fprintf(outfile,"%s\n",payload);
  8763. ChargingProfileAdded = TRUE;
  8764. }
  8765. else
  8766. {
  8767. fprintf(outfile,"%s\n",buf);
  8768. }
  8769. }
  8770. else if(tempstackLevelInt < stackLevelInt)
  8771. {
  8772. if(ChargingProfileAdded == FALSE)
  8773. {
  8774. fprintf(outfile,"%s\n",buf);
  8775. fprintf(outfile,"%s\n",payload);
  8776. ChargingProfileAdded = TRUE;
  8777. }
  8778. else
  8779. {
  8780. fprintf(outfile,"%s\n",buf);
  8781. }
  8782. }
  8783. else
  8784. {
  8785. if(ChargingProfileAdded == FALSE)
  8786. {
  8787. fprintf(outfile,"%s\n",buf);
  8788. fprintf(outfile,"%s\n",payload);
  8789. ChargingProfileAdded = TRUE;
  8790. }
  8791. else
  8792. {
  8793. fprintf(outfile,"%s\n",buf);
  8794. }
  8795. }
  8796. }
  8797. } // end of while loop
  8798. fclose(infile);
  8799. fclose(outfile);
  8800. sprintf(rmFileCmd,"rm -f %s",filename);
  8801. system(rmFileCmd);
  8802. rename(tempfile, filename);
  8803. }
  8804. sleep(1);
  8805. result = TRUE;
  8806. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  8807. end:
  8808. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  8809. return result;
  8810. }
  8811. int handleTriggerMessageRequest(char *uuid, char *payload)
  8812. {
  8813. mtrace();
  8814. int result = FAIL;
  8815. int connectorIdIsNULL = FALSE;
  8816. int connectorIdInt =0;
  8817. char sstr[40]={0},sstrtemp[100]={ 0 };
  8818. char requestedMessagestr[40]={0};
  8819. char comfirmstr[20]={0};
  8820. int c = 0;
  8821. char *loc;
  8822. DEBUG_INFO("handleTriggerMessageRequest\n");
  8823. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  8824. strcpy(sstrtemp, stringtrimspace(payload));
  8825. c = 0;
  8826. loc = strstr(sstrtemp, "requestedMessage");
  8827. while (loc[3+strlen("requestedMessage")+c] != '\"')
  8828. {
  8829. sstr[c] = loc[3+strlen("requestedMessage")+c];
  8830. c++;
  8831. }
  8832. sstr[c] = '\0';
  8833. strcpy(requestedMessagestr, sstr);
  8834. c = 0;
  8835. loc = strstr(sstrtemp, "connectorId");
  8836. if(loc == NULL)
  8837. {
  8838. connectorIdIsNULL = TRUE;
  8839. }
  8840. else
  8841. {
  8842. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8843. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  8844. {
  8845. sstr[c] = loc[strlen("connectorId")+2+c];
  8846. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8847. c++;
  8848. }
  8849. sstr[c] = '\0';
  8850. connectorIdInt = atoi(sstr);
  8851. }
  8852. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  8853. {
  8854. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  8855. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  8856. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  8857. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  8858. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  8859. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  8860. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  8861. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  8862. {
  8863. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  8864. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8865. return TRUE;
  8866. }
  8867. else
  8868. {
  8869. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  8870. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8871. }
  8872. }
  8873. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  8874. {
  8875. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  8876. sendTriggerMessageConfirmation(uuid,comfirmstr);
  8877. return TRUE;
  8878. }
  8879. //==========================
  8880. // Trigger message
  8881. //==========================
  8882. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  8883. {
  8884. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  8885. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  8886. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  8887. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  8888. {
  8889. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  8890. }
  8891. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  8892. }
  8893. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  8894. {
  8895. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  8896. }
  8897. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  8898. {
  8899. //sendBootNotificationRequest();
  8900. server_sign = FALSE;
  8901. }
  8902. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  8903. {
  8904. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  8905. }
  8906. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  8907. {
  8908. if(connectorIdIsNULL == FALSE)
  8909. {
  8910. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8911. {
  8912. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  8913. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  8914. }
  8915. }
  8916. else
  8917. {
  8918. for(int idx=0;idx< gunTotalNumber;idx++)
  8919. {
  8920. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  8921. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  8922. }
  8923. }
  8924. }
  8925. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  8926. {
  8927. if(connectorIdIsNULL == FALSE)
  8928. {
  8929. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  8930. {
  8931. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  8932. }
  8933. }
  8934. else
  8935. {
  8936. for(int idx=0;idx< gunTotalNumber;idx++)
  8937. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  8938. }
  8939. }
  8940. return result;
  8941. }
  8942. int handleUnlockConnectorRequest(char *uuid, char *payload)
  8943. {
  8944. mtrace();
  8945. int result = FAIL;
  8946. int connectorIdInt =0;
  8947. char comfirmstr[20]={0};
  8948. int tempIndex = 0;
  8949. json_object *UnlockConnector;
  8950. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  8951. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  8952. UnlockConnector = json_tokener_parse(payload);
  8953. if(!is_error(UnlockConnector))
  8954. {
  8955. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  8956. {
  8957. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  8958. }
  8959. }
  8960. json_object_put(UnlockConnector);
  8961. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  8962. if(gunTotalNumber == 0)
  8963. {
  8964. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8965. goto end;
  8966. }
  8967. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  8968. {
  8969. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8970. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  8971. goto end;
  8972. }
  8973. else
  8974. {
  8975. //check Transaction active
  8976. if(gunType[connectorIdInt-1] == 'J')
  8977. {
  8978. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8979. {
  8980. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8981. }
  8982. else
  8983. {
  8984. tempIndex = connectorIdInt -1;
  8985. }
  8986. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8987. {
  8988. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  8989. {
  8990. //stop Transaction
  8991. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  8992. }
  8993. }
  8994. }
  8995. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  8996. {
  8997. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8998. {
  8999. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9000. }
  9001. else
  9002. {
  9003. tempIndex = connectorIdInt -1;
  9004. }
  9005. for (int index = 0; index < CCS_QUANTITY; index++)
  9006. {
  9007. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9008. {
  9009. //stop Transaction
  9010. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9011. }
  9012. }
  9013. }
  9014. else if(gunType[connectorIdInt-1] == 'G')
  9015. {
  9016. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9017. {
  9018. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9019. }
  9020. else
  9021. {
  9022. tempIndex = connectorIdInt -1;
  9023. }
  9024. for (int index = 0; index < GB_QUANTITY; index++)
  9025. {
  9026. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9027. {
  9028. //stop Transaction
  9029. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9030. }
  9031. }
  9032. }
  9033. else
  9034. {
  9035. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9036. {
  9037. tempIndex = 2;
  9038. }
  9039. else
  9040. {
  9041. tempIndex = connectorIdInt-1;
  9042. }
  9043. for (int index = 0; index < AC_QUANTITY; index++)
  9044. {
  9045. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9046. {
  9047. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9048. }
  9049. }
  9050. }
  9051. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9052. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9053. result = TRUE;
  9054. return result;
  9055. }
  9056. end:
  9057. //json_object_put(obj); --- remove temporally
  9058. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9059. return result;
  9060. }
  9061. static char UpdateFirmwarepayloadData[300]={0};
  9062. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9063. {
  9064. mtrace();
  9065. int result = FAIL;
  9066. pthread_t t;
  9067. sendUpdateFirmwareConfirmation(uuid);
  9068. memset(UpdateFirmwarepayloadData, 0, 300);
  9069. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9070. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9071. ////pthread_join(t, NULL); //
  9072. //pthread_detach(t);
  9073. //sendUpdateFirmwareConfirmation(uuid);
  9074. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9075. return result;
  9076. }
  9077. void *UpdateFirmwareProcess(void *data)
  9078. {
  9079. pthread_detach(pthread_self());
  9080. mtrace();
  9081. int retriesInt =0, retryIntervalInt=0;
  9082. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9083. int port=0;
  9084. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9085. int isSuccess = 0;
  9086. char ftpbuf[200];
  9087. char temp[100];
  9088. char * pch;
  9089. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9090. json_object *UpdateFirmware;
  9091. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  9092. if(!is_error(UpdateFirmware))
  9093. {
  9094. // Required data
  9095. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  9096. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  9097. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  9098. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  9099. // Optional data
  9100. if(json_object_object_get(UpdateFirmware, "retries"))
  9101. {
  9102. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  9103. }
  9104. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  9105. {
  9106. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  9107. }
  9108. }
  9109. json_object_put(UpdateFirmware);
  9110. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9111. memset(path, 0, ARRAY_SIZE(path));
  9112. system("rm -f /mnt/*");
  9113. if(strncmp(locationstr,"http", 4) == 0)
  9114. {
  9115. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9116. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9117. // protocol, user, password, host, path);
  9118. sprintf(ftppath,"/%s", path);
  9119. DEBUG_INFO("locationstr: %s\n", locationstr);
  9120. DEBUG_INFO("protocol: %s\n",protocol);
  9121. DEBUG_INFO("host: %s\n",host);
  9122. DEBUG_INFO("path: %s\n",path);
  9123. DEBUG_INFO("ftppath: %s\n",ftppath);
  9124. int ftppathlen=strlen(ftppath);
  9125. int i=1;
  9126. char filenametemp[50];
  9127. while(i < ftppathlen)
  9128. {
  9129. int len=ftppathlen-i;
  9130. if(ftppath[len]== 47) // '/' ascll code: 47
  9131. {
  9132. DEBUG_INFO("compare '/' all right\n");
  9133. break;
  9134. }
  9135. i=i+1;
  9136. }
  9137. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9138. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9139. filenametemp[i+1] = 0;
  9140. do
  9141. {
  9142. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9143. sleep(3);
  9144. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9145. if(!isSuccess)
  9146. {
  9147. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9148. sleep(retryIntervalInt);
  9149. }
  9150. else
  9151. {
  9152. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9153. }
  9154. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9155. }
  9156. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9157. {
  9158. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9159. memset(temp, 0, ARRAY_SIZE(temp));
  9160. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9161. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9162. int ftppathlen=strlen(ftpbuf);
  9163. int i=1;
  9164. char filenametemp[50];
  9165. while(i < ftppathlen)
  9166. {
  9167. int len=ftppathlen-i;
  9168. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9169. {
  9170. DEBUG_INFO(" compare '/' all right\n");
  9171. break;
  9172. }
  9173. i=i+1;
  9174. }
  9175. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9176. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9177. filenametemp[i+1] = 0;
  9178. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9179. pch=strchr(temp,'@');
  9180. if(pch==NULL)
  9181. {
  9182. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9183. protocol, host, &port, path);
  9184. strcpy(user,"anonymous");
  9185. strcpy(password,"");
  9186. }
  9187. else
  9188. {
  9189. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9190. protocol, user, password, host, &port, path);
  9191. }
  9192. sscanf(host,"%[^/]%s",host1, path1);
  9193. sprintf(ftppath,"%s", path1);
  9194. //DEBUG_INFO("protocol =%s\n",protocol);
  9195. //DEBUG_INFO("user =%s\n",user);
  9196. //DEBUG_INFO("password =%s\n",password);
  9197. //DEBUG_INFO("host1 =%s\n",host1);
  9198. //DEBUG_INFO("port =%d\n",port);
  9199. //DEBUG_INFO("path1 =%s\n",path1);
  9200. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9201. //ftpFile(host, user, password, port, ftppath, fname);
  9202. //download firmware pthred
  9203. if(port == 0)
  9204. {
  9205. port = 21;
  9206. }
  9207. do
  9208. {
  9209. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9210. sleep(3);
  9211. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9212. if(!isSuccess)
  9213. {
  9214. //BulldogUtil.sleepMs(interval*1000);
  9215. DEBUG_INFO("Update firmware request and download file fail.\n");
  9216. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9217. sleep(retryIntervalInt);
  9218. }
  9219. else
  9220. {
  9221. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9222. }
  9223. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9224. }
  9225. else
  9226. {
  9227. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9228. }
  9229. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9230. pthread_exit(NULL);
  9231. }
  9232. //==========================================
  9233. // Handle server response routine
  9234. //==========================================
  9235. void handleAuthorizeResponse(char *payload, int gun_index)
  9236. {
  9237. mtrace();
  9238. char expiryDatestr[30]={0};
  9239. char parentIdTagstr[20]={0};
  9240. char statusstr[20]={0};
  9241. char expiryDatestrtemp[30]={0};
  9242. char parentIdTagstrtemp[20]={0};
  9243. char IdTagstrtemp[20]={0};
  9244. char statusstrtemp[20]={0};
  9245. int expiryDateISNULL=FALSE;
  9246. int parentIdTagISNULL=FALSE;
  9247. char sstr[160]={0};
  9248. char* filename = AuthorizationCache_JSON;
  9249. char tempfile[] = "/Storage/OCPP/Authorizetemp.json";
  9250. char *loc;
  9251. int resultRename=0;
  9252. int responseIdTagInfoAsZero= 0;
  9253. char rmFileCmd[50]={0};
  9254. DEBUG_INFO("handleAuthorizeResponse...\n");
  9255. json_object *Authorize;
  9256. Authorize = json_tokener_parse(payload);
  9257. if(!is_error(Authorize))
  9258. {
  9259. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9260. {
  9261. // Required data
  9262. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9263. // Optional data
  9264. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9265. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9266. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9267. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9268. }
  9269. }
  9270. json_object_put(Authorize);
  9271. if(expiryDateISNULL == FALSE)
  9272. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9273. if(parentIdTagISNULL == FALSE)
  9274. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9275. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9276. //Update idTag information to authorization cache if supproted
  9277. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9278. {
  9279. if((access(filename,F_OK))!=-1)
  9280. {
  9281. printf("AuthorizationCache exist.\n");
  9282. }
  9283. else
  9284. {
  9285. printf("AuthorizationCache not exist\n");
  9286. FILE *log = fopen(filename, "w+");
  9287. if(log == NULL)
  9288. {
  9289. printf("log is NULL\n");
  9290. goto out;
  9291. }
  9292. else
  9293. {
  9294. fclose(log);
  9295. }
  9296. }
  9297. FILE *infile;
  9298. FILE *outfile;
  9299. // open file for writing
  9300. infile = fopen (filename, "r");
  9301. outfile = fopen (tempfile, "w");
  9302. int c;
  9303. c = fgetc(infile);
  9304. //DEBUG_INFO("c:%d\n",c);
  9305. rewind(infile);
  9306. if(c == EOF)
  9307. {
  9308. DEBUG_INFO("Orignal File is NULL\n");
  9309. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9310. {
  9311. strcpy(expiryDatestrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9312. }
  9313. else
  9314. {
  9315. strcpy(expiryDatestrtemp, "");
  9316. }
  9317. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9318. {
  9319. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9320. }
  9321. else
  9322. {
  9323. strcpy(parentIdTagstrtemp, (const char *)ShmOCPP16Data->Authorize.IdTag);
  9324. }
  9325. strcpy(statusstrtemp, (const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9326. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9327. fclose(infile);
  9328. fclose(outfile);
  9329. sprintf(rmFileCmd,"rm -f %s",filename);
  9330. system(rmFileCmd);
  9331. resultRename = rename(tempfile, filename);
  9332. if(resultRename == 0)
  9333. {
  9334. printf("File renamed successfully");
  9335. }
  9336. else
  9337. {
  9338. printf("Error: unable to rename the file");
  9339. }
  9340. }
  9341. else
  9342. {
  9343. char buf[160]={0};
  9344. while (fgets(buf, ARRAY_SIZE(buf), infile) != NULL)
  9345. {
  9346. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  9347. memset(expiryDatestr, 0, ARRAY_SIZE(expiryDatestrtemp));
  9348. memset(parentIdTagstr,0, ARRAY_SIZE(parentIdTagstrtemp));
  9349. memset(statusstr, 0, ARRAY_SIZE(statusstrtemp));
  9350. memset(IdTagstrtemp, 0, ARRAY_SIZE(IdTagstrtemp));
  9351. memset(expiryDatestrtemp, 0, ARRAY_SIZE(expiryDatestrtemp));
  9352. memset(parentIdTagstrtemp, 0, ARRAY_SIZE(parentIdTagstrtemp));
  9353. memset(statusstrtemp, 0, ARRAY_SIZE(statusstrtemp));
  9354. //------------------IdTag-----------------------
  9355. loc = strstr(buf, "idTag");
  9356. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9357. c = 0;
  9358. while (loc[3+strlen("idTag")+c] != '\"')
  9359. {
  9360. sstr[c] = loc[3+strlen("idTag")+c];
  9361. c++;
  9362. }
  9363. sstr[c] = '\0';
  9364. strcpy(IdTagstrtemp,sstr);
  9365. //*********************expiryDate***************/
  9366. loc = strstr(buf, "expiryDate");
  9367. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9368. c = 0;
  9369. while (loc[3+strlen("expiryDate")+c] != '\"')
  9370. {
  9371. sstr[c] = loc[3+strlen("expiryDate")+c];
  9372. c++;
  9373. }
  9374. sstr[c] = '\0';
  9375. strcpy(expiryDatestr,sstr);
  9376. //*********************parentIdTag***************/
  9377. loc = strstr(buf, "parentIdTag");
  9378. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9379. c = 0;
  9380. while (loc[3+strlen("parentIdTag")+c] != '\"')
  9381. {
  9382. sstr[c] = loc[3+strlen("parentIdTag")+c];
  9383. c++;
  9384. }
  9385. sstr[c] = '\0';
  9386. strcpy(parentIdTagstr,sstr);
  9387. //*********************status***************/
  9388. loc = strstr(buf, "status");
  9389. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9390. c = 0;
  9391. while (loc[3+strlen("status")+c] != '\"')
  9392. {
  9393. sstr[c] = loc[3+strlen("status")+c];
  9394. c++;
  9395. }
  9396. sstr[c] = '\0';
  9397. strcpy(statusstr,sstr);
  9398. if(((ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag == NULL) || strcmp((const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "") == 0) || (strcmp((const char *)ShmOCPP16Data->Authorize.IdTag, IdTagstrtemp) == 0))
  9399. {
  9400. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag is NULL\n");
  9401. responseIdTagInfoAsZero = 1;
  9402. }
  9403. else
  9404. {
  9405. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag=%s\n",ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9406. }
  9407. if((responseIdTagInfoAsZero == 0)&&((strcmp(parentIdTagstr,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag) == 0)|| (strcmp(IdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.IdTag) == 0)))
  9408. {
  9409. //modify item
  9410. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL)
  9411. {
  9412. strcpy(expiryDatestrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate);
  9413. }
  9414. else
  9415. {
  9416. strcpy(expiryDatestrtemp, "");
  9417. }
  9418. if(ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL)
  9419. {
  9420. strcpy(parentIdTagstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag);
  9421. }
  9422. else
  9423. {
  9424. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9425. }
  9426. strcpy(statusstrtemp,(const char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  9427. }
  9428. else
  9429. {
  9430. //wrie original item
  9431. strcpy(expiryDatestrtemp, expiryDatestr);
  9432. strcpy(parentIdTagstrtemp, parentIdTagstr);
  9433. strcpy(statusstrtemp, statusstr);
  9434. }
  9435. fprintf(outfile,"[{\"idTag\":\"%s\",\"idTagInfo\":{\"expiryDate\":\"%s\",\"parentIdTag\":\"%s\",\"status\":\"%s\"}}]\n",ShmOCPP16Data->Authorize.IdTag, expiryDatestrtemp, parentIdTagstrtemp, statusstrtemp);
  9436. }
  9437. fclose(infile);
  9438. fclose(outfile);
  9439. sprintf(rmFileCmd,"rm -f %s",filename);
  9440. system(rmFileCmd);
  9441. resultRename = rename(tempfile, filename);
  9442. if(resultRename == 0)
  9443. {
  9444. DEBUG_INFO("File renamed successfully");
  9445. }
  9446. else
  9447. {
  9448. DEBUG_INFO("Error: unable to rename the file");
  9449. }
  9450. }
  9451. }
  9452. out:
  9453. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9454. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9455. authorizeRetryTimes = 0;
  9456. }
  9457. char * strtrimc( char * s )
  9458. {
  9459. char * p1 = s;
  9460. char * p2 = s;
  9461. while(*p1 != '\0')
  9462. {
  9463. while(*p1 == ' ' || *p1 == '\t' || *p1 == '\"' || *p1 == '\n' || *p1 == '}' || *p1 == '\r')
  9464. {
  9465. if(*p1 != ',')
  9466. {
  9467. p1 ++;
  9468. }
  9469. else
  9470. {
  9471. break;
  9472. }
  9473. }
  9474. if(*p1 != ',')
  9475. {
  9476. * p2 ++ = *p1 ++;
  9477. //printf("p2=%s\n",p2);
  9478. }
  9479. else
  9480. {
  9481. break;
  9482. }
  9483. }
  9484. *p2 = '\0';
  9485. return (s);
  9486. }
  9487. void handleBootNotificationResponse(char *payload, int gun_index)
  9488. {
  9489. mtrace();
  9490. char statusStr[12]={0};
  9491. char currentTimeStr[30]={0};
  9492. int intervalInt = 0;
  9493. struct tm tp;
  9494. char buf[28]={0};
  9495. char timebuf[50]={0};
  9496. DEBUG_INFO("handleBootNotificationResponse...\n");
  9497. json_object *BootNotification;
  9498. BootNotification = json_tokener_parse(payload);
  9499. if(!is_error(BootNotification))
  9500. {
  9501. // Required data
  9502. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9503. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9504. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9505. }
  9506. json_object_put(BootNotification);
  9507. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9508. BootNotificationInterval = intervalInt;
  9509. HeartBeatWaitTime = intervalInt;
  9510. //write back to ShmOCPP16Data->BootNotification
  9511. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9512. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9513. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9514. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9515. {
  9516. server_sign = TRUE;
  9517. server_pending =FALSE;
  9518. }
  9519. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9520. {
  9521. server_pending = TRUE;
  9522. }
  9523. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9524. tp.tm_isdst = -1;
  9525. //time_t utc = mktime(&tp);
  9526. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9527. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9528. sprintf(timebuf,"date -s '%s'",buf);
  9529. system(timebuf);
  9530. srand(time(NULL));
  9531. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  9532. //==============================================
  9533. // RTC sync
  9534. //==============================================
  9535. system("/sbin/hwclock -w --systohc");
  9536. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9537. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9538. }
  9539. void handleDataTransferResponse(char *payload, int gun_index)
  9540. {
  9541. char sstr[160]={0};//sstr[200]={ 0 };
  9542. int c = 0;
  9543. char *loc;
  9544. DEBUG_INFO("handleDataTransferResponse ...\n");
  9545. loc = strstr(payload, "status");
  9546. printf("loc=%s\n",loc);
  9547. c = 0;
  9548. while (loc[3+strlen("status")+c] != '\"')
  9549. {
  9550. sstr[c] = loc[3+strlen("status")+c];
  9551. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9552. c++;
  9553. }
  9554. sstr[c] = '\0';
  9555. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9556. }
  9557. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9558. {
  9559. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9560. //struct json_object *obj;
  9561. // obj = json_tokener_parse(payload);
  9562. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9563. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9564. //No fields are defined.
  9565. }
  9566. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9567. {
  9568. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9569. //struct json_object *obj;
  9570. // obj = json_tokener_parse(payload);
  9571. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9572. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9573. //No fields are defined.
  9574. }
  9575. void handleHeartbeatResponse(char *payload, int gun_index)
  9576. {
  9577. mtrace();
  9578. struct tm tp;
  9579. char buf[28]={0};
  9580. char timebuf[50]={0};
  9581. DEBUG_INFO("handleHeartbeatResponse...\n");
  9582. json_object *Heartbeat;
  9583. Heartbeat = json_tokener_parse(payload);
  9584. if(!is_error(Heartbeat))
  9585. {
  9586. // Required data
  9587. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  9588. }
  9589. json_object_put(Heartbeat);
  9590. if(FirstHeartBeat == 0)
  9591. {
  9592. FirstHeartBeat = 1;
  9593. DEBUG_INFO("FirstHeartBeat \n");
  9594. }
  9595. HeartBeatWithNOResponse = 0;
  9596. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9597. tp.tm_isdst = -1;
  9598. //time_t utc = mktime(&tp);
  9599. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9600. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9601. sprintf(timebuf,"date -s '%s'",buf);
  9602. system(timebuf);
  9603. //==============================================
  9604. // RTC sync
  9605. //==============================================
  9606. system("/sbin/hwclock -w --systohc");
  9607. }
  9608. void handleMeterValuesResponse(char *payload, int gun_index)
  9609. {
  9610. mtrace();
  9611. DEBUG_INFO("handleMeterValuesResponse...\n");
  9612. }
  9613. void handleStartTransactionResponse(char *payload, int gun_index)
  9614. {
  9615. mtrace();
  9616. //int transactionIdInt = 0;
  9617. FILE *outfile;
  9618. char data[100]={0};
  9619. DEBUG_INFO("handleStartTransactionResponse...\n");
  9620. json_object *StartTransaction;
  9621. StartTransaction = json_tokener_parse(payload);
  9622. if(!is_error(StartTransaction))
  9623. {
  9624. // Required data
  9625. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  9626. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  9627. // Optional data
  9628. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  9629. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  9630. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9631. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  9632. }
  9633. json_object_put(StartTransaction);
  9634. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9635. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9636. //-----------Start : write to the Queue TransactionId file -----------------//
  9637. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9638. {}
  9639. else
  9640. {
  9641. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9642. if(log == NULL)
  9643. {
  9644. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9645. return ;
  9646. }
  9647. else
  9648. {
  9649. fclose(log);
  9650. }
  9651. }
  9652. // open file for writing
  9653. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  9654. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  9655. {
  9656. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9657. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9658. fputs(data, outfile);
  9659. fclose (outfile);
  9660. }
  9661. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9662. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9663. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9664. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9665. }
  9666. void handleStatusNotificationResponse(char *payload, int gun_index)
  9667. {
  9668. mtrace();
  9669. DEBUG_INFO("handleStatusNotificationResponse...\n");
  9670. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9671. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9672. }
  9673. void handleStopTransactionnResponse(char *payload, int gun_index)
  9674. {
  9675. mtrace();
  9676. DEBUG_INFO("handleStopTransactionnResponse...\n");
  9677. json_object *StopTransaction;
  9678. StopTransaction = json_tokener_parse(payload);
  9679. if(!is_error(StopTransaction))
  9680. {
  9681. // Optional data
  9682. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  9683. {
  9684. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  9685. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  9686. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  9687. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9688. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  9689. }
  9690. }
  9691. json_object_put(StopTransaction);
  9692. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  9693. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  9694. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9695. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9696. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9697. }
  9698. //==========================================
  9699. // Handle Error routine
  9700. //==========================================
  9701. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9702. {
  9703. mtrace();
  9704. #ifdef SystemLogMessage
  9705. DEBUG_INFO("errorCode: %s\n", errorCode);
  9706. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9707. DEBUG_INFO("errorDetails: %s\n", payload);
  9708. #endif
  9709. }
  9710. //===============================================
  9711. // Common routine
  9712. //===============================================
  9713. int initialConfigurationTable(void)
  9714. {
  9715. //clock_t start_t, end_t, total_t;
  9716. FILE *fp;
  9717. FILE *outfile;
  9718. char str[200]={0};
  9719. char sstr[100]={0};
  9720. int c = 0;
  9721. char *loc;
  9722. DEBUG_INFO("initialConfigurationTable...\n");
  9723. //start_t = clock();
  9724. //printf("Starting of the program, start_t = %ld\n", start_t);
  9725. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  9726. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  9727. {
  9728. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  9729. if(outfile == NULL)
  9730. {
  9731. DEBUG_INFO("Error opening file\n");
  9732. return FALSE;
  9733. }
  9734. /*Core Profile*/
  9735. //AllowOfflineTxForUnknownId
  9736. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  9739. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  9740. //AuthorizationCacheEnabled
  9741. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9742. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9743. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9744. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  9745. //AuthorizeRemoteTxRequests
  9746. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9747. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9748. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  9749. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  9750. //BlinkRepeat
  9751. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9754. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  9755. //ClockAlignedDataInterval
  9756. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9757. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9758. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9759. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  9760. //ConnectionTimeOut
  9761. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9762. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9763. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9764. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  9765. //GetConfigurationMaxKeys
  9766. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9768. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "44" );
  9769. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  9770. // HeartbeatInterval
  9771. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9772. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9773. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  9774. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  9775. // LightIntensity
  9776. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9777. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9778. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9779. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  9780. // LocalAuthorizeOffline
  9781. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  9782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9783. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  9785. // LocalPreAuthorize
  9786. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9787. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9789. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  9790. // MaxEnergyOnInvalidId
  9791. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9792. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9793. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9794. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9795. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  9796. // MeterValuesAlignedData
  9797. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  9798. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9799. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9800. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  9801. else
  9802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  9803. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  9804. // MeterValuesAlignedDataMaxLength
  9805. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9806. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9807. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9808. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  9809. else
  9810. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9811. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  9812. // MeterValuesSampledData
  9813. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  9814. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9815. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9816. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  9817. else
  9818. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  9819. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  9820. // MeterValuesSampledDataMaxLength
  9821. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9822. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9823. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9824. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  9825. else
  9826. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9827. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  9828. // MeterValueSampleInterval
  9829. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9830. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9831. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  9832. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  9833. // MinimumStatusDuration
  9834. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9835. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9836. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  9837. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  9838. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  9839. // NumberOfConnectors
  9840. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9841. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9842. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9843. {
  9844. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9845. }
  9846. else
  9847. {
  9848. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9849. }
  9850. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9851. // ResetRetries
  9852. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9854. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9855. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  9856. // ConnectorPhaseRotation
  9857. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9859. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9860. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  9861. // ConnectorPhaseRotationMaxLength
  9862. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9864. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9865. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  9866. // StopTransactionOnEVSideDisconnect
  9867. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9869. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9870. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  9871. // StopTransactionOnInvalidId
  9872. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  9873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9874. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9875. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  9876. // StopTxnAlignedData
  9877. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  9878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9879. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9880. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  9881. // StopTxnAlignedDataMaxLength
  9882. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9884. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9885. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  9886. // StopTxnSampledData
  9887. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  9888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9889. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9890. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  9891. else
  9892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  9893. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  9894. // StopTxnSampledDataMaxLength
  9895. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  9896. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  9897. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9898. {
  9899. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  9900. }
  9901. else
  9902. {
  9903. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  9904. }
  9905. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  9906. // SupportedFeatureProfiles
  9907. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  9908. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  9909. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  9910. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  9911. // SupportedFeatureProfilesMaxLength
  9912. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  9913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  9914. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  9915. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  9916. // TransactionMessageAttempts
  9917. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  9918. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  9919. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  9920. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9921. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  9922. // TransactionMessageRetryInterval
  9923. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  9924. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  9925. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  9926. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9927. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  9928. // UnlockConnectorOnEVSideDisconnect
  9929. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  9930. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  9931. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  9932. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  9933. // WebSocketPingInterval
  9934. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  9935. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  9936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  9937. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  9938. // QueueOffLineStartTransactionMessage
  9939. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  9940. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  9941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  9942. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  9943. // AuthorizationKey
  9944. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  9945. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  9946. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "" );
  9947. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  9948. // SecurityProfile
  9949. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  9950. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  9951. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "0" );
  9952. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  9953. // DefaultPrice
  9954. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  9955. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  9956. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  9957. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  9958. // CustomDisplayCostAndPrice
  9959. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  9960. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  9961. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  9962. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  9963. // CustomIdleFeeAfterStop
  9964. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  9965. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  9966. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  9967. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  9968. //* Local Auth List Management Profile*/
  9969. #if 0
  9970. //For OCTT Test Case
  9971. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9972. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  9973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9974. #endif
  9975. #if 1
  9976. //LocalAuthListEnabled
  9977. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  9978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  9979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  9980. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  9981. #endif
  9982. //LocalAuthListMaxLength
  9983. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  9984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  9985. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  9986. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  9987. //SendLocalListMaxLength
  9988. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  9989. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  9990. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  9991. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  9992. //ReserveConnectorZeroSupported
  9993. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  9994. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  9995. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  9996. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  9997. //* Smart Charging Profile */
  9998. //ChargeProfileMaxStackLevel
  9999. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10000. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10002. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10003. // ChargingScheduleAllowedChargingRateUnit
  10004. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10005. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10006. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10007. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10008. // ChargingScheduleMaxPeriods
  10009. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10010. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10011. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10012. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10013. // ConnectorSwitch3to1PhaseSupported
  10014. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10015. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10016. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10017. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10018. // MaxChargingProfilesInstalled
  10019. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10020. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10021. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "5" );
  10022. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10023. fclose(outfile);
  10024. }
  10025. else
  10026. {
  10027. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10028. char keystr[60]={0};
  10029. char readonlystr[10]={0};
  10030. char valuestr[100]={0};
  10031. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10032. if(fp == NULL) {
  10033. DEBUG_INFO("Error opening file");
  10034. return FALSE;
  10035. }
  10036. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10037. {
  10038. //DEBUG_INFO("Get Configuration \n");
  10039. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10040. //*************************key*********************************/
  10041. loc = strstr(str, "key");
  10042. c = 0;
  10043. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10044. while (loc[strlen("key")+3+c] != '\"')
  10045. {
  10046. sstr[c] = loc[strlen("key")+3+c];
  10047. c++;
  10048. }
  10049. sstr[c] = '\0';
  10050. strcpy(keystr,sstr);
  10051. //*************************readonly*********************************/
  10052. loc = strstr(str, "readonly");
  10053. c = 0;
  10054. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10055. while (loc[strlen("readonly")+2+c] != ',')
  10056. {
  10057. sstr[c] = loc[strlen("readonly")+2+c];
  10058. c++;
  10059. }
  10060. sstr[c] = '\0';
  10061. strcpy(readonlystr,sstr);
  10062. //*************************value*********************************/
  10063. loc = strstr(str, "value");
  10064. c = 0;
  10065. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10066. while (loc[strlen("value")+3+c] != '\"')
  10067. {
  10068. sstr[c] = loc[strlen("value")+3+c];
  10069. c++;
  10070. }
  10071. sstr[c] = '\0';
  10072. strcpy(valuestr,sstr);
  10073. // DEBUG_INFO("keystr=%s\n",keystr);
  10074. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10075. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10076. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10077. {
  10078. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10079. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10080. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10081. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10082. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10083. }
  10084. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10085. {
  10086. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10087. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10088. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10089. }
  10090. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10091. {
  10092. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10093. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10094. }
  10095. if(strcmp(keystr, "BlinkRepeat") == 0)
  10096. {
  10097. //Charger.BlinkRepeat = Integer.parseInt(value);
  10098. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10099. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10100. }
  10101. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10102. {
  10103. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10104. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10105. }
  10106. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10107. {
  10108. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10109. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10110. }
  10111. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10112. {
  10113. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10114. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  10115. }
  10116. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10117. {
  10118. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10119. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10120. HeartBeatWaitTime = atoi(valuestr);
  10121. }
  10122. if(strcmp(keystr, "LightIntensity") == 0)
  10123. {
  10124. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10125. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10126. }
  10127. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10128. {
  10129. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10130. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10131. }
  10132. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10133. {
  10134. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10135. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10136. }
  10137. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10138. {
  10139. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10140. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10141. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10142. }
  10143. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10144. {
  10145. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10146. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10147. }
  10148. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10149. {
  10150. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10151. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10152. }
  10153. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10154. {
  10155. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10156. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10157. }
  10158. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10159. {
  10160. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10161. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10162. }
  10163. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10164. {
  10165. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10166. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10167. }
  10168. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10169. {
  10170. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10171. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10172. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10173. }
  10174. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10175. {
  10176. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10177. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10178. }
  10179. if(strcmp(keystr, "ResetRetries") == 0)
  10180. {
  10181. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10182. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10183. }
  10184. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10185. {
  10186. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10187. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10188. }
  10189. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10190. {
  10191. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10192. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10193. }
  10194. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10195. {
  10196. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10197. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10198. }
  10199. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10200. {
  10201. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10202. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10203. }
  10204. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10205. {
  10206. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10207. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10208. }
  10209. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10210. {
  10211. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10212. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10213. }
  10214. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10215. {
  10216. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10217. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10218. }
  10219. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10220. {
  10221. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10222. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10223. }
  10224. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10225. {
  10226. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10227. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10228. }
  10229. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10230. {
  10231. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10232. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10233. }
  10234. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10235. {
  10236. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10237. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10238. TransactionMessageAttemptsValue = atoi(valuestr);
  10239. }
  10240. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10241. {
  10242. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10243. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10244. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10245. }
  10246. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10247. {
  10248. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10249. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10250. }
  10251. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10252. {
  10253. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10254. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10255. }
  10256. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10257. {
  10258. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10259. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10260. }
  10261. if(strcmp(keystr, "AuthorizationKey") == 0)
  10262. {
  10263. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10264. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  10265. }
  10266. if(strcmp(keystr, "SecurityProfile") == 0)
  10267. {
  10268. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10269. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  10270. }
  10271. if(strcmp(keystr, "DefaultPrice") == 0)
  10272. {
  10273. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10274. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  10275. }
  10276. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  10277. {
  10278. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10279. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  10280. }
  10281. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  10282. {
  10283. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10284. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  10285. }
  10286. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10287. {
  10288. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10289. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10290. }
  10291. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10292. {
  10293. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10294. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10295. }
  10296. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10297. {
  10298. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10299. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10300. }
  10301. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10302. {
  10303. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10304. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10305. }
  10306. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10307. {
  10308. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10309. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10310. }
  10311. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10312. {
  10313. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10314. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10315. }
  10316. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10317. {
  10318. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10319. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10320. }
  10321. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10322. {
  10323. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10324. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10325. }
  10326. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10327. {
  10328. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10329. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10330. }
  10331. }
  10332. fclose(fp);
  10333. }
  10334. return 0;
  10335. }
  10336. void StoreConfigurationTable(void)
  10337. {
  10338. FILE *outfile;
  10339. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10340. if(outfile == NULL)
  10341. {
  10342. DEBUG_INFO("Error opening file");
  10343. return ;
  10344. }
  10345. /*Core Profile*/
  10346. //AllowOfflineTxForUnknownId
  10347. /*
  10348. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10349. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10350. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10351. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10352. */
  10353. //DEBUG_INFO("data=%s\n",data);
  10354. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10355. //AuthorizationCacheEnabled
  10356. /*
  10357. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10358. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10359. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10360. */
  10361. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10362. //AuthorizeRemoteTxRequests
  10363. /*
  10364. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10365. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10366. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10367. */
  10368. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10369. //BlinkRepeat
  10370. /*
  10371. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10372. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10373. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10374. */
  10375. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10376. //ClockAlignedDataInterval
  10377. /*
  10378. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10379. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10380. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10381. */
  10382. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10383. //ConnectionTimeOut
  10384. /*
  10385. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10386. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10387. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10388. */
  10389. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10390. //GetConfigurationMaxKeys
  10391. /*
  10392. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10393. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10394. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10395. */
  10396. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10397. // HeartbeatInterval
  10398. /*
  10399. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10400. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10401. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10402. */
  10403. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10404. // LightIntensity
  10405. /*
  10406. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10407. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10408. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10409. */
  10410. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10411. // LocalAuthorizeOffline
  10412. /*
  10413. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10414. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10415. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10416. */
  10417. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10418. // LocalPreAuthorize
  10419. /*
  10420. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10421. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10422. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10423. */
  10424. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10425. // MaxEnergyOnInvalidId
  10426. /*
  10427. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10428. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10429. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10430. */
  10431. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10432. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10433. // MeterValuesAlignedData
  10434. /*
  10435. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10436. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10437. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10438. */
  10439. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10440. // MeterValuesAlignedDataMaxLength
  10441. /*
  10442. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10443. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10444. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10445. */
  10446. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10447. // MeterValuesSampledData
  10448. /*
  10449. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10450. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10451. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10452. */
  10453. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10454. // MeterValuesSampledDataMaxLength
  10455. /*
  10456. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10457. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10458. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10459. */
  10460. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10461. // MeterValueSampleInterval
  10462. /*
  10463. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10464. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10465. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10466. */
  10467. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10468. // MinimumStatusDuration
  10469. /*
  10470. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10471. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10472. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10473. */
  10474. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10475. // NumberOfConnectors
  10476. /*
  10477. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10479. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10480. {
  10481. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10482. }
  10483. else
  10484. {
  10485. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10486. }
  10487. */
  10488. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10489. // ResetRetries
  10490. /*
  10491. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10492. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10493. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10494. */
  10495. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10496. // ConnectorPhaseRotation
  10497. /*
  10498. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10499. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10500. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10501. */
  10502. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10503. // ConnectorPhaseRotationMaxLength
  10504. /*
  10505. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10506. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10507. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10508. */
  10509. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10510. // StopTransactionOnEVSideDisconnect
  10511. /*
  10512. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10513. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10514. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10515. */
  10516. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10517. // StopTransactionOnInvalidId
  10518. /*
  10519. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10520. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10521. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10522. */
  10523. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10524. // StopTxnAlignedData
  10525. /*
  10526. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10528. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10529. */
  10530. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10531. // StopTxnAlignedDataMaxLength
  10532. /*
  10533. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10534. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10535. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10536. */
  10537. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10538. // StopTxnSampledData
  10539. /*
  10540. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10543. */
  10544. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10545. // StopTxnSampledDataMaxLength
  10546. /*
  10547. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10550. */
  10551. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10552. // SupportedFeatureProfiles
  10553. /*
  10554. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10555. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10557. */
  10558. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10559. // SupportedFeatureProfilesMaxLength
  10560. /*
  10561. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10564. */
  10565. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10566. // TransactionMessageAttempts
  10567. /*
  10568. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10571. */
  10572. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10573. // TransactionMessageRetryInterval
  10574. /*
  10575. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10578. */
  10579. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10580. // UnlockConnectorOnEVSideDisconnect
  10581. /*
  10582. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10584. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10585. */
  10586. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10587. // WebSocketPingInterval
  10588. /*
  10589. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10590. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10591. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10592. */
  10593. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10594. // QueueOffLineStartTransactionMessage
  10595. /*
  10596. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  10597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10599. */
  10600. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10601. // AuthorizationKey
  10602. /*
  10603. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  10606. */
  10607. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10608. // SecurityProfile
  10609. /*
  10610. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  10613. */
  10614. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10615. // DefaultPrice
  10616. /*
  10617. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  10618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  10619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  10620. */
  10621. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  10622. // CustomDisplayCostAndPrice
  10623. /*
  10624. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  10625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  10626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  10627. */
  10628. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  10629. // CustomIdleFeeAfterStop
  10630. /*
  10631. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  10632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  10633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  10634. */
  10635. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  10636. //* Local Auth List Management Profile*/
  10637. //LocalAuthListEnabled
  10638. /*
  10639. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10641. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10642. */
  10643. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10644. //LocalAuthListMaxLength
  10645. /*
  10646. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10648. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10649. */
  10650. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10651. //SendLocalListMaxLength
  10652. /*
  10653. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10655. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10656. */
  10657. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10658. //ReserveConnectorZeroSupported
  10659. /*
  10660. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10662. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10663. */
  10664. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10665. //* Smart Charging Profile */
  10666. //ChargeProfileMaxStackLevel
  10667. /*
  10668. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10669. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10670. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10671. */
  10672. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10673. // ChargingScheduleAllowedChargingRateUnit
  10674. /*
  10675. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10676. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10677. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10678. */
  10679. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10680. // ChargingScheduleMaxPeriods
  10681. /*
  10682. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10683. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10684. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10685. */
  10686. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10687. // ConnectorSwitch3to1PhaseSupported
  10688. /*
  10689. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10690. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10691. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10692. */
  10693. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10694. // MaxChargingProfilesInstalled
  10695. /*
  10696. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10697. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10698. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "3" );
  10699. */
  10700. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10701. fclose(outfile);
  10702. }
  10703. void getKeyValue(char *keyReq)
  10704. {
  10705. int isEmpty = FALSE;
  10706. int isKnowKey = FALSE;
  10707. DEBUG_INFO("keyReq = %s\n", keyReq);
  10708. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10709. isEmpty = TRUE;
  10710. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10711. {
  10712. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10713. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10714. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10715. {
  10716. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10717. }
  10718. else
  10719. {
  10720. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10721. }
  10722. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10723. isKnowKey = TRUE;
  10724. }
  10725. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10726. {
  10727. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10728. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10729. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10730. {
  10731. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10732. }
  10733. else
  10734. {
  10735. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10736. }
  10737. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10738. isKnowKey = TRUE;
  10739. }
  10740. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10741. {
  10742. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10743. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10744. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10745. {
  10746. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10747. }
  10748. else
  10749. {
  10750. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10751. }
  10752. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10753. isKnowKey = TRUE;
  10754. }
  10755. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10756. {
  10757. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10758. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  10759. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10760. {
  10761. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  10762. }
  10763. else
  10764. {
  10765. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  10766. }
  10767. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  10768. isKnowKey = TRUE;
  10769. }
  10770. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  10771. {
  10772. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  10773. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  10774. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10775. {
  10776. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  10777. }
  10778. else
  10779. {
  10780. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  10781. }
  10782. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  10783. isKnowKey = TRUE;
  10784. }
  10785. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  10786. {
  10787. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  10788. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  10789. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10790. {
  10791. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  10792. }
  10793. else
  10794. {
  10795. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  10796. }
  10797. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  10798. isKnowKey = TRUE;
  10799. }
  10800. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  10801. {
  10802. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  10803. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  10804. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10805. {
  10806. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  10807. }
  10808. else
  10809. {
  10810. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  10811. }
  10812. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  10813. isKnowKey = TRUE;
  10814. }
  10815. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  10816. {
  10817. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  10818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  10819. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10820. {
  10821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  10822. }
  10823. else
  10824. {
  10825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  10826. }
  10827. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  10828. isKnowKey = TRUE;
  10829. }
  10830. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  10831. {
  10832. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  10833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  10834. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10835. {
  10836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  10837. }
  10838. else
  10839. {
  10840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  10841. }
  10842. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  10843. isKnowKey = TRUE;
  10844. }
  10845. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  10846. {
  10847. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  10848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  10849. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10850. {
  10851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  10852. }
  10853. else
  10854. {
  10855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  10856. }
  10857. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  10858. isKnowKey = TRUE;
  10859. }
  10860. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  10861. {
  10862. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  10863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  10864. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10865. {
  10866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  10867. }
  10868. else
  10869. {
  10870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  10871. }
  10872. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  10873. isKnowKey = TRUE;
  10874. }
  10875. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  10876. {
  10877. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  10878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  10879. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10880. {
  10881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10882. }
  10883. else
  10884. {
  10885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10886. }
  10887. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  10888. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  10889. isKnowKey = TRUE;
  10890. }
  10891. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  10892. {
  10893. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  10894. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  10895. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  10896. {
  10897. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  10898. }
  10899. else
  10900. {
  10901. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  10902. }
  10903. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  10904. isKnowKey = TRUE;
  10905. }
  10906. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  10907. {
  10908. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  10909. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  10910. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  10911. {
  10912. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10913. }
  10914. else
  10915. {
  10916. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10917. }
  10918. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  10919. isKnowKey = TRUE;
  10920. }
  10921. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  10922. {
  10923. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  10924. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  10925. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  10926. {
  10927. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  10928. }
  10929. else
  10930. {
  10931. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  10932. }
  10933. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  10934. isKnowKey = TRUE;
  10935. }
  10936. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  10937. {
  10938. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  10939. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  10940. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  10941. {
  10942. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  10943. }
  10944. else
  10945. {
  10946. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  10947. }
  10948. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  10949. isKnowKey = TRUE;
  10950. }
  10951. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  10952. {
  10953. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  10954. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  10955. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  10956. {
  10957. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  10958. }
  10959. else
  10960. {
  10961. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  10962. }
  10963. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  10964. isKnowKey = TRUE;
  10965. }
  10966. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  10967. {
  10968. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  10969. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  10970. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  10971. {
  10972. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  10973. }
  10974. else
  10975. {
  10976. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  10977. }
  10978. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  10979. isKnowKey = TRUE;
  10980. }
  10981. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  10982. {
  10983. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  10984. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  10985. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  10986. {
  10987. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  10988. }
  10989. else
  10990. {
  10991. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  10992. }
  10993. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  10994. isKnowKey = TRUE;
  10995. }
  10996. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  10997. {
  10998. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  10999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11000. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11001. {
  11002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11003. }
  11004. else
  11005. {
  11006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11007. }
  11008. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11009. isKnowKey = TRUE;
  11010. }
  11011. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11012. {
  11013. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11015. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11016. {
  11017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11018. }
  11019. else
  11020. {
  11021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11022. }
  11023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11024. isKnowKey = TRUE;
  11025. }
  11026. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11027. {
  11028. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11030. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11031. {
  11032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11033. }
  11034. else
  11035. {
  11036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11037. }
  11038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11039. isKnowKey = TRUE;
  11040. }
  11041. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11042. {
  11043. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11045. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11046. {
  11047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11048. }
  11049. else
  11050. {
  11051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11052. }
  11053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11054. isKnowKey = TRUE;
  11055. }
  11056. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11057. {
  11058. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11060. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11061. {
  11062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11063. }
  11064. else
  11065. {
  11066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11067. }
  11068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11069. isKnowKey = TRUE;
  11070. }
  11071. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11072. {
  11073. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11075. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11076. {
  11077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11078. }
  11079. else
  11080. {
  11081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11082. }
  11083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11084. isKnowKey = TRUE;
  11085. }
  11086. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11087. {
  11088. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11090. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11091. {
  11092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11093. }
  11094. else
  11095. {
  11096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11097. }
  11098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11099. isKnowKey = TRUE;
  11100. }
  11101. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11102. {
  11103. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11105. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11106. {
  11107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11108. }
  11109. else
  11110. {
  11111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11112. }
  11113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11114. isKnowKey = TRUE;
  11115. }
  11116. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11117. {
  11118. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11120. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11121. {
  11122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11123. }
  11124. else
  11125. {
  11126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11127. }
  11128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11129. isKnowKey = TRUE;
  11130. }
  11131. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11132. {
  11133. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11135. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11136. {
  11137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11138. }
  11139. else
  11140. {
  11141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11142. }
  11143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11144. isKnowKey = TRUE;
  11145. }
  11146. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11147. {
  11148. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11150. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11151. {
  11152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11153. }
  11154. else
  11155. {
  11156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11157. }
  11158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11159. isKnowKey = TRUE;
  11160. }
  11161. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11162. {
  11163. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11165. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11166. {
  11167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11168. }
  11169. else
  11170. {
  11171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11172. }
  11173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11174. isKnowKey = TRUE;
  11175. }
  11176. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11177. {
  11178. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11180. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11181. {
  11182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11183. }
  11184. else
  11185. {
  11186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11187. }
  11188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11189. isKnowKey = TRUE;
  11190. }
  11191. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11192. {
  11193. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11195. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11196. {
  11197. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11198. }
  11199. else
  11200. {
  11201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11202. }
  11203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11204. isKnowKey = TRUE;
  11205. }
  11206. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11207. {
  11208. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11210. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11211. {
  11212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11213. }
  11214. else
  11215. {
  11216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11217. }
  11218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11219. isKnowKey = TRUE;
  11220. }
  11221. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11222. {
  11223. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11225. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11226. {
  11227. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11228. }
  11229. else
  11230. {
  11231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11232. }
  11233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11234. isKnowKey = TRUE;
  11235. }
  11236. /*
  11237. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  11238. {
  11239. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  11240. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  11241. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  11242. {
  11243. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  11244. }
  11245. else
  11246. {
  11247. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  11248. }
  11249. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  11250. isKnowKey = TRUE;
  11251. }*/
  11252. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  11253. {
  11254. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  11255. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  11256. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  11257. {
  11258. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  11259. }
  11260. else
  11261. {
  11262. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  11263. }
  11264. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  11265. isKnowKey = TRUE;
  11266. }
  11267. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  11268. {
  11269. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  11270. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  11271. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  11272. {
  11273. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  11274. }
  11275. else
  11276. {
  11277. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  11278. }
  11279. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  11280. isKnowKey = TRUE;
  11281. }
  11282. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  11283. {
  11284. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  11285. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  11286. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  11287. {
  11288. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  11289. }
  11290. else
  11291. {
  11292. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  11293. }
  11294. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  11295. isKnowKey = TRUE;
  11296. }
  11297. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  11298. {
  11299. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  11300. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  11301. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  11302. {
  11303. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  11304. }
  11305. else
  11306. {
  11307. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  11308. }
  11309. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  11310. isKnowKey = TRUE;
  11311. }
  11312. #if 1
  11313. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11314. {
  11315. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11316. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11317. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11318. {
  11319. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11320. }
  11321. else
  11322. {
  11323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11324. }
  11325. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11326. isKnowKey = TRUE;
  11327. }
  11328. #endif
  11329. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11330. {
  11331. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11333. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11334. {
  11335. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11336. }
  11337. else
  11338. {
  11339. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11340. }
  11341. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11342. isKnowKey = TRUE;
  11343. }
  11344. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11345. {
  11346. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11347. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11348. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11349. {
  11350. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11351. }
  11352. else
  11353. {
  11354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11355. }
  11356. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11357. isKnowKey = TRUE;
  11358. }
  11359. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11360. {
  11361. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11362. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11363. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11364. {
  11365. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11366. }
  11367. else
  11368. {
  11369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11370. }
  11371. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11372. isKnowKey = TRUE;
  11373. }
  11374. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11375. {
  11376. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11377. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11378. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11379. {
  11380. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11381. }
  11382. else
  11383. {
  11384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11385. }
  11386. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11387. isKnowKey = TRUE;
  11388. }
  11389. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11390. {
  11391. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11392. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11393. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11394. {
  11395. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11396. }
  11397. else
  11398. {
  11399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11400. }
  11401. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11402. isKnowKey = TRUE;
  11403. }
  11404. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11405. {
  11406. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11407. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11408. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11409. {
  11410. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11411. }
  11412. else
  11413. {
  11414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11415. }
  11416. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11417. isKnowKey = TRUE;
  11418. }
  11419. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11420. {
  11421. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11422. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11423. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11424. {
  11425. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11426. }
  11427. else
  11428. {
  11429. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11430. }
  11431. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11432. isKnowKey = TRUE;
  11433. }
  11434. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11435. {
  11436. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11438. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11439. {
  11440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11441. }
  11442. else
  11443. {
  11444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11445. }
  11446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11447. isKnowKey = TRUE;
  11448. }
  11449. //=========================================================
  11450. if(!isEmpty && !isKnowKey)
  11451. {
  11452. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11453. strcpy(unknownkey[UnknownKeynum], keyReq);
  11454. UnknownKeynum = UnknownKeynum + 1;
  11455. }
  11456. }
  11457. void processUnkownKey(void)
  11458. {
  11459. DEBUG_INFO("processUnkownKey...\n");
  11460. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11461. for(int index=0; index < UnknownKeynum; index++)
  11462. {
  11463. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11464. {
  11465. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11466. }
  11467. }
  11468. }
  11469. int setKeyValue(char *key, char *value)
  11470. {
  11471. int isSuccess = NotSupported;
  11472. int check_ascii=0;
  11473. char str[10]={0};
  11474. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11475. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11476. {
  11477. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11478. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11479. {
  11480. strcpy(str, (const char*)value);
  11481. for(int i = 0; str[i]; i++){
  11482. str[i] = tolower(str[i]);
  11483. }
  11484. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11485. isSuccess = ConfigurationStatus_Accepted;
  11486. }
  11487. else
  11488. {
  11489. isSuccess = ConfigurationStatus_Rejected;
  11490. }
  11491. }
  11492. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11493. {
  11494. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11495. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11496. {
  11497. strcpy(str, (const char*)value);
  11498. for(int i = 0; str[i]; i++){
  11499. str[i] = tolower(str[i]);
  11500. }
  11501. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11502. isSuccess = ConfigurationStatus_Accepted;
  11503. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11504. }
  11505. else
  11506. {
  11507. isSuccess = ConfigurationStatus_Rejected;
  11508. }
  11509. }
  11510. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11511. {
  11512. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11513. {
  11514. strcpy(str, (const char*)value);
  11515. for(int i = 0; str[i]; i++)
  11516. {
  11517. str[i] = tolower(str[i]);
  11518. }
  11519. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11520. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11521. isSuccess = ConfigurationStatus_Accepted;
  11522. }
  11523. else
  11524. {
  11525. isSuccess = ConfigurationStatus_Rejected;
  11526. }
  11527. }
  11528. if(strcmp(key, "BlinkRepeat") == 0)
  11529. {
  11530. //Charger.BlinkRepeat = Integer.parseInt(value);
  11531. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11532. {
  11533. check_ascii = value[0];
  11534. if( (check_ascii < 48) || (check_ascii > 57) )
  11535. {
  11536. isSuccess = ConfigurationStatus_Rejected;
  11537. }
  11538. else
  11539. {
  11540. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11541. isSuccess = ConfigurationStatus_Accepted;
  11542. }
  11543. }
  11544. else
  11545. {
  11546. isSuccess = ConfigurationStatus_Rejected;
  11547. }
  11548. }
  11549. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11550. {
  11551. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11552. {
  11553. check_ascii = value[0];
  11554. if( (check_ascii < 48) || (check_ascii > 57) )
  11555. {
  11556. isSuccess = ConfigurationStatus_Rejected;
  11557. }
  11558. else
  11559. {
  11560. if((atoi(value) == 0) || (atoi(value) >= 10))
  11561. {
  11562. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11563. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11564. isSuccess = ConfigurationStatus_Accepted;
  11565. }
  11566. else
  11567. isSuccess = ConfigurationStatus_Rejected;
  11568. }
  11569. }
  11570. else
  11571. {
  11572. isSuccess = ConfigurationStatus_Rejected;
  11573. }
  11574. }
  11575. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11576. {
  11577. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11578. {
  11579. check_ascii = value[0];
  11580. if( (check_ascii < 48) || (check_ascii > 57) )
  11581. {
  11582. isSuccess = ConfigurationStatus_Rejected;
  11583. }
  11584. else
  11585. {
  11586. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11587. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11588. isSuccess = ConfigurationStatus_Accepted;
  11589. }
  11590. }
  11591. else
  11592. {
  11593. isSuccess = ConfigurationStatus_Rejected;
  11594. }
  11595. }
  11596. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11597. {
  11598. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  11599. {
  11600. check_ascii = value[0];
  11601. if( (check_ascii < 48) || (check_ascii > 57) )
  11602. {
  11603. isSuccess = ConfigurationStatus_Rejected;
  11604. }
  11605. else
  11606. {
  11607. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11608. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11609. isSuccess = ConfigurationStatus_Accepted;
  11610. }
  11611. }
  11612. else
  11613. {
  11614. isSuccess = ConfigurationStatus_Rejected;
  11615. }
  11616. }
  11617. if(strcmp(key, "HeartbeatInterval") == 0)
  11618. {
  11619. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].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. if((atoi(value) == 0) || (atoi(value) >= 10))
  11629. {
  11630. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11631. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11632. HeartBeatWaitTime = atoi(value);
  11633. isSuccess = ConfigurationStatus_Accepted;
  11634. }
  11635. else
  11636. {
  11637. isSuccess = ConfigurationStatus_Rejected;
  11638. }
  11639. }
  11640. }
  11641. else
  11642. {
  11643. isSuccess = ConfigurationStatus_Rejected;
  11644. }
  11645. }
  11646. if(strcmp(key, "LightIntensity") == 0)
  11647. {
  11648. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11649. {
  11650. check_ascii = value[0];
  11651. if( (check_ascii < 48) || (check_ascii > 57) )
  11652. {
  11653. isSuccess = ConfigurationStatus_Rejected;
  11654. }
  11655. else
  11656. {
  11657. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11658. isSuccess = ConfigurationStatus_Accepted;
  11659. }
  11660. }
  11661. else
  11662. {
  11663. isSuccess = ConfigurationStatus_Rejected;
  11664. }
  11665. }
  11666. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11667. {
  11668. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11669. {
  11670. strcpy(str, (const char*)value);
  11671. for(int i = 0; str[i]; i++)
  11672. {
  11673. str[i] = tolower(str[i]);
  11674. }
  11675. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11676. isSuccess = ConfigurationStatus_Accepted;
  11677. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11678. }
  11679. else
  11680. {
  11681. isSuccess = ConfigurationStatus_Rejected;
  11682. }
  11683. }
  11684. if(strcmp(key, "LocalPreAuthorize") == 0)
  11685. {
  11686. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11687. {
  11688. strcpy(str, (const char*)value);
  11689. for(int i = 0; str[i]; i++)
  11690. {
  11691. str[i] = tolower(str[i]);
  11692. }
  11693. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11694. isSuccess = ConfigurationStatus_Accepted;
  11695. }
  11696. else
  11697. {
  11698. isSuccess = ConfigurationStatus_Rejected;
  11699. }
  11700. }
  11701. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11702. {
  11703. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11704. {
  11705. check_ascii = value[0];
  11706. if( (check_ascii < 48) || (check_ascii > 57) )
  11707. {
  11708. isSuccess = ConfigurationStatus_Rejected;
  11709. }
  11710. else
  11711. {
  11712. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11713. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11714. isSuccess = ConfigurationStatus_Accepted;
  11715. }
  11716. }
  11717. else
  11718. {
  11719. isSuccess = ConfigurationStatus_Rejected;
  11720. }
  11721. }
  11722. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11723. {
  11724. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11725. {
  11726. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11727. isSuccess = ConfigurationStatus_Accepted;
  11728. }
  11729. else
  11730. {
  11731. isSuccess = ConfigurationStatus_Rejected;
  11732. }
  11733. }
  11734. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11735. {
  11736. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11737. {
  11738. check_ascii = value[0];
  11739. if( (check_ascii < 48) || (check_ascii > 57) )
  11740. {
  11741. isSuccess = ConfigurationStatus_Rejected;
  11742. }
  11743. else
  11744. {
  11745. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11746. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11747. isSuccess = ConfigurationStatus_Accepted;
  11748. }
  11749. }
  11750. else
  11751. {
  11752. isSuccess = ConfigurationStatus_Rejected;
  11753. }
  11754. }
  11755. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11756. {
  11757. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11758. {
  11759. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11760. isSuccess = ConfigurationStatus_Accepted;
  11761. }
  11762. else
  11763. {
  11764. isSuccess = ConfigurationStatus_Rejected;
  11765. }
  11766. }
  11767. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11768. {
  11769. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11770. {
  11771. check_ascii = value[0];
  11772. if( (check_ascii < 48) || (check_ascii > 57) )
  11773. {
  11774. isSuccess = ConfigurationStatus_Rejected;
  11775. }
  11776. else
  11777. {
  11778. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11779. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11780. isSuccess = ConfigurationStatus_Accepted;
  11781. }
  11782. }
  11783. else
  11784. {
  11785. isSuccess = ConfigurationStatus_Rejected;
  11786. }
  11787. }
  11788. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11789. {
  11790. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11791. {
  11792. check_ascii = value[0];
  11793. if( (check_ascii < 48) || (check_ascii > 57) )
  11794. {
  11795. isSuccess = ConfigurationStatus_Rejected;
  11796. }
  11797. else
  11798. {
  11799. if((atoi(value) == 0) || (atoi(value) >= 10))
  11800. {
  11801. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11802. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  11803. isSuccess = ConfigurationStatus_Accepted;
  11804. }
  11805. else
  11806. {
  11807. isSuccess = ConfigurationStatus_Rejected;
  11808. }
  11809. }
  11810. }
  11811. else
  11812. {
  11813. isSuccess = ConfigurationStatus_Rejected;
  11814. }
  11815. }
  11816. if(strcmp(key, "MinimumStatusDuration") == 0)
  11817. {
  11818. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11819. {
  11820. check_ascii = value[0];
  11821. if( (check_ascii < 48) || (check_ascii > 57) )
  11822. {
  11823. isSuccess = ConfigurationStatus_Rejected;
  11824. }
  11825. else
  11826. {
  11827. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  11828. {
  11829. isSuccess = ConfigurationStatus_Rejected;
  11830. }
  11831. else
  11832. {
  11833. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  11834. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  11835. server_cycle_Status = atoi(value); //StatusNotification Cycle
  11836. isSuccess = ConfigurationStatus_Accepted;
  11837. }
  11838. }
  11839. }
  11840. else
  11841. {
  11842. isSuccess = ConfigurationStatus_Rejected;
  11843. }
  11844. }
  11845. if(strcmp(key, "NumberOfConnectors") == 0)
  11846. {
  11847. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11848. {
  11849. check_ascii = value[0];
  11850. if( (check_ascii < 48) || (check_ascii > 57) )
  11851. {
  11852. isSuccess = ConfigurationStatus_Rejected;
  11853. }
  11854. else
  11855. {
  11856. //Charger.ResetRetries = Integer.parseInt(value);
  11857. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  11858. isSuccess = ConfigurationStatus_Accepted;
  11859. }
  11860. }
  11861. else
  11862. {
  11863. isSuccess = ConfigurationStatus_Rejected;
  11864. }
  11865. }
  11866. if(strcmp(key, "ResetRetries") == 0)
  11867. {
  11868. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11869. {
  11870. check_ascii = value[0];
  11871. if( (check_ascii < 48) || (check_ascii > 57) )
  11872. {
  11873. isSuccess = ConfigurationStatus_Rejected;
  11874. }
  11875. else
  11876. {
  11877. //Charger.ResetRetries = Integer.parseInt(value);
  11878. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  11879. isSuccess = ConfigurationStatus_Accepted;
  11880. }
  11881. }
  11882. else
  11883. {
  11884. isSuccess = ConfigurationStatus_Rejected;
  11885. }
  11886. }
  11887. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  11888. {
  11889. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11890. {
  11891. strcpy(str, (const char*)value);
  11892. for(int i = 0; str[i]; i++)
  11893. {
  11894. str[i] = tolower(str[i]);
  11895. }
  11896. if(strcmp(str, "notapplicable")== 0)
  11897. {
  11898. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  11899. isSuccess = ConfigurationStatus_Accepted;
  11900. }
  11901. else if(strcmp(str, "unknown")== 0)
  11902. {
  11903. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  11904. isSuccess = ConfigurationStatus_Accepted;
  11905. }
  11906. else if(strcmp(str, "rst")== 0)
  11907. {
  11908. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  11909. isSuccess = ConfigurationStatus_Accepted;
  11910. }
  11911. else if(strcmp(str, "rts")== 0)
  11912. {
  11913. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  11914. isSuccess = ConfigurationStatus_Accepted;
  11915. }
  11916. else if(strcmp(str, "srt")== 0)
  11917. {
  11918. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  11919. isSuccess = ConfigurationStatus_Accepted;
  11920. }
  11921. else if(strcmp(str, "str")== 0)
  11922. {
  11923. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  11924. isSuccess = ConfigurationStatus_Accepted;
  11925. }
  11926. else if(strcmp(str, "trs")== 0)
  11927. {
  11928. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  11929. isSuccess = ConfigurationStatus_Accepted;
  11930. }
  11931. else if(strcmp(str, "tsr")== 0)
  11932. {
  11933. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  11934. isSuccess = ConfigurationStatus_Accepted;
  11935. }
  11936. else
  11937. {
  11938. isSuccess = ConfigurationStatus_Rejected;
  11939. }
  11940. }
  11941. else
  11942. {
  11943. isSuccess = ConfigurationStatus_Rejected;
  11944. }
  11945. }
  11946. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  11947. {
  11948. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11949. {
  11950. check_ascii = value[0];
  11951. if( (check_ascii < 48) || (check_ascii > 57) )
  11952. {
  11953. isSuccess = ConfigurationStatus_Rejected;
  11954. }
  11955. else
  11956. {
  11957. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  11958. isSuccess = ConfigurationStatus_Accepted;
  11959. }
  11960. }
  11961. else
  11962. {
  11963. isSuccess = ConfigurationStatus_Rejected;
  11964. }
  11965. }
  11966. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  11967. {
  11968. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11969. {
  11970. strcpy(str, (const char*)value);
  11971. for(int i = 0; str[i]; i++)
  11972. {
  11973. str[i] = tolower(str[i]);
  11974. }
  11975. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  11976. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11977. isSuccess = ConfigurationStatus_Accepted;
  11978. }
  11979. else
  11980. {
  11981. isSuccess = ConfigurationStatus_Rejected;
  11982. }
  11983. }
  11984. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  11985. {
  11986. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11987. {
  11988. strcpy(str, (const char*)value);
  11989. for(int i = 0; str[i]; i++)
  11990. {
  11991. str[i] = tolower(str[i]);
  11992. }
  11993. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  11994. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11995. isSuccess = ConfigurationStatus_Accepted;
  11996. }
  11997. else
  11998. {
  11999. isSuccess = ConfigurationStatus_Rejected;
  12000. }
  12001. }
  12002. if(strcmp(key, "StopTxnAlignedData") == 0)
  12003. {
  12004. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12005. {
  12006. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12007. isSuccess = ConfigurationStatus_Accepted;
  12008. }
  12009. else
  12010. {
  12011. isSuccess = ConfigurationStatus_Rejected;
  12012. }
  12013. }
  12014. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12015. {
  12016. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12017. {
  12018. check_ascii = value[0];
  12019. if( (check_ascii < 48) || (check_ascii > 57) )
  12020. {
  12021. isSuccess = ConfigurationStatus_Rejected;
  12022. }
  12023. else
  12024. {
  12025. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12026. isSuccess = ConfigurationStatus_Accepted;
  12027. }
  12028. }
  12029. else
  12030. {
  12031. isSuccess = ConfigurationStatus_Rejected;
  12032. }
  12033. }
  12034. if(strcmp(key, "StopTxnSampledData") == 0)
  12035. {
  12036. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12037. {
  12038. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12039. isSuccess = ConfigurationStatus_Accepted;
  12040. }
  12041. else
  12042. {
  12043. isSuccess = ConfigurationStatus_Rejected;
  12044. }
  12045. }
  12046. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12047. {
  12048. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12049. {
  12050. check_ascii = value[0];
  12051. if( (check_ascii < 48) || (check_ascii > 57) )
  12052. {
  12053. isSuccess = ConfigurationStatus_Rejected;
  12054. }
  12055. else
  12056. {
  12057. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12058. isSuccess = ConfigurationStatus_Accepted;
  12059. }
  12060. }
  12061. else
  12062. {
  12063. isSuccess = ConfigurationStatus_Rejected;
  12064. }
  12065. }
  12066. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12067. {
  12068. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12069. {
  12070. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12071. isSuccess = ConfigurationStatus_Accepted;
  12072. }
  12073. else
  12074. {
  12075. isSuccess = ConfigurationStatus_Rejected;
  12076. }
  12077. }
  12078. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12079. {
  12080. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12081. {
  12082. check_ascii = value[0];
  12083. if( (check_ascii < 48) || (check_ascii > 57) )
  12084. {
  12085. isSuccess = ConfigurationStatus_Rejected;
  12086. }
  12087. else
  12088. {
  12089. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12090. isSuccess = ConfigurationStatus_Accepted;
  12091. }
  12092. }
  12093. else
  12094. {
  12095. isSuccess = ConfigurationStatus_Rejected;
  12096. }
  12097. }
  12098. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12099. {
  12100. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12101. {
  12102. check_ascii = value[0];
  12103. if( (check_ascii < 48) || (check_ascii > 57) )
  12104. {
  12105. isSuccess = ConfigurationStatus_Rejected;
  12106. }
  12107. else
  12108. {
  12109. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12110. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12111. TransactionMessageAttemptsValue = atoi(value);
  12112. isSuccess = ConfigurationStatus_Accepted;
  12113. }
  12114. }
  12115. else
  12116. {
  12117. isSuccess = ConfigurationStatus_Rejected;
  12118. }
  12119. }
  12120. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12121. {
  12122. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].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. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12132. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12133. TransactionMessageRetryIntervalValue = atoi(value);
  12134. isSuccess = ConfigurationStatus_Accepted;
  12135. }
  12136. }
  12137. else
  12138. {
  12139. isSuccess = ConfigurationStatus_Rejected;
  12140. }
  12141. }
  12142. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12143. {
  12144. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12145. {
  12146. strcpy(str, (const char*)value);
  12147. for(int i = 0; str[i]; i++)
  12148. {
  12149. str[i] = tolower(str[i]);
  12150. }
  12151. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12152. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12153. isSuccess = ConfigurationStatus_Accepted;
  12154. }
  12155. else
  12156. {
  12157. isSuccess = ConfigurationStatus_Rejected;
  12158. }
  12159. }
  12160. if(strcmp(key, "WebSocketPingInterval") == 0)
  12161. {
  12162. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12163. {
  12164. check_ascii = value[0];
  12165. if( (check_ascii < 48) || (check_ascii > 57) )
  12166. {
  12167. isSuccess = ConfigurationStatus_Rejected;
  12168. }
  12169. else
  12170. {
  12171. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12172. isSuccess = ConfigurationStatus_Accepted;
  12173. }
  12174. }
  12175. else
  12176. {
  12177. isSuccess = ConfigurationStatus_Rejected;
  12178. }
  12179. }
  12180. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12181. {
  12182. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12183. {
  12184. strcpy(str, (const char*)value);
  12185. for(int i = 0; str[i]; i++)
  12186. {
  12187. str[i] = tolower(str[i]);
  12188. }
  12189. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12190. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12191. isSuccess = ConfigurationStatus_Accepted;
  12192. }
  12193. else
  12194. {
  12195. isSuccess = ConfigurationStatus_Rejected;
  12196. }
  12197. }
  12198. if(strcmp(key, "AuthorizationKey") == 0)
  12199. {
  12200. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  12201. {
  12202. strcpy(str, (const char*)value);
  12203. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  12204. isSuccess = ConfigurationStatus_Accepted;
  12205. }
  12206. else
  12207. {
  12208. isSuccess = ConfigurationStatus_Rejected;
  12209. }
  12210. }
  12211. if(strcmp(key, "SecurityProfile") == 0)
  12212. {
  12213. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12214. {
  12215. check_ascii = value[0];
  12216. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  12217. {
  12218. isSuccess = ConfigurationStatus_Rejected;
  12219. }
  12220. else if(check_ascii == 0x33)
  12221. {
  12222. isSuccess = NotSupported;
  12223. }
  12224. else
  12225. {
  12226. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  12227. {
  12228. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  12229. isSuccess = ConfigurationStatus_Accepted;
  12230. }
  12231. else
  12232. isSuccess = ConfigurationStatus_Rejected;
  12233. }
  12234. }
  12235. else
  12236. {
  12237. isSuccess = ConfigurationStatus_Rejected;
  12238. }
  12239. }
  12240. if(strcmp(key, "DefaultPrice") == 0)
  12241. {
  12242. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  12243. {
  12244. strcpy(str, (const char*)value);
  12245. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  12246. isSuccess = ConfigurationStatus_Accepted;
  12247. }
  12248. else
  12249. {
  12250. isSuccess = ConfigurationStatus_Rejected;
  12251. }
  12252. }
  12253. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  12254. {
  12255. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12256. {
  12257. strcpy(str, (const char*)value);
  12258. for(int i = 0; str[i]; i++)
  12259. {
  12260. str[i] = tolower(str[i]);
  12261. }
  12262. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12263. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12264. isSuccess = ConfigurationStatus_Accepted;
  12265. }
  12266. else
  12267. {
  12268. isSuccess = ConfigurationStatus_Rejected;
  12269. }
  12270. }
  12271. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  12272. {
  12273. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12274. {
  12275. strcpy(str, (const char*)value);
  12276. for(int i = 0; str[i]; i++)
  12277. {
  12278. str[i] = tolower(str[i]);
  12279. }
  12280. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12281. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12282. isSuccess = ConfigurationStatus_Accepted;
  12283. }
  12284. else
  12285. {
  12286. isSuccess = ConfigurationStatus_Rejected;
  12287. }
  12288. }
  12289. #if 0
  12290. //For OCPP Test Case
  12291. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12292. {
  12293. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12294. {
  12295. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12296. isSuccess = ConfigurationStatus_Accepted;
  12297. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12298. }
  12299. else
  12300. {
  12301. isSuccess = ConfigurationStatus_Rejected;
  12302. }
  12303. }
  12304. #endif
  12305. #if 1
  12306. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12307. {
  12308. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12309. {
  12310. strcpy(str, (const char*)value);
  12311. for(int i = 0; str[i]; i++)
  12312. {
  12313. str[i] = tolower(str[i]);
  12314. }
  12315. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12316. isSuccess = ConfigurationStatus_Accepted;
  12317. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12318. }
  12319. else
  12320. {
  12321. isSuccess = ConfigurationStatus_Rejected;
  12322. }
  12323. }
  12324. #endif
  12325. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12326. {
  12327. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12328. {
  12329. check_ascii = value[0];
  12330. if( (check_ascii < 48) || (check_ascii > 57) )
  12331. {
  12332. isSuccess = ConfigurationStatus_Rejected;
  12333. }
  12334. else
  12335. {
  12336. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12337. isSuccess = ConfigurationStatus_Accepted;
  12338. }
  12339. }
  12340. else
  12341. {
  12342. isSuccess = ConfigurationStatus_Rejected;
  12343. }
  12344. }
  12345. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12346. {
  12347. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12348. {
  12349. check_ascii = value[0];
  12350. if( (check_ascii < 48) || (check_ascii > 57) )
  12351. {
  12352. isSuccess = ConfigurationStatus_Rejected;
  12353. }
  12354. else
  12355. {
  12356. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12357. isSuccess = ConfigurationStatus_Accepted;
  12358. }
  12359. }
  12360. else
  12361. {
  12362. isSuccess = ConfigurationStatus_Rejected;
  12363. }
  12364. }
  12365. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12366. {
  12367. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12368. {
  12369. strcpy(str, (const char*)value);
  12370. for(int i = 0; str[i]; i++)
  12371. {
  12372. str[i] = tolower(str[i]);
  12373. }
  12374. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12375. isSuccess = ConfigurationStatus_Accepted;
  12376. }
  12377. else
  12378. {
  12379. isSuccess = ConfigurationStatus_Rejected;
  12380. }
  12381. }
  12382. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12383. {
  12384. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12385. {
  12386. check_ascii = value[0];
  12387. if( (check_ascii < 48) || (check_ascii > 57) )
  12388. {
  12389. isSuccess = ConfigurationStatus_Rejected;
  12390. }
  12391. else
  12392. {
  12393. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12394. isSuccess = ConfigurationStatus_Accepted;
  12395. }
  12396. }
  12397. else
  12398. {
  12399. isSuccess = ConfigurationStatus_Rejected;
  12400. }
  12401. }
  12402. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12403. {
  12404. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12405. {
  12406. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12407. isSuccess = ConfigurationStatus_Accepted;
  12408. }
  12409. else
  12410. {
  12411. isSuccess = ConfigurationStatus_Rejected;
  12412. }
  12413. }
  12414. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12415. {
  12416. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12417. {
  12418. check_ascii = value[0];
  12419. if( (check_ascii < 48) || (check_ascii > 57) )
  12420. {
  12421. isSuccess = ConfigurationStatus_Rejected;
  12422. }
  12423. else
  12424. {
  12425. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12426. isSuccess = ConfigurationStatus_Accepted;
  12427. }
  12428. }
  12429. else
  12430. {
  12431. isSuccess = ConfigurationStatus_Rejected;
  12432. }
  12433. }
  12434. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12435. {
  12436. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12437. {
  12438. strcpy(str, (const char*)value);
  12439. for(int i = 0; str[i]; i++)
  12440. {
  12441. str[i] = tolower(str[i]);
  12442. }
  12443. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12444. isSuccess = ConfigurationStatus_Accepted;
  12445. }
  12446. else
  12447. {
  12448. isSuccess = ConfigurationStatus_Rejected;
  12449. }
  12450. }
  12451. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12452. {
  12453. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12454. {
  12455. check_ascii = value[0];
  12456. if( (check_ascii < 48) || (check_ascii > 57) )
  12457. {
  12458. isSuccess = ConfigurationStatus_Rejected;
  12459. }
  12460. else
  12461. {
  12462. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12463. isSuccess = ConfigurationStatus_Accepted;
  12464. }
  12465. }
  12466. else
  12467. {
  12468. isSuccess = ConfigurationStatus_Rejected;
  12469. }
  12470. }
  12471. return isSuccess;
  12472. }
  12473. int TransactionMessageAttemptsGet(void)
  12474. {
  12475. return TransactionMessageAttemptsValue;
  12476. }
  12477. int FirstHeartBeatResponse(void)
  12478. {
  12479. return FirstHeartBeat;
  12480. }
  12481. int TransactionMessageRetryIntervalGet(void)
  12482. {
  12483. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12484. }
  12485. int ReadHttpStatus(int sock)
  12486. {
  12487. //char c;
  12488. char buff[1024]="",*ptr=buff+1;
  12489. int bytes_received, status;
  12490. DEBUG_INFO("Begin Response ..\n");
  12491. while((bytes_received = recv(sock, ptr, 1, 0))){
  12492. if(bytes_received==-1){
  12493. perror("ReadHttpStatus");
  12494. exit(1);
  12495. }
  12496. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12497. ptr++;
  12498. }
  12499. *ptr=0;
  12500. ptr=buff+1;
  12501. sscanf(ptr,"%*s %d ", &status);
  12502. DEBUG_INFO("%s\n",ptr);
  12503. DEBUG_INFO("status=%d\n",status);
  12504. DEBUG_INFO("End Response ..\n");
  12505. return (bytes_received>0)?status:0;
  12506. }
  12507. //the only filed that it parsed is 'Content-Length'
  12508. int ParseHeader(int sock)
  12509. {
  12510. //char c;
  12511. char buff[1024]="",*ptr=buff+4;
  12512. int bytes_received;
  12513. DEBUG_INFO("Begin HEADER ..\n");
  12514. while((bytes_received = recv(sock, ptr, 1, 0))){
  12515. if(bytes_received==-1){
  12516. perror("Parse Header");
  12517. exit(1);
  12518. }
  12519. if(
  12520. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12521. (ptr[-1]=='\r') && (*ptr=='\n' )
  12522. ) break;
  12523. ptr++;
  12524. }
  12525. *ptr=0;
  12526. ptr=buff+4;
  12527. //printf("%s",ptr);
  12528. if(bytes_received){
  12529. ptr=strstr(ptr,"Content-Length:");
  12530. if(ptr){
  12531. sscanf(ptr,"%*s %d",&bytes_received);
  12532. }else
  12533. bytes_received=-1; //unknown size
  12534. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12535. }
  12536. DEBUG_INFO("End HEADER ..\n");
  12537. return bytes_received ;
  12538. }
  12539. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12540. {
  12541. char rmFileCmd[100]={0};
  12542. char FilePath[100]={0};
  12543. char ftpbuf[200];
  12544. int systemresult;
  12545. //DEBUG_INFO("filename=%s\n",filename);
  12546. //DEBUG_INFO("url=%s\n",url);
  12547. sprintf(FilePath,"/mnt/%s",filename);
  12548. if((access(FilePath,F_OK))!=-1)
  12549. {
  12550. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12551. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12552. system(rmFileCmd);
  12553. }
  12554. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12555. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  12556. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12557. systemresult = system(ftpbuf);
  12558. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12559. if(systemresult != 0)
  12560. {
  12561. DEBUG_INFO("http DownLoad error!\n");
  12562. return FALSE;
  12563. }
  12564. return TRUE;
  12565. }
  12566. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12567. {
  12568. char rmFileCmd[100]={0};
  12569. char FilePath[100]={0};
  12570. char ftpbuf[200];
  12571. int systemresult;
  12572. //char temp[100];
  12573. sprintf(FilePath,"/mnt/%s",filename);
  12574. if((access(FilePath,F_OK))!=-1)
  12575. {
  12576. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12577. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12578. system(rmFileCmd);
  12579. }
  12580. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12581. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  12582. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12583. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12584. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12585. systemresult = system(ftpbuf);
  12586. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12587. if(systemresult != 0)
  12588. {
  12589. printf("wget error!\n");
  12590. return FALSE;
  12591. }
  12592. return TRUE;
  12593. }
  12594. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12595. {
  12596. char rmFileCmd[100]={0};
  12597. char FilePath[100]={0};
  12598. char ftpbuf[200];
  12599. int systemresult;
  12600. //DEBUG_INFO("filename=%s\n",filename);
  12601. //DEBUG_INFO("url=%s\n",url);
  12602. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12603. if((access(FilePath,F_OK))!=-1)
  12604. {
  12605. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12606. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12607. system(rmFileCmd);
  12608. }
  12609. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12610. if(fp == NULL)
  12611. {
  12612. DEBUG_INFO("log is NULL\n");
  12613. return FALSE;
  12614. }
  12615. else
  12616. {
  12617. fprintf(fp, "%s\n", url);
  12618. fprintf(fp, "%s\n", filename);
  12619. fclose(fp);
  12620. }
  12621. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12622. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12623. systemresult = system(ftpbuf);
  12624. DEBUG_INFO("systemresult = %d\n",systemresult);
  12625. if(systemresult != 0)
  12626. {
  12627. DEBUG_INFO("http upload error!\n");
  12628. return FALSE;
  12629. }
  12630. return TRUE;
  12631. }
  12632. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12633. {
  12634. struct hostent* server;
  12635. char *IPbuffer;
  12636. char ftpbuf[200];
  12637. int systemresult;
  12638. // To retrieve host information
  12639. server = gethostbyname(location);
  12640. // To convert an Internet network
  12641. // address into ASCII string
  12642. IPbuffer = inet_ntoa(*((struct in_addr*)
  12643. server->h_addr_list[0]));
  12644. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12645. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12646. /* format : ftpput -u username -p passwd IP target source*/
  12647. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12648. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12649. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12650. systemresult = system(ftpbuf);
  12651. DEBUG_INFO("systemresult=%d\n",systemresult);
  12652. if(systemresult != 0)
  12653. {
  12654. DEBUG_INFO("ftpput error!\n");
  12655. return FALSE;
  12656. }
  12657. return TRUE;
  12658. }
  12659. /**
  12660. * Place the contents of the specified file into a memory buffer
  12661. *
  12662. * @param[in] filename The path and name of the file to read
  12663. * @param[out] filebuffer A pointer to the contents in memory
  12664. * @return status 0 success, 1 on failure
  12665. */
  12666. int get_file_contents(const char* filename, char** outbuffer) {
  12667. FILE* file = NULL;
  12668. long filesize;
  12669. const int blocksize = 1;
  12670. size_t readsize;
  12671. char* filebuffer;
  12672. // Open the file
  12673. file = fopen(filename, "r");
  12674. if (NULL == file)
  12675. {
  12676. printf("'%s' not opened\n", filename);
  12677. exit(EXIT_FAILURE);
  12678. }
  12679. // Determine the file size
  12680. fseek(file, 0, SEEK_END);
  12681. filesize = ftell(file);
  12682. rewind (file);
  12683. // Allocate memory for the file contents
  12684. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12685. *outbuffer = filebuffer;
  12686. if (filebuffer == NULL)
  12687. {
  12688. fputs ("malloc out-of-memory", stderr);
  12689. exit(EXIT_FAILURE);
  12690. }
  12691. // Read in the file
  12692. readsize = fread(filebuffer, blocksize, filesize, file);
  12693. if (readsize != filesize)
  12694. {
  12695. fputs ("didn't read file completely",stderr);
  12696. exit(EXIT_FAILURE);
  12697. }
  12698. // Clean exit
  12699. fclose(file);
  12700. return EXIT_SUCCESS;
  12701. }
  12702. static int selectSqlCount = 0;
  12703. static int callback(void *data, int argc, char **argv, char **azColName){
  12704. int i;
  12705. //printf("%s: ", (const char*)data);
  12706. selectSqlCount = argc;
  12707. for(i = 0; i<argc; i++){
  12708. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12709. }
  12710. //printf("\n");
  12711. return 0;
  12712. }
  12713. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12714. //int i;
  12715. //printf("%s:\n", (const char*)data);
  12716. localversion = argv[5] ? atoi(argv[5]) : 0;
  12717. //printf("localversion=%d\n", localversion);
  12718. return 0;
  12719. }
  12720. static int IdTagcallback(void *data, int argc, char **argv, char **azColName){
  12721. //int i;
  12722. //printf("%s:\n", (const char*)data);
  12723. //idTag
  12724. sprintf(idTagAuthorization,"%s", argv[1] ? argv[1] : "NULL");
  12725. sprintf(idTagQuery.idTagstr,"%s", argv[1] ? argv[1] : "NULL");
  12726. //parentIdTag
  12727. sprintf(idTagQuery.parentIdTag,"%s", argv[2] ? argv[2] : "NULL");
  12728. //expir_date
  12729. sprintf(idTagQuery.expiryDate,"%s", argv[3] ? argv[3] : "NULL");
  12730. //status
  12731. sprintf(idTagQuery.idTagstatus,"%s", argv[4] ? argv[4] : "NULL");
  12732. //version
  12733. idTagQuery.listVersionInt = atoi(argv[5]);
  12734. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12735. return 0;
  12736. }
  12737. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  12738. {
  12739. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12740. // printf("localversion=%d\n", localversion);
  12741. return 0;
  12742. }
  12743. //=========================================
  12744. // Sqlite3 related function
  12745. //=========================================
  12746. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12747. {
  12748. for (int i = 0; i < n_columns; i++)
  12749. {
  12750. DEBUG_INFO("%s\t", col_values[i]);
  12751. }
  12752. DEBUG_INFO("\n");
  12753. return 0;
  12754. }
  12755. void OCPP_getListVerion()
  12756. {
  12757. int rc = 0;
  12758. // const char* data = "Callback function called";
  12759. char sql[100];
  12760. char zErrMsg[100];
  12761. memset(sql, 0, 100);
  12762. memset(zErrMsg, 0, 100);
  12763. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12764. /* Execute SQL statement */
  12765. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12766. if( rc != SQLITE_OK )
  12767. {
  12768. DEBUG_INFO("SQL error: %s", zErrMsg);
  12769. }
  12770. }
  12771. void OCPP_getIdTag(char idTag[])
  12772. {
  12773. int rc = 0;
  12774. // const char* data = "Callback function called";
  12775. char sql[100];
  12776. char zErrMsg[100];
  12777. memset(sql, 0, 100);
  12778. memset(zErrMsg, 0, 100);
  12779. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  12780. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12781. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12782. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12783. /* Execute SQL statement */
  12784. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12785. if( rc != SQLITE_OK )
  12786. {
  12787. DEBUG_INFO("SQL error: %s", zErrMsg);
  12788. }
  12789. //return ver;
  12790. }
  12791. void OCPP_get_TableAuthlocalAllData(void)
  12792. {
  12793. int rc = 0;
  12794. char sql[100];
  12795. char zErrMsg[100];
  12796. memset(sql, 0, 100);
  12797. memset(zErrMsg, 0, 100);
  12798. sprintf(sql,"select * from ocpp_auth_local ");
  12799. /* Execute SQL statement */
  12800. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12801. if( rc != SQLITE_OK )
  12802. {
  12803. DEBUG_INFO("SQL error: %s", zErrMsg);
  12804. }
  12805. //return ver;
  12806. }
  12807. int OCPP_cleanLocalList()
  12808. {
  12809. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12810. char *errMsg = 0;
  12811. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12812. if (SQLITE_OK != rc)
  12813. {
  12814. DEBUG_INFO("%s\n",errMsg);
  12815. return FALSE;
  12816. }
  12817. return TRUE;
  12818. }
  12819. int OCPP_addLocalList_1(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12820. {
  12821. int isSuccess = FALSE;
  12822. int ret = 0;
  12823. //const char* data = "Callback function called";
  12824. char sql[300];
  12825. char zErrMsg[200];
  12826. memset(sql, 0, 300);
  12827. memset(zErrMsg, 0, 200);
  12828. 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);
  12829. //* Execute SQL statement */
  12830. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12831. if( ret != SQLITE_OK )
  12832. {
  12833. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12834. return isSuccess;
  12835. }
  12836. memset(sql, 0, 300);
  12837. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  12838. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  12839. if( ret != SQLITE_OK )
  12840. {
  12841. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12842. return isSuccess;
  12843. }
  12844. isSuccess = TRUE;
  12845. return isSuccess;
  12846. }
  12847. void OCPP_deleteIdTag(char idTag[])
  12848. {
  12849. //int ver = 0;
  12850. //int isSuccess = FALSE;
  12851. int rc = 0;
  12852. char sql[100];
  12853. char zErrMsg[100];
  12854. memset(sql, 0, 100);
  12855. memset(zErrMsg, 0, 100);
  12856. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  12857. //* Execute SQL statement */
  12858. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  12859. if( rc != SQLITE_OK )
  12860. {
  12861. DEBUG_INFO("SQL error: %s", zErrMsg);
  12862. }
  12863. }
  12864. int GetOcppServerURL()
  12865. {
  12866. int result = FALSE;
  12867. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  12868. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  12869. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  12870. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  12871. {
  12872. #if 1
  12873. sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  12874. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12875. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12876. #endif
  12877. result = TRUE;
  12878. goto End;
  12879. }
  12880. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  12881. {
  12882. sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  12883. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  12884. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);
  12885. result = TRUE;
  12886. goto End;
  12887. }
  12888. else
  12889. {
  12890. strcpy(OcppHost,"");
  12891. }
  12892. End:
  12893. return result;
  12894. }
  12895. int GetOcppPath()
  12896. {
  12897. int result = FALSE;
  12898. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  12899. {
  12900. if(OcppTempPath == NULL)
  12901. {
  12902. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12903. }
  12904. else
  12905. {
  12906. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  12907. }
  12908. result = TRUE;
  12909. goto End;
  12910. }
  12911. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  12912. {
  12913. if(OcppTempPath == NULL)
  12914. {
  12915. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  12916. }
  12917. else
  12918. {
  12919. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  12920. }
  12921. result = TRUE;
  12922. goto End;
  12923. }
  12924. else
  12925. {
  12926. strcpy(OcppPath,"");
  12927. }
  12928. End:
  12929. return result;
  12930. }
  12931. int GetOcppPort()
  12932. {
  12933. return OcppPort;
  12934. }
  12935. int GetOcppConnStatus(void)
  12936. {
  12937. return ShmOCPP16Data->OcppConnStatus;
  12938. }
  12939. void SetOcppConnStatus(uint8_t status)
  12940. {
  12941. ShmOCPP16Data->OcppConnStatus = status;
  12942. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  12943. }
  12944. int GetHeartBeatWithNOResponse(void)
  12945. {
  12946. return HeartBeatWithNOResponse;
  12947. }
  12948. void SetHeartBeatWithNOResponse(void)
  12949. {
  12950. HeartBeatWithNOResponse = 0;
  12951. }
  12952. void GetStartTransactionIdTag(int gun_index)
  12953. {
  12954. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  12955. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  12956. }
  12957. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  12958. {
  12959. char ch;
  12960. FILE *fptr1;
  12961. int temptransactionId;
  12962. char str[100]={0};
  12963. temptransactionId = 0;
  12964. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  12965. {
  12966. DEBUG_INFO("IdTag is empty.\n");
  12967. return temptransactionId;
  12968. }
  12969. /*------ Read the file ----------------*/
  12970. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  12971. if (!fptr1)
  12972. {
  12973. DEBUG_INFO("QueueTransactionId file open error.\n");
  12974. //printf(" File not found or unable to open the input file!!\n");
  12975. return temptransactionId;
  12976. }
  12977. ch=fgetc(fptr1);
  12978. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  12979. rewind(fptr1);
  12980. if(ch!=EOF)
  12981. {
  12982. // printf("%c",ch);
  12983. while (fgets(str, 100, fptr1) != NULL)
  12984. {
  12985. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  12986. if(str[0]=='\0')
  12987. {
  12988. break;
  12989. }
  12990. char *revbuf[8] = {0}; //存放分割後的子字串
  12991. int num = 0;//分割後子字串的個數
  12992. DEBUG_INFO("str: %s\n", str);
  12993. splitstring(str,",",revbuf,&num); //呼叫函式進行分割
  12994. DEBUG_INFO("revbuf[0]: %s\n", revbuf[0]);
  12995. DEBUG_INFO("revbuf[1]: %s\n", revbuf[1]);
  12996. DEBUG_INFO("revbuf[2]: %s\n", revbuf[2]);
  12997. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  12998. {
  12999. if(isStopTransaction)
  13000. {
  13001. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13002. {
  13003. temptransactionId = atoi(revbuf[2]);
  13004. break;
  13005. }
  13006. }
  13007. else
  13008. {
  13009. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13010. {
  13011. temptransactionId = atoi(revbuf[2]);
  13012. break;
  13013. }
  13014. }
  13015. }
  13016. }
  13017. }
  13018. else
  13019. DEBUG_INFO("EOF\n");
  13020. fclose(fptr1);
  13021. /*------- End of reading ---------------*/
  13022. return temptransactionId;
  13023. }
  13024. void SetTransactionIdZero(int transactionId)
  13025. {
  13026. char ch;
  13027. FILE *fptr1, *fptr2;
  13028. int temptransactionId = 0;
  13029. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13030. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13031. if (!fptr1)
  13032. {
  13033. //printf(" File not found or unable to open the input file!!\n");
  13034. return ;
  13035. }
  13036. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13037. if (!fptr2)
  13038. {
  13039. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13040. fclose(fptr1);
  13041. return ;
  13042. }
  13043. ch=fgetc(fptr1);
  13044. rewind(fptr1);
  13045. if(ch!=EOF)
  13046. {
  13047. // copy all contents to the temporary file except the specific line
  13048. while (fgets(str, 100, fptr1) != NULL)
  13049. {
  13050. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13051. if(str[0]=='\0')
  13052. {
  13053. break;
  13054. }
  13055. char *revbuf[8] = {0};
  13056. int num = 0;
  13057. strcpy(strtemp, str);
  13058. splitstring(str,",",revbuf,&num);
  13059. if(revbuf[2][0] != '\0')
  13060. {
  13061. temptransactionId = atoi(revbuf[2]);
  13062. if(transactionId != temptransactionId)
  13063. {
  13064. fprintf(fptr2, "%s\n", strtemp);
  13065. }
  13066. }
  13067. }
  13068. }
  13069. fclose(fptr1);
  13070. fclose(fptr2);
  13071. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13072. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13073. /*------ Read the file ----------------*/
  13074. }
  13075. int InternetDisconnect(void)
  13076. {
  13077. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13078. }
  13079. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13080. void storeTempStopTransaction(int gun_index)
  13081. {
  13082. char guid[37]={0};
  13083. int tempIndex = 0;
  13084. char TempStopTransaction[256];
  13085. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  13086. DEBUG_INFO("storeTempStopTransaction...\n");
  13087. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13088. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13089. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13090. if(gunType[gun_index] == 'J')
  13091. {
  13092. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13093. {
  13094. tempIndex = ((gun_index==2) ? 1: 0);
  13095. }
  13096. else
  13097. {
  13098. tempIndex = gun_index;
  13099. }
  13100. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13101. {
  13102. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13103. {
  13104. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13105. }
  13106. }// END OF CHAdeMO_QUANTITY
  13107. }
  13108. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13109. {
  13110. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13111. {
  13112. tempIndex = ((gun_index==2) ? 1: 0);
  13113. }
  13114. else
  13115. {
  13116. tempIndex = gun_index;
  13117. }
  13118. for (int index = 0; index < CCS_QUANTITY; index++)
  13119. {
  13120. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13121. {
  13122. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13123. }
  13124. }// END OF CCS_QUANTITY
  13125. }
  13126. else if(gunType[gun_index] == 'G')
  13127. {
  13128. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13129. {
  13130. tempIndex = ((gun_index==2) ? 1: 0);
  13131. }
  13132. else
  13133. {
  13134. tempIndex = gun_index;
  13135. }
  13136. for (int index = 0; index < GB_QUANTITY; index++)
  13137. {
  13138. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13139. {
  13140. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13141. }
  13142. }// END OF GB_QUANTITY
  13143. }
  13144. else
  13145. {
  13146. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13147. {
  13148. tempIndex = 2;
  13149. }
  13150. else
  13151. {
  13152. tempIndex = gun_index;
  13153. }
  13154. for (int index = 0; index < AC_QUANTITY; index++)
  13155. {
  13156. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13157. {
  13158. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13159. }
  13160. }// END OF AC_QUANTITY
  13161. }
  13162. //Stop Transaction Time
  13163. struct timeval tmnow;
  13164. struct tm *tm;
  13165. char buf[28];//, usec_buf[6];
  13166. gettimeofday(&tmnow, NULL);
  13167. time_t t;
  13168. t = time(NULL);
  13169. /*UTC time and date*/
  13170. tm = gmtime(&t);
  13171. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13172. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13173. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13174. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13175. random_uuid(guid);
  13176. /***********************************transactionData******************************************************/
  13177. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13178. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13179. //=================================
  13180. //1. Transaction_Begin
  13181. //=================================
  13182. //============================== Energy.Active.Import.Interval ===========================================
  13183. //idx_sample=0;
  13184. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  13185. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13186. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13187. 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*/]);
  13188. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13189. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13190. {
  13191. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13192. }
  13193. else
  13194. {
  13195. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13196. }
  13197. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13198. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13199. //=================================
  13200. //2. Transaction_End
  13201. //=================================
  13202. //2.1====================================== Current.Import L1 ==============================================
  13203. //idx_sample=1;
  13204. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13205. if(gunType[gun_index] == 'J')
  13206. {
  13207. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13208. {
  13209. tempIndex = ((gun_index==2) ? 1: 0);
  13210. }
  13211. else
  13212. {
  13213. tempIndex = gun_index;
  13214. }
  13215. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13216. {
  13217. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13218. {
  13219. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13220. }
  13221. }// End of for CHAdeMO_QUANTITY
  13222. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13223. }
  13224. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13225. {
  13226. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13227. {
  13228. tempIndex = ((gun_index==2) ? 1: 0);
  13229. }
  13230. else
  13231. {
  13232. tempIndex = gun_index;
  13233. }
  13234. for (int index = 0; index < CCS_QUANTITY; index++)
  13235. {
  13236. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13237. {
  13238. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13239. }
  13240. }// End of for CCS_QUANTITY
  13241. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13242. }
  13243. else if(gunType[gun_index] == 'G')
  13244. {
  13245. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13246. {
  13247. tempIndex = ((gun_index==2) ? 1: 0);
  13248. }
  13249. else
  13250. {
  13251. tempIndex = gun_index;
  13252. }
  13253. for (int index = 0; index < GB_QUANTITY; index++)
  13254. {
  13255. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13256. {
  13257. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13258. }
  13259. }// End of for GB_QUANTITY
  13260. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13261. }
  13262. else
  13263. {
  13264. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13265. {
  13266. tempIndex = 2;
  13267. }
  13268. else
  13269. {
  13270. tempIndex = gun_index;
  13271. }
  13272. for (int index = 0; index < AC_QUANTITY; index++)
  13273. {
  13274. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13275. {
  13276. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13277. }
  13278. }// End of for AC_QUANTITY
  13279. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13280. }
  13281. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13282. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13283. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13284. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13285. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13286. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13287. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13288. //idx_sample=2;
  13289. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13290. if(gunType[gun_index] == 'J')
  13291. {
  13292. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13293. {
  13294. tempIndex = ((gun_index==2) ? 1: 0);
  13295. }
  13296. else
  13297. {
  13298. tempIndex = gun_index;
  13299. }
  13300. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13301. {
  13302. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13303. {
  13304. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13305. }
  13306. }// END OF CHAdeMO_QUANTITY
  13307. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13308. }
  13309. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13310. {
  13311. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13312. {
  13313. tempIndex = ((gun_index==2) ? 1: 0);
  13314. }
  13315. else
  13316. {
  13317. tempIndex = gun_index;
  13318. }
  13319. for (int index = 0; index < CCS_QUANTITY; index++)
  13320. {
  13321. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13322. {
  13323. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13324. }
  13325. }// END OF CCS_QUANTITY
  13326. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13327. }
  13328. else if(gunType[gun_index] == 'G')
  13329. {
  13330. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13331. {
  13332. tempIndex = ((gun_index==2) ? 1: 0);
  13333. }
  13334. else
  13335. {
  13336. tempIndex = gun_index;
  13337. }
  13338. for (int index = 0; index < GB_QUANTITY; index++)
  13339. {
  13340. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13341. {
  13342. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13343. }
  13344. }// END OF GB_QUANTITY
  13345. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13346. }
  13347. else
  13348. {
  13349. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13350. {
  13351. tempIndex = 2;
  13352. }
  13353. else
  13354. {
  13355. tempIndex = gun_index;
  13356. }
  13357. for (int index = 0; index < AC_QUANTITY; index++)
  13358. {
  13359. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13360. {
  13361. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13362. }
  13363. }// END OF AC_QUANTITY
  13364. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13365. }
  13366. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13367. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13368. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13369. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13370. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13371. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13372. //2.3====================================== Power.Active.Import =========================================
  13373. //idx_sample=3;
  13374. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13375. if(gunType[gun_index] == 'J')
  13376. {
  13377. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13378. {
  13379. tempIndex = ((gun_index==2) ? 1: 0);
  13380. }
  13381. else
  13382. {
  13383. tempIndex = gun_index;
  13384. }
  13385. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13386. {
  13387. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13388. {
  13389. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13390. }
  13391. } // End for CHAdeMO_QUANTITY
  13392. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13393. }
  13394. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13395. {
  13396. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13397. {
  13398. tempIndex = ((gun_index==2) ? 1: 0);
  13399. }
  13400. else
  13401. {
  13402. tempIndex = gun_index;
  13403. }
  13404. for (int index = 0; index < CCS_QUANTITY; index++)
  13405. {
  13406. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13407. {
  13408. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13409. }
  13410. } // END for CCS_QUANTITY
  13411. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13412. }
  13413. else if(gunType[gun_index] == 'G')
  13414. {
  13415. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13416. {
  13417. tempIndex = ((gun_index==2) ? 1: 0);
  13418. }
  13419. else
  13420. {
  13421. tempIndex = gun_index;
  13422. }
  13423. for (int index = 0; index < GB_QUANTITY; index++)
  13424. {
  13425. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13426. {
  13427. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13428. }
  13429. }// END for GB_QUANTITY
  13430. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13431. }
  13432. else
  13433. {
  13434. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13435. {
  13436. tempIndex = 2;
  13437. }
  13438. else
  13439. {
  13440. tempIndex = gun_index;
  13441. }
  13442. for (int index = 0; index < AC_QUANTITY; index++)
  13443. {
  13444. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13445. {
  13446. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13447. }
  13448. } // END for AC_QUANTITY
  13449. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13450. }
  13451. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13452. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13453. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13454. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13455. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13456. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13457. //2.4====================================== Voltage L1 ====================================================
  13458. //idx_sample=4;
  13459. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13460. if(gunType[gun_index] == 'J')
  13461. {
  13462. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13463. {
  13464. tempIndex = ((gun_index==2) ? 1: 0);
  13465. }
  13466. else
  13467. {
  13468. tempIndex = gun_index;
  13469. }
  13470. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13471. {
  13472. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13473. {
  13474. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13475. }
  13476. } // END OF FOR CHAdeMO_QUANTITY
  13477. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13478. }
  13479. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13480. {
  13481. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13482. {
  13483. tempIndex = ((gun_index==2) ? 1: 0);
  13484. }
  13485. else
  13486. {
  13487. tempIndex = gun_index;
  13488. }
  13489. for (int index = 0; index < CCS_QUANTITY; index++)
  13490. {
  13491. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13492. {
  13493. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13494. }
  13495. } // END OF FOR CCS_QUANTITY
  13496. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13497. }
  13498. else if(gunType[gun_index] == 'G')
  13499. {
  13500. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13501. {
  13502. tempIndex = ((gun_index==2) ? 1: 0);
  13503. }
  13504. else
  13505. {
  13506. tempIndex = gun_index;
  13507. }
  13508. for (int index = 0; index < GB_QUANTITY; index++)
  13509. {
  13510. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13511. {
  13512. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13513. }
  13514. } // END OF FOR GB_QUANTITY
  13515. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13516. }
  13517. else
  13518. {
  13519. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13520. {
  13521. tempIndex = 2;
  13522. }
  13523. else
  13524. {
  13525. tempIndex = gun_index;
  13526. }
  13527. for (int index = 0; index < AC_QUANTITY; index++)
  13528. {
  13529. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13530. {
  13531. 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
  13532. }
  13533. } // END OF FOR AC_QUANTITY
  13534. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13535. }
  13536. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13537. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13538. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13539. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13540. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13541. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13542. //2.5============================================== SoC =========================================================
  13543. //idx_sample=5;
  13544. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13545. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13546. {
  13547. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13548. {
  13549. tempIndex = ((gun_index==2) ? 1: 0);
  13550. }
  13551. else
  13552. {
  13553. tempIndex = gun_index;
  13554. }
  13555. if(gunType[gun_index] == 'J')
  13556. {
  13557. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13558. {
  13559. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13560. {
  13561. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13562. }
  13563. }
  13564. }
  13565. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13566. {
  13567. for (int index = 0; index < CCS_QUANTITY; index++)
  13568. {
  13569. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13570. {
  13571. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13572. }
  13573. }
  13574. }
  13575. else if(gunType[gun_index] == 'G')
  13576. {
  13577. for (int index = 0; index < GB_QUANTITY; index++)
  13578. {
  13579. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13580. {
  13581. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13582. }
  13583. }
  13584. }
  13585. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13586. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13587. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13588. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13589. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_Outlet]);
  13590. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13591. } // END FOR DC CASE
  13592. //2.6====================================== Current.Import L2 ==============================================
  13593. // idx_sample=6;
  13594. // AC 3 phase L2 current
  13595. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13596. {
  13597. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13598. {
  13599. tempIndex = 2;
  13600. }
  13601. else
  13602. {
  13603. tempIndex = gun_index;
  13604. }
  13605. for (int index = 0; index < AC_QUANTITY; index++)
  13606. {
  13607. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13608. {
  13609. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  13610. }
  13611. }// End of for AC_QUANTITY
  13612. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  13613. }
  13614. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13615. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  13616. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  13617. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  13618. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13619. //2.7====================================== Current.Import L3 ==============================================
  13620. // idx_sample=7;
  13621. // AC 3 phase L3 current
  13622. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13623. {
  13624. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13625. {
  13626. tempIndex = 2;
  13627. }
  13628. else
  13629. {
  13630. tempIndex = gun_index;
  13631. }
  13632. for (int index = 0; index < AC_QUANTITY; index++)
  13633. {
  13634. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13635. {
  13636. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  13637. }
  13638. }// End of for AC_QUANTITY
  13639. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  13640. }
  13641. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13642. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  13643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  13644. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  13645. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13646. //2.9====================================== Voltage L2 ====================================================
  13647. //idx_sample=8;
  13648. // AC 3 phase L2 volatge
  13649. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13650. {
  13651. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13652. {
  13653. tempIndex = 2;
  13654. }
  13655. else
  13656. {
  13657. tempIndex = gun_index;
  13658. }
  13659. for (int index = 0; index < AC_QUANTITY; index++)
  13660. {
  13661. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13662. {
  13663. 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
  13664. }
  13665. } // END OF FOR AC_QUANTITY
  13666. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  13667. }
  13668. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13669. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  13670. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  13671. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  13672. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13673. //2.10====================================== Voltage L3 ====================================================
  13674. //idx_sample=9;
  13675. // AC 3 phase L3 volatge
  13676. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13677. {
  13678. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13679. {
  13680. tempIndex = 2;
  13681. }
  13682. else
  13683. {
  13684. tempIndex = gun_index;
  13685. }
  13686. for (int index = 0; index < AC_QUANTITY; index++)
  13687. {
  13688. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13689. {
  13690. 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
  13691. }
  13692. } // END OF FOR AC_QUANTITY
  13693. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  13694. }
  13695. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13696. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  13697. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  13698. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  13699. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13700. //======================================== Message create ==============================================
  13701. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13702. {
  13703. 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\"}]}]}]"
  13704. ,gun_index+1
  13705. ,MESSAGE_TYPE_CALL
  13706. ,guid
  13707. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13708. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13709. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13710. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13711. ,"PowerLoss"
  13712. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13713. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13714. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13715. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13716. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13717. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13718. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13719. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13720. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13721. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13722. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13723. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13724. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13725. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13726. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13727. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13728. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13729. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13730. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13731. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13732. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13733. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13734. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13735. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13736. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13737. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13738. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13739. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13740. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13741. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13742. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13743. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13744. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13745. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13746. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13747. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13748. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value
  13749. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context
  13750. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format
  13751. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand
  13752. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase
  13753. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location
  13754. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit
  13755. );
  13756. }
  13757. else
  13758. {
  13759. if(((ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'Y') && (ShmSysConfigAndInfo->SysConfig.ModelName[2] != 'W')))
  13760. {
  13761. 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\"}]}]}]"
  13762. ,gun_index+1
  13763. ,MESSAGE_TYPE_CALL
  13764. ,guid
  13765. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13766. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13767. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13768. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13769. ,"PowerLoss"
  13770. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13771. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13772. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13773. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13774. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13775. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13776. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13777. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13778. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13779. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13780. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13781. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13782. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13783. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13784. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13785. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13786. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13787. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13788. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13789. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13790. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13791. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13792. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13793. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13794. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13795. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13796. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13797. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13798. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13799. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13800. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13801. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13802. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13803. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13804. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13805. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13806. );
  13807. }
  13808. else
  13809. {
  13810. 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\"}]}]}]"
  13811. ,gun_index+1
  13812. ,MESSAGE_TYPE_CALL
  13813. ,guid
  13814. ,ShmOCPP16Data->StopTransaction[gun_index].IdTag
  13815. ,ShmOCPP16Data->StopTransaction[gun_index].MeterStop
  13816. ,ShmOCPP16Data->StopTransaction[gun_index].Timestamp
  13817. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionId
  13818. ,"PowerLoss"
  13819. ,(const char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp
  13820. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value
  13821. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context
  13822. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format
  13823. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Measurand
  13824. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase
  13825. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location
  13826. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit
  13827. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value
  13828. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context
  13829. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format
  13830. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand
  13831. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase
  13832. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location
  13833. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit
  13834. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value
  13835. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context
  13836. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format
  13837. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand
  13838. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase
  13839. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location
  13840. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit
  13841. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value
  13842. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context
  13843. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format
  13844. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand
  13845. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase
  13846. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location
  13847. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit
  13848. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value
  13849. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context
  13850. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format
  13851. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand
  13852. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase
  13853. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location
  13854. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit
  13855. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value
  13856. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context
  13857. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format
  13858. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand
  13859. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase
  13860. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location
  13861. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit
  13862. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value
  13863. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context
  13864. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format
  13865. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand
  13866. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase
  13867. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location
  13868. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit
  13869. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Value
  13870. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context
  13871. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format
  13872. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand
  13873. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase
  13874. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location
  13875. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit
  13876. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Value
  13877. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context
  13878. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format
  13879. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand
  13880. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase
  13881. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location
  13882. ,ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit
  13883. );
  13884. }
  13885. }
  13886. // Check File "TempStopTransaction" Exist
  13887. if((access(TempStopTransaction,F_OK))!=-1)
  13888. {
  13889. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  13890. fclose(fopen(TempStopTransaction, "w"));
  13891. }
  13892. else
  13893. {
  13894. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  13895. FILE *log = fopen(TempStopTransaction, "w+");
  13896. if(log == NULL)
  13897. {
  13898. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  13899. return ;
  13900. }
  13901. else
  13902. {
  13903. fclose(log);
  13904. }
  13905. }
  13906. //Add TempStopTransaction | Update TempStopTransaction
  13907. // open file for writing
  13908. FILE *outfile;
  13909. outfile = fopen (TempStopTransaction, "a");
  13910. //DEBUG_INFO("data = %s\n", queuedata);
  13911. fputs(queuedata, outfile);
  13912. fputs("\n", outfile);
  13913. fclose (outfile);
  13914. }
  13915. void checkTempStopTransaction(int gun_index)
  13916. {
  13917. FILE *fptr1;
  13918. char ch;
  13919. char str[QUEUE_MESSAGE_LENGTH]={0};
  13920. char guid[37]={0};
  13921. char tempdata[65]={0};
  13922. char connectorStr[2]={0};
  13923. char TempStopTransaction[256];
  13924. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  13925. fptr1 = fopen(TempStopTransaction, "r");
  13926. //TempStopTransaction格式: 槍號,StopTransaction封包
  13927. if (!fptr1)
  13928. {
  13929. //printf(" File not found or unable to open the input file!!\n");
  13930. return ;
  13931. }
  13932. ch=fgetc(fptr1);
  13933. //printf(" Now the content of the file %s is : \n",fname);
  13934. rewind(fptr1);
  13935. if(ch!=EOF)
  13936. {
  13937. // copy all contents to the temporary file except the specific line
  13938. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  13939. {
  13940. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13941. if(str[0]=='\0')
  13942. {
  13943. break;
  13944. }
  13945. //TempStopTransaction格式: 槍號,StopTransaction封包
  13946. strncpy(connectorStr, str, 1);
  13947. if(atoi(connectorStr) != (gun_index+1))
  13948. {
  13949. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  13950. fclose(fptr1);
  13951. return ;
  13952. }
  13953. //random_uuid(guid);
  13954. strncpy(guid, str+6, 36); //copy guid
  13955. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  13956. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  13957. {
  13958. DEBUG_INFO("StopTransaction mapitem pass\n");
  13959. }
  13960. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  13961. memset(str,0,ARRAY_SIZE(str));
  13962. }
  13963. }
  13964. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  13965. fclose(fptr1);
  13966. remove(TempStopTransaction); // remove the original file
  13967. }
  13968. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  13969. {
  13970. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  13971. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  13972. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  13973. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  13974. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  13975. }
  13976. int GetWebSocketPingInterval(void)
  13977. {
  13978. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  13979. }
  13980. int GetServerSign(void)
  13981. {
  13982. return server_sign;
  13983. }
  13984. uint8_t GetOcppSecurityProfile()
  13985. {
  13986. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  13987. }
  13988. void GetOcppChargerBoxId(uint8_t *data)
  13989. {
  13990. sprintf((char*)data, "%s", ShmOCPP16Data->ChargeBoxId);
  13991. }
  13992. void GetOcppSecurityPassword(uint8_t *data)
  13993. {
  13994. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  13995. }
  13996. void SetServerSign(int value)
  13997. {
  13998. server_sign = value;
  13999. }
  14000. int GetBootNotificationInterval(void)
  14001. {
  14002. return BootNotificationInterval;
  14003. }
  14004. int GetInternetConn(void)
  14005. {
  14006. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14007. }
  14008. void InitialSystemValue(void)
  14009. {
  14010. int connectorIndex = 0;
  14011. //int valueASCII = 0;
  14012. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14013. gunTotalNumber=0;
  14014. SystemInitial = 0;
  14015. localversion=0;
  14016. BootNotificationInterval = 0;
  14017. authorizeRetryTimes = 0;
  14018. GunStatusInterval = 10;
  14019. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14020. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14021. //Hear Beat
  14022. HeartBeatWithNOResponse = 0;
  14023. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14024. FirstHeartBeat = 0;
  14025. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14026. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14027. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14028. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14029. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14030. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14031. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14032. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14033. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14034. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14035. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14036. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14037. memset(gunType, 0, ARRAY_SIZE(gunType));
  14038. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14039. {
  14040. //check connector / socket type (index: 8, 9, 10)
  14041. for(int index=7; index <10 ; index++)
  14042. {
  14043. if(index != 8)
  14044. {
  14045. // DC Connector
  14046. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  14047. {
  14048. SystemInitial = SystemInitial + 1;
  14049. gunTotalNumber = gunTotalNumber + 1;
  14050. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14051. connectorIndex = connectorIndex + 1;
  14052. }
  14053. }
  14054. else
  14055. {
  14056. // AC Connector
  14057. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14058. {
  14059. SystemInitial = SystemInitial + 1;
  14060. gunTotalNumber = gunTotalNumber + 1;
  14061. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14062. connectorIndex = connectorIndex + 1;
  14063. }
  14064. }
  14065. }
  14066. //DEBUG_INFO("DC ...\n");
  14067. }
  14068. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14069. {
  14070. //check connector / socket type (index: 8, 9, 10)
  14071. for(int index=7; index <10 ; index++)
  14072. {
  14073. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14074. {
  14075. SystemInitial = SystemInitial + 1;
  14076. gunTotalNumber = gunTotalNumber + 1;
  14077. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14078. connectorIndex = connectorIndex + 1;
  14079. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14080. }
  14081. }
  14082. }
  14083. //Status && ConnectorPlugIn Setting
  14084. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14085. {
  14086. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14087. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14088. }
  14089. for (int index = 0; index < CCS_QUANTITY; index++)
  14090. {
  14091. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14092. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14093. }
  14094. for (int index = 0; index < GB_QUANTITY; index++)
  14095. {
  14096. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14097. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14098. }
  14099. for (int index = 0; index < AC_QUANTITY; index++)
  14100. {
  14101. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14102. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14103. }
  14104. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14105. {
  14106. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14107. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14108. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14109. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14110. }
  14111. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14112. clientTime.Heartbeat=time((time_t*)NULL);
  14113. sleep(1);
  14114. }
  14115. void LWS_Send(char * str)
  14116. {
  14117. //=====================================================
  14118. // Check InternetConn 0: disconnected, 1: connected
  14119. //====================================================
  14120. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14121. {
  14122. DEBUG_INFO("offline now !!!\n");
  14123. return;
  14124. }
  14125. pthread_mutex_lock(&lock_send);
  14126. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14127. sprintf((char *)SendBuffer, "%s", str);
  14128. SendBufLen = strlen(str);
  14129. pthread_mutex_unlock(&lock_send);
  14130. lws_callback_on_writable(wsi_client);
  14131. //lws_service(context, 0);
  14132. //sleep(1);
  14133. }
  14134. void LWS_SendNow(char * str)
  14135. {
  14136. //=====================================================
  14137. // Check InternetConn 0: disconnected, 1: connected
  14138. //====================================================
  14139. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14140. {
  14141. DEBUG_INFO("offline now !!!\n");
  14142. return;
  14143. }
  14144. pthread_mutex_lock(&lock_send);
  14145. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14146. sprintf((char *)SendBuffer, "%s", str);
  14147. SendBufLen = strlen(str);
  14148. pthread_mutex_unlock(&lock_send);
  14149. lws_callback_on_writable(wsi_client);
  14150. lws_service(context, 0);
  14151. //sleep(1);
  14152. }