MessageHandler.c 685 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511
  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. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  8. struct StatusCodeData *ShmStatusCodeData;
  9. struct PsuData *ShmPsuData ;
  10. struct OCPP16Data *ShmOCPP16Data;
  11. //ConfigurationMaxKeys
  12. #define GetConfigurationMaxKeysNUM _GetConfiguration_CNT
  13. pthread_mutex_t lock_send = PTHREAD_MUTEX_INITIALIZER;
  14. char queuedata[QUEUE_MESSAGE_LENGTH] = {0};
  15. //=================================
  16. // StatusNotification cycle
  17. //=================================
  18. static int server_cycle_Status = 120;
  19. //===============================
  20. // Configuration: unknownkey
  21. //===============================
  22. static char unknownkey[10][20] = {0};
  23. static int UnknownKeynum = 0;
  24. //===============================
  25. // Gun Total Numbers
  26. //===============================
  27. static int gunTotalNumber = 0;
  28. static uint8_t gunType[4] = {0};
  29. //===============================
  30. // Local List Version
  31. //===============================
  32. static int localversion=0;
  33. static char idTagAuthorization[32] = {0};
  34. //===============================
  35. // OCPP sign variable
  36. //===============================
  37. static int server_sign = FALSE;
  38. int server_pending = FALSE;
  39. static int BootNotificationInterval = 0;
  40. static int SystemInitial = 0;//= CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY; // System Boot UP
  41. //===============================
  42. // OCPP auth variable
  43. //===============================
  44. static int authorizeRetryTimes = 0; //number of Retry times
  45. //===============================
  46. // OCPP other variables
  47. //===============================
  48. static int HeartBeatWaitTime = 10;
  49. static int FirstHeartBeat = 0;
  50. static int FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  51. static int DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  52. static char CurrentChargingProfileScheduleStr[30] = {0};
  53. //========================================
  54. // OCPP status/previous related variables
  55. //========================================
  56. static int GunStatusInterval = 10;
  57. static uint8_t statusModeChage[CONNECTOR_QUANTITY] = {FALSE};
  58. static uint8_t ChademoPreviousSystemStatus[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  59. static uint8_t CcsPreviousSystemStatus[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  60. static uint8_t GbPreviousSystemStatus[(GB_QUANTITY>0?GB_QUANTITY:1)];
  61. static uint8_t AcPreviousSystemStatus[(AC_QUANTITY>0?AC_QUANTITY:1)];
  62. static uint8_t DoPreviousSystemStatus[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  63. static uint8_t ChademoPreviousConnectorPlugIn[(CHAdeMO_QUANTITY>0?CHAdeMO_QUANTITY:1)];
  64. static uint8_t CcsPreviousConnectorPlugIn[(CCS_QUANTITY>0?CCS_QUANTITY:1)];
  65. static uint8_t GbPreviousConnectorPlugIn[(GB_QUANTITY>0?GB_QUANTITY:1)];
  66. static uint8_t AcPreviousConnectorPlugIn[(AC_QUANTITY>0?AC_QUANTITY:1)];
  67. static uint8_t DoPreviousConnectorPlugIn[(CONNECTOR_QUANTITY>0?CONNECTOR_QUANTITY:1)];
  68. static int TransactionMessageAttemptsValue = 0;
  69. static int TransactionMessageRetryIntervalValue = 0;
  70. static int TempMeterValueInterval = 0;
  71. static struct OCPPAuthLocalElemet
  72. {
  73. int listVersionInt;
  74. char idTagstr[20];
  75. char parentIdTag[20];
  76. char expiryDate[30];
  77. char idTagstatus[16];
  78. }idTagQuery;
  79. //=============================================
  80. // OCPP HeartBeat Response Not Receive Counts
  81. //============================================
  82. static int HeartBeatWithNOResponse = 0;
  83. extern void ChageWebSocketPingInterval(int WebSocketPingInterval);
  84. extern sqlite3 *db;
  85. int TransactionMessageAttemptsGet(void);
  86. int TransactionMessageRetryIntervalGet(void);
  87. int GetOcppConnStatus(void);
  88. void SetOcppConnStatus(uint8_t status);
  89. int setKeyValue(char *key, char *value);
  90. void OCPP_get_TableAuthlocalAllData(void);
  91. void processUnkownKey(void);
  92. struct StructOCPPMeterValue
  93. {
  94. unsigned char TimeStamp[28];
  95. struct StructSampledValue SampledValue[10];
  96. };
  97. struct ClientTime
  98. {
  99. unsigned int Heartbeat;
  100. unsigned int StatusNotification[CONNECTOR_QUANTITY];
  101. unsigned int StartTransaction;
  102. unsigned int StopTransaction;
  103. unsigned int MeterValues[CONNECTOR_QUANTITY];
  104. }clientTime;
  105. typedef union
  106. {
  107. //Operations Initiated by Central System
  108. unsigned char CsMsgValue[CONNECTOR_QUANTITY];
  109. struct
  110. {
  111. //CsMsgValue[0]
  112. unsigned char StatusNotificationReq:1; //bit 0,
  113. unsigned char StatusNotificationConf:1; //bit 1,
  114. unsigned char TriggerMeterValue:1; //bit 2,
  115. unsigned char :5; //bit 5~7
  116. }bits[CONNECTOR_QUANTITY];
  117. }CpinitiateMsg;
  118. CpinitiateMsg cpinitateMsg;
  119. //GetConfiguration Array
  120. struct StructConfigurationKeyItems staticKeyArray[GetConfigurationMaxKeysNUM]={0};
  121. struct StructConfigurationKey staticResponseConfigurationKeyArray[GetConfigurationMaxKeysNUM]={0};
  122. struct StructConfigurationKeyItems staticResponseUnknownKey[10]={0};
  123. struct StructLocalAuthorizationList staticLocalAuthorizationList[500]={0};
  124. #if 0
  125. static char *ChargePointErrorCodeStr[] = {
  126. MACROSTR(ConnectorLockFailure),
  127. MACROSTR(EVCommunicationError),
  128. MACROSTR(GroundFailure),
  129. MACROSTR(HighTemperature),
  130. MACROSTR(InternalError),
  131. MACROSTR(LocalListConflict),
  132. MACROSTR(NoError),
  133. MACROSTR(OtherError),
  134. MACROSTR(OverCurrentFailure),
  135. MACROSTR(OverVoltage),
  136. MACROSTR(PowerMeterFailure),
  137. MACROSTR(PowerSwitchFailure),
  138. MACROSTR(ReaderFailure),
  139. MACROSTR(ResetFailure),
  140. MACROSTR(UnderVoltage),
  141. MACROSTR(WeakSignal)
  142. };
  143. #endif
  144. static char * ChargePointStatusStr[] = {
  145. MACROSTR(Available),
  146. MACROSTR(Preparing),
  147. MACROSTR(Charging),
  148. MACROSTR(SuspendedEVSE),
  149. MACROSTR(SuspendedEV),
  150. MACROSTR(Finishing),
  151. MACROSTR(Reserved),
  152. MACROSTR(Unavailable),
  153. MACROSTR(Faulted)
  154. };
  155. static char *RegistrationStatusStr[] = {
  156. MACROSTR(Accepted),
  157. MACROSTR(Pending),
  158. MACROSTR(Rejected)
  159. };
  160. static char *AvailabilityTypeStr[] = {
  161. MACROSTR(Inoperative),
  162. MACROSTR(Operative)
  163. };
  164. static char *AvailabilityStatusStr[] = {
  165. MACROSTR(Accepted),
  166. MACROSTR(Rejected),
  167. MACROSTR(Scheduled)
  168. };
  169. static char *ConfigurationStatusStr[] = {
  170. MACROSTR(Accepted),
  171. MACROSTR(Rejected),
  172. MACROSTR(RebootRequired),
  173. MACROSTR(NotSupported)
  174. };
  175. static char *ClearCacheStatusStr[] = {
  176. MACROSTR(Accepted),
  177. MACROSTR(Rejected)
  178. };
  179. static char *ChargingProfilePurposeTypeStr[] = {
  180. MACROSTR(ChargePointMaxProfile),
  181. MACROSTR(TxDefaultProfile),
  182. MACROSTR(TxProfile)
  183. };
  184. static char *ChargingProfileStatusStr[] = {
  185. MACROSTR(Accepted),
  186. MACROSTR(Rejected),
  187. MACROSTR(NotSupported)
  188. };
  189. static char *ClearChargingProfileStatusStr[] = {
  190. MACROSTR(Accepted),
  191. MACROSTR(Unknown)
  192. };
  193. static char *GetCompositeScheduleStatusStr[] = {
  194. MACROSTR(Accepted),
  195. MACROSTR(Rejected)
  196. };
  197. static char *UpdateTypeStr[] = {
  198. MACROSTR(Differential),
  199. MACROSTR(Full)
  200. };
  201. static char *UpdateStatusStr[] = {
  202. MACROSTR(Accepted),
  203. MACROSTR(Failed),
  204. MACROSTR(NotSupported),
  205. MACROSTR(VersionMismatch)
  206. };
  207. static char *RemoteStartStopStatusStr[] = {
  208. MACROSTR(Accepted),
  209. MACROSTR(Rejected)
  210. };
  211. static char *ReservationStatusStr[] = {
  212. MACROSTR(Accepted),
  213. MACROSTR(Faulted),
  214. MACROSTR(Occupied),
  215. MACROSTR(Rejected),
  216. MACROSTR(Unavailable)
  217. };
  218. static char *ResetTypeStr[] = {
  219. MACROSTR(Hard),
  220. MACROSTR(Soft)
  221. };
  222. static char *ResetStatusStr[] = {
  223. MACROSTR(Accepted),
  224. MACROSTR(Rejected)
  225. };
  226. static char * DiagnosticsStatusStr[] = {
  227. MACROSTR(Idle),
  228. MACROSTR(Uploaded),
  229. MACROSTR(UploadFailed),
  230. MACROSTR(Uploading)
  231. };
  232. static char * FirmwareStatusStr[] = {
  233. MACROSTR(Downloaded),
  234. MACROSTR(DownloadFailed),
  235. MACROSTR(Downloading),
  236. MACROSTR(Idle),
  237. MACROSTR(InstallationFailed),
  238. MACROSTR(Installing),
  239. MACROSTR(Installed)
  240. };
  241. static char * MessageTriggerStr[] = {
  242. MACROSTR(BootNotification),
  243. MACROSTR(DiagnosticsStatusNotification),
  244. MACROSTR(FirmwareStatusNotification),
  245. MACROSTR(Heartbeat),
  246. MACROSTR(MeterValues),
  247. MACROSTR(StatusNotification)
  248. };
  249. static char * TriggerMessageStatusStr[] = {
  250. MACROSTR(Accepted),
  251. MACROSTR(Rejected),
  252. MACROSTR(NotImplemented)
  253. };
  254. static char * UnlockStatusStr[] = {
  255. MACROSTR(Unlocked),
  256. MACROSTR(UnlockFailed),
  257. MACROSTR(NotSupported)
  258. };
  259. #if 0
  260. static char * StopTransactionReasonStr[] = {
  261. MACROSTR(EmergencyStop),
  262. MACROSTR(EVDisconnected),
  263. MACROSTR(HardReset),
  264. MACROSTR(Local),
  265. MACROSTR(Other),
  266. MACROSTR(PowerLoss),
  267. MACROSTR(Reboot),
  268. MACROSTR(Remote),
  269. MACROSTR(SoftReset),
  270. MACROSTR(UnlockCommand),
  271. MACROSTR(DeAuthorized)
  272. };
  273. #endif
  274. static char * CancelReservationStatusStr[] = {
  275. MACROSTR(Accepted),
  276. MACROSTR(Rejected)
  277. };
  278. static char * ReadingContextStr[] = {
  279. MACROSTR(Interruption.Begin),
  280. MACROSTR(Interruption.End),
  281. MACROSTR(Other),
  282. MACROSTR(Sample.Clock),
  283. MACROSTR(Sample.Periodic),
  284. MACROSTR(Transaction.Begin),
  285. MACROSTR(Transaction.End),
  286. MACROSTR(Trigger)
  287. };
  288. static char * ValueFormatStr[] = {
  289. MACROSTR(Raw),
  290. MACROSTR(SignedData)
  291. };
  292. static char * MeasurandStr[] = {
  293. MACROSTR(Current.Export),
  294. MACROSTR(Current.Import),
  295. MACROSTR(Current.Offered),
  296. MACROSTR(Energy.Active.Export.Register),
  297. MACROSTR(Energy.Active.Import.Register),
  298. MACROSTR(Energy.Reactive.Export.Register),
  299. MACROSTR(Energy.Reactive.Import.Register),
  300. MACROSTR(Energy.Active.Export.Interval),
  301. MACROSTR(Energy.Active.Import.Interval),
  302. MACROSTR(Energy.Reactive.Export.Interval),
  303. MACROSTR(Energy.Reactive.Import.Interval),
  304. MACROSTR(Frequency),
  305. MACROSTR(Power.Active.Export),
  306. MACROSTR(Power.Active.Import),
  307. MACROSTR(Power.Factor),
  308. MACROSTR(Power.Offered),
  309. MACROSTR(Power.Reactive.ExportMACROSTR),
  310. MACROSTR(Power.Reactive.Import),
  311. MACROSTR(RPM),
  312. MACROSTR(SoC),
  313. MACROSTR(Temperature),
  314. MACROSTR(Voltage)
  315. };
  316. static char * LocationStr[] = {
  317. MACROSTR(Body),
  318. MACROSTR(Cable),
  319. MACROSTR(EV),
  320. MACROSTR(Inlet),
  321. MACROSTR(Outlet)
  322. };
  323. static char * PhaseStr[] = {
  324. MACROSTR(L1),
  325. MACROSTR(L2),
  326. MACROSTR(L3),
  327. MACROSTR(N),
  328. MACROSTR(L1-N),
  329. MACROSTR(L2-N),
  330. MACROSTR(L3-N),
  331. MACROSTR(L1-L2),
  332. MACROSTR(L2-L3),
  333. MACROSTR(L3-L1)
  334. };
  335. static char * UnitOfMeasureStr[] = {
  336. MACROSTR(Wh),
  337. MACROSTR(kWh),
  338. MACROSTR(varh),
  339. MACROSTR(kvarh),
  340. MACROSTR(W),
  341. MACROSTR(kW),
  342. MACROSTR(VA),
  343. MACROSTR(kVA),
  344. MACROSTR(var),
  345. MACROSTR(kvar),
  346. MACROSTR(A),
  347. MACROSTR(V),
  348. MACROSTR(Celsius),
  349. MACROSTR(Fahrenheit),
  350. MACROSTR(K),
  351. MACROSTR(Percent)
  352. };
  353. //==========================================
  354. // Check time passed since today
  355. //==========================================
  356. long long DiffTimebWithNow(struct timeb ST)
  357. {
  358. //return milli-second
  359. struct timeb ET;
  360. long long StartTime,StopTime;
  361. ftime(&ET);
  362. StartTime=(long long)ST.time;
  363. StopTime=(long long)ET.time;
  364. return ((StopTime-StartTime)*1000) + (ET.millitm-ST.millitm);
  365. }
  366. int getTimePassSinceToday()
  367. {
  368. int result = -1;
  369. static time_t lastTime;
  370. time_t t;
  371. struct tm *tmStartToday;
  372. struct timeb tbStartToday;
  373. t=time(NULL);
  374. if(difftime(t, lastTime)>0)
  375. {
  376. tmStartToday=localtime(&t);
  377. tmStartToday->tm_hour = 0;
  378. tmStartToday->tm_min = 0;
  379. tmStartToday->tm_sec = 0;
  380. tbStartToday.time = mktime(tmStartToday);
  381. tbStartToday.millitm = 0;
  382. result = DiffTimebWithNow(tbStartToday)/1000;
  383. lastTime = t;
  384. }
  385. return result;
  386. }
  387. //==========================================
  388. // GetCompositeSchedule logic related function
  389. //==========================================
  390. int DiffTimebSec(struct timeb ST, struct timeb ET)
  391. {
  392. //return milli-second
  393. unsigned int StartTime,StopTime;
  394. StartTime=(unsigned int)ST.time;
  395. StopTime=(unsigned int)ET.time;
  396. return (StopTime-StartTime);
  397. }
  398. int DiffTimebWithNowSec(struct timeb ST)
  399. {
  400. //return milli-second
  401. struct timeb ET;
  402. unsigned int StartTime,StopTime;
  403. ftime(&ET);
  404. StartTime=(unsigned int)ST.time;
  405. StopTime=(unsigned int)ET.time;
  406. return (StopTime-StartTime);
  407. }
  408. int getStartStop(uint8_t *start, uint8_t *stop)
  409. {
  410. int result = -1;
  411. struct tm tmStart;
  412. struct timeb tbStart;
  413. struct tm tmStop;
  414. struct timeb tbStop;
  415. 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) &&
  416. (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))
  417. {
  418. //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);
  419. //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);
  420. tmStart.tm_year -= 1900;
  421. tmStart.tm_mon -= 1;
  422. tbStart.time = mktime(&tmStart);
  423. tbStart.millitm = 0;
  424. tmStop.tm_year -= 1900;
  425. tmStop.tm_mon -= 1;
  426. tbStop.time = mktime(&tmStop);
  427. tbStop.millitm = 0;
  428. result = DiffTimebSec(tbStart, tbStop);
  429. //DEBUG_INFO("getStartStop(): %d\n", result);
  430. }
  431. else
  432. {
  433. DEBUG_WARN("Start or stop date parsing error.\r\n");
  434. }
  435. return result;
  436. }
  437. int isOvertNow(uint8_t *start)
  438. {
  439. int result = YES;
  440. struct tm tmStart;
  441. struct timeb tbStart;
  442. 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))
  443. {
  444. //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);
  445. tmStart.tm_year -= 1900;
  446. tmStart.tm_mon -= 1;
  447. tbStart.time = mktime(&tmStart);
  448. tbStart.millitm = 0;
  449. if(DiffTimebWithNowSec(tbStart) <= 0)
  450. result = NO;
  451. }
  452. else
  453. {
  454. DEBUG_WARN("Start date parsing error.\r\n");
  455. }
  456. return result;
  457. }
  458. int getStartSinceRecurring(uint8_t *start, uint8_t *stop, uint8_t isDaily)
  459. {
  460. int result = -1;
  461. struct tm tmStart;
  462. struct timeb tbStart;
  463. struct tm tmStop;
  464. struct timeb tbStop;
  465. 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) &&
  466. (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))
  467. {
  468. tmStart.tm_year -= 1900;
  469. tmStart.tm_mon -= 1;
  470. tbStart.time = mktime(&tmStart);
  471. tbStart.millitm = 0;
  472. tmStop.tm_year -= 1900;
  473. tmStop.tm_mon -= 1;
  474. tbStop.time = mktime(&tmStop);
  475. tbStop.millitm = 0;
  476. result = DiffTimebSec(tbStart, tbStop)%(isDaily?86400:604800);
  477. }
  478. return result;
  479. }
  480. void checkCompositeSchedule(uint8_t connectorId, uint32_t durationReq, struct StructChargingProfile *compositeProfile)
  481. {
  482. FILE *fp;
  483. char profileFileName[128];
  484. char *line = NULL;
  485. size_t len = 0;
  486. time_t CurrentTime;
  487. struct tm *tmComposite;
  488. struct StructChargingProfile maxProfile;
  489. struct StructChargingProfile defaultTxProfile;
  490. struct StructChargingProfile txProfile;
  491. struct StructChargingSchedulePeriod tmpPeriod;
  492. uint8_t limitMax=0;
  493. uint8_t limitDef=0;
  494. uint8_t limitTx=0;
  495. int compositePeriodIdx = 0;
  496. CurrentTime = time(NULL);
  497. tmComposite=localtime(&CurrentTime);
  498. 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);
  499. sprintf((char*)compositeProfile->ChargingSchedule.ChargingRateUnit, "A");
  500. compositeProfile->ChargingSchedule.Duration = durationReq;
  501. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  502. {
  503. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  504. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  505. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  506. }
  507. compositeProfile->ChargingProfileId = 0;
  508. compositeProfile->StackLevel = 99 ;
  509. sprintf((char*)compositeProfile->ChargingProfileKind ,"Absolute");
  510. maxProfile.ChargingProfileId = -1;
  511. defaultTxProfile.ChargingProfileId = -1;
  512. txProfile.ChargingProfileId = -1;
  513. maxProfile.ChargingSchedule.Duration = -1;
  514. defaultTxProfile.ChargingSchedule.Duration = -1;
  515. txProfile.ChargingSchedule.Duration = -1;
  516. system("yes|rm /tmp/*.json");
  517. system("cp /Storage/OCPP/*.json /tmp");
  518. /*
  519. * Search valid charging profile
  520. */
  521. //DEBUG_INFO("====================================\n");
  522. // Search tx profile
  523. sprintf(profileFileName, "/tmp/TxProfile_%d.json", connectorId);
  524. if((access(profileFileName, F_OK))!=-1)
  525. {
  526. fp = fopen(profileFileName, "r");
  527. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  528. {
  529. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  530. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  531. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  532. }
  533. txProfile.ChargingProfileId = -1;
  534. txProfile.StackLevel = -1;
  535. while(getline(&line, &len, fp) != -1)
  536. {
  537. json_object *obj = NULL;
  538. obj = json_tokener_parse(line);
  539. if(is_error(obj))
  540. {
  541. DEBUG_ERROR("Parse txProfile from file error.\n");
  542. }
  543. else
  544. {
  545. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != txProfile.ChargingProfileId) &&
  546. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= txProfile.StackLevel)
  547. )
  548. {
  549. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  550. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  551. )
  552. {
  553. struct tm tmFrom, tmTo;
  554. struct timeb tbFrom, tbTo;
  555. 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) &&
  556. (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))
  557. {
  558. tmFrom.tm_year -= 1900;
  559. tmFrom.tm_mon -= 1;
  560. tbFrom.time = mktime(&tmFrom);
  561. tmTo.tm_year -= 1900;
  562. tmTo.tm_mon -= 1;
  563. tbTo.time = mktime(&tmTo);
  564. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  565. {
  566. if(txProfile.ChargingProfileId == -1)
  567. DEBUG_INFO("TxProfile found.\n");
  568. else
  569. DEBUG_INFO("TxProfile updated.\n");
  570. // Required item
  571. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  572. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  573. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  574. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  575. 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++)
  576. {
  577. 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"));
  578. 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")));
  579. 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?
  580. 3:
  581. 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")));
  582. }
  583. // Optional item
  584. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  585. {
  586. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  587. }
  588. else
  589. {
  590. sprintf((char*)txProfile.ValidFrom, " ");
  591. }
  592. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  593. {
  594. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  595. }
  596. else
  597. {
  598. sprintf((char*)txProfile.ValidTo, " ");
  599. }
  600. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  601. {
  602. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  603. }
  604. else
  605. {
  606. sprintf((char*)txProfile.RecurrencyKind, " ");
  607. }
  608. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  609. {
  610. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  611. }
  612. else
  613. {
  614. txProfile.TransactionId = -1;
  615. }
  616. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  617. {
  618. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  619. }
  620. else
  621. {
  622. txProfile.ChargingSchedule.Duration = 86400;
  623. }
  624. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  625. {
  626. 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")));
  627. }
  628. else
  629. {
  630. 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));
  631. }
  632. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  633. {
  634. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  635. }
  636. else
  637. {
  638. txProfile.ChargingSchedule.MinChargingRate = -1;
  639. }
  640. }
  641. }
  642. }
  643. else
  644. {
  645. if(txProfile.ChargingProfileId == -1)
  646. DEBUG_INFO("TxProfile found.\n");
  647. else
  648. DEBUG_INFO("TxProfile updated.\n");
  649. // Required item
  650. txProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  651. txProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  652. sprintf((char*)txProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  653. sprintf((char*)txProfile.ChargingSchedule.ChargingRateUnit, "A");
  654. 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++)
  655. {
  656. 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"));
  657. 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")));
  658. 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?
  659. 3:
  660. 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")));
  661. }
  662. // Optional item
  663. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  664. {
  665. sprintf((char*)txProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  666. }
  667. else
  668. {
  669. sprintf((char*)txProfile.ValidFrom, " ");
  670. }
  671. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  672. {
  673. sprintf((char*)txProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  674. }
  675. else
  676. {
  677. sprintf((char*)txProfile.ValidTo, " ");
  678. }
  679. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  680. {
  681. sprintf((char*)txProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  682. }
  683. else
  684. {
  685. sprintf((char*)txProfile.RecurrencyKind, " ");
  686. }
  687. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  688. {
  689. txProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  690. }
  691. else
  692. {
  693. txProfile.TransactionId = -1;
  694. }
  695. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  696. {
  697. txProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  698. }
  699. else
  700. {
  701. txProfile.ChargingSchedule.Duration = 86400;
  702. }
  703. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  704. {
  705. 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")));
  706. }
  707. else
  708. {
  709. 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));
  710. }
  711. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  712. {
  713. txProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  714. }
  715. else
  716. {
  717. txProfile.ChargingSchedule.MinChargingRate = -1;
  718. }
  719. }
  720. }
  721. }
  722. json_object_put(obj);
  723. }
  724. fclose(fp);
  725. /*
  726. if(txProfile.ChargingProfileId != -1)
  727. {
  728. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  729. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  730. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  731. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  732. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  733. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  734. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  735. DEBUG_INFO("Profile start schedule: %s\n", txProfile.ChargingSchedule.StartSchedule);
  736. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  737. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  738. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  739. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  740. {
  741. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  742. {
  743. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  744. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  745. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  746. }
  747. }
  748. }
  749. else
  750. DEBUG_INFO("TxProfile not found.\n");*/
  751. }
  752. // Search default tx profile
  753. sprintf(profileFileName, "/tmp/TxDefaultProfile_%d.json", connectorId);
  754. if((access(profileFileName, F_OK))==-1)
  755. sprintf(profileFileName, "/tmp/TxDefaultProfile_0.json");
  756. if((access(profileFileName, F_OK))!=-1)
  757. {
  758. fp = fopen(profileFileName, "r");
  759. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  760. {
  761. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  762. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  763. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  764. }
  765. defaultTxProfile.ChargingProfileId = -1;
  766. defaultTxProfile.StackLevel = -1;
  767. while(getline(&line, &len, fp) != -1)
  768. {
  769. json_object *obj = NULL;
  770. obj = json_tokener_parse(line);
  771. if(is_error(obj))
  772. {
  773. DEBUG_ERROR("Parse TxDefaultProfile from file error.\n");
  774. }
  775. else
  776. {
  777. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != defaultTxProfile.ChargingProfileId) &&
  778. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= defaultTxProfile.StackLevel)
  779. )
  780. {
  781. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  782. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  783. )
  784. {
  785. struct tm tmFrom, tmTo;
  786. struct timeb tbFrom, tbTo;
  787. 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) &&
  788. (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))
  789. {
  790. tmFrom.tm_year -= 1900;
  791. tmFrom.tm_mon -= 1;
  792. tbFrom.time = mktime(&tmFrom);
  793. tmTo.tm_year -= 1900;
  794. tmTo.tm_mon -= 1;
  795. tbTo.time = mktime(&tmTo);
  796. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  797. {
  798. if(defaultTxProfile.ChargingProfileId == -1)
  799. DEBUG_INFO("TxDefaultProfile found.\n");
  800. else
  801. DEBUG_INFO("TxDefaultProfile updated.\n");
  802. // Required item
  803. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  804. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  805. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  806. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  807. 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++)
  808. {
  809. 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"));
  810. 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")));
  811. 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?
  812. 3:
  813. 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")));
  814. }
  815. // Optional item
  816. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  817. {
  818. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  819. }
  820. else
  821. {
  822. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  823. }
  824. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  825. {
  826. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  827. }
  828. else
  829. {
  830. sprintf((char*)defaultTxProfile.ValidTo, " ");
  831. }
  832. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  833. {
  834. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  835. }
  836. else
  837. {
  838. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  839. }
  840. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  841. {
  842. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  843. }
  844. else
  845. {
  846. defaultTxProfile.TransactionId = -1;
  847. }
  848. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  849. {
  850. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  851. }
  852. else
  853. {
  854. defaultTxProfile.ChargingSchedule.Duration = 86400;
  855. }
  856. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  857. {
  858. 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")));
  859. }
  860. else
  861. {
  862. 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));
  863. }
  864. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  865. {
  866. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  867. }
  868. else
  869. {
  870. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  871. }
  872. }
  873. }
  874. }
  875. else
  876. {
  877. if(defaultTxProfile.ChargingProfileId == -1)
  878. DEBUG_INFO("TxDefaultProfile found.\n");
  879. else
  880. DEBUG_INFO("TxDefaultProfile updated.\n");
  881. // Required item
  882. defaultTxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  883. defaultTxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  884. sprintf((char*)defaultTxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  885. sprintf((char*)defaultTxProfile.ChargingSchedule.ChargingRateUnit, "A");
  886. 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++)
  887. {
  888. 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"));
  889. 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")));
  890. 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?
  891. 3:
  892. 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")));
  893. }
  894. // Optional item
  895. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  896. {
  897. sprintf((char*)defaultTxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  898. }
  899. else
  900. {
  901. sprintf((char*)defaultTxProfile.ValidFrom, " ");
  902. }
  903. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  904. {
  905. sprintf((char*)defaultTxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  906. }
  907. else
  908. {
  909. sprintf((char*)defaultTxProfile.ValidTo, " ");
  910. }
  911. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  912. {
  913. sprintf((char*)defaultTxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  914. }
  915. else
  916. {
  917. sprintf((char*)defaultTxProfile.RecurrencyKind, " ");
  918. }
  919. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  920. {
  921. defaultTxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  922. }
  923. else
  924. {
  925. defaultTxProfile.TransactionId = -1;
  926. }
  927. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  928. {
  929. defaultTxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  930. }
  931. else
  932. {
  933. defaultTxProfile.ChargingSchedule.Duration = 86400;
  934. }
  935. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  936. {
  937. 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")));
  938. }
  939. else
  940. {
  941. 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));
  942. }
  943. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  944. {
  945. defaultTxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  946. }
  947. else
  948. {
  949. defaultTxProfile.ChargingSchedule.MinChargingRate = -1;
  950. }
  951. }
  952. }
  953. }
  954. json_object_put(obj);
  955. }
  956. fclose(fp);
  957. /*
  958. if(defaultTxProfile.ChargingProfileId != -1)
  959. {
  960. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  961. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  962. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  963. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  964. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  965. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  966. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  967. DEBUG_INFO("Profile start schedule: %s\n", defaultTxProfile.ChargingSchedule.StartSchedule);
  968. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  969. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  970. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  971. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  972. {
  973. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  974. {
  975. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  976. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  977. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  978. }
  979. }
  980. }
  981. else
  982. DEBUG_INFO("TxDefaultProfile not found.\n");
  983. DEBUG_INFO("------------------------------------\n");*/
  984. }
  985. // Search max profile
  986. sprintf(profileFileName, "/tmp/ChargePointMaxProfile.json");
  987. if((access(profileFileName, F_OK))!=-1)
  988. {
  989. fp = fopen(profileFileName, "r");
  990. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  991. {
  992. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = -1;
  993. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = -1;
  994. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = 3;
  995. }
  996. maxProfile.ChargingProfileId = -1;
  997. maxProfile.StackLevel = -1;
  998. while(getline(&line, &len, fp) != -1)
  999. {
  1000. json_object *obj = NULL;
  1001. obj = json_tokener_parse(line);
  1002. if(is_error(obj))
  1003. {
  1004. DEBUG_ERROR("Parse MaxProfile from file error.\n");
  1005. }
  1006. else
  1007. {
  1008. if((json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "ChargingProfileId")) != maxProfile.ChargingProfileId) &&
  1009. (json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel")) >= maxProfile.StackLevel)
  1010. )
  1011. {
  1012. if((json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL) &&
  1013. (json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1014. )
  1015. {
  1016. struct tm tmFrom, tmTo;
  1017. struct timeb tbFrom, tbTo;
  1018. 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) &&
  1019. (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))
  1020. {
  1021. tmFrom.tm_year -= 1900;
  1022. tmFrom.tm_mon -= 1;
  1023. tbFrom.time = mktime(&tmFrom);
  1024. tmTo.tm_year -= 1900;
  1025. tmTo.tm_mon -= 1;
  1026. tbTo.time = mktime(&tmTo);
  1027. if((DiffTimebWithNowSec(tbFrom)>=0) && (DiffTimebWithNowSec(tbTo)<=0))
  1028. {
  1029. if(maxProfile.ChargingProfileId == -1)
  1030. DEBUG_INFO("MaxProfile found.\n");
  1031. else
  1032. DEBUG_INFO("MaxProfile updated.\n");
  1033. // Required item
  1034. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1035. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1036. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1037. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1038. 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++)
  1039. {
  1040. 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"));
  1041. 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")));
  1042. 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?
  1043. 3:
  1044. 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")));
  1045. }
  1046. // Optional item
  1047. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1048. {
  1049. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1050. }
  1051. else
  1052. {
  1053. sprintf((char*)maxProfile.ValidFrom, " ");
  1054. }
  1055. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1056. {
  1057. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1058. }
  1059. else
  1060. {
  1061. sprintf((char*)maxProfile.ValidTo, " ");
  1062. }
  1063. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1064. {
  1065. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1066. }
  1067. else
  1068. {
  1069. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1070. }
  1071. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1072. {
  1073. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1074. }
  1075. else
  1076. {
  1077. maxProfile.TransactionId = -1;
  1078. }
  1079. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1080. {
  1081. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1082. }
  1083. else
  1084. {
  1085. maxProfile.ChargingSchedule.Duration = 86400;
  1086. }
  1087. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1088. {
  1089. 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")));
  1090. }
  1091. else
  1092. {
  1093. 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));
  1094. }
  1095. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1096. {
  1097. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1098. }
  1099. else
  1100. {
  1101. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1102. }
  1103. }
  1104. }
  1105. }
  1106. else
  1107. {
  1108. if(maxProfile.ChargingProfileId == -1)
  1109. DEBUG_INFO("MaxProfile found.\n");
  1110. else
  1111. DEBUG_INFO("MaxProfile updated.\n");
  1112. // Required item
  1113. maxProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileId"));
  1114. maxProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "stackLevel"));
  1115. sprintf((char*)maxProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingProfileKind")));
  1116. sprintf((char*)maxProfile.ChargingSchedule.ChargingRateUnit, "A");
  1117. 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++)
  1118. {
  1119. 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"));
  1120. 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")));
  1121. 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?
  1122. 3:
  1123. 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")));
  1124. }
  1125. // Optional item
  1126. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom") != NULL)
  1127. {
  1128. sprintf((char*)maxProfile.ValidFrom, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validFrom")));
  1129. }
  1130. else
  1131. {
  1132. sprintf((char*)maxProfile.ValidFrom, " ");
  1133. }
  1134. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo") != NULL)
  1135. {
  1136. sprintf((char*)maxProfile.ValidTo, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "validTo")));
  1137. }
  1138. else
  1139. {
  1140. sprintf((char*)maxProfile.ValidTo, " ");
  1141. }
  1142. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind") != NULL)
  1143. {
  1144. sprintf((char*)maxProfile.RecurrencyKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "RecurrencyKind")));
  1145. }
  1146. else
  1147. {
  1148. sprintf((char*)maxProfile.RecurrencyKind, " ");
  1149. }
  1150. if(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId") != NULL)
  1151. {
  1152. maxProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "transactionId"));
  1153. }
  1154. else
  1155. {
  1156. maxProfile.TransactionId = -1;
  1157. }
  1158. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  1159. {
  1160. maxProfile.ChargingSchedule.Duration = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "duration"));
  1161. }
  1162. else
  1163. {
  1164. maxProfile.ChargingSchedule.Duration = 86400;
  1165. }
  1166. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  1167. {
  1168. 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")));
  1169. }
  1170. else
  1171. {
  1172. 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));
  1173. }
  1174. if(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  1175. {
  1176. maxProfile.ChargingSchedule.MinChargingRate = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(obj, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  1177. }
  1178. else
  1179. {
  1180. maxProfile.ChargingSchedule.MinChargingRate = -1;
  1181. }
  1182. }
  1183. }
  1184. }
  1185. json_object_put(obj);
  1186. }
  1187. fclose(fp);
  1188. /*
  1189. if(maxProfile.ChargingProfileId !=-1)
  1190. {
  1191. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1192. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1193. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1194. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1195. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1196. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1197. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1198. DEBUG_INFO("Profile start schedule: %s\n", maxProfile.ChargingSchedule.StartSchedule);
  1199. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1200. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1201. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1202. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1203. {
  1204. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1205. {
  1206. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1207. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1208. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1209. }
  1210. }
  1211. }
  1212. else
  1213. DEBUG_INFO("MaxProfile not found.\n");
  1214. DEBUG_INFO("------------------------------------\n");*/
  1215. }
  1216. /*
  1217. * Align found profile start schedule & periods
  1218. */
  1219. //DEBUG_INFO("====================================\n");
  1220. /*
  1221. // For local test usage, force modify found profile start schedule info
  1222. 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);
  1223. 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);
  1224. 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);
  1225. */
  1226. if(txProfile.ChargingProfileId != -1)
  1227. {
  1228. if(strstr((char*)txProfile.ChargingProfileKind, "Absolute") != NULL)
  1229. {
  1230. if(txProfile.ChargingSchedule.Duration != -1)
  1231. {
  1232. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1233. 0:
  1234. (txProfile.ChargingSchedule.Duration-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1235. }
  1236. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1237. {
  1238. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1239. {
  1240. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1241. 0:
  1242. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1243. if(idxPeriod > 0)
  1244. {
  1245. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1246. {
  1247. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1248. }
  1249. }
  1250. }
  1251. }
  1252. }
  1253. else if(strstr((char*)txProfile.ChargingProfileKind, "Relative") != NULL)
  1254. {
  1255. if(txProfile.ChargingSchedule.Duration != -1)
  1256. {
  1257. 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?
  1258. 0:
  1259. (txProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1260. }
  1261. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1262. {
  1263. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1264. {
  1265. 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?
  1266. 0:
  1267. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1268. if(idxPeriod > 0)
  1269. {
  1270. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1271. {
  1272. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1273. }
  1274. }
  1275. }
  1276. }
  1277. }
  1278. else
  1279. {
  1280. if(strstr((char*)txProfile.RecurrencyKind, "Weekly") != NULL)
  1281. {
  1282. if(txProfile.ChargingSchedule.Duration != -1)
  1283. {
  1284. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1285. 0:
  1286. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1287. }
  1288. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1289. {
  1290. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1291. {
  1292. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1293. 0:
  1294. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1295. if(idxPeriod > 0)
  1296. {
  1297. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1298. {
  1299. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1300. }
  1301. }
  1302. }
  1303. }
  1304. }
  1305. else
  1306. {
  1307. if(txProfile.ChargingSchedule.Duration != -1)
  1308. {
  1309. txProfile.ChargingSchedule.Duration = ((txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1310. 0:
  1311. (txProfile.ChargingSchedule.Duration-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1312. }
  1313. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1314. {
  1315. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1316. {
  1317. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1318. 0:
  1319. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(txProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1320. if(idxPeriod > 0)
  1321. {
  1322. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1323. {
  1324. txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1325. }
  1326. }
  1327. }
  1328. }
  1329. }
  1330. }
  1331. /*
  1332. DEBUG_INFO("txProfile after align.\n");
  1333. DEBUG_INFO("Profile ID: %d\n", txProfile.ChargingProfileId);
  1334. DEBUG_INFO("Profile stackLevel: %d\n", txProfile.StackLevel);
  1335. DEBUG_INFO("Profile TransactionId: %d\n", txProfile.TransactionId);
  1336. DEBUG_INFO("Profile valid from: %s\n", txProfile.ValidFrom);
  1337. DEBUG_INFO("Profile valid to: %s\n", txProfile.ValidTo);
  1338. DEBUG_INFO("Profile ChargingProfileKind: %s\n", txProfile.ChargingProfileKind);
  1339. DEBUG_INFO("Profile RecurrencyKind: %s\n", txProfile.RecurrencyKind);
  1340. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1341. DEBUG_INFO("Profile schedule duration: %d\n", txProfile.ChargingSchedule.Duration);
  1342. DEBUG_INFO("Profile charging rate unit: %s\n", txProfile.ChargingSchedule.ChargingRateUnit);
  1343. DEBUG_INFO("Profile charging min rate: %f\n", txProfile.ChargingSchedule.MinChargingRate);
  1344. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1345. {
  1346. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1347. {
  1348. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1349. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1350. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, txProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1351. }
  1352. }*/
  1353. }
  1354. if(defaultTxProfile.ChargingProfileId != -1)
  1355. {
  1356. if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Absolute") != NULL)
  1357. {
  1358. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1359. {
  1360. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1361. 0:
  1362. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1363. }
  1364. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1365. {
  1366. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1367. {
  1368. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1369. 0:
  1370. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1371. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1372. {
  1373. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1374. }
  1375. if(idxPeriod > 0)
  1376. {
  1377. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1378. {
  1379. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1380. }
  1381. }
  1382. }
  1383. }
  1384. }
  1385. else if(strstr((char*)defaultTxProfile.ChargingProfileKind, "Relative") != NULL)
  1386. {
  1387. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1388. {
  1389. 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?
  1390. 0:
  1391. (defaultTxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1392. }
  1393. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1394. {
  1395. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1396. {
  1397. 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?
  1398. 0:
  1399. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1400. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1401. {
  1402. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1403. }
  1404. if(idxPeriod > 0)
  1405. {
  1406. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1407. {
  1408. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1409. }
  1410. }
  1411. }
  1412. }
  1413. }
  1414. else
  1415. {
  1416. if(strstr((char*)defaultTxProfile.RecurrencyKind, "Weekly") != NULL)
  1417. {
  1418. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1419. {
  1420. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1421. 0:
  1422. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1423. }
  1424. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1425. {
  1426. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1427. {
  1428. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1429. 0:
  1430. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1431. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1432. {
  1433. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1434. }
  1435. if(idxPeriod > 0)
  1436. {
  1437. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1438. {
  1439. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1440. }
  1441. }
  1442. }
  1443. }
  1444. }
  1445. else
  1446. {
  1447. if(defaultTxProfile.ChargingSchedule.Duration != -1)
  1448. {
  1449. defaultTxProfile.ChargingSchedule.Duration = ((defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1450. 0:
  1451. (defaultTxProfile.ChargingSchedule.Duration-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1452. }
  1453. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1454. {
  1455. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1456. {
  1457. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1458. 0:
  1459. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(defaultTxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1460. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod < txProfile.ChargingSchedule.Duration)
  1461. {
  1462. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod += (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1463. }
  1464. if(idxPeriod > 0)
  1465. {
  1466. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1467. {
  1468. defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1469. }
  1470. }
  1471. }
  1472. }
  1473. }
  1474. }
  1475. /*
  1476. DEBUG_INFO("defaultTxProfile after align.\n");
  1477. DEBUG_INFO("Profile ID: %d\n", defaultTxProfile.ChargingProfileId);
  1478. DEBUG_INFO("Profile stackLevel: %d\n", defaultTxProfile.StackLevel);
  1479. DEBUG_INFO("Profile TransactionId: %d\n", defaultTxProfile.TransactionId);
  1480. DEBUG_INFO("Profile valid from: %s\n", defaultTxProfile.ValidFrom);
  1481. DEBUG_INFO("Profile valid to: %s\n", defaultTxProfile.ValidTo);
  1482. DEBUG_INFO("Profile ChargingProfileKind: %s\n", defaultTxProfile.ChargingProfileKind);
  1483. DEBUG_INFO("Profile RecurrencyKind: %s\n", defaultTxProfile.RecurrencyKind);
  1484. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1485. DEBUG_INFO("Profile schedule duration: %d\n", defaultTxProfile.ChargingSchedule.Duration);
  1486. DEBUG_INFO("Profile charging rate unit: %s\n", defaultTxProfile.ChargingSchedule.ChargingRateUnit);
  1487. DEBUG_INFO("Profile charging min rate: %f\n", defaultTxProfile.ChargingSchedule.MinChargingRate);
  1488. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1489. {
  1490. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1491. {
  1492. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1493. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1494. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1495. }
  1496. }
  1497. DEBUG_INFO("------------------------------------\n");*/
  1498. }
  1499. if(maxProfile.ChargingProfileId != -1)
  1500. {
  1501. if(strstr((char*)maxProfile.ChargingProfileKind, "Absolute") != NULL)
  1502. {
  1503. if(maxProfile.ChargingSchedule.Duration != -1)
  1504. {
  1505. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1506. 0:
  1507. (maxProfile.ChargingSchedule.Duration-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1508. }
  1509. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1510. {
  1511. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1512. {
  1513. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule))<0?
  1514. 0:
  1515. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule)));
  1516. if(idxPeriod > 0)
  1517. {
  1518. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1519. {
  1520. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1521. }
  1522. }
  1523. }
  1524. }
  1525. }
  1526. else if(strstr((char*)maxProfile.ChargingProfileKind, "Relative") != NULL)
  1527. {
  1528. if(maxProfile.ChargingSchedule.Duration != -1)
  1529. {
  1530. 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?
  1531. 0:
  1532. (maxProfile.ChargingSchedule.Duration-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1533. }
  1534. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1535. {
  1536. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1537. {
  1538. 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?
  1539. 0:
  1540. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartStop(ShmOCPP16Data->StartTransaction[(connectorId==0?0:connectorId-1)].Timestamp, compositeProfile->ChargingSchedule.StartSchedule)));
  1541. if(idxPeriod > 0)
  1542. {
  1543. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1544. {
  1545. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1546. }
  1547. }
  1548. }
  1549. }
  1550. }
  1551. else
  1552. {
  1553. if(strstr((char*)maxProfile.RecurrencyKind, "Weekly") != NULL)
  1554. {
  1555. if(maxProfile.ChargingSchedule.Duration != -1)
  1556. {
  1557. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1558. 0:
  1559. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1560. }
  1561. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1562. {
  1563. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1564. {
  1565. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE))<0?
  1566. 0:
  1567. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, FALSE)));
  1568. if(idxPeriod > 0)
  1569. {
  1570. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1571. {
  1572. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1573. }
  1574. }
  1575. }
  1576. }
  1577. }
  1578. else
  1579. {
  1580. if(maxProfile.ChargingSchedule.Duration != -1)
  1581. {
  1582. maxProfile.ChargingSchedule.Duration = ((maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1583. 0:
  1584. (maxProfile.ChargingSchedule.Duration-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1585. }
  1586. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1587. {
  1588. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod != -1)
  1589. {
  1590. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = ((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE))<0?
  1591. 0:
  1592. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod-getStartSinceRecurring(maxProfile.ChargingSchedule.StartSchedule, compositeProfile->ChargingSchedule.StartSchedule, TRUE)));
  1593. if(idxPeriod > 0)
  1594. {
  1595. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].StartPeriod == maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod)
  1596. {
  1597. maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod-1].Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit;
  1598. }
  1599. }
  1600. }
  1601. }
  1602. }
  1603. }
  1604. /*
  1605. DEBUG_INFO("MaxProfile after align.\n");
  1606. DEBUG_INFO("Profile ID: %d\n", maxProfile.ChargingProfileId);
  1607. DEBUG_INFO("Profile stackLevel: %d\n", maxProfile.StackLevel);
  1608. DEBUG_INFO("Profile TransactionId: %d\n", maxProfile.TransactionId);
  1609. DEBUG_INFO("Profile valid from: %s\n", maxProfile.ValidFrom);
  1610. DEBUG_INFO("Profile valid to: %s\n", maxProfile.ValidTo);
  1611. DEBUG_INFO("Profile ChargingProfileKind: %s\n", maxProfile.ChargingProfileKind);
  1612. DEBUG_INFO("Profile RecurrencyKind: %s\n", maxProfile.RecurrencyKind);
  1613. DEBUG_INFO("Profile start schedule: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1614. DEBUG_INFO("Profile schedule duration: %d\n", maxProfile.ChargingSchedule.Duration);
  1615. DEBUG_INFO("Profile charging rate unit: %s\n", maxProfile.ChargingSchedule.ChargingRateUnit);
  1616. DEBUG_INFO("Profile charging min rate: %f\n", maxProfile.ChargingSchedule.MinChargingRate);
  1617. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1618. {
  1619. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1620. {
  1621. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1622. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1623. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1624. }
  1625. }
  1626. DEBUG_INFO("------------------------------------\n");*/
  1627. }
  1628. /*
  1629. * Merge to conposite schedule
  1630. */
  1631. //DEBUG_INFO("====================================\n");
  1632. // Find each profile period quantity
  1633. for(int idx=0;idx<ARRAY_SIZE(maxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1634. {
  1635. if(maxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1636. limitMax = idx+1;
  1637. }
  1638. for(int idx=0;idx<ARRAY_SIZE(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1639. {
  1640. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1641. limitDef = idx+1;
  1642. }
  1643. for(int idx=0;idx<ARRAY_SIZE(txProfile.ChargingSchedule.ChargingSchedulePeriod);idx++)
  1644. {
  1645. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idx].Limit != -1)
  1646. limitTx = idx+1;
  1647. }
  1648. // TxProfile found, composite schedule based on it
  1649. if(txProfile.ChargingProfileId != -1)
  1650. {
  1651. for(int idxTxPeriod=0;idxTxPeriod<limitTx;idxTxPeriod++)
  1652. {
  1653. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit != -1) &&
  1654. (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod < durationReq) &&
  1655. (txProfile.ChargingSchedule.Duration > 0))
  1656. {
  1657. if(maxProfile.ChargingProfileId != -1)
  1658. {
  1659. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1660. {
  1661. if((txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod))
  1662. {
  1663. if((maxProfile.ChargingSchedule.Duration > 0))
  1664. {
  1665. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1666. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1667. tmpPeriod.Limit = (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1668. }
  1669. else
  1670. {
  1671. tmpPeriod.StartPeriod = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod;
  1672. tmpPeriod.NumberPhases = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].NumberPhases;
  1673. tmpPeriod.Limit = txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit;
  1674. }
  1675. }
  1676. if(idxMaxPeriod == (limitMax-1))
  1677. {
  1678. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1679. {
  1680. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1681. {
  1682. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1683. compositePeriodIdx++;
  1684. }
  1685. else
  1686. {
  1687. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1688. }
  1689. }
  1690. }
  1691. }
  1692. }
  1693. else
  1694. {
  1695. if(txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1696. {
  1697. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1698. compositePeriodIdx++;
  1699. }
  1700. else
  1701. {
  1702. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod],sizeof(struct StructChargingSchedulePeriod));
  1703. }
  1704. }
  1705. }
  1706. if(idxTxPeriod == (limitTx-1))
  1707. {
  1708. if(defaultTxProfile.ChargingProfileId != -1)
  1709. {
  1710. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1711. {
  1712. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= (txProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].StartPeriod + (txProfile.ChargingSchedule.Duration-defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod))) &&
  1713. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1714. (defaultTxProfile.ChargingSchedule.Duration>0))
  1715. {
  1716. if(maxProfile.ChargingProfileId != -1)
  1717. {
  1718. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1719. {
  1720. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1721. {
  1722. if((maxProfile.ChargingSchedule.Duration > 0))
  1723. {
  1724. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1725. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1726. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxTxPeriod].Limit);
  1727. }
  1728. else
  1729. {
  1730. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1731. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1732. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1733. }
  1734. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1735. {
  1736. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1737. {
  1738. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1739. compositePeriodIdx++;
  1740. }
  1741. else
  1742. {
  1743. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1744. }
  1745. }
  1746. break;
  1747. }
  1748. }
  1749. }
  1750. else
  1751. {
  1752. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1753. {
  1754. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1755. compositePeriodIdx++;
  1756. }
  1757. else
  1758. {
  1759. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1760. }
  1761. }
  1762. }
  1763. }
  1764. }
  1765. }
  1766. }
  1767. }
  1768. // TxProfile not found but defaultTxProfile found, composite schedule based on it
  1769. else if(defaultTxProfile.ChargingProfileId != -1)
  1770. {
  1771. for(int idxDefPeriod=0;idxDefPeriod<limitDef;idxDefPeriod++)
  1772. {
  1773. if((defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit != -1) &&
  1774. (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod < durationReq) &&
  1775. (defaultTxProfile.ChargingSchedule.Duration > 0))
  1776. {
  1777. if(maxProfile.ChargingProfileId != -1)
  1778. {
  1779. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1780. {
  1781. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod >= maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod)
  1782. {
  1783. if((maxProfile.ChargingSchedule.Duration > 0))
  1784. {
  1785. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1786. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1787. tmpPeriod.Limit = (defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit>maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit?maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit:defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit);
  1788. }
  1789. else
  1790. {
  1791. tmpPeriod.StartPeriod = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod;
  1792. tmpPeriod.NumberPhases = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].NumberPhases;
  1793. tmpPeriod.Limit = defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].Limit;
  1794. }
  1795. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1796. {
  1797. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1798. {
  1799. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1800. compositePeriodIdx++;
  1801. }
  1802. else
  1803. {
  1804. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1805. }
  1806. }
  1807. break;
  1808. }
  1809. }
  1810. }
  1811. else
  1812. {
  1813. if(defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod].StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1814. {
  1815. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1816. compositePeriodIdx++;
  1817. }
  1818. else
  1819. {
  1820. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &defaultTxProfile.ChargingSchedule.ChargingSchedulePeriod[idxDefPeriod],sizeof(struct StructChargingSchedulePeriod));
  1821. }
  1822. }
  1823. }
  1824. }
  1825. }
  1826. // Fill other period by MaxProfile
  1827. if(maxProfile.ChargingProfileId != -1)
  1828. {
  1829. for(int idxMaxPeriod=0;idxMaxPeriod<limitMax;idxMaxPeriod++)
  1830. {
  1831. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit != -1) &&
  1832. (maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod < durationReq) &&
  1833. (maxProfile.ChargingSchedule.Duration > 0))
  1834. {
  1835. if((maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].StartPeriod >= compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod) &&
  1836. (maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1837. {
  1838. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod;
  1839. tmpPeriod.NumberPhases = compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].NumberPhases;
  1840. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1841. }
  1842. if((maxProfile.ChargingSchedule.Duration > compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx==0?0:compositePeriodIdx-1].StartPeriod))
  1843. {
  1844. tmpPeriod.StartPeriod = compositeProfile->ChargingSchedule.Duration;
  1845. tmpPeriod.NumberPhases = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].NumberPhases;
  1846. tmpPeriod.Limit = maxProfile.ChargingSchedule.ChargingSchedulePeriod[idxMaxPeriod].Limit;
  1847. }
  1848. if(tmpPeriod.Limit != -1)
  1849. {
  1850. if(tmpPeriod.Limit != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].Limit)
  1851. {
  1852. if(tmpPeriod.StartPeriod != compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)].StartPeriod)
  1853. {
  1854. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[compositePeriodIdx], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1855. compositePeriodIdx++;
  1856. }
  1857. else
  1858. {
  1859. memcpy(&compositeProfile->ChargingSchedule.ChargingSchedulePeriod[(compositePeriodIdx==0?compositePeriodIdx:compositePeriodIdx-1)], &tmpPeriod , sizeof(struct StructChargingSchedulePeriod));
  1860. }
  1861. }
  1862. }
  1863. }
  1864. }
  1865. }
  1866. DEBUG_INFO("Connector-%d composite schedule ready.\n", connectorId);
  1867. DEBUG_INFO("Schedule start: %s\n", compositeProfile->ChargingSchedule.StartSchedule);
  1868. DEBUG_INFO("Schedule duration: %d\n", compositeProfile->ChargingSchedule.Duration);
  1869. DEBUG_INFO("Rate unit: %s\n", compositeProfile->ChargingSchedule.ChargingRateUnit);
  1870. for(int idxPeriod=0;idxPeriod<ARRAY_SIZE(compositeProfile->ChargingSchedule.ChargingSchedulePeriod);idxPeriod++)
  1871. {
  1872. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod >= 0)
  1873. {
  1874. compositeProfile->ChargingProfileId = 1;
  1875. DEBUG_INFO("Period-%02d startPeriod: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod);
  1876. DEBUG_INFO("Period-%02d limit: %f\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit);
  1877. DEBUG_INFO("Period-%02d NumberPhases: %d\n", idxPeriod, compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases);
  1878. }
  1879. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit == -1)
  1880. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit =0;
  1881. if(compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod == -1)
  1882. compositeProfile->ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod =0;
  1883. }
  1884. if(line)
  1885. free(line);
  1886. ShmOCPP16Data->CSUMsg.bits[(connectorId==0?0:connectorId-1)].ChargingProfileConf = 1;
  1887. }
  1888. //==========================================
  1889. // Init all share memory
  1890. //==========================================
  1891. int InitShareMemory()
  1892. {
  1893. int result = PASS;
  1894. int MeterSMId;
  1895. //creat ShmSysConfigAndInfo
  1896. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  1897. {
  1898. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  1899. result = FAIL;
  1900. }
  1901. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1902. {
  1903. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  1904. result = FAIL;
  1905. }
  1906. else
  1907. {}
  1908. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  1909. {
  1910. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  1911. result = FAIL;
  1912. }
  1913. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1914. {
  1915. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  1916. result = FAIL;
  1917. }
  1918. else
  1919. {}
  1920. //creat ShmPsuData
  1921. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), 0777)) < 0)
  1922. {
  1923. DEBUG_ERROR("shmget ShmPsuData NG\n");
  1924. result = FAIL;
  1925. }
  1926. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1927. {
  1928. DEBUG_ERROR("shmat ShmPsuData NG\n");
  1929. result = FAIL;
  1930. }
  1931. else
  1932. {}
  1933. //creat ShmOCPP16Data
  1934. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  1935. {
  1936. DEBUG_ERROR("shmget ShmOCPP16Data NG");
  1937. result = FAIL;
  1938. }
  1939. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  1940. {
  1941. DEBUG_ERROR("shmat ShmOCPP16Data NG");
  1942. result = FAIL;
  1943. }
  1944. else
  1945. {}
  1946. /****************************** For Initial Settings************************************************/
  1947. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = NULL;
  1948. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = NULL;
  1949. // allocate Configuration memory address
  1950. ShmOCPP16Data->GetConfiguration.Key = staticKeyArray;
  1951. ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey = staticResponseConfigurationKeyArray;
  1952. ShmOCPP16Data->GetConfiguration.ResponseUnknownKey = staticResponseUnknownKey;
  1953. ShmOCPP16Data->SendLocalList.LocalAuthorizationList = staticLocalAuthorizationList;
  1954. //offline MeterValue Interval
  1955. TempMeterValueInterval = 0;
  1956. return result;
  1957. }
  1958. int ProcessShareMemory()
  1959. {
  1960. if(InitShareMemory() == FAIL)
  1961. {
  1962. DEBUG_ERROR("InitShareMemory NG\n");
  1963. if(ShmStatusCodeData!=NULL)
  1964. {
  1965. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1966. }
  1967. sleep(5);
  1968. return FAIL;
  1969. }
  1970. return PASS;
  1971. }
  1972. //---------------------common routine---------------------------//
  1973. int isOFFline(void)
  1974. {
  1975. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  1976. {
  1977. if(TempMeterValueInterval >= 2 )
  1978. {
  1979. TempMeterValueInterval = 0;
  1980. return TRUE;
  1981. }
  1982. else
  1983. {
  1984. TempMeterValueInterval = TempMeterValueInterval+ 1;
  1985. return FALSE;
  1986. }
  1987. }
  1988. else
  1989. {
  1990. return FALSE;
  1991. }
  1992. }
  1993. //---------------------------------------------
  1994. // new:
  1995. // enum SYSTEM_STATUS
  1996. // {
  1997. // SYS_MODE_BOOTING = 0,
  1998. // SYS_MODE_IDLE = 1,
  1999. // SYS_MODE_AUTHORIZING = 2,
  2000. // SYS_MODE_MODE_REASSIGN_CHECK = 3,
  2001. // SYS_MODE_REASSIGN = 4,
  2002. // SYS_MODE_PREPARING = 5,
  2003. // SYS_MODE_PREPARE_FOR_EV = 6,
  2004. // SYS_MODE_PREPARE_FOR_EVSE = 7,
  2005. // SYS_MODE_CHARGING = 8,
  2006. // SYS_MODE_TERMINATING = 9,
  2007. // SYS_MODE_COMPLETE = 10,
  2008. // SYS_MODE_ALARM = 11,
  2009. // SYS_MODE_FAULT = 12,
  2010. // SYS_MODE_RESERVATION = 13,
  2011. // SYS_MODE_BOOKING = 14,
  2012. // SYS_MODE_MAINTAIN = 15,
  2013. // SYS_MODE_DEBUG = 16,
  2014. // SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  2015. // SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  2016. // SYS_MODE_UPDATE = 19
  2017. // };
  2018. //
  2019. //
  2020. //-----------------------------------------
  2021. void CheckSystemValue(void)
  2022. {
  2023. uint8_t reqSampleMeter[CONNECTOR_QUANTITY]={0};
  2024. uint8_t reqClockAlignMeter[CONNECTOR_QUANTITY]={0};
  2025. char filenmae[100]={0};
  2026. char str[100]={0};
  2027. int tempIndex = 0;
  2028. //===============================
  2029. // send Heartbeat
  2030. //===============================
  2031. //HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2032. if((difftime(time((time_t*)NULL), clientTime.Heartbeat) < 0) || (HeartBeatWaitTime <= 0))
  2033. {
  2034. clientTime.Heartbeat=time((time_t*)NULL);
  2035. if(server_sign == TRUE)
  2036. {
  2037. HeartBeatWaitTime = ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval;
  2038. }
  2039. else
  2040. {
  2041. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  2042. }
  2043. }
  2044. if((server_sign == TRUE) && (difftime(time((time_t*)NULL), clientTime.Heartbeat) >= (HeartBeatWaitTime + HeartBeatWithNOResponse)))
  2045. {
  2046. //parameter for test
  2047. sendHeartbeatRequest(0);
  2048. //==============================================
  2049. // Reset Waiting Time
  2050. //==============================================
  2051. HeartBeatWithNOResponse += 1;
  2052. }
  2053. for(int gun_index=0;gun_index < gunTotalNumber ;gun_index++)
  2054. {
  2055. //===============================
  2056. // CSU Trigger Reset Conf
  2057. //===============================
  2058. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->MsMsg.bits.ResetConf == 1))
  2059. {
  2060. sendResetConfirmation((char *)ShmOCPP16Data->Reset.guid, (char *)ShmOCPP16Data->Reset.ResponseStatus);
  2061. }
  2062. //===============================
  2063. // CSU Trigger Authorize Request
  2064. //===============================
  2065. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1)&&(authorizeRetryTimes < 3))
  2066. {
  2067. sendAuthorizeRequest(0);
  2068. authorizeRetryTimes = authorizeRetryTimes + 1;
  2069. if(authorizeRetryTimes < 3)
  2070. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2071. }
  2072. else if((server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.AuthorizeReq == 1) && (authorizeRetryTimes >= 3))
  2073. {
  2074. authorizeRetryTimes = 0;
  2075. ShmOCPP16Data->OcppConnStatus = 0; // ocpp offline
  2076. server_sign = FALSE;
  2077. }
  2078. 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))
  2079. {
  2080. sendAuthorizeRequest(0);
  2081. }
  2082. //===============================
  2083. // CSU Trigger Smart Charging Profilw
  2084. //===============================
  2085. if(ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq == 1)
  2086. {
  2087. checkCompositeSchedule(gun_index+1, 86400, &ShmOCPP16Data->SmartChargingProfile[gun_index]);
  2088. ShmOCPP16Data->CSUMsg.bits[gun_index].ChargingProfileReq = 0;
  2089. }
  2090. //==============================================
  2091. // Charger start transaction
  2092. //==============================================
  2093. if(/*(server_sign == TRUE) &&*/ (ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq == 1))
  2094. {
  2095. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  2096. sendStartTransactionRequest(gun_index);
  2097. clientTime.StartTransaction = time((time_t*)NULL);
  2098. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2099. }
  2100. //==============================================
  2101. // Charger stop transaction
  2102. //==============================================
  2103. if(/*(server_sign == TRUE) &&*/ ((ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 1)))
  2104. {
  2105. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  2106. sendStopTransactionRequest(gun_index);
  2107. clientTime.StopTransaction = time((time_t*)NULL);
  2108. }
  2109. //==============================================
  2110. // Charger status report
  2111. //==============================================
  2112. //--- Check Mode Change ---//
  2113. // J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2114. if(gunType[gun_index] == 'J')
  2115. {
  2116. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2117. {
  2118. tempIndex = ((gun_index==2) ? 1: 0);
  2119. }
  2120. else
  2121. {
  2122. tempIndex = gun_index;
  2123. }
  2124. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2125. {
  2126. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2127. {
  2128. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != ChademoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn != ChademoPreviousConnectorPlugIn[index]) )
  2129. {
  2130. ChademoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus;
  2131. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  2132. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2133. statusModeChage[gun_index] = TRUE;
  2134. }
  2135. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2136. {
  2137. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2138. if((access(filenmae,F_OK))!=-1)
  2139. {
  2140. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2141. sprintf(str,"rm -f %s",filenmae);
  2142. system(str);
  2143. }
  2144. }
  2145. #if 1 // for TempStopTransaction
  2146. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2147. {
  2148. checkTempStopTransaction(gun_index);
  2149. }
  2150. #endif
  2151. }
  2152. }
  2153. }
  2154. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2155. {
  2156. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2157. {
  2158. tempIndex = ((gun_index==2) ? 1: 0);
  2159. }
  2160. else
  2161. {
  2162. tempIndex = gun_index;
  2163. }
  2164. for (int index = 0; index < CCS_QUANTITY; index++)
  2165. {
  2166. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2167. {
  2168. 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]*/ )
  2169. {
  2170. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus;
  2171. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  2172. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2173. statusModeChage[gun_index] = TRUE;
  2174. }
  2175. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2176. {
  2177. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2178. if((access(filenmae,F_OK))!=-1)
  2179. {
  2180. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2181. sprintf(str,"rm -f %s",filenmae);
  2182. system(str);
  2183. }
  2184. }
  2185. #if 1 // for TempStopTransaction
  2186. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2187. {
  2188. checkTempStopTransaction(gun_index);
  2189. }
  2190. #endif
  2191. }
  2192. }
  2193. }
  2194. else if(gunType[gun_index] == 'G')
  2195. {
  2196. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2197. {
  2198. tempIndex = ((gun_index==2) ? 1: 0);
  2199. }
  2200. else
  2201. {
  2202. tempIndex = gun_index;
  2203. }
  2204. for (int index = 0; index < GB_QUANTITY; index++)
  2205. {
  2206. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2207. {
  2208. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != GbPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn != GbPreviousConnectorPlugIn[index]) )
  2209. {
  2210. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus;
  2211. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  2212. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2213. statusModeChage[gun_index] = TRUE;
  2214. }
  2215. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2216. {
  2217. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2218. if((access(filenmae,F_OK))!=-1)
  2219. {
  2220. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2221. sprintf(str,"rm -f %s",filenmae);
  2222. system(str);
  2223. }
  2224. }
  2225. #if 1 // for TempStopTransaction
  2226. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2227. {
  2228. checkTempStopTransaction(gun_index);
  2229. }
  2230. #endif
  2231. }
  2232. }
  2233. }
  2234. else if(gunType[gun_index] == 'O')
  2235. {
  2236. tempIndex = gun_index;
  2237. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2238. {
  2239. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2240. {
  2241. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != DoPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn != DoPreviousConnectorPlugIn[index]) )
  2242. {
  2243. DoPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus;
  2244. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn;
  2245. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2246. statusModeChage[gun_index] = TRUE;
  2247. }
  2248. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARING))) // complete
  2249. {
  2250. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2251. if((access(filenmae,F_OK))!=-1)
  2252. {
  2253. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2254. sprintf(str,"rm -f %s",filenmae);
  2255. system(str);
  2256. }
  2257. }
  2258. #if 1 // for TempStopTransaction
  2259. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2260. {
  2261. checkTempStopTransaction(gun_index);
  2262. }
  2263. #endif
  2264. }
  2265. }
  2266. }
  2267. else
  2268. {
  2269. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2270. {
  2271. tempIndex = 2;
  2272. }
  2273. else
  2274. {
  2275. tempIndex = gun_index;
  2276. }
  2277. for (int index = 0; index < AC_QUANTITY; index++)
  2278. {
  2279. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2280. {
  2281. if((SystemInitial > 0) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != AcPreviousSystemStatus[index]) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState != AcPreviousConnectorPlugIn[index]) )
  2282. {
  2283. AcPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus;
  2284. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  2285. cpinitateMsg.bits[gun_index].StatusNotificationReq = 1;
  2286. statusModeChage[gun_index] = TRUE;
  2287. }
  2288. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus <= SYS_MODE_PREPARING))) // complete
  2289. {
  2290. sprintf(filenmae,"/Storage/OCPP/TxProfile_%d.json",(gun_index+1));
  2291. if((access(filenmae,F_OK))!=-1)
  2292. {
  2293. DEBUG_INFO("TxProfile exist. OCPP will delete TX Charging Profile\n");
  2294. sprintf(str,"rm -f %s",filenmae);
  2295. system(str);
  2296. }
  2297. }
  2298. #if 1 // for TempStopTransaction
  2299. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) && (ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq == 0))
  2300. {
  2301. checkTempStopTransaction(gun_index);
  2302. }
  2303. #endif
  2304. }
  2305. }// END
  2306. }
  2307. if(isWebsocketSendable &&
  2308. (
  2309. (statusModeChage[gun_index] == TRUE) ||
  2310. //((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > (server_cycle_Status + (GunStatusInterval*gun_index))) ||
  2311. ((cpinitateMsg.bits[gun_index].StatusNotificationReq == 1) && ((time((time_t*)NULL)-clientTime.StatusNotification[gun_index]) > 10))
  2312. )
  2313. )
  2314. {
  2315. if(SystemInitial > 0)
  2316. SystemInitial -= 1;
  2317. sendStatusNotificationRequest(gun_index);
  2318. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  2319. statusModeChage[gun_index] = FALSE;
  2320. }
  2321. //==============================================
  2322. // Meter report
  2323. //==============================================
  2324. // Trigger MeterValue
  2325. if(isWebsocketSendable && (server_sign == TRUE) && cpinitateMsg.bits[gun_index].TriggerMeterValue)
  2326. {
  2327. sendMeterValuesRequest(gun_index, ReadingContext_Trigger);
  2328. cpinitateMsg.bits[gun_index].TriggerMeterValue = 0;
  2329. }
  2330. // ClockAlign MeterValue
  2331. if(isWebsocketSendable && (server_sign == TRUE) && ((atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData) > 0)?((getTimePassSinceToday()%(atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData)))==0):FALSE))
  2332. {
  2333. if(gunType[gun_index] == 'J')
  2334. {
  2335. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2336. {
  2337. tempIndex = ((gun_index==2) ? 1: 0);
  2338. }
  2339. else
  2340. {
  2341. tempIndex = gun_index;
  2342. }
  2343. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2344. {
  2345. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2346. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2347. {
  2348. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2349. {
  2350. reqClockAlignMeter[gun_index] = 1;
  2351. }
  2352. }
  2353. }// End for CHAdeMO
  2354. }
  2355. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2356. {
  2357. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2358. {
  2359. tempIndex = ((gun_index==2) ? 1: 0);
  2360. }
  2361. else
  2362. {
  2363. tempIndex = gun_index;
  2364. }
  2365. for (int index = 0; index < CCS_QUANTITY; index++)
  2366. {
  2367. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2368. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2369. {
  2370. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2371. {
  2372. reqClockAlignMeter[gun_index] = 1;
  2373. }
  2374. }
  2375. } // End for CCS
  2376. }
  2377. else if(gunType[gun_index] == 'G')
  2378. {
  2379. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2380. {
  2381. tempIndex = ((gun_index==2) ? 1: 0);
  2382. }
  2383. else
  2384. {
  2385. tempIndex = gun_index;
  2386. }
  2387. for (int index = 0; index < GB_QUANTITY; index++)
  2388. {
  2389. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2390. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2391. {
  2392. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2393. {
  2394. reqClockAlignMeter[gun_index] = 1;
  2395. }
  2396. }
  2397. }// End for GB
  2398. }
  2399. else if(gunType[gun_index] == 'O')
  2400. {
  2401. tempIndex = gun_index;
  2402. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2403. {
  2404. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2405. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2406. {
  2407. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_CHARGING)
  2408. {
  2409. reqClockAlignMeter[gun_index] = 1;
  2410. }
  2411. }
  2412. }
  2413. }
  2414. else
  2415. {
  2416. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2417. {
  2418. tempIndex = 2;
  2419. }
  2420. else
  2421. {
  2422. tempIndex = gun_index;
  2423. }
  2424. for (int index = 0; index < AC_QUANTITY; index++)
  2425. {
  2426. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2427. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2428. {
  2429. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_CHARGING)
  2430. {
  2431. reqClockAlignMeter[gun_index] = 1;
  2432. }
  2433. }
  2434. }//End for AC
  2435. }
  2436. if(reqClockAlignMeter[gun_index] == 1)
  2437. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Clock);
  2438. }
  2439. // Sample period MeterValue
  2440. if(/*(server_sign == TRUE) &&(isOFFline() == TRUE) ||*/
  2441. (((time((time_t*)NULL) - clientTime.MeterValues[gun_index]) > (atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData)- 1))))
  2442. {
  2443. //check Transaction active
  2444. if(gunType[gun_index] == 'J')
  2445. {
  2446. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2447. {
  2448. tempIndex = ((gun_index==2) ? 1: 0);
  2449. }
  2450. else
  2451. {
  2452. tempIndex = gun_index;
  2453. }
  2454. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2455. {
  2456. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2457. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2458. {
  2459. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2460. {
  2461. reqSampleMeter[gun_index] = 1;
  2462. }
  2463. }
  2464. }// End for CHAdeMO
  2465. }
  2466. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2467. {
  2468. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2469. {
  2470. tempIndex = ((gun_index==2) ? 1: 0);
  2471. }
  2472. else
  2473. {
  2474. tempIndex = gun_index;
  2475. }
  2476. for (int index = 0; index < CCS_QUANTITY; index++)
  2477. {
  2478. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2479. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2480. {
  2481. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2482. {
  2483. reqSampleMeter[gun_index] = 1;
  2484. }
  2485. }
  2486. } // End for CCS
  2487. }
  2488. else if(gunType[gun_index] == 'G')
  2489. {
  2490. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2491. {
  2492. tempIndex = ((gun_index==2) ? 1: 0);
  2493. }
  2494. else
  2495. {
  2496. tempIndex = gun_index;
  2497. }
  2498. for (int index = 0; index < GB_QUANTITY; index++)
  2499. {
  2500. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2501. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2502. {
  2503. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2504. {
  2505. reqSampleMeter[gun_index] = 1;
  2506. }
  2507. }
  2508. }// End for GB
  2509. }
  2510. else if(gunType[gun_index] == 'O')
  2511. {
  2512. tempIndex = gun_index;
  2513. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2514. {
  2515. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2516. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2517. {
  2518. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)
  2519. {
  2520. reqSampleMeter[gun_index] = 1;
  2521. }
  2522. }
  2523. }
  2524. }
  2525. else
  2526. {
  2527. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2528. {
  2529. tempIndex = 2;
  2530. }
  2531. else
  2532. {
  2533. tempIndex = gun_index;
  2534. }
  2535. for (int index = 0; index < AC_QUANTITY; index++)
  2536. {
  2537. // 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault
  2538. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  2539. {
  2540. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING)
  2541. {
  2542. reqSampleMeter[gun_index] = 1;
  2543. }
  2544. }
  2545. }//End for AC
  2546. }
  2547. if(reqSampleMeter[gun_index] == 1)
  2548. {
  2549. sendMeterValuesRequest(gun_index, ReadingContext_Sample_Periodic);
  2550. storeTempStopTransaction(gun_index);
  2551. }
  2552. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2553. }
  2554. //==============================================
  2555. // Check Connector reserved
  2556. //==============================================
  2557. //===============================
  2558. // Check if Reserve is expired
  2559. //===============================
  2560. if((server_sign == TRUE) && (ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate[0] != 0) )
  2561. {
  2562. double diff_t;
  2563. struct tm tp;
  2564. // current time
  2565. time_t t = time(NULL);
  2566. strptime((char *)ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate, "%Y-%m-%dT%H:%M:%S", &tp);
  2567. tp.tm_isdst = -1;
  2568. time_t utc = mktime(&tp);
  2569. diff_t = difftime(utc, t);
  2570. if(diff_t <= 0)
  2571. {
  2572. DEBUG_INFO("reserve expired.\n");
  2573. memset(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate,0,ARRAY_SIZE(ShmOCPP16Data->ReserveNow[gun_index].ExpiryDate));
  2574. }
  2575. }//END OF Check if Reserve is expired
  2576. //==========================================
  2577. // csu trigger FirmwareStatusNotificationReq
  2578. //==========================================
  2579. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq == 1))
  2580. {
  2581. sendFirmwareStatusNotificationRequest((char *)ShmOCPP16Data->FirmwareStatusNotification.Status);
  2582. }
  2583. //==========================================
  2584. // csu trigger CancelReservationConf
  2585. //==========================================
  2586. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].CancelReservationConf == 1))
  2587. {
  2588. sendCancelReservationConfirmation((char *)ShmOCPP16Data->CancelReservation[gun_index].guid,(char *)ShmOCPP16Data->CancelReservation[gun_index].ResponseStatus);
  2589. }
  2590. //==========================================
  2591. // csu trigger ChangeAvailabilityConf
  2592. //==========================================
  2593. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ChangeAvailabilityConf == 1))
  2594. {
  2595. //sendChangeAvailabilityConfirmation(,(char *)ShmOCPP16Data->ChangeAvailability[gun_index].ResponseStatus);
  2596. }
  2597. //==========================================
  2598. // csu trigger UnlockConnectorConf
  2599. //==========================================
  2600. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf == 1))
  2601. {
  2602. sendUnlockConnectorConfirmation((char *)ShmOCPP16Data->UnlockConnector[gun_index].guid, (char *)ShmOCPP16Data->UnlockConnector[gun_index].ResponseStatus);
  2603. ShmOCPP16Data->CsMsg.bits[gun_index].UnlockConnectorConf = 0;
  2604. }
  2605. //==========================================
  2606. // csu trigger ReserveNowConf
  2607. //==========================================
  2608. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf == 1))
  2609. {
  2610. sendReserveNowTransactionConfirmation((char *)ShmOCPP16Data->ReserveNow[gun_index].guid, (char *)ShmOCPP16Data->ReserveNow[gun_index].ResponseStatus);
  2611. ShmOCPP16Data->CsMsg.bits[gun_index].ReserveNowConf = 0;
  2612. }
  2613. //==========================================
  2614. // csu trigger DataTransferReq
  2615. //==========================================
  2616. if(isWebsocketSendable && (server_sign == TRUE) && (ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq == 1))
  2617. {
  2618. sendDataTransferRequest(gun_index);
  2619. ShmOCPP16Data->CsMsg.bits[gun_index].DataTransferReq = 0;
  2620. }
  2621. }
  2622. }
  2623. //==========================================
  2624. // send request routine
  2625. //==========================================
  2626. int sendAuthorizeRequest(int gun_index)
  2627. {
  2628. mtrace();
  2629. int result = FAIL;
  2630. char message[100]={0};
  2631. char guid[37];
  2632. char tempdata[65]={0};
  2633. DEBUG_INFO("sendAuthorizeRequest...\n");
  2634. memset(&(ShmOCPP16Data->Authorize.ResponseIdTagInfo),0,sizeof(struct StructIdTagInfo));
  2635. //Local Authorize
  2636. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData , "TRUE")==0) &&(ShmOCPP16Data->OcppConnStatus == 0))
  2637. {
  2638. DEBUG_INFO("Allow OfflineTx UnknownId Pass !!!!\n");
  2639. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2640. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, "");
  2641. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Accepted");
  2642. result = PASS;
  2643. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2644. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2645. authorizeRetryTimes = 0;
  2646. return result;
  2647. }
  2648. 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))||
  2649. ((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "TRUE") == 0)&&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE") == 0)))
  2650. {
  2651. // Query from cache
  2652. DEBUG_INFO("Authorize from cache.\n");
  2653. OCPP_getIdTagFromLocalCache((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2654. // Query from list
  2655. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2656. {
  2657. DEBUG_INFO("Authorize from list.\n");
  2658. OCPP_getIdTagFromLocalList((char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2659. }
  2660. if((strcmp(idTagQuery.idTagstr,"") == 0) || (strcmp(idTagQuery.idTagstatus,"Accepted") != 0) )
  2661. {
  2662. if(strcmp(idTagQuery.idTagstr,"") == 0)
  2663. {
  2664. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is blank!!!!\n", idTagQuery.idTagstr);
  2665. }
  2666. if(strcmp(idTagQuery.idTagstatus,"Accepted") != 0)
  2667. {
  2668. DEBUG_INFO("off-line Local Authorization Fail !!!!, Card %s is not Accepted!!!!\n", idTagQuery.idTagstr);
  2669. }
  2670. DEBUG_INFO("off-line Local Authorization Fail !!!!\n");
  2671. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, "");
  2672. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2673. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Invalid");
  2674. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2675. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2676. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2677. authorizeRetryTimes = 0;
  2678. return result;
  2679. }
  2680. else
  2681. {
  2682. DEBUG_INFO("off-line Local Authorization get result !!!!\n");
  2683. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, idTagQuery.expiryDate);
  2684. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2685. if(isOvertNow((uint8_t*)&idTagQuery.expiryDate[0]))
  2686. sprintf((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, "Expired");
  2687. else
  2688. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, idTagQuery.idTagstatus);
  2689. DEBUG_INFO("ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status: %s \n", ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status);
  2690. result = PASS;
  2691. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2692. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  2693. authorizeRetryTimes = 0;
  2694. return result;
  2695. }
  2696. }
  2697. //initialize struct Authorize
  2698. memset(&(ShmOCPP16Data->Authorize), 0 , sizeof(struct StructAuthorize));
  2699. //get data from shared memory
  2700. strcpy((char *)ShmOCPP16Data->Authorize.IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2701. random_uuid(guid);
  2702. sprintf(message,"[%d,\"%s\",\"Authorize\",{\"idTag\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, ShmOCPP16Data->Authorize.IdTag);
  2703. LWS_Send(message);
  2704. sprintf(tempdata, "Authorize,%d", gun_index);
  2705. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2706. {
  2707. result = PASS;
  2708. DEBUG_INFO("Authorize mapItem pass\n");
  2709. }
  2710. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  2711. return result;
  2712. }
  2713. int sendBootNotificationRequest(void)
  2714. {
  2715. mtrace();
  2716. int result = FAIL;
  2717. char message[500]={0}, payload[700]={0};
  2718. char guid[37]={0};
  2719. char tempdata[65]={0};
  2720. // Fill BootNotification fields
  2721. strcpy((char *)ShmOCPP16Data->BootNotification.CbSN,(const char *)ShmOCPP16Data->ChargeBoxId);
  2722. strcpy((char *)ShmOCPP16Data->BootNotification.CpModel,(const char *)ShmSysConfigAndInfo->SysConfig.ModelName);
  2723. strcpy((char *)ShmOCPP16Data->BootNotification.CpSN,(const char *)ShmSysConfigAndInfo->SysConfig.SerialNumber);
  2724. strcpy((char *)ShmOCPP16Data->BootNotification.CpVendor,(const char *)ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2725. strcpy((char *)ShmOCPP16Data->BootNotification.CpFwVersion,(const char *)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  2726. strcpy((char *)ShmOCPP16Data->BootNotification.CpIccid,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimIccid);
  2727. strcpy((char *)ShmOCPP16Data->BootNotification.CpImsi,(const char *)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSimImsi);
  2728. sprintf(payload, "{\"chargeBoxSerialNumber\":\"%s\",\"chargePointModel\":\"%s\",\"chargePointSerialNumber\":\"%s\",\"chargePointVendor\":\"%s\",\"firmwareVersion\":\"%s\",\"iccid\":\"%s\",\"imsi\":\"%s\"} ",
  2729. ShmOCPP16Data->ChargeBoxId
  2730. ,ShmSysConfigAndInfo->SysConfig.ModelName
  2731. ,ShmSysConfigAndInfo->SysConfig.SerialNumber
  2732. ,ShmSysConfigAndInfo->SysConfig.chargePointVendor
  2733. ,ShmOCPP16Data->BootNotification.CpFwVersion
  2734. ,ShmOCPP16Data->BootNotification.CpIccid
  2735. ,ShmOCPP16Data->BootNotification.CpImsi);
  2736. random_uuid(guid);
  2737. sprintf(message,"[%d,\"%s\",\"%s\",%s]",MESSAGE_TYPE_CALL, guid, "BootNotification", payload);
  2738. LWS_Send(message);
  2739. sprintf(tempdata, "BootNotification,0");
  2740. 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*/)
  2741. {
  2742. result = PASS;
  2743. }
  2744. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  2745. strcpy(queuedata,message);
  2746. return result;
  2747. }
  2748. int sendDataTransferRequest(int gun_index)
  2749. {
  2750. mtrace();
  2751. char message[1000]={0};
  2752. char guid[37]={0};
  2753. char tempdata[65]={0};
  2754. int result = FAIL;
  2755. //[2,"696e8a35-f394-45e3-a0c7-7098b86f38a6","DataTransfer",{"vendorId":"Phihong","messageId":"FeePerKWH","data":"1"}]
  2756. random_uuid(guid);
  2757. sprintf(message,"[%d,\"%s\",\"DataTransfer\",{\"vendorId\":\"%s\",\"messageId\":\"%s\",\"data\":\"%s\"}]",
  2758. MESSAGE_TYPE_CALL,
  2759. guid,
  2760. ShmOCPP16Data->DataTransfer[gun_index].VendorId,
  2761. ShmOCPP16Data->DataTransfer[gun_index].MessageId,
  2762. ShmOCPP16Data->DataTransfer[gun_index].Data);
  2763. LWS_Send(message);
  2764. sprintf(tempdata, "DataTransfer,%d", (gun_index + 1));
  2765. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2766. {
  2767. result = PASS;
  2768. DEBUG_INFO("DataTransfer mapItem pass\n");
  2769. }
  2770. return result;
  2771. }
  2772. int sendDiagnosticsStatusNotificationRequest(char *status)
  2773. {
  2774. mtrace();
  2775. int result = FAIL;
  2776. char message[110]={0};
  2777. char guid[37]={0};
  2778. char tempdata[65]={0};
  2779. //[ 2, "9f7bced1-b8b1-40ec-b3bb-2e15630e3cdc", "DiagnosticsStatusNotification", { "status": "Idle" } ]
  2780. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest \n");
  2781. sprintf((char *)ShmOCPP16Data->DiagnosticsStatusNotification.Status,"%s",(const char *)status);
  2782. random_uuid(guid);
  2783. sprintf(message,"[%d,\"%s\",\"DiagnosticsStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid,status);
  2784. LWS_SendNow(message);
  2785. sprintf(tempdata, "DiagnosticsStatusNotification,%d", 0);
  2786. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  2787. {
  2788. result = PASS;
  2789. //DEBUG_INFO("DiagnosticsStatusNotification mapItem pass\n");
  2790. }
  2791. //#ifdef SystemLogMessage
  2792. //DEBUG_INFO(">>>>>DiagnosticsStatusNotification request\n");
  2793. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2794. //DEBUG_INFO("After push hash length: %d\n", hashmapForMessageLength()/*hashmap_length(hashMap)*/);
  2795. //#endif
  2796. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  2797. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 0;
  2798. //record status
  2799. if(strcmp(status,"Idle")==0)
  2800. {
  2801. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  2802. }
  2803. else if(strcmp(status,"Uploaded")==0)
  2804. {
  2805. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADED;
  2806. }
  2807. else if(strcmp(status,"UploadFailed")==0)
  2808. {
  2809. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOAD_FAIL;
  2810. }
  2811. else if(strcmp(status,"Uploading")==0)
  2812. {
  2813. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_UPLOADING;
  2814. }
  2815. return result;
  2816. }
  2817. int sendFirmwareStatusNotificationRequest(char *status)
  2818. {
  2819. mtrace();
  2820. int result = FAIL;
  2821. char message[110]={0};
  2822. char guid[37]={0};
  2823. char tempdata[65]={0};
  2824. // [ 2, "eb841424-ae56-42b0-8c84-d5296018c33c", "FirmwareStatusNotification", { "status": "Downloaded" } ]
  2825. DEBUG_INFO("sendFirmwareStatusNotificationRequest \n");
  2826. sprintf((char *)ShmOCPP16Data->FirmwareStatusNotification.Status, "%s", (const char *)status);
  2827. random_uuid(guid);
  2828. sprintf(message,"[%d,\"%s\",\"FirmwareStatusNotification\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALL, guid, status);
  2829. LWS_SendNow(message);
  2830. sprintf(tempdata, "FirmwareStatusNotification,%d", 0);
  2831. 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*/)
  2832. {
  2833. result = PASS;
  2834. DEBUG_INFO("FirmwareStatusNotification mapItem pass\n");
  2835. }
  2836. //#ifdef SystemLogMessage
  2837. //DEBUG_INFO(">>>>>FirmwareStatusNotification request\n");
  2838. //DEBUG_INFO("Message: %s\n", SendBuffer);
  2839. //#endif
  2840. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  2841. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 0;
  2842. //record status
  2843. if(strcmp(status,"Downloaded")==0)
  2844. {
  2845. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADED;
  2846. }
  2847. else if(strcmp(status,"DownloadFailed")==0)
  2848. {
  2849. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOAD_FAILED;
  2850. }
  2851. else if(strcmp(status,"Downloading")==0)
  2852. {
  2853. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_DOWNLOADING;
  2854. }
  2855. else if(strcmp(status,"Idle")==0)
  2856. {
  2857. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  2858. }
  2859. else if(strcmp(status,"InstallationFailed")==0)
  2860. {
  2861. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLATION_FAILED;
  2862. }
  2863. else if(strcmp(status,"Installing")==0)
  2864. {
  2865. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLING;
  2866. }
  2867. else if(strcmp(status,"Installed")==0)
  2868. {
  2869. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_INSTALLED;
  2870. }
  2871. return result;
  2872. }
  2873. int sendHeartbeatRequest(int gun_index)
  2874. {
  2875. mtrace();
  2876. int result = FAIL;
  2877. char message[80]={0};
  2878. char guid[37]={0};
  2879. char tempdata[65]={0};
  2880. random_uuid(guid);
  2881. sprintf(message, "[%d,\"%s\",\"Heartbeat\",{ }]"
  2882. , MESSAGE_TYPE_CALL
  2883. , guid );
  2884. LWS_Send(message);
  2885. sprintf(tempdata, "Heartbeat,%d", 0);
  2886. 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*/)
  2887. {
  2888. result = PASS;
  2889. }
  2890. return result;
  2891. }
  2892. int sendStartTransactionRequest(int gun_index)
  2893. {
  2894. mtrace();
  2895. int result = FAIL;
  2896. char message[250]={0};
  2897. char guid[37]={0};
  2898. struct timeval tmnow;
  2899. struct tm *tm;
  2900. char buf[28];//, usec_buf[6];
  2901. char tempdata[65]={0};
  2902. int tempIndex = 0;
  2903. DEBUG_INFO("sendStartTransactionRequest...\n");
  2904. gettimeofday(&tmnow, NULL);
  2905. time_t t;
  2906. t = time(NULL);
  2907. /*UTC time and date*/
  2908. tm = gmtime(&t);
  2909. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  2910. #if 0 // remove temporally
  2911. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  2912. strcat(buf,".");
  2913. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  2914. strcat(buf,usec_buf);
  2915. #endif
  2916. ShmOCPP16Data->StartTransaction[gun_index].ConnectorId = gun_index +1 ; // gun start from 1~
  2917. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].Timestamp, buf);
  2918. //strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag, (const char *)ShmSysConfigAndInfo->SysConfig.UserId);
  2919. // clear StartTransaction Response
  2920. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "");
  2921. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "");
  2922. strcpy((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "");
  2923. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = 0;
  2924. clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  2925. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  2926. if(gunType[gun_index] == 'J')
  2927. {
  2928. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2929. {
  2930. tempIndex = ((gun_index==2) ? 1: 0);
  2931. }
  2932. else
  2933. {
  2934. tempIndex = gun_index;
  2935. }
  2936. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  2937. {
  2938. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  2939. {
  2940. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  2941. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId;
  2942. }
  2943. }
  2944. }
  2945. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  2946. {
  2947. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2948. {
  2949. tempIndex = ((gun_index==2) ? 1: 0);
  2950. }
  2951. else
  2952. {
  2953. tempIndex = gun_index;
  2954. }
  2955. for (int index = 0; index < CCS_QUANTITY; index++)
  2956. {
  2957. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  2958. {
  2959. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  2960. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId;
  2961. }
  2962. }
  2963. }
  2964. else if(gunType[gun_index] == 'G')
  2965. {
  2966. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  2967. {
  2968. tempIndex = ((gun_index==2) ? 1: 0);
  2969. }
  2970. else
  2971. {
  2972. tempIndex = gun_index;
  2973. }
  2974. for (int index = 0; index < GB_QUANTITY; index++)
  2975. {
  2976. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  2977. {
  2978. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  2979. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId;
  2980. }
  2981. }
  2982. }
  2983. else if(gunType[gun_index] == 'O')
  2984. {
  2985. tempIndex = gun_index;
  2986. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  2987. {
  2988. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  2989. {
  2990. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  2991. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId;
  2992. }
  2993. }
  2994. }
  2995. else
  2996. {
  2997. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  2998. {
  2999. tempIndex = 2;
  3000. }
  3001. else
  3002. {
  3003. tempIndex = gun_index;
  3004. }
  3005. for (int index = 0; index < AC_QUANTITY; index++)
  3006. {
  3007. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3008. {
  3009. ShmOCPP16Data->StartTransaction[gun_index].MeterStart = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3010. ShmOCPP16Data->StartTransaction[gun_index].ReservationId = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId;
  3011. }
  3012. }
  3013. }
  3014. random_uuid(guid);
  3015. if(ShmOCPP16Data->StartTransaction[gun_index].ReservationId == -1) // No Reservation
  3016. {
  3017. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"timestamp\":\"%s\"}]"
  3018. , gun_index +1
  3019. , MESSAGE_TYPE_CALL
  3020. , guid
  3021. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3022. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3023. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3024. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3025. }
  3026. else
  3027. {
  3028. sprintf(message, "%d,[%d,\"%s\",\"StartTransaction\",{\"connectorId\":%d,\"idTag\":\"%s\",\"meterStart\":%d,\"reservationId\":%d,\"timestamp\":\"%s\"}]"
  3029. , gun_index +1
  3030. , MESSAGE_TYPE_CALL
  3031. , guid
  3032. , ShmOCPP16Data->StartTransaction[gun_index].ConnectorId
  3033. , ShmOCPP16Data->StartTransaction[gun_index].IdTag
  3034. , ShmOCPP16Data->StartTransaction[gun_index].MeterStart
  3035. , ShmOCPP16Data->StartTransaction[gun_index].ReservationId
  3036. , ShmOCPP16Data->StartTransaction[gun_index].Timestamp );
  3037. }
  3038. #if 1
  3039. sprintf(tempdata, "StartTransaction,%d", (gun_index));
  3040. 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*/)
  3041. {
  3042. result = PASS;
  3043. }
  3044. #endif
  3045. strcpy(queuedata, message);
  3046. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  3047. return result;
  3048. }
  3049. int sendStatusNotificationRequest(int gun_index)
  3050. {
  3051. mtrace();
  3052. int result = FAIL;
  3053. char message[600]={0};
  3054. char guid[37];
  3055. int currentStatus = 0;
  3056. struct timeval tmnow;
  3057. struct tm *tm;
  3058. char buf[28];//, usec_buf[6];
  3059. char tempdata[65]={0};
  3060. int tempIndex = 0;
  3061. gettimeofday(&tmnow, NULL);
  3062. time_t t;
  3063. t = time(NULL);
  3064. /*UTC time and date*/
  3065. tm = gmtime(&t);
  3066. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3067. #if 0 // remove temporally
  3068. strftime(buf,30,"%Y-%m-%dT%H:%M:%S", tm);
  3069. strcat(buf,".");
  3070. sprintf(usec_buf,"%dZ",(int)tmnow.tv_usec);
  3071. strcat(buf,usec_buf);
  3072. #endif
  3073. printf("%s",buf);
  3074. ShmOCPP16Data->StatusNotification[gun_index].ConnectorId = (gun_index + 1);
  3075. //strcpy(ShmOCPP16Data->StatusNotification[gun_index].ErrorCode, "NoError"); --- CSU Setting
  3076. // it's option
  3077. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Info, "");
  3078. /*
  3079. enum _SYSTEM_STATUS
  3080. {
  3081. S_BOOTING = 0,
  3082. S_IDLE, = 1
  3083. S_AUTHORIZING, =2
  3084. S_REASSIGN_CHECK, =3
  3085. S_REASSIGN, =4
  3086. S_PRECHARGE, =5
  3087. S_PREPARING_FOR_EV, =6
  3088. S_PREPARING_FOR_EVSE, =7
  3089. S_CHARGING, =8
  3090. S_TERMINATING, =9
  3091. S_COMPLETE, =10
  3092. S_ALARM, =11
  3093. S_FAULT =12
  3094. }
  3095. */
  3096. //check Transaction active
  3097. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3098. if(gunType[gun_index] == 'J')
  3099. {
  3100. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3101. {
  3102. tempIndex = ((gun_index==2) ? 1: 0);
  3103. }
  3104. else
  3105. {
  3106. tempIndex = gun_index;
  3107. }
  3108. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3109. {
  3110. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex))
  3111. {
  3112. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE)//S_IDLE
  3113. {
  3114. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3115. {
  3116. currentStatus = 1; //OCPP Status: Preparing
  3117. }
  3118. else
  3119. {
  3120. currentStatus = 0; //OCPP Status: Available
  3121. }
  3122. }
  3123. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3124. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3125. ) //S_PRECHARGE
  3126. {
  3127. currentStatus = 1; //OCPP Status: Preparing
  3128. }
  3129. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3130. {
  3131. currentStatus = 2; //OCPP Status: Charging
  3132. }
  3133. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3134. {
  3135. currentStatus = 5; //OCPP Status: Finishing
  3136. }
  3137. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3138. {
  3139. currentStatus = 4; //OCPP Status: SuspendedEV
  3140. }
  3141. 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
  3142. {
  3143. currentStatus = 7; //OCPP Status: Unavailable
  3144. }
  3145. else if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT)|| (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3146. {
  3147. currentStatus = 8; //OCPP Status: Faulted
  3148. }
  3149. else if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3150. {
  3151. currentStatus = 6; //OCPP Status: Reserved
  3152. }
  3153. } //end of the same index
  3154. }//end of for CHAdeMO_QUANTITY
  3155. }
  3156. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3157. {
  3158. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3159. {
  3160. tempIndex = ((gun_index==2) ? 1: 0);
  3161. }
  3162. else
  3163. {
  3164. tempIndex = gun_index;
  3165. }
  3166. for (int index = 0; index < CCS_QUANTITY; index++)
  3167. {
  3168. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3169. {
  3170. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3171. {
  3172. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn == 1) //0: unplug, 1: Plug-in
  3173. {
  3174. currentStatus = 1; //OCPP Status: Preparing
  3175. }
  3176. else
  3177. {
  3178. currentStatus = 0; //OCPP Status: Available
  3179. }
  3180. }
  3181. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3182. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3183. ) //S_PRECHARGE
  3184. {
  3185. currentStatus = 1; //OCPP Status: Preparing
  3186. }
  3187. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3188. {
  3189. currentStatus = 2; //OCPP Status: Charging
  3190. }
  3191. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3192. {
  3193. currentStatus = 5; //OCPP Status: Finishing
  3194. }
  3195. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) //S_TERMINATING ---> SuspendedEV
  3196. {
  3197. currentStatus = 4; //OCPP Status: SuspendedEV
  3198. }
  3199. 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
  3200. {
  3201. currentStatus = 7; //OCPP Status : Unavailable
  3202. }
  3203. else if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3204. {
  3205. currentStatus = 8; //OCPP Status: Faulted
  3206. }
  3207. else if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3208. {
  3209. currentStatus = 6; //OCPP Status: Reserved
  3210. }
  3211. } //end of the same index
  3212. } // end of for CCS_QUANTITY
  3213. }
  3214. else if(gunType[gun_index] == 'G')
  3215. {
  3216. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3217. {
  3218. tempIndex = ((gun_index==2) ? 1: 0);
  3219. }
  3220. else
  3221. {
  3222. tempIndex = gun_index;
  3223. }
  3224. for (int index = 0; index < GB_QUANTITY; index++)
  3225. {
  3226. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3227. {
  3228. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3229. {
  3230. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3231. {
  3232. currentStatus = 1; //OCPP Status: Preparing
  3233. }
  3234. else
  3235. {
  3236. currentStatus = 0; //OCPP Status: Available
  3237. }
  3238. }
  3239. else if ( ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_PREPARING)&&( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3240. ( ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && ( ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3241. ) //S_PRECHARGE
  3242. {
  3243. currentStatus = 1; //OCPP Status: Preparing
  3244. }
  3245. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3246. {
  3247. currentStatus = 2; //OCPP Status: Charging
  3248. }
  3249. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3250. {
  3251. currentStatus = 5; //OCPP Status: Finishing
  3252. }
  3253. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3254. {
  3255. currentStatus = 4; //OCPP Status: SuspendedEV
  3256. }
  3257. 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
  3258. {
  3259. currentStatus = 7; //OCPP Status: Unavailable
  3260. }
  3261. else if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3262. {
  3263. currentStatus = 8; //OCPP Status: Faulted
  3264. }
  3265. else if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3266. {
  3267. currentStatus = 6; //OCPP Status: Reserved
  3268. }
  3269. } //end of the same index
  3270. } // end of for GB_QUANTITY
  3271. }
  3272. else if(gunType[gun_index] == 'O')
  3273. {
  3274. tempIndex = gun_index;
  3275. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3276. {
  3277. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3278. {
  3279. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  3280. {
  3281. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ConnectorPlugIn == 1) // //0: unplug, 1: Plug-in
  3282. {
  3283. currentStatus = 1; //OCPP Status: Preparing
  3284. }
  3285. else
  3286. {
  3287. currentStatus = 0; //OCPP Status: Available
  3288. }
  3289. }
  3290. else if ( ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_PREPARING) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_PREPARE_FOR_EVSE)) ||
  3291. ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus >= SYS_MODE_CCS_PRECHARGE_STEP0) && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus <= SYS_MODE_CCS_PRECHARGE_STEP1) )
  3292. ) //S_PRECHARGE
  3293. {
  3294. currentStatus = 1; //OCPP Status: Preparing
  3295. }
  3296. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) //S_CHARGING
  3297. {
  3298. currentStatus = 2; //OCPP Status: Charging
  3299. }
  3300. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE) //S_COMPLETE
  3301. {
  3302. currentStatus = 5; //OCPP Status: Finishing
  3303. }
  3304. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3305. {
  3306. currentStatus = 4; //OCPP Status: SuspendedEV
  3307. }
  3308. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) // ---> Unavailable
  3309. {
  3310. currentStatus = 7; //OCPP Status: Unavailable
  3311. }
  3312. else if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_ALARM)) //S_ALARM ,S_FAULT ---> Faulted
  3313. {
  3314. currentStatus = 8; //OCPP Status: Faulted
  3315. }
  3316. else if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3317. {
  3318. currentStatus = 6; //OCPP Status: Reserved
  3319. }
  3320. } //end of the same index
  3321. }
  3322. }
  3323. else
  3324. {
  3325. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3326. {
  3327. tempIndex = 2;
  3328. }
  3329. else
  3330. {
  3331. tempIndex = gun_index;
  3332. }
  3333. for (int index = 0; index < AC_QUANTITY; index++)
  3334. {
  3335. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3336. {
  3337. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //SYS_MODE_IDLE
  3338. {
  3339. 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))
  3340. {
  3341. currentStatus = 1; //OCPP Status: Preparing
  3342. }
  3343. else
  3344. {
  3345. currentStatus = 0; //OCPP Status: Available
  3346. }
  3347. }
  3348. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING)) //SYS_MODE_PREPARING
  3349. {
  3350. currentStatus = 1; //OCPP Status: Preparing
  3351. }
  3352. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) //SYS_MODE_CHARGING
  3353. {
  3354. currentStatus = 2; //OCPP Status: Charging
  3355. }
  3356. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE) //SYS_MODE_COMPLETE
  3357. {
  3358. currentStatus = 5; //OCPP Status: Finishing
  3359. }
  3360. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) // S_TERMINATING ---> SuspendedEV
  3361. {
  3362. currentStatus = 4; //OCPP Status: SuspendedEV
  3363. }
  3364. 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
  3365. {
  3366. currentStatus = 7; //OCPP Status: Unavailable
  3367. }
  3368. else if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_ALARM)) //S_ALARM,S_FAULT ---> Faulted
  3369. {
  3370. currentStatus = 8; //OCPP Status: Faulted
  3371. }
  3372. else if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // ---> Reserved
  3373. {
  3374. currentStatus = 6; //OCPP Status: Reserved
  3375. }
  3376. }//end of the same index
  3377. }//end of for AC_QUANTITY
  3378. }
  3379. //it's option
  3380. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Timestamp, buf);
  3381. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].VendorId, "PhihongTechnology");
  3382. strcpy((char *)ShmOCPP16Data->StatusNotification[gun_index].Status, ChargePointStatusStr[currentStatus]);
  3383. random_uuid(guid);
  3384. sprintf(message, "[%d,\"%s\",\"StatusNotification\",{\"connectorId\":%d,\"errorCode\":\"%s\",\"info\":\"%s\",\"status\":\"%s\",\"timestamp\":\"%s\",\"vendorId\":\"%s\",\"vendorErrorCode\":\"%s\"}]"
  3385. , MESSAGE_TYPE_CALL
  3386. , guid
  3387. , ShmOCPP16Data->StatusNotification[gun_index].ConnectorId
  3388. , ShmOCPP16Data->StatusNotification[gun_index].ErrorCode
  3389. , ShmOCPP16Data->StatusNotification[gun_index].Info
  3390. , ShmOCPP16Data->StatusNotification[gun_index].Status
  3391. , ShmOCPP16Data->StatusNotification[gun_index].Timestamp
  3392. , ShmOCPP16Data->StatusNotification[gun_index].VendorId
  3393. , ShmOCPP16Data->StatusNotification[gun_index].VendorErrorCode);
  3394. if((server_sign == TRUE))
  3395. {
  3396. LWS_Send(message);
  3397. sprintf(tempdata, "StatusNotification,%d", (gun_index));
  3398. 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*/)
  3399. {
  3400. //DEBUG_ERROR("statusNotification mapitem pass");
  3401. result = PASS;
  3402. }
  3403. }
  3404. else
  3405. {
  3406. result = PASS;
  3407. }
  3408. return result;
  3409. }
  3410. int sendStopTransactionRequest(int gun_index)
  3411. {
  3412. mtrace();
  3413. int result = FAIL;
  3414. //char message[1500]={0};
  3415. char guid[37]={0};
  3416. char tempdata[65]={0};
  3417. int tempIndex = 0;
  3418. char TempStopTransaction[256];
  3419. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  3420. //int idx_sample=0;
  3421. DEBUG_INFO("sendStopTransactionRequest \n");
  3422. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  3423. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  3424. //=========================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  3425. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3426. if(gunType[gun_index] == 'J')
  3427. {
  3428. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3429. {
  3430. tempIndex = ((gun_index==2) ? 1: 0);
  3431. }
  3432. else
  3433. {
  3434. tempIndex = gun_index;
  3435. }
  3436. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3437. {
  3438. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3439. {
  3440. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  3441. }
  3442. }// END OF CHAdeMO_QUANTITY
  3443. }
  3444. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3445. {
  3446. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3447. {
  3448. tempIndex = ((gun_index==2) ? 1: 0);
  3449. }
  3450. else
  3451. {
  3452. tempIndex = gun_index;
  3453. }
  3454. for (int index = 0; index < CCS_QUANTITY; index++)
  3455. {
  3456. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3457. {
  3458. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  3459. }
  3460. }// END OF CCS_QUANTITY
  3461. }
  3462. else if(gunType[gun_index] == 'G')
  3463. {
  3464. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3465. {
  3466. tempIndex = ((gun_index==2) ? 1: 0);
  3467. }
  3468. else
  3469. {
  3470. tempIndex = gun_index;
  3471. }
  3472. for (int index = 0; index < GB_QUANTITY; index++)
  3473. {
  3474. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3475. {
  3476. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  3477. }
  3478. }// END OF GB_QUANTITY
  3479. }
  3480. else if(gunType[gun_index] == 'O')
  3481. {
  3482. tempIndex = gun_index;
  3483. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3484. {
  3485. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3486. {
  3487. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  3488. }
  3489. }// END OF GB_QUANTITY
  3490. }
  3491. else
  3492. {
  3493. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3494. {
  3495. tempIndex = 2;
  3496. }
  3497. else
  3498. {
  3499. tempIndex = gun_index;
  3500. }
  3501. for (int index = 0; index < AC_QUANTITY; index++)
  3502. {
  3503. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3504. {
  3505. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  3506. }
  3507. }// END OF AC_QUANTITY
  3508. }
  3509. //====================================== Stop Transaction Time =====================================================
  3510. struct timeval tmnow;
  3511. struct tm *tm;
  3512. char buf[28];//, usec_buf[6];
  3513. gettimeofday(&tmnow, NULL);
  3514. time_t t;
  3515. t = time(NULL);
  3516. /*UTC time and date*/
  3517. tm = gmtime(&t);
  3518. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  3519. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  3520. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  3521. random_uuid(guid);
  3522. /***********************************transactionData******************************************************/
  3523. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  3524. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  3525. //=================================
  3526. // Transaction_Begin
  3527. //=================================
  3528. //============================================ Energy.Active.Import.Interval ================================
  3529. //idx_sample=0;
  3530. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  3531. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  3532. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  3533. 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*/]);
  3534. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  3535. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  3536. {
  3537. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  3538. }
  3539. else
  3540. {
  3541. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  3542. }
  3543. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  3544. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3545. //=================================
  3546. // Transaction_End
  3547. //=================================
  3548. // ================================= Current.Import L1 ===============================================
  3549. //idx_sample=1;
  3550. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  3551. if(gunType[gun_index] == 'J')
  3552. {
  3553. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3554. {
  3555. tempIndex = ((gun_index==2) ? 1: 0);
  3556. }
  3557. else
  3558. {
  3559. tempIndex = gun_index;
  3560. }
  3561. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3562. {
  3563. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3564. {
  3565. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3566. }
  3567. }// End of for CHAdeMO_QUANTITY
  3568. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3569. }
  3570. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3571. {
  3572. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3573. {
  3574. tempIndex = ((gun_index==2) ? 1: 0);
  3575. }
  3576. else
  3577. {
  3578. tempIndex = gun_index;
  3579. }
  3580. for (int index = 0; index < CCS_QUANTITY; index++)
  3581. {
  3582. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3583. {
  3584. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3585. }
  3586. }// End of for CCS_QUANTITY
  3587. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3588. }
  3589. else if(gunType[gun_index] == 'G')
  3590. {
  3591. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3592. {
  3593. tempIndex = ((gun_index==2) ? 1: 0);
  3594. }
  3595. else
  3596. {
  3597. tempIndex = gun_index;
  3598. }
  3599. for (int index = 0; index < GB_QUANTITY; index++)
  3600. {
  3601. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3602. {
  3603. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3604. }
  3605. }// End of for GB_QUANTITY
  3606. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3607. }
  3608. else if(gunType[gun_index] == 'O')
  3609. {
  3610. tempIndex = gun_index;
  3611. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3612. {
  3613. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3614. {
  3615. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  3616. }
  3617. }
  3618. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  3619. }
  3620. else
  3621. {
  3622. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3623. {
  3624. tempIndex = 2;
  3625. }
  3626. else
  3627. {
  3628. tempIndex = gun_index;
  3629. }
  3630. for (int index = 0; index < AC_QUANTITY; index++)
  3631. {
  3632. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3633. {
  3634. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  3635. }
  3636. }// End of for AC_QUANTITY
  3637. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  3638. }
  3639. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3640. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  3641. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  3642. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  3643. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  3644. // ================================= Energy.Active.Import.Interval ==============================================
  3645. //idx_sample=2;
  3646. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3647. if(gunType[gun_index] == 'J')
  3648. {
  3649. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3650. {
  3651. tempIndex = ((gun_index==2) ? 1: 0);
  3652. }
  3653. else
  3654. {
  3655. tempIndex = gun_index;
  3656. }
  3657. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3658. {
  3659. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3660. {
  3661. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3662. }
  3663. }// END OF CHAdeMO_QUANTITY
  3664. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3665. }
  3666. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3667. {
  3668. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3669. {
  3670. tempIndex = ((gun_index==2) ? 1: 0);
  3671. }
  3672. else
  3673. {
  3674. tempIndex = gun_index;
  3675. }
  3676. for (int index = 0; index < CCS_QUANTITY; index++)
  3677. {
  3678. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3679. {
  3680. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3681. }
  3682. }// END OF CCS_QUANTITY
  3683. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3684. }
  3685. else if(gunType[gun_index] == 'G')
  3686. {
  3687. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3688. {
  3689. tempIndex = ((gun_index==2) ? 1: 0);
  3690. }
  3691. else
  3692. {
  3693. tempIndex = gun_index;
  3694. }
  3695. for (int index = 0; index < GB_QUANTITY; index++)
  3696. {
  3697. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3698. {
  3699. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3700. }
  3701. }// END OF GB_QUANTITY
  3702. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3703. }
  3704. else if(gunType[gun_index] == 'O')
  3705. {
  3706. tempIndex = gun_index;
  3707. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3708. {
  3709. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3710. {
  3711. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3712. }
  3713. }
  3714. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  3715. }
  3716. else
  3717. {
  3718. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3719. {
  3720. tempIndex = 2;
  3721. }
  3722. else
  3723. {
  3724. tempIndex = gun_index;
  3725. }
  3726. for (int index = 0; index < AC_QUANTITY; index++)
  3727. {
  3728. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3729. {
  3730. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  3731. }
  3732. }// END OF AC_QUANTITY
  3733. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  3734. }
  3735. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3736. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  3737. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  3738. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  3739. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  3740. //=================================== Power.Active.Import ==================================================
  3741. //idx_sample=3;
  3742. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3743. if(gunType[gun_index] == 'J')
  3744. {
  3745. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3746. {
  3747. tempIndex = ((gun_index==2) ? 1: 0);
  3748. }
  3749. else
  3750. {
  3751. tempIndex = gun_index;
  3752. }
  3753. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3754. {
  3755. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3756. {
  3757. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3758. }
  3759. } // End for CHAdeMO_QUANTITY
  3760. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3761. }
  3762. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3763. {
  3764. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3765. {
  3766. tempIndex = ((gun_index==2) ? 1: 0);
  3767. }
  3768. else
  3769. {
  3770. tempIndex = gun_index;
  3771. }
  3772. for (int index = 0; index < CCS_QUANTITY; index++)
  3773. {
  3774. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3775. {
  3776. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3777. }
  3778. } // END for CCS_QUANTITY
  3779. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3780. }
  3781. else if(gunType[gun_index] == 'G')
  3782. {
  3783. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3784. {
  3785. tempIndex = ((gun_index==2) ? 1: 0);
  3786. }
  3787. else
  3788. {
  3789. tempIndex = gun_index;
  3790. }
  3791. for (int index = 0; index < GB_QUANTITY; index++)
  3792. {
  3793. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3794. {
  3795. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3796. }
  3797. }// END for GB_QUANTITY
  3798. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3799. }
  3800. else if(gunType[gun_index] == 'O')
  3801. {
  3802. tempIndex = gun_index;
  3803. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3804. {
  3805. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3806. {
  3807. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3808. }
  3809. }
  3810. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  3811. }
  3812. else
  3813. {
  3814. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3815. {
  3816. tempIndex = 2;
  3817. }
  3818. else
  3819. {
  3820. tempIndex = gun_index;
  3821. }
  3822. for (int index = 0; index < AC_QUANTITY; index++)
  3823. {
  3824. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3825. {
  3826. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  3827. }
  3828. } // END for AC_QUANTITY
  3829. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  3830. }
  3831. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3832. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  3833. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  3834. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  3835. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  3836. //============================ Voltage L1 ====================================
  3837. //idx_sample=4;
  3838. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3839. if(gunType[gun_index] == 'J')
  3840. {
  3841. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3842. {
  3843. tempIndex = ((gun_index==2) ? 1: 0);
  3844. }
  3845. else
  3846. {
  3847. tempIndex = gun_index;
  3848. }
  3849. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3850. {
  3851. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3852. {
  3853. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3854. }
  3855. } // END OF FOR CHAdeMO_QUANTITY
  3856. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3857. }
  3858. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3859. {
  3860. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3861. {
  3862. tempIndex = ((gun_index==2) ? 1: 0);
  3863. }
  3864. else
  3865. {
  3866. tempIndex = gun_index;
  3867. }
  3868. for (int index = 0; index < CCS_QUANTITY; index++)
  3869. {
  3870. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3871. {
  3872. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3873. }
  3874. } // END OF FOR CCS_QUANTITY
  3875. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3876. }
  3877. else if(gunType[gun_index] == 'G')
  3878. {
  3879. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  3880. {
  3881. tempIndex = ((gun_index==2) ? 1: 0);
  3882. }
  3883. else
  3884. {
  3885. tempIndex = gun_index;
  3886. }
  3887. for (int index = 0; index < GB_QUANTITY; index++)
  3888. {
  3889. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3890. {
  3891. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3892. }
  3893. } // END OF FOR GB_QUANTITY
  3894. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3895. }
  3896. else if(gunType[gun_index] == 'O')
  3897. {
  3898. tempIndex = gun_index;
  3899. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3900. {
  3901. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3902. {
  3903. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  3904. }
  3905. }
  3906. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  3907. }
  3908. else
  3909. {
  3910. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3911. {
  3912. tempIndex = 2;
  3913. }
  3914. else
  3915. {
  3916. tempIndex = gun_index;
  3917. }
  3918. for (int index = 0; index < AC_QUANTITY; index++)
  3919. {
  3920. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  3921. {
  3922. 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
  3923. }
  3924. } // END OF FOR AC_QUANTITY
  3925. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  3926. }
  3927. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3928. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  3929. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  3930. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  3931. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  3932. //====================== End SoC ================================
  3933. //idx_sample=5;
  3934. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  3935. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  3936. {
  3937. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  3938. {
  3939. tempIndex = ((gun_index==2) ? 1: 0);
  3940. }
  3941. else
  3942. {
  3943. tempIndex = gun_index;
  3944. }
  3945. if(gunType[gun_index] == 'J')
  3946. {
  3947. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  3948. {
  3949. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  3950. {
  3951. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  3952. }
  3953. }
  3954. }
  3955. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  3956. {
  3957. for (int index = 0; index < CCS_QUANTITY; index++)
  3958. {
  3959. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  3960. {
  3961. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  3962. }
  3963. }
  3964. }
  3965. else if(gunType[gun_index] == 'G')
  3966. {
  3967. for (int index = 0; index < GB_QUANTITY; index++)
  3968. {
  3969. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  3970. {
  3971. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  3972. }
  3973. }
  3974. }
  3975. else if(gunType[gun_index] == 'O')
  3976. {
  3977. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  3978. {
  3979. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  3980. {
  3981. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  3982. }
  3983. }
  3984. }
  3985. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  3986. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  3987. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  3988. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  3989. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  3990. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  3991. } // END FOR DC CASE
  3992. // ================================= Current.Import L2 ===============================================
  3993. //idx_sample=6;
  3994. // AC 3 phse L2 current
  3995. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  3996. {
  3997. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  3998. {
  3999. tempIndex = 2;
  4000. }
  4001. else
  4002. {
  4003. tempIndex = gun_index;
  4004. }
  4005. for (int index = 0; index < AC_QUANTITY; index++)
  4006. {
  4007. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4008. {
  4009. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2 );// 0~6553.5 amp for EVSE
  4010. }
  4011. }// End of for AC_QUANTITY
  4012. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  4013. }
  4014. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4015. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  4016. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  4017. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  4018. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4019. // ================================= Current.Import L3 ===============================================
  4020. //idx_sample=7;
  4021. // AC 3 phse L3 current
  4022. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  4023. {
  4024. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4025. {
  4026. tempIndex = 2;
  4027. }
  4028. else
  4029. {
  4030. tempIndex = gun_index;
  4031. }
  4032. for (int index = 0; index < AC_QUANTITY; index++)
  4033. {
  4034. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4035. {
  4036. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3 );// 0~6553.5 amp for EVSE
  4037. }
  4038. }// End of for AC_QUANTITY
  4039. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  4040. }
  4041. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4042. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  4043. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  4044. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  4045. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4046. //============================ Voltage L2 ====================================
  4047. //idx_sample=8;
  4048. // AC 3 phse L2 voltage
  4049. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  4050. {
  4051. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4052. {
  4053. tempIndex = 2;
  4054. }
  4055. else
  4056. {
  4057. tempIndex = gun_index;
  4058. }
  4059. for (int index = 0; index < AC_QUANTITY; index++)
  4060. {
  4061. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4062. {
  4063. 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
  4064. }
  4065. } // END OF FOR AC_QUANTITY
  4066. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  4067. }
  4068. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4069. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  4070. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  4071. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  4072. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4073. //============================ Voltage L3 ====================================
  4074. //idx_sample=8;
  4075. // AC 3 phse L3 voltage
  4076. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2]=='Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2]=='W')))
  4077. {
  4078. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4079. {
  4080. tempIndex = 2;
  4081. }
  4082. else
  4083. {
  4084. tempIndex = gun_index;
  4085. }
  4086. for (int index = 0; index < AC_QUANTITY; index++)
  4087. {
  4088. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4089. {
  4090. 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
  4091. }
  4092. } // END OF FOR AC_QUANTITY
  4093. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  4094. }
  4095. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  4096. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  4097. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  4098. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  4099. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4100. //====================== Start SoC ================================
  4101. //idx_sample=10;
  4102. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4103. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  4104. {
  4105. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  4106. {
  4107. tempIndex = ((gun_index==2) ? 1: 0);
  4108. }
  4109. else
  4110. {
  4111. tempIndex = gun_index;
  4112. }
  4113. if(gunType[gun_index] == 'J')
  4114. {
  4115. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4116. {
  4117. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4118. {
  4119. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  4120. }
  4121. }
  4122. }
  4123. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4124. {
  4125. for (int index = 0; index < CCS_QUANTITY; index++)
  4126. {
  4127. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4128. {
  4129. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  4130. }
  4131. }
  4132. }
  4133. else if(gunType[gun_index] == 'G')
  4134. {
  4135. for (int index = 0; index < GB_QUANTITY; index++)
  4136. {
  4137. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4138. {
  4139. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  4140. }
  4141. }
  4142. }
  4143. else if(gunType[gun_index] == 'O')
  4144. {
  4145. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4146. {
  4147. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4148. {
  4149. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  4150. }
  4151. }
  4152. }
  4153. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  4154. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  4155. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  4156. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  4157. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  4158. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  4159. } // END FOR DC CASE
  4160. //================================================ Message create ====================================================
  4161. json_object *StopTransaction = json_object_new_object();
  4162. json_object *transactionDatas = json_object_new_array();
  4163. json_object *sampledValues = json_object_new_array();
  4164. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  4165. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  4166. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  4167. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  4168. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  4169. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  4170. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  4171. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  4172. {
  4173. json_object *transactionData = json_object_new_object();
  4174. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  4175. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  4176. {
  4177. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  4178. {
  4179. json_object *sampledValue = json_object_new_object();
  4180. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  4181. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  4182. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  4183. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  4184. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  4185. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  4186. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  4187. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  4188. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  4189. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  4190. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  4191. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  4192. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  4193. json_object_array_add(sampledValues, sampledValue);
  4194. }
  4195. }
  4196. json_object_object_add(transactionData, "sampledValue", sampledValues);
  4197. json_object_array_add(transactionDatas, transactionData);
  4198. }
  4199. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  4200. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  4201. ,MESSAGE_TYPE_CALL
  4202. ,guid
  4203. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  4204. json_object_put(StopTransaction);
  4205. #if 1 // for TempStopTransaction
  4206. //Delete TempStopTransaction
  4207. if((access(TempStopTransaction,F_OK))!=-1)
  4208. {
  4209. remove(TempStopTransaction); // remove file "TempStopTransaction"
  4210. }
  4211. #endif
  4212. #if 1
  4213. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  4214. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  4215. {
  4216. result = PASS;
  4217. //DEBUG_INFO("StopTransaction mapitem pass\n");
  4218. }
  4219. #endif
  4220. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );//addq(guid, queuedata); ---> remove temporally
  4221. //----------------------------replace queue StopTransaction TransactionId ---------------------------//
  4222. //int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StopTransaction[gun_index].IdTag);
  4223. int gettransactionId = GetTransactionId(gun_index+1, ShmOCPP16Data->StartTransaction[gun_index].IdTag, TRUE);
  4224. if((ShmOCPP16Data->StopTransaction[gun_index].TransactionId != 0) && (gettransactionId != 0))
  4225. {
  4226. SetTransactionIdZero(ShmOCPP16Data->StopTransaction[gun_index].TransactionId);
  4227. }
  4228. //for test
  4229. //ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  4230. return result;
  4231. }
  4232. int sendMeterValuesRequest(int gun_index, ReadingContext dataType)
  4233. {
  4234. mtrace();
  4235. int result = FAIL;
  4236. char guid[37]={0};
  4237. char tempdata[65]={0};
  4238. int tempIndex = 0;
  4239. DEBUG_INFO("sendMeterValuesRequest ...\n");
  4240. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  4241. memset(&ShmOCPP16Data->MeterValues[gun_index], 0, sizeof(struct StructMeterValues));
  4242. //set value
  4243. ShmOCPP16Data->MeterValues[gun_index].ConnectorId = gun_index + 1; // gun start from 1~
  4244. ShmOCPP16Data->MeterValues[gun_index].TransactionId = ((strstr((char*)ShmOCPP16Data->StatusNotification[gun_index].Status, "Charging") != NULL) ? ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId : -1);
  4245. random_uuid(guid);
  4246. //UTC Date time
  4247. struct timeval tmnow;
  4248. struct tm *tm;
  4249. char buf[28];//, usec_buf[6];
  4250. gettimeofday(&tmnow, NULL);
  4251. time_t t;
  4252. t = time(NULL);
  4253. /*UTC time and date*/
  4254. tm = gmtime(&t);
  4255. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  4256. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].TimeStamp, buf);
  4257. //DEBUG_INFO("ShmSysConfigAndInfo->SysConfig.ModelName[0]=%c\n", ShmSysConfigAndInfo->SysConfig.ModelName[0]);
  4258. //idx_sample=0;
  4259. //********************************(1)Current.Import L1************************************************/
  4260. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4261. if(gunType[gun_index] == 'J')
  4262. {
  4263. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4264. {
  4265. tempIndex = ((gun_index==2) ? 1: 0);
  4266. }
  4267. else
  4268. {
  4269. tempIndex = gun_index;
  4270. }
  4271. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4272. {
  4273. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4274. {
  4275. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );
  4276. }
  4277. }
  4278. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4279. }
  4280. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4281. {
  4282. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4283. {
  4284. tempIndex = ((gun_index==2) ? 1: 0);
  4285. }
  4286. else
  4287. {
  4288. tempIndex = gun_index;
  4289. }
  4290. for (int index = 0; index < CCS_QUANTITY; index++)
  4291. {
  4292. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4293. {
  4294. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );
  4295. }
  4296. }
  4297. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4298. }
  4299. else if(gunType[gun_index] == 'G')
  4300. {
  4301. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4302. {
  4303. tempIndex = ((gun_index==2) ? 1: 0);
  4304. }
  4305. else
  4306. {
  4307. tempIndex = gun_index;
  4308. }
  4309. for (int index = 0; index < GB_QUANTITY; index++)
  4310. {
  4311. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4312. {
  4313. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );
  4314. }
  4315. }
  4316. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4317. }
  4318. else if(gunType[gun_index] == 'O')
  4319. {
  4320. tempIndex = gun_index;
  4321. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4322. {
  4323. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4324. {
  4325. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );
  4326. }
  4327. }
  4328. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L3_N]);
  4329. }
  4330. else
  4331. {
  4332. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4333. {
  4334. tempIndex = 2;
  4335. }
  4336. else
  4337. {
  4338. tempIndex = gun_index;
  4339. }
  4340. for (int index = 0; index < AC_QUANTITY; index++)
  4341. {
  4342. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4343. {
  4344. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );
  4345. }
  4346. }
  4347. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Phase, PhaseStr[L1_N]);
  4348. }
  4349. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Context, ReadingContextStr[dataType]);
  4350. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Format, ValueFormatStr[Raw]);
  4351. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Measurand, MeasurandStr[Current_Import]);
  4352. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Location, LocationStr[Location_Outlet]);
  4353. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4354. //idx_sample=1;
  4355. //********************************(2)Energy.Active.Import.Register ************************************************/
  4356. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4357. if(gunType[gun_index] == 'J')
  4358. {
  4359. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4360. {
  4361. tempIndex = ((gun_index==2) ? 1: 0);
  4362. }
  4363. else
  4364. {
  4365. tempIndex = gun_index;
  4366. }
  4367. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4368. {
  4369. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4370. {
  4371. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption );
  4372. }
  4373. }
  4374. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4375. }
  4376. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4377. {
  4378. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4379. {
  4380. tempIndex = ((gun_index==2) ? 1: 0);
  4381. }
  4382. else
  4383. {
  4384. tempIndex = gun_index;
  4385. }
  4386. for (int index = 0; index < CCS_QUANTITY; index++)
  4387. {
  4388. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4389. {
  4390. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption );
  4391. }
  4392. }
  4393. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4394. }
  4395. else if(gunType[gun_index] == 'G')
  4396. {
  4397. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4398. {
  4399. tempIndex = ((gun_index==2) ? 1: 0);
  4400. }
  4401. else
  4402. {
  4403. tempIndex = gun_index;
  4404. }
  4405. for (int index = 0; index < GB_QUANTITY; index++)
  4406. {
  4407. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4408. {
  4409. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption );
  4410. }
  4411. }
  4412. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4413. }
  4414. else if(gunType[gun_index] == 'O')
  4415. {
  4416. tempIndex = gun_index;
  4417. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4418. {
  4419. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4420. {
  4421. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption );
  4422. }
  4423. }
  4424. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L3_N]);
  4425. }
  4426. else
  4427. {
  4428. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4429. {
  4430. tempIndex = 2;
  4431. }
  4432. else
  4433. {
  4434. tempIndex = gun_index;
  4435. }
  4436. for (int index = 0; index < AC_QUANTITY; index++)
  4437. {
  4438. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4439. {
  4440. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption );
  4441. }
  4442. }
  4443. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Phase, PhaseStr[L1_N]);
  4444. }
  4445. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Context, ReadingContextStr[dataType]);
  4446. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Format, ValueFormatStr[Raw]);
  4447. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Measurand, MeasurandStr[Energy_Active_Import_Register]);
  4448. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Location, LocationStr[Location_Outlet]);
  4449. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4450. //idx_sample=2;
  4451. //****************************************************(3)Energy.Active.Import.Interval*********************************************/
  4452. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4453. if(gunType[gun_index] == 'J')
  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 < CHAdeMO_QUANTITY; index++)
  4464. {
  4465. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4466. {
  4467. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );
  4468. }
  4469. } // END OF FOR CHAdeMO_QUANTITY
  4470. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4471. }
  4472. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  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 < CCS_QUANTITY; index++)
  4483. {
  4484. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4485. {
  4486. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );
  4487. }
  4488. } // END OF CCS_QUANTITY
  4489. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4490. }
  4491. else if(gunType[gun_index] == 'G')
  4492. {
  4493. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4494. {
  4495. tempIndex = ((gun_index==2) ? 1: 0);
  4496. }
  4497. else
  4498. {
  4499. tempIndex = gun_index;
  4500. }
  4501. for (int index = 0; index < GB_QUANTITY; index++)
  4502. {
  4503. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4504. {
  4505. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy);
  4506. }
  4507. } // END OF GB_QUANTITY
  4508. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4509. }
  4510. else if(gunType[gun_index] == 'O')
  4511. {
  4512. tempIndex = gun_index;
  4513. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4514. {
  4515. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4516. {
  4517. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy);
  4518. }
  4519. }
  4520. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L3_N]);
  4521. }
  4522. else
  4523. {
  4524. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4525. {
  4526. tempIndex = 2;
  4527. }
  4528. else
  4529. {
  4530. tempIndex = gun_index;
  4531. }
  4532. for (int index = 0; index < AC_QUANTITY; index++)
  4533. {
  4534. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4535. {
  4536. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );
  4537. }
  4538. }
  4539. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Phase, PhaseStr[L1_N]);
  4540. }
  4541. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Context, ReadingContextStr[dataType]);
  4542. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Format, ValueFormatStr[Raw]);
  4543. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Measurand, MeasurandStr[Energy_Active_Import_Interval]);
  4544. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Location, LocationStr[Location_Outlet]);
  4545. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  4546. //idx_sample=3;
  4547. //********************************(4)Power.Active.Import************************************************/
  4548. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4549. if(gunType[gun_index] == 'J')
  4550. {
  4551. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4552. {
  4553. tempIndex = ((gun_index==2) ? 1: 0);
  4554. }
  4555. else
  4556. {
  4557. tempIndex = gun_index;
  4558. }
  4559. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4560. {
  4561. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4562. {
  4563. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower);
  4564. }
  4565. } // END OF FOR
  4566. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4567. }
  4568. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4569. {
  4570. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4571. {
  4572. tempIndex = ((gun_index==2) ? 1: 0);
  4573. }
  4574. else
  4575. {
  4576. tempIndex = gun_index;
  4577. }
  4578. for (int index = 0; index < CCS_QUANTITY; index++)
  4579. {
  4580. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4581. {
  4582. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower);
  4583. }
  4584. }
  4585. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4586. }
  4587. else if(gunType[gun_index] == 'G')
  4588. {
  4589. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4590. {
  4591. tempIndex = ((gun_index==2) ? 1: 0);
  4592. }
  4593. else
  4594. {
  4595. tempIndex = gun_index;
  4596. }
  4597. for (int index = 0; index < GB_QUANTITY; index++)
  4598. {
  4599. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4600. {
  4601. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4602. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower);
  4603. }
  4604. }
  4605. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4606. }
  4607. else if(gunType[gun_index] == 'O')
  4608. {
  4609. tempIndex = gun_index;
  4610. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4611. {
  4612. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4613. {
  4614. //ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower = 100.0;
  4615. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower);
  4616. }
  4617. }
  4618. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L3_N]);
  4619. }
  4620. else
  4621. {
  4622. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4623. {
  4624. tempIndex = 2;
  4625. }
  4626. else
  4627. {
  4628. tempIndex = gun_index;
  4629. }
  4630. for (int index = 0; index < AC_QUANTITY; index++)
  4631. {
  4632. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4633. {
  4634. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Value, "%.1f" , ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower);
  4635. }
  4636. }
  4637. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Phase, PhaseStr[L1_N]);
  4638. }
  4639. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Context, ReadingContextStr[dataType]);
  4640. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Format, ValueFormatStr[Raw]);
  4641. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Measurand, MeasurandStr[Power_Active_Import]);
  4642. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Location, LocationStr[Location_Outlet]);
  4643. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW]);
  4644. //idx_sample=4;
  4645. //***********************************************(5)VOLTAGE L1******************************************************/
  4646. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  4647. if(gunType[gun_index] == 'J')
  4648. {
  4649. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4650. {
  4651. tempIndex = ((gun_index==2) ? 1: 0);
  4652. }
  4653. else
  4654. {
  4655. tempIndex = gun_index;
  4656. }
  4657. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4658. {
  4659. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4660. {
  4661. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );
  4662. }
  4663. }
  4664. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4665. }
  4666. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4667. {
  4668. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4669. {
  4670. tempIndex = ((gun_index==2) ? 1: 0);
  4671. }
  4672. else
  4673. {
  4674. tempIndex = gun_index;
  4675. }
  4676. for (int index = 0; index < CCS_QUANTITY; index++)
  4677. {
  4678. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4679. {
  4680. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );
  4681. }
  4682. }
  4683. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4684. }
  4685. else if(gunType[gun_index] == 'G')
  4686. {
  4687. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  4688. {
  4689. tempIndex = ((gun_index==2) ? 1: 0);
  4690. }
  4691. else
  4692. {
  4693. tempIndex = gun_index;
  4694. }
  4695. for (int index = 0; index < GB_QUANTITY; index++)
  4696. {
  4697. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4698. {
  4699. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );
  4700. }
  4701. }
  4702. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4703. }
  4704. else if(gunType[gun_index] == 'O')
  4705. {
  4706. tempIndex = gun_index;
  4707. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4708. {
  4709. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4710. {
  4711. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );
  4712. }
  4713. }
  4714. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L3_N]);
  4715. }
  4716. else
  4717. {
  4718. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4719. {
  4720. tempIndex = 2;
  4721. }
  4722. else
  4723. {
  4724. tempIndex = gun_index;
  4725. }
  4726. for (int index = 0; index < AC_QUANTITY; index++)
  4727. {
  4728. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4729. {
  4730. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltage );
  4731. }
  4732. }
  4733. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Phase, PhaseStr[L1_N]);
  4734. }
  4735. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Context, ReadingContextStr[dataType]);
  4736. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Format, ValueFormatStr[Raw]);
  4737. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Measurand, MeasurandStr[Voltage]);
  4738. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Location, LocationStr[Location_Outlet]);
  4739. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4740. //***********************************************(6)SOC******************************************************/
  4741. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  4742. {
  4743. //idx_sample=5;
  4744. //sampledValue = NULL;
  4745. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  4746. {
  4747. tempIndex = ((gun_index==2) ? 1: 0);
  4748. }
  4749. else
  4750. {
  4751. tempIndex = gun_index;
  4752. }
  4753. if(gunType[gun_index] == 'J')
  4754. {
  4755. //tempIndex = ((gun_index==2) ? 1: 0);
  4756. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  4757. {
  4758. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  4759. {
  4760. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );
  4761. }
  4762. }
  4763. }
  4764. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  4765. {
  4766. //tempIndex = ((gun_index==2) ? 1: 0);
  4767. for (int index = 0; index < CCS_QUANTITY; index++)
  4768. {
  4769. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  4770. {
  4771. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );
  4772. }
  4773. }
  4774. }
  4775. else if(gunType[gun_index] == 'G')
  4776. {
  4777. //tempIndex = ((gun_index==2) ? 1: 0);
  4778. for (int index = 0; index < GB_QUANTITY; index++)
  4779. {
  4780. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  4781. {
  4782. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );
  4783. }
  4784. }
  4785. }
  4786. else if(gunType[gun_index] == 'O')
  4787. {
  4788. //tempIndex = ((gun_index==2) ? 1: 0);
  4789. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  4790. {
  4791. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  4792. {
  4793. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );
  4794. }
  4795. }
  4796. }
  4797. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Context, ReadingContextStr[dataType]);
  4798. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Format, ValueFormatStr[Raw]);
  4799. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Measurand, MeasurandStr[SoC]);
  4800. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Phase, PhaseStr[L3_N]);
  4801. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Location, LocationStr[Location_EV]);
  4802. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent]);
  4803. }
  4804. //********************************(7)Current.Import L2************************************************/
  4805. // Only for AC 3 phase
  4806. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4807. {
  4808. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4809. {
  4810. tempIndex = 2;
  4811. }
  4812. else
  4813. {
  4814. tempIndex = gun_index;
  4815. }
  4816. for (int index = 0; index < AC_QUANTITY; index++)
  4817. {
  4818. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4819. {
  4820. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);
  4821. }
  4822. }
  4823. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Phase, PhaseStr[L2_N]);
  4824. }
  4825. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Context, ReadingContextStr[dataType]);
  4826. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Format, ValueFormatStr[Raw]);
  4827. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Measurand, MeasurandStr[Current_Import]);
  4828. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Location, LocationStr[Location_Outlet]);
  4829. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4830. //********************************(8)Current.Import L3************************************************/
  4831. // Only for AC 3 phase
  4832. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4833. {
  4834. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4835. {
  4836. tempIndex = 2;
  4837. }
  4838. else
  4839. {
  4840. tempIndex = gun_index;
  4841. }
  4842. for (int index = 0; index < AC_QUANTITY; index++)
  4843. {
  4844. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4845. {
  4846. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);
  4847. }
  4848. }
  4849. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Phase, PhaseStr[L3_N]);
  4850. }
  4851. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Context, ReadingContextStr[dataType]);
  4852. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Format, ValueFormatStr[Raw]);
  4853. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Measurand, MeasurandStr[Current_Import]);
  4854. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Location, LocationStr[Location_Outlet]);
  4855. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  4856. //***********************************************(9)VOLTAGE L2******************************************************/
  4857. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4858. {
  4859. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4860. {
  4861. tempIndex = 2;
  4862. }
  4863. else
  4864. {
  4865. tempIndex = gun_index;
  4866. }
  4867. for (int index = 0; index < AC_QUANTITY; index++)
  4868. {
  4869. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4870. {
  4871. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL2);
  4872. }
  4873. }
  4874. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Phase, PhaseStr[L2_N]);
  4875. }
  4876. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Context, ReadingContextStr[dataType]);
  4877. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Format, ValueFormatStr[Raw]);
  4878. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Measurand, MeasurandStr[Voltage]);
  4879. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Location, LocationStr[Location_Outlet]);
  4880. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4881. //***********************************************(10)VOLTAGE L3******************************************************/
  4882. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  4883. {
  4884. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  4885. {
  4886. tempIndex = 2;
  4887. }
  4888. else
  4889. {
  4890. tempIndex = gun_index;
  4891. }
  4892. for (int index = 0; index < AC_QUANTITY; index++)
  4893. {
  4894. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  4895. {
  4896. sprintf((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingVoltageL3);
  4897. }
  4898. }
  4899. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Phase, PhaseStr[L3_N]);
  4900. }
  4901. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Context, ReadingContextStr[dataType]);
  4902. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Format, ValueFormatStr[Raw]);
  4903. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Measurand, MeasurandStr[Voltage]);
  4904. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Location, LocationStr[Location_Outlet]);
  4905. strcpy((char *)ShmOCPP16Data->MeterValues[gun_index].MeterValue[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  4906. // Message create ====================================================================================================
  4907. if(TRUE)
  4908. {
  4909. json_object *MeterValueReq = json_object_new_object();
  4910. json_object *MeterValues = json_object_new_array();
  4911. json_object *sampledValues = json_object_new_array();
  4912. json_object_object_add(MeterValueReq, "connectorId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].ConnectorId));
  4913. if(ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1)
  4914. json_object_object_add(MeterValueReq, "transactionId", json_object_new_int(ShmOCPP16Data->MeterValues[gun_index].TransactionId));
  4915. for(uint8_t idxMeter=0;idxMeter<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue);idxMeter++)
  4916. {
  4917. json_object *MeterValue = json_object_new_object();
  4918. for(int idxSample=0;idxSample<ARRAY_SIZE(ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue);idxSample++)
  4919. {
  4920. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value) > 0)
  4921. {
  4922. json_object *sampledValue = json_object_new_object();
  4923. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Value));
  4924. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context) > 0)
  4925. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Context));
  4926. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format) > 0)
  4927. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Format));
  4928. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand) > 0)
  4929. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Measurand));
  4930. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase) > 0)
  4931. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Phase));
  4932. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location) > 0)
  4933. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Location));
  4934. if(strlen((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit) > 0)
  4935. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].SampledValue[idxSample].Unit));
  4936. json_object_array_add(sampledValues, sampledValue);
  4937. }
  4938. }
  4939. json_object_object_add(MeterValue, "timestamp", json_object_new_string((char*)ShmOCPP16Data->MeterValues[gun_index].MeterValue[idxMeter].TimeStamp));
  4940. json_object_object_add(MeterValue, "sampledValue", sampledValues);
  4941. json_object_array_add(MeterValues, MeterValue);
  4942. }
  4943. json_object_object_add(MeterValueReq, "meterValue", MeterValues);
  4944. sprintf(queuedata,"%d,[%d,\"%s\",\"MeterValues\",%s]"
  4945. ,gun_index + 1
  4946. ,MESSAGE_TYPE_CALL
  4947. ,guid
  4948. ,json_object_to_json_string_ext(MeterValueReq, JSON_C_TO_STRING_PLAIN));
  4949. json_object_put(MeterValueReq);
  4950. }
  4951. // Put request guid to hash map
  4952. sprintf(tempdata, "MeterValues,%d", (gun_index));
  4953. 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*/)
  4954. {
  4955. result = PASS;
  4956. //DEBUG_INFO("MeterValues mapitem pass\n");
  4957. }
  4958. if((dataType != ReadingContext_Trigger) &&
  4959. (dataType != ReadingContext_Sample_Clock) &&
  4960. (ShmOCPP16Data->MeterValues[gun_index].TransactionId != -1))
  4961. queue_operation(QUEUE_OPERATION_ADD, guid, queuedata );
  4962. else
  4963. {
  4964. if(FirstHeartBeat)
  4965. LWS_Send(queuedata +2);
  4966. }
  4967. return result;
  4968. }
  4969. //==========================================
  4970. // send confirm routine
  4971. //==========================================
  4972. int sendCancelReservationConfirmation(char *uuid,char *payload)
  4973. {
  4974. mtrace();
  4975. int result = FAIL;
  4976. char message[100]={0};
  4977. DEBUG_INFO("sendCancelReservationConfirmation...\n");
  4978. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4979. LWS_Send(message);
  4980. result = TRUE;
  4981. ShmOCPP16Data->CsMsg.bits[0].CancelReservationConf = 0;
  4982. return result;
  4983. }
  4984. int sendChangeAvailabilityConfirmation(char *uuid,char *payload)
  4985. {
  4986. mtrace();
  4987. int result = FAIL;
  4988. char message[100]={0};
  4989. DEBUG_INFO("sendChangeAvailabilityConfirmation...\n");
  4990. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  4991. LWS_Send(message);
  4992. result = TRUE;
  4993. return result;
  4994. }
  4995. int sendChangeConfigurationConfirmation(char *uuid,char *payload)
  4996. {
  4997. mtrace();
  4998. int result = FAIL;
  4999. char message[100]={0};
  5000. DEBUG_INFO("sendChangeConfigurationConfirmation...\n");
  5001. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT,uuid, payload);
  5002. LWS_Send(message);
  5003. result = TRUE;
  5004. return result;
  5005. }
  5006. int sendClearCacheConfirmation(char *uuid,char *payload)
  5007. {
  5008. mtrace();
  5009. int result = FAIL;
  5010. char message[500]={0};
  5011. DEBUG_INFO("sendClearCacheConfirmation...\n");
  5012. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5013. LWS_Send(message);
  5014. return result;
  5015. }
  5016. int sendClearChargingProfileConfirmation(char *uuid,char *payload)
  5017. {
  5018. mtrace();
  5019. int result = FAIL;
  5020. char message[500]={0};
  5021. DEBUG_INFO("sendClearChargingProfileConfirmation...\n");
  5022. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5023. LWS_Send(message);
  5024. return result;
  5025. }
  5026. int sendDataTransferConfirmation(char *uuid,char *payload)
  5027. {
  5028. mtrace();
  5029. char statusStr[20]={0};
  5030. char dataStr[10]={0};
  5031. char sstr[20]={0};
  5032. int c = 0;
  5033. char *loc;
  5034. int result = FAIL;
  5035. DEBUG_INFO("sendDataTransferConfirmation...\n");
  5036. /**********************status**************************/
  5037. loc = strstr(payload, "status");
  5038. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5039. c = 0;
  5040. while (loc[3+strlen("status")+c] != '\"')
  5041. {
  5042. sstr[c] = loc[3+strlen("status")+c];
  5043. c++;
  5044. }
  5045. sstr[c] = '\0';
  5046. strcpy(statusStr, sstr);
  5047. /**********************data**************************/
  5048. loc = strstr(payload, "data");
  5049. memset(sstr ,0, ARRAY_SIZE(sstr) );
  5050. c = 0;
  5051. while (loc[3+strlen("data")+c] != '\"')
  5052. {
  5053. sstr[c] = loc[3+strlen("data")+c];
  5054. c++;
  5055. }
  5056. sstr[c] = '\0';
  5057. strcpy(dataStr, sstr);
  5058. return result;
  5059. }
  5060. int sendGetCompositeScheduleConfirmation(char *uuid, char *payload, int connectorIdInt, int nPeriod)
  5061. {
  5062. mtrace();
  5063. int result = FAIL;
  5064. char message[1000]={0};
  5065. int CompositeScheduleIndex = 0;
  5066. DEBUG_INFO("sendGetCompositeScheduleConfirmation...\n");
  5067. CompositeScheduleIndex = (connectorIdInt > 0) ?(connectorIdInt -1) : 0;
  5068. if(nPeriod == 0)
  5069. {
  5070. if(strcmp((const char *)ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule,"")==0)
  5071. {
  5072. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d}]"
  5073. ,MESSAGE_TYPE_CALLRESULT
  5074. ,uuid
  5075. ,payload
  5076. ,connectorIdInt);
  5077. }
  5078. else
  5079. {
  5080. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":[{\"startPeriod\":0,\"limit\":%d,\"numberPhases\":3}]}}]"
  5081. ,MESSAGE_TYPE_CALLRESULT
  5082. ,uuid
  5083. ,payload
  5084. ,connectorIdInt
  5085. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5086. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5087. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5088. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit
  5089. ,(ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent==0?ShmSysConfigAndInfo->SysConfig.RatingCurrent:ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent));
  5090. }
  5091. }
  5092. else
  5093. {
  5094. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"connectorId\":%d,\"scheduleStart\":\"%s\",\"chargingSchedule\":{\"duration\":%d,\"startSchedule\":\"%s\",\"chargingRateUnit\":\"%s\",\"chargingSchedulePeriod\":["
  5095. ,MESSAGE_TYPE_CALLRESULT
  5096. ,uuid
  5097. ,payload
  5098. ,connectorIdInt
  5099. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5100. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.Duration
  5101. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.StartSchedule
  5102. ,ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingRateUnit);
  5103. for(int idx_sample=0;idx_sample< nPeriod;idx_sample++)
  5104. {
  5105. if (idx_sample == 0)
  5106. {
  5107. sprintf(message + strlen(message), "{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5108. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5109. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5110. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5111. }
  5112. else
  5113. {
  5114. sprintf(message + strlen(message), ",{\"startPeriod\":%d,\"limit\":%.1f,\"numberPhases\":%d}"
  5115. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].StartPeriod
  5116. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].Limit
  5117. , ShmOCPP16Data->GetCompositeSchedule[CompositeScheduleIndex].ResponseChargingSchedule.ChargingSchedulePeriod[idx_sample].NumberPhases );
  5118. }
  5119. }
  5120. sprintf(message + strlen(message), "]}}]");
  5121. }
  5122. LWS_Send(message);
  5123. result = TRUE;
  5124. return result;
  5125. }
  5126. int sendGetConfigurationConfirmation(char *uuid)
  5127. {
  5128. mtrace();
  5129. int result = FAIL;
  5130. int MaxKeySupported = 0;
  5131. int sentConfigurationNumber= 0;
  5132. int sentunConfigurationNumber= 0;
  5133. char message[4000]={0};
  5134. DEBUG_INFO("sendGetConfigurationConfirmation...\n");
  5135. MaxKeySupported = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  5136. //DEBUG_INFO("MaxKeySupported=%d\n",MaxKeySupported);
  5137. sprintf(message,"[%d,\"%s\",{\"configurationKey\":["
  5138. ,MESSAGE_TYPE_CALLRESULT
  5139. ,uuid );
  5140. //configuration key
  5141. for(int idx_sample=0;idx_sample< MaxKeySupported/*43*/;idx_sample++)
  5142. {
  5143. if(strcmp((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key, "")!= 0)
  5144. {
  5145. if (sentConfigurationNumber == 0)
  5146. {
  5147. sprintf(message + strlen(message), "{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5148. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5149. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5150. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5151. }
  5152. else
  5153. {
  5154. sprintf(message + strlen(message), ", {\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}"
  5155. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Key
  5156. , atoi((const char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].ReadOnly) == 1 ? "true":"false"
  5157. , ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[idx_sample].Value );
  5158. }
  5159. sentConfigurationNumber = sentConfigurationNumber + 1;
  5160. }
  5161. }
  5162. sprintf(message + strlen(message), "]");
  5163. if(UnknownKeynum != 0)
  5164. {
  5165. sprintf(message + strlen(message), ",\"unknownKey\":[");
  5166. //unkown key
  5167. for(int idx_sample=0;idx_sample< UnknownKeynum ;idx_sample++)
  5168. {
  5169. // json_object *jstring1 = json_object_new_string((const char *)((ShmOCPP16Data->GetConfiguration.ResponseUnknownKey + idx_sample)->Item));
  5170. DEBUG_INFO("unkown key:%s\n", ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item);
  5171. if(sentunConfigurationNumber == 0)
  5172. {
  5173. sprintf(message + strlen(message), "\"%s\""
  5174. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5175. }
  5176. else
  5177. {
  5178. sprintf(message + strlen(message), ",\"%s\""
  5179. , ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[idx_sample].Item );
  5180. }
  5181. sentunConfigurationNumber = sentunConfigurationNumber + 1;
  5182. }
  5183. sprintf(message + strlen(message), "]");
  5184. }
  5185. sprintf(message + strlen(message), "}]");
  5186. LWS_Send(message);
  5187. return result;
  5188. }
  5189. int sendGetDiagnosticsConfirmation(char *uuid,char *payload)
  5190. {
  5191. mtrace();
  5192. int result = FAIL;
  5193. char message[400]={0};
  5194. DEBUG_INFO("sendGetDiagnosticsConfirmation...\n");
  5195. if(strcmp(payload,"")==0)
  5196. {
  5197. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5198. }
  5199. else
  5200. {
  5201. sprintf(message,"[%d,\"%s\",{\"fileName\":\"%s\"}]", MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5202. }
  5203. LWS_Send(message);
  5204. result = TRUE;
  5205. return result;
  5206. }
  5207. int sendGetLocalListVersionConfirmation(char *uuid,char *payload)
  5208. {
  5209. mtrace();
  5210. int result = FAIL;
  5211. char message[80]={0};
  5212. DEBUG_INFO("sendGetLocalListVersionConfirmation...\n");
  5213. sprintf(message,"[%d,\"%s\",{\"listVersion\":%d}]",MESSAGE_TYPE_CALLRESULT, uuid, ShmOCPP16Data->GetLocalListVersion.ResponseListVersion);
  5214. LWS_Send(message);
  5215. result = TRUE;
  5216. return result;
  5217. }
  5218. int sendRemoteStartConfirmation(char *uuid,char *payload)
  5219. {
  5220. mtrace();
  5221. int result = FAIL;
  5222. char message[80]={0};
  5223. DEBUG_INFO("sendRemoteStartConfirmation...\n");
  5224. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5225. LWS_Send(message);
  5226. result = TRUE;
  5227. return result;
  5228. }
  5229. int sendRemoteStopTransactionConfirmation(char *uuid,char *payload)
  5230. {
  5231. mtrace();
  5232. int result = FAIL;
  5233. char message[80]={0};
  5234. DEBUG_INFO("sendRemoteStopTransactionConfirmation...\n");
  5235. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5236. LWS_Send(message);
  5237. result = TRUE;
  5238. return result;
  5239. }
  5240. int sendReserveNowTransactionConfirmation(char *uuid,char *payload)
  5241. {
  5242. mtrace();
  5243. int result = FAIL;
  5244. char message[80]={0};
  5245. // [3,"287d837d-809e-41ea-8385-fdab7f72a01c",{"status":"Accepted"}]
  5246. DEBUG_INFO("sendReserveNowTransactionConfirmation...\n");
  5247. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5248. LWS_Send(message);
  5249. result = TRUE;
  5250. return result;
  5251. }
  5252. int sendResetConfirmation(char *uuid,char *payload)
  5253. {
  5254. mtrace();
  5255. int result = FAIL;
  5256. //[ 3, "6f88d461-4d17-462c-a69b-1f7a8c5b12df", { "status": 0 } ]
  5257. char message[80]={0};
  5258. ShmOCPP16Data->MsMsg.bits.ResetConf = 0;
  5259. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5260. LWS_Send(message);
  5261. result = TRUE;
  5262. return result;
  5263. }
  5264. int sendSendLocalListConfirmation(char *uuid,char *payload)
  5265. {
  5266. mtrace();
  5267. int result = FAIL;
  5268. char message[500]={0};
  5269. // [ 3, "1571284266109", { "status": "Accepted" } ]
  5270. sprintf(message,"[%d,\"%s\",{\"%s\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "status", payload);
  5271. LWS_Send(message);
  5272. result = TRUE;
  5273. return result;
  5274. }
  5275. int sendSetChargingProfileConfirmation(char *uuid,char *payload)
  5276. {
  5277. mtrace();
  5278. int result = FAIL;
  5279. //[3,"5748585f-8524-4fa6-9b4f-4a7eca750b90",{"status":"NotSupported"}]
  5280. char message[80]={0};
  5281. DEBUG_INFO("sendSetChargingProfileConfirmation...\n");
  5282. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5283. LWS_Send(message);
  5284. result = TRUE;
  5285. return result;
  5286. }
  5287. int sendTriggerMessageConfirmation(char *uuid,char *payload)
  5288. {
  5289. mtrace();
  5290. int result = FAIL;
  5291. char message[80]={0};
  5292. DEBUG_INFO("sendTriggerMessageConfirmation...\n");
  5293. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5294. LWS_Send(message);
  5295. result = TRUE;
  5296. return result;
  5297. }
  5298. int sendUnlockConnectorConfirmation(char *uuid,char *payload)
  5299. {
  5300. mtrace();
  5301. int result = FAIL;
  5302. char message[80]={0};
  5303. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5304. DEBUG_INFO("sendUnlockConnectorConfirmation...\n");
  5305. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, payload);
  5306. LWS_Send(message);
  5307. result = TRUE;
  5308. return result;
  5309. }
  5310. int sendUpdateFirmwareConfirmation(char *uuid)
  5311. {
  5312. mtrace();
  5313. int result = FAIL;
  5314. char message[60]={0};
  5315. //[ 3, "ba1cbd49-2a76-493a-8f76-fa23e7606532", { "status": "Unlocked" } ]
  5316. DEBUG_INFO("sendUpdateFirmwareConfirmation...\n");
  5317. sprintf(message,"[%d,\"%s\",{}]",MESSAGE_TYPE_CALLRESULT, uuid);
  5318. LWS_Send(message);
  5319. result = TRUE;
  5320. return result;
  5321. }
  5322. //==========================================
  5323. // send CallError routine
  5324. //==========================================
  5325. void SendCallError(char *uniqueId, char *action, char *errorCode, char *errorDescription)
  5326. {
  5327. mtrace();
  5328. char message[220]={0};
  5329. DEBUG_INFO("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}\n", uniqueId, action, errorCode, errorDescription);
  5330. sprintf(message,"[%d,\"%s\",\"%s\",\"%s\",{}]",MESSAGE_TYPE_CALLERROR, uniqueId, errorCode, errorDescription);
  5331. LWS_Send(message);
  5332. }
  5333. //==========================================
  5334. // Handle server request routine Start
  5335. //==========================================
  5336. int handleCancelReservationRequest(char *uuid, char *payload)
  5337. {
  5338. mtrace();
  5339. int result = FAIL;
  5340. int gunNO = 0;
  5341. int reservationIdInt = -1;
  5342. char comfirmstr[20];
  5343. DEBUG_INFO("handleCancelReservationRequest...\n");
  5344. json_object *CancelReservation;
  5345. CancelReservation = json_tokener_parse(payload);
  5346. if(!is_error(CancelReservation))
  5347. {
  5348. // Required data
  5349. if(json_object_object_get(CancelReservation, "reservationId") != NULL)
  5350. reservationIdInt = json_object_get_int(json_object_object_get(CancelReservation, "reservationId"));
  5351. }
  5352. json_object_put(CancelReservation);
  5353. DEBUG_INFO("reservationIdInt = %d\n", reservationIdInt);
  5354. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5355. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Rejected]);
  5356. if(reservationIdInt != -1)
  5357. {
  5358. //0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  5359. //check Transaction active
  5360. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  5361. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5362. {
  5363. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId == reservationIdInt)
  5364. {
  5365. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5366. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5367. if(gunType[2] == 'J')
  5368. {
  5369. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index + 1;
  5370. }
  5371. else
  5372. {
  5373. gunNO = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index;
  5374. }
  5375. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5376. goto end;
  5377. }
  5378. }
  5379. for (int index = 0; index < CCS_QUANTITY; index++)
  5380. {
  5381. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId == reservationIdInt)
  5382. {
  5383. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5384. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5385. if((gunType[2] == 'U') || (gunType[2] == 'E'))
  5386. {
  5387. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index + 1;
  5388. }
  5389. else
  5390. {
  5391. gunNO = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index;
  5392. }
  5393. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5394. goto end;
  5395. }
  5396. }
  5397. for (int index = 0; index < GB_QUANTITY; index++)
  5398. {
  5399. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId == reservationIdInt)
  5400. {
  5401. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5402. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5403. if(gunType[2] == 'G')
  5404. {
  5405. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index + 1;
  5406. }
  5407. else
  5408. {
  5409. gunNO = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index;
  5410. }
  5411. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5412. goto end;
  5413. }
  5414. }
  5415. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5416. {
  5417. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId == reservationIdInt)
  5418. {
  5419. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5420. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5421. if(gunType[2] == 'G')
  5422. {
  5423. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index + 1;
  5424. }
  5425. else
  5426. {
  5427. gunNO = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index;
  5428. }
  5429. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5430. goto end;
  5431. }
  5432. }
  5433. for (int index = 0; index < AC_QUANTITY; index++)
  5434. {
  5435. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId == reservationIdInt)
  5436. {
  5437. sprintf(comfirmstr, "%s", CancelReservationStatusStr[CancelReservationStatus_Accepted] );
  5438. sprintf((char *)ShmOCPP16Data->CancelReservation[ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index].ResponseStatus, "%s", comfirmstr );
  5439. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  5440. {
  5441. gunNO = 1; //ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index ;
  5442. }
  5443. else
  5444. {
  5445. gunNO = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index;
  5446. }
  5447. ShmOCPP16Data->CsMsg.bits[gunNO].CancelReservationReq = 1;
  5448. goto end;
  5449. }
  5450. }
  5451. }
  5452. //The reservationId does NOT match the reservationId
  5453. sendCancelReservationConfirmation(uuid, comfirmstr);
  5454. end:
  5455. // Fill in ocpp packet uuid
  5456. strcpy((char *)ShmOCPP16Data->CancelReservation[gunNO].guid, uuid);
  5457. return result;
  5458. }
  5459. int handleChangeAvailabilityRequest(char *uuid, char *payload)
  5460. {
  5461. mtrace();
  5462. int result = FAIL;
  5463. int gunIndex = 0;
  5464. char typeStr[16]={0};
  5465. char comfirmstr[20];
  5466. int specificId = FALSE;
  5467. DEBUG_INFO("handleChangeAvailabilityRequest...\n");
  5468. json_object *ChangeAvailability;
  5469. ChangeAvailability = json_tokener_parse(payload);
  5470. if(!is_error(ChangeAvailability))
  5471. {
  5472. // Required data
  5473. if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
  5474. gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
  5475. if(json_object_object_get(ChangeAvailability, "type") != NULL)
  5476. sprintf((char*)typeStr, "%s", json_object_get_string(json_object_object_get(ChangeAvailability, "type")));
  5477. }
  5478. json_object_put(ChangeAvailability);
  5479. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5480. {
  5481. ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
  5482. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
  5483. }
  5484. else if(gunIndex == 0)
  5485. {
  5486. for(int i=0; i < gunTotalNumber; i++)
  5487. {
  5488. ShmOCPP16Data->ChangeAvailability[i].ConnectorId= gunIndex;
  5489. sprintf((char *)ShmOCPP16Data->ChangeAvailability[i].Type, "%s", typeStr);
  5490. }
  5491. }
  5492. memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
  5493. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5494. if((gunIndex == 0) || (gunIndex <= gunTotalNumber))
  5495. {
  5496. specificId = TRUE;
  5497. }
  5498. if(specificId == FALSE)
  5499. goto end;
  5500. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Inoperative]) == 0)
  5501. {
  5502. //----------------------gunIndex is 0 ------------------------------------------------//
  5503. if(gunIndex == 0)
  5504. {
  5505. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5506. {
  5507. for(int i=0; i < gunTotalNumber; i++)
  5508. {
  5509. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5510. {
  5511. if ((gunType[i] == 'J')&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == i))
  5512. {
  5513. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5514. {
  5515. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5516. goto end;
  5517. }
  5518. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5519. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5520. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5521. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5522. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5523. {
  5524. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5525. goto end;
  5526. }
  5527. }
  5528. }//END FOR CHAdeMO_QUANTITY
  5529. for (int index = 0; index < CCS_QUANTITY; index++)
  5530. {
  5531. if (((gunType[i] == 'U')||(gunType[i] == 'E'))&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == i))
  5532. {
  5533. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)// S_PRECHARGE
  5534. {
  5535. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5536. goto end;
  5537. }
  5538. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5539. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5540. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5541. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5542. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5543. {
  5544. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5545. goto end;
  5546. }
  5547. }
  5548. }//END FOR CCS_QUANTITY
  5549. for (int index = 0; index < GB_QUANTITY; index++)
  5550. {
  5551. if ((gunType[i] == 'G')&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == i))
  5552. {
  5553. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5554. {
  5555. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5556. goto end;
  5557. }
  5558. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5559. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5560. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5561. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5562. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5563. {
  5564. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5565. goto end;
  5566. }
  5567. }
  5568. }// END FOR GB_QUANTITY
  5569. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5570. {
  5571. if ((gunType[i] == 'O')&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i))
  5572. {
  5573. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5574. {
  5575. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5576. goto end;
  5577. }
  5578. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5579. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5580. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5581. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5582. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5583. {
  5584. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5585. goto end;
  5586. }
  5587. }
  5588. }// END FOR GENERAL_GUN_QUANTITY
  5589. for (int index = 0; index < AC_QUANTITY; index++)
  5590. {
  5591. if (((gunType[i] > '0')&&(gunType[i] <= '9'))&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == i))
  5592. {
  5593. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5594. {
  5595. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5596. goto end;
  5597. }
  5598. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5599. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5600. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5601. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5602. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5603. {
  5604. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5605. goto end;
  5606. }
  5607. }
  5608. }//END FOR AC_QUANTITY
  5609. }// END FOR gunTotalNumber
  5610. }
  5611. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5612. {
  5613. for(int i=0; i < gunTotalNumber; i++)
  5614. {
  5615. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_RESERVATION) // S_PRECHARGE
  5616. {
  5617. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5618. goto end;
  5619. }
  5620. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5621. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_PREPARING) ||
  5622. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_CHARGING) ||
  5623. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_TERMINATING) ||
  5624. (ShmSysConfigAndInfo->SysInfo.AcChargingData[i].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5625. {
  5626. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5627. goto end;
  5628. }
  5629. }
  5630. }
  5631. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5632. goto end;
  5633. }
  5634. //----------------------gunIndex is not 0 ------------------------------------------------//
  5635. //check Transaction active
  5636. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5637. {
  5638. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'J'))
  5639. {
  5640. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) // S_PRECHARGE
  5641. {
  5642. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5643. goto end;
  5644. }
  5645. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5646. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5647. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5648. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5649. (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5650. {
  5651. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5652. goto end;
  5653. }
  5654. else
  5655. {
  5656. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.ChademoChargingData[%d].SystemStatus = %d\n",index, ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus);
  5657. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5658. goto end;
  5659. }
  5660. }
  5661. }//END FOR CHAdeMO_QUANTITY
  5662. for (int index = 0; index < CCS_QUANTITY; index++)
  5663. {
  5664. if ((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E')))
  5665. {
  5666. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION) )// S_PRECHARGE
  5667. {
  5668. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5669. goto end;
  5670. }
  5671. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5672. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5673. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5674. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5675. (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5676. {
  5677. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5678. goto end;
  5679. }
  5680. else
  5681. {
  5682. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.CcsChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus);
  5683. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5684. goto end;
  5685. }
  5686. }
  5687. }//END FOR CCS_QUANTITY
  5688. for (int index = 0; index < GB_QUANTITY; index++)
  5689. {
  5690. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))
  5691. {
  5692. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5693. {
  5694. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5695. goto end;
  5696. }
  5697. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5698. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5699. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5700. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5701. (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5702. {
  5703. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5704. goto end;
  5705. }
  5706. else
  5707. {
  5708. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus);
  5709. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5710. goto end;
  5711. }
  5712. }
  5713. }// END FOR GB_QUANTITY
  5714. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5715. {
  5716. if ((gunIndex > 0)&&(gunType[gunIndex-1] == 'O'))
  5717. {
  5718. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5719. {
  5720. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5721. goto end;
  5722. }
  5723. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_AUTHORIZING) ||
  5724. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) ||
  5725. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) ||
  5726. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING) ||
  5727. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5728. {
  5729. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5730. goto end;
  5731. }
  5732. else
  5733. {
  5734. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.GbChargingData[%d].SystemStatus=%d\n",index,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus);
  5735. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5736. goto end;
  5737. }
  5738. }
  5739. }// END FOR GENERAL_GUN_QUANTITY
  5740. for (int index = 0; index < AC_QUANTITY; index++)
  5741. {
  5742. if ((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9')))
  5743. {
  5744. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) // S_PRECHARGE
  5745. {
  5746. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5747. goto end;
  5748. }
  5749. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_AUTHORIZING) ||
  5750. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) ||
  5751. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) ||
  5752. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ||
  5753. (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_COMPLETE)) // S_CHARGING
  5754. {
  5755. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Scheduled] );
  5756. goto end;
  5757. }
  5758. else
  5759. {
  5760. DEBUG_INFO("ShmSysConfigAndInfo->SysInfo.AcChargingData[%d].SystemStatus=%d\n",index, ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus);
  5761. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5762. goto end;
  5763. }
  5764. }
  5765. }//END FOR AC_QUANTITY
  5766. }//END FOR AvailabilityTypeStr[Inoperative]
  5767. if(strcmp((const char *)typeStr, AvailabilityTypeStr[Operative]) == 0)
  5768. {
  5769. //----------------------gunIndex is 0 ------------------------------------------------//
  5770. if(gunIndex == 0)
  5771. {
  5772. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  5773. {
  5774. for(int i=0; i < gunTotalNumber; i++)
  5775. {
  5776. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5777. {
  5778. 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
  5779. {
  5780. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5781. goto end;
  5782. }
  5783. }//END FOR CHAdeMO_QUANTITY
  5784. for (int index = 0; index < CCS_QUANTITY; index++)
  5785. {
  5786. 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
  5787. {
  5788. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5789. goto end;
  5790. }
  5791. }//END FOR CCS_QUANTITY
  5792. for (int index = 0; index < GB_QUANTITY; index++)
  5793. {
  5794. 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
  5795. {
  5796. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5797. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5798. goto end;
  5799. }
  5800. }// END FOR GB_QUANTITY
  5801. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5802. {
  5803. if ((gunType[i] == 'O')&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == i)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_FAULT)) //S_FAULT //(((gunIndex == 0)|| ((gunIndex > 0)&&(gunType[gunIndex-1] == 'O')))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5804. {
  5805. //ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5806. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5807. goto end;
  5808. }
  5809. }// END FOR GENERAL_GUN_QUANTITY
  5810. for (int index = 0; index < AC_QUANTITY; index++)
  5811. {
  5812. 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
  5813. {
  5814. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5815. goto end;
  5816. }
  5817. }//END FOR CHAdeMO_QUANTITY
  5818. }// END FOR gunTotalNumber
  5819. }
  5820. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  5821. {
  5822. for(int i=0; i < gunTotalNumber; i++)
  5823. {
  5824. for (int index = 0; index < AC_QUANTITY; index++)
  5825. {
  5826. 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
  5827. {
  5828. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
  5829. goto end;
  5830. }
  5831. }//END FOR CHAdeMO_QUANTITY
  5832. } // END FOR gunTotalNumber
  5833. }
  5834. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5835. goto end;
  5836. }
  5837. //----------------------gunIndex is not 0 ------------------------------------------------//
  5838. //check Transaction active
  5839. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  5840. {
  5841. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'J') ) &&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5842. {
  5843. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5844. goto end;
  5845. }
  5846. }//END FOR CHAdeMO_QUANTITY
  5847. for (int index = 0; index < CCS_QUANTITY; index++)
  5848. {
  5849. if ((((gunIndex > 0)&&((gunType[gunIndex - 1] == 'U')||(gunType[gunIndex - 1] == 'E'))) )&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5850. {
  5851. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5852. goto end;
  5853. }
  5854. }//END FOR CCS_QUANTITY
  5855. for (int index = 0; index < GB_QUANTITY; index++)
  5856. {
  5857. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'G'))&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5858. {
  5859. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5860. goto end;
  5861. }
  5862. }// END FOR GB_QUANTITY
  5863. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  5864. {
  5865. if (((gunIndex > 0)&&(gunType[gunIndex-1] == 'O'))&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5866. {
  5867. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5868. goto end;
  5869. }
  5870. }// END FOR GENERAL_GUN_QUANTITY
  5871. for (int index = 0; index < AC_QUANTITY; index++)
  5872. {
  5873. if (((gunIndex > 0)&&((gunType[gunIndex-1] > '0')&&(gunType[gunIndex-1] <= '9'))) &&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)) //S_FAULT
  5874. {
  5875. sprintf(comfirmstr, "%s", AvailabilityStatusStr[Accepted] );
  5876. goto end;
  5877. }
  5878. }//END FOR AC_QUANTITY
  5879. }//END FOR AvailabilityTypeStr[Operative]
  5880. end:
  5881. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5882. {
  5883. sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ResponseStatus, "%s", comfirmstr );
  5884. }
  5885. else
  5886. {
  5887. sprintf((char *)ShmOCPP16Data->ChangeAvailability[0].ResponseStatus, "%s", comfirmstr );
  5888. }
  5889. if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
  5890. {
  5891. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5892. ShmOCPP16Data->CsMsg.bits[gunIndex - 1].ChangeAvailabilityReq = 1;
  5893. }
  5894. else if(gunIndex == 0)
  5895. {
  5896. if(strstr(comfirmstr, AvailabilityStatusStr[Rejected]) == NULL)
  5897. {
  5898. for(int i=0; i < gunTotalNumber/*(CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY)*/; i++)
  5899. ShmOCPP16Data->CsMsg.bits[i].ChangeAvailabilityReq = 1;
  5900. }
  5901. }
  5902. sendChangeAvailabilityConfirmation(uuid, comfirmstr);
  5903. return result;
  5904. }
  5905. int handleChangeConfigurationRequest(char *uuid, char *payload)
  5906. {
  5907. mtrace();
  5908. int result = FAIL;
  5909. char keystr[40]={0};
  5910. char valuestr[100]={0};
  5911. char comfirmstr[20]={0};
  5912. DEBUG_INFO("handleChangeConfigurationRequest...\n");
  5913. json_object *ChangeConfiguration;
  5914. ChangeConfiguration = json_tokener_parse(payload);
  5915. if(!is_error(ChangeConfiguration))
  5916. {
  5917. // Required data
  5918. if(json_object_object_get(ChangeConfiguration, "key") != NULL)
  5919. sprintf((char*)keystr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "key")));
  5920. if(json_object_object_get(ChangeConfiguration, "value") != NULL)
  5921. sprintf((char*)valuestr, "%s", json_object_get_string(json_object_object_get(ChangeConfiguration, "value")));
  5922. }
  5923. json_object_put(ChangeConfiguration);
  5924. if((uuid==NULL) || (payload ==NULL) )
  5925. {
  5926. DEBUG_ERROR("Payload is null\n");
  5927. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5928. }
  5929. else
  5930. {
  5931. int status = setKeyValue(keystr, valuestr);
  5932. switch(status)
  5933. {
  5934. case ConfigurationStatus_Accepted:
  5935. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Accepted]);
  5936. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationReq = 1;
  5937. StoreConfigurationTable();
  5938. break;
  5939. case RebootRequired:
  5940. sprintf(comfirmstr, "%s", ConfigurationStatusStr[RebootRequired]);
  5941. StoreConfigurationTable();
  5942. break;
  5943. case NotSupported:
  5944. sprintf(comfirmstr, "%s", ConfigurationStatusStr[NotSupported] );
  5945. break;
  5946. case ConfigurationStatus_Rejected:
  5947. default:
  5948. sprintf(comfirmstr, "%s", ConfigurationStatusStr[ConfigurationStatus_Rejected] );
  5949. break;
  5950. }
  5951. }
  5952. sendChangeConfigurationConfirmation(uuid, comfirmstr);
  5953. ShmOCPP16Data->MsMsg.bits.ChangeConfigurationConf = 1;
  5954. if((strcmp(keystr,"WebSocketPingInterval")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5955. {
  5956. ChageWebSocketPingInterval(atoi(valuestr));
  5957. }
  5958. if((strcmp(keystr,"SecurityProfile")==0)&&(strcmp(comfirmstr,"Accepted")==0))
  5959. {
  5960. ShmSysConfigAndInfo->SysInfo.InternetConn = 0;
  5961. }
  5962. return result;
  5963. }
  5964. int handleClearCacheRequest(char *uuid, char *payload)
  5965. {
  5966. mtrace();
  5967. int result = FAIL;
  5968. char comfirmstr[20];
  5969. char rmFileCmd[100]={0};
  5970. struct stat stats;
  5971. DEBUG_INFO("handleClearCacheRequest...\n");
  5972. stat("/Storage/OCPP", &stats);
  5973. // Check for directory existence
  5974. if (S_ISDIR(stats.st_mode) == 1)
  5975. {}
  5976. else
  5977. {
  5978. DEBUG_INFO("\n OCPP directory not exist, create dir \n");
  5979. sprintf(rmFileCmd,"mkdir -p %s","/Storage/OCPP");
  5980. system(rmFileCmd);
  5981. }
  5982. if(OCPP_cleanLocalCache())
  5983. {
  5984. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Accepted] );
  5985. }
  5986. else
  5987. {
  5988. sprintf(comfirmstr, "%s", ClearCacheStatusStr[ClearCacheStatus_Rejected] );
  5989. }
  5990. sendClearCacheConfirmation(uuid, comfirmstr);
  5991. return result;
  5992. }
  5993. int handleClearChargingProfileRequest(char *uuid, char *payload)
  5994. {
  5995. mtrace();
  5996. int result = FAIL;
  5997. int resultRename;
  5998. int connectorIdInt, chargingProfileIdInt, stackLevelInt;
  5999. char chargingProfilePurposeStr[26]={0};
  6000. int tempconnectorIdInt, tempchargingProfileIdInt, tempstackLevelInt;
  6001. char tempchargingProfilePurposeStr[26]={0};
  6002. char str[100]={0};
  6003. char fname[200]={0};
  6004. char comfirmstr[20]={0};
  6005. char word[1600]={0};
  6006. int clearflag = FALSE;
  6007. int chargingProfileIdIsNULL = FALSE;
  6008. int connectorIsNULL = FALSE;
  6009. int chargingProfilePurposeIsNULL = FALSE;
  6010. int stackLevelIsNULL = FALSE;
  6011. //int GotoEnd = FALSE;
  6012. FILE *fptr1, *fptr2;
  6013. char temp[] = "/Storage/OCPP/ClearChargingProfiletemp.json"; // Create temp file
  6014. int n_chargingProfile=0;
  6015. int isEmptyFile = FALSE;
  6016. char sLineWord[1600]={0};
  6017. char chargingProfiles[10][100]={0};
  6018. int ChargeProfileCount = 0;
  6019. int ch;
  6020. connectorIdInt = chargingProfileIdInt = stackLevelInt = 0;
  6021. DEBUG_INFO("handleClearChargingProfileRequest...\n");
  6022. json_object *ClearChargingProfile;
  6023. ClearChargingProfile = json_tokener_parse(payload);
  6024. if(!is_error(ClearChargingProfile))
  6025. {
  6026. // Optional data
  6027. if(json_object_object_get(ClearChargingProfile, "id") != NULL)
  6028. chargingProfileIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "id"));
  6029. else
  6030. chargingProfileIdIsNULL = TRUE;
  6031. if(json_object_object_get(ClearChargingProfile, "connectorId") != NULL)
  6032. connectorIdInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "connectorId"));
  6033. else
  6034. connectorIsNULL = TRUE;
  6035. if(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose") != NULL)
  6036. sprintf((char*)chargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(ClearChargingProfile, "chargingProfilePurpose")));
  6037. else
  6038. chargingProfilePurposeIsNULL = TRUE;
  6039. if(json_object_object_get(ClearChargingProfile, "stackLevel") != NULL)
  6040. stackLevelInt = json_object_get_int(json_object_object_get(ClearChargingProfile, "stackLevel"));
  6041. else
  6042. stackLevelIsNULL = TRUE;
  6043. }
  6044. json_object_put(ClearChargingProfile);
  6045. if(connectorIsNULL == FALSE)
  6046. {
  6047. switch(connectorIdInt)
  6048. {
  6049. case 0:
  6050. if(chargingProfilePurposeIsNULL == TRUE)
  6051. {
  6052. int l = 0;
  6053. strcpy(fname, ChargePointMaxProfile_JSON);
  6054. if((access(fname,F_OK))!=-1)
  6055. {
  6056. strcpy(chargingProfiles[l], fname);
  6057. l = l + 1;
  6058. }
  6059. strcpy(fname, TxDefaultProfile_0_JSON);
  6060. if((access(fname,F_OK))!=-1)
  6061. {
  6062. strcpy(chargingProfiles[l], fname);
  6063. l = l + 1;
  6064. }
  6065. ChargeProfileCount = l;
  6066. }
  6067. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"ChargePointMaxProfile")==0))
  6068. {
  6069. strcpy(fname, ChargePointMaxProfile_JSON);
  6070. if((access(fname,F_OK))!=-1)
  6071. {
  6072. strcpy(chargingProfiles[0], fname);
  6073. ChargeProfileCount = 1;
  6074. }
  6075. }
  6076. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6077. {
  6078. strcpy(fname, TxDefaultProfile_0_JSON);
  6079. if((access(fname,F_OK))!=-1)
  6080. {
  6081. strcpy(chargingProfiles[0], fname);
  6082. ChargeProfileCount = 1;
  6083. }
  6084. }
  6085. break;
  6086. default:
  6087. if(chargingProfilePurposeIsNULL == TRUE)
  6088. {
  6089. int m = 0;
  6090. memset(fname, 0, ARRAY_SIZE(fname));
  6091. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6092. if((access(fname,F_OK))!=-1)
  6093. {
  6094. strcpy(chargingProfiles[m], fname);
  6095. m = m + 1;
  6096. }
  6097. memset(fname, 0, ARRAY_SIZE(fname));
  6098. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6099. if((access(fname,F_OK))!=-1)
  6100. {
  6101. strcpy(chargingProfiles[m], fname);
  6102. m = m + 1;
  6103. }
  6104. ChargeProfileCount = m;
  6105. }
  6106. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxDefaultProfile")==0))
  6107. {
  6108. //strcpy(fname, TxDefaultProfile_1_JSON);
  6109. sprintf(fname, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  6110. if((access(fname,F_OK))!=-1)
  6111. {
  6112. strcpy(chargingProfiles[0], fname);
  6113. ChargeProfileCount = 1;
  6114. }
  6115. }
  6116. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(chargingProfilePurposeStr,"TxProfile")==0))
  6117. {
  6118. sprintf(fname, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  6119. if((access(fname,F_OK))!=-1)
  6120. {
  6121. strcpy(chargingProfiles[0], fname);
  6122. ChargeProfileCount = 1;
  6123. }
  6124. //strcpy(fname, TxProfile_1_JSON);
  6125. }
  6126. //strcpy(fname, ChargePointMaxProfile_JSON );
  6127. break;
  6128. }
  6129. }
  6130. else // Check all Charging Profiles
  6131. {
  6132. int i = 0;
  6133. char fnametemp[200]={0};
  6134. ChargeProfileCount = 0;
  6135. //Check ChargePointMaxProfile.json exit
  6136. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  6137. {
  6138. strcpy(chargingProfiles[i], "/Storage/OCPP/ChargePointMaxProfile.json");
  6139. i = i + 1;
  6140. }
  6141. //Check TxDefaultProfile_0.json exit
  6142. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  6143. {
  6144. strcpy(chargingProfiles[i], "/Storage/OCPP/TxDefaultProfile_0.json");
  6145. i = i + 1;
  6146. }
  6147. //Check TxDefaultProfile_%d.json
  6148. for(int j=1; j <= gunTotalNumber; j++)
  6149. {
  6150. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6151. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  6152. if((access(fnametemp,F_OK))!=-1)
  6153. {
  6154. strcpy(chargingProfiles[i], fnametemp);
  6155. i = i + 1;
  6156. }
  6157. }
  6158. //Check TxProfile_%d.json
  6159. for(int j=1; j <= gunTotalNumber; j++)
  6160. {
  6161. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  6162. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  6163. if((access(fnametemp,F_OK))!=-1)
  6164. {
  6165. strcpy(chargingProfiles[i], fnametemp);
  6166. i = i + 1;
  6167. }
  6168. }
  6169. ChargeProfileCount = i;
  6170. }// End connectorIsNULL is TRUE
  6171. if(ChargeProfileCount == 0)
  6172. {
  6173. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6174. goto end;
  6175. }
  6176. if(connectorIsNULL == FALSE && (connectorIdInt != 0) && ( (connectorIdInt-1) > gunTotalNumber) )
  6177. {
  6178. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6179. goto end;
  6180. }
  6181. if((connectorIsNULL == FALSE) && (connectorIdInt == 0) )
  6182. {
  6183. memset(str, 0, ARRAY_SIZE(str));
  6184. // clear temp file
  6185. sprintf(str,"rm -f %s",temp);
  6186. system(str);
  6187. for(int k=0; k < ChargeProfileCount; k++)
  6188. {
  6189. memset(str, 0, ARRAY_SIZE(str));
  6190. //clear file in C
  6191. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6192. system(str);
  6193. }
  6194. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6195. goto end;
  6196. }
  6197. else if(connectorIsNULL == TRUE)
  6198. {
  6199. for(int k=0; k < ChargeProfileCount; k++)
  6200. {
  6201. fptr1 = fopen(chargingProfiles[k], "r");
  6202. fptr2 = fopen("/Storage/OCPP/ClearChargingProfiletemp.json", "w+");
  6203. //Check Charging Profile Count
  6204. while(fscanf(fptr1, "%s", word) != EOF)
  6205. {
  6206. //DEBUG_INFO("word=%s\n",word);
  6207. if(strstr(word, "chargingProfileId")!= NULL)
  6208. {
  6209. //DEBUG_INFO("test chargingProfileId \n");
  6210. n_chargingProfile = n_chargingProfile + 1;
  6211. //DEBUG_INFO("chargingProfileId Found\n");
  6212. }
  6213. }
  6214. rewind(fptr1);
  6215. //search Charging Profile Element
  6216. //int i= 0;
  6217. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6218. {
  6219. json_object *tmpProfilee;
  6220. tmpProfilee = json_tokener_parse(sLineWord);
  6221. if(!is_error(tmpProfilee))
  6222. {
  6223. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6224. {
  6225. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6226. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6227. }
  6228. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6229. {
  6230. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6231. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6232. }
  6233. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6234. {
  6235. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6236. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6237. }
  6238. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6239. {
  6240. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6241. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6242. }
  6243. }
  6244. json_object_put(tmpProfilee);
  6245. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6246. {
  6247. //------- not write to fptr2-------//
  6248. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6249. //clearflag = TRUE;
  6250. }
  6251. else if((chargingProfilePurposeIsNULL == FALSE)&&(strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  6252. {
  6253. //------- not write to fptr2-------//
  6254. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6255. }
  6256. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6257. {
  6258. //------- not write to fptr2-------//
  6259. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6260. }
  6261. else if(chargingProfileIdIsNULL && chargingProfilePurposeIsNULL && stackLevelIsNULL)
  6262. {
  6263. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6264. }
  6265. else
  6266. {
  6267. fprintf(fptr2, sLineWord);//writing data into file
  6268. }
  6269. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6270. } //End of while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6271. if(clearflag == TRUE)
  6272. {
  6273. fclose(fptr1);
  6274. fclose(fptr2);
  6275. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6276. system(str);
  6277. // clear temp file
  6278. sprintf(str,"rm -f %s",temp);
  6279. system(str);
  6280. }
  6281. else
  6282. {
  6283. fclose(fptr1);
  6284. fclose(fptr2);
  6285. memset(str, 0, ARRAY_SIZE(str));
  6286. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6287. system(str);
  6288. resultRename = rename(temp, chargingProfiles[k]);
  6289. if(resultRename == 0)
  6290. {
  6291. DEBUG_INFO("File ChargingProfile renamed successfully\n");
  6292. }
  6293. else
  6294. {
  6295. DEBUG_INFO("Error: unable to rename the ChargingProfile file\n");
  6296. }
  6297. if(comfirmstr[0]== 0)
  6298. {
  6299. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6300. }
  6301. //Check chargingProfile is empty file
  6302. /*------ Read the file ----------------*/
  6303. fptr1=fopen(chargingProfiles[k],"r");
  6304. ch=fgetc(fptr1);
  6305. rewind(fptr1);
  6306. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6307. if(ch!=EOF)
  6308. {
  6309. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6310. {
  6311. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6312. if(sLineWord[0]=='\0')
  6313. {
  6314. isEmptyFile = TRUE;
  6315. break;
  6316. }
  6317. else
  6318. {
  6319. isEmptyFile = FALSE;
  6320. break;
  6321. }
  6322. }
  6323. }
  6324. else
  6325. isEmptyFile = TRUE;
  6326. fclose(fptr1);
  6327. if(isEmptyFile == TRUE)
  6328. {
  6329. memset(str, 0, ARRAY_SIZE(str));
  6330. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6331. system(str);
  6332. }
  6333. }
  6334. }// End of while(int k=0; k < ChargePointCount; k++)
  6335. }
  6336. else if((connectorIsNULL == FALSE) && (connectorIdInt != 0) )
  6337. {
  6338. DEBUG_INFO("ChargeProfileCount = %d\n", ChargeProfileCount);
  6339. for(int k=0; k < ChargeProfileCount; k++)
  6340. {
  6341. fptr1 = fopen(chargingProfiles[k], "r");
  6342. fptr2 = fopen(temp, "w+");
  6343. //Check Charging Profile Count
  6344. while(fscanf(fptr1, "%s", word) != EOF)
  6345. {
  6346. //DEBUG_INFO("word=%s\n",word);
  6347. if(strstr(word, "chargingProfileId")!= NULL)
  6348. {
  6349. n_chargingProfile = n_chargingProfile + 1;
  6350. }
  6351. }
  6352. rewind(fptr1);
  6353. //search Charging Profile Element
  6354. //int i= 0;
  6355. while ( fgets( sLineWord, sizeof sLineWord, fptr1 ) != NULL )
  6356. {
  6357. json_object *tmpProfilee;
  6358. tmpProfilee = json_tokener_parse(sLineWord);
  6359. if(!is_error(tmpProfilee))
  6360. {
  6361. if(json_object_object_get(tmpProfilee, "connectorId") != NULL)
  6362. {
  6363. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpProfilee, "connectorId"));
  6364. DEBUG_INFO("file's gun number: %d\n", tempconnectorIdInt);
  6365. }
  6366. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId") != NULL)
  6367. {
  6368. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfileId"));
  6369. DEBUG_INFO("file's chargingProfileId: %d\n", tempchargingProfileIdInt);
  6370. }
  6371. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel") != NULL)
  6372. {
  6373. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "stackLevel"));
  6374. DEBUG_INFO("file's stackLevel: %d\n", tempstackLevelInt);
  6375. }
  6376. if(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  6377. {
  6378. sprintf((char*)tempchargingProfilePurposeStr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(tmpProfilee, "csChargingProfiles"), "chargingProfilePurpose")));
  6379. DEBUG_INFO("file's chargingProfilePurpose: %s\n", tempchargingProfilePurposeStr);
  6380. }
  6381. }
  6382. json_object_put(tmpProfilee);
  6383. if((chargingProfileIdIsNULL == FALSE)&&(tempchargingProfileIdInt == chargingProfileIdInt))
  6384. {
  6385. //------- not write to fptr2-------//
  6386. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6387. //clearflag = TRUE;
  6388. }
  6389. else if((stackLevelIsNULL == FALSE) &&(tempstackLevelInt == stackLevelInt))
  6390. {
  6391. //------- not write to fptr2-------//
  6392. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6393. }
  6394. else if(stackLevelIsNULL == TRUE)
  6395. {
  6396. //Clear Whole File
  6397. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted] );
  6398. clearflag = TRUE;
  6399. break;
  6400. }
  6401. else
  6402. {
  6403. fprintf(fptr2, sLineWord);//writing data into file
  6404. }
  6405. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6406. }
  6407. if(clearflag == TRUE)
  6408. {
  6409. fclose(fptr1);
  6410. fclose(fptr2);
  6411. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6412. system(str);
  6413. // clear temp file
  6414. sprintf(str,"rm -f %s",temp);
  6415. system(str);
  6416. }
  6417. else
  6418. {
  6419. fclose(fptr1);
  6420. fclose(fptr2);
  6421. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6422. system(str);
  6423. resultRename = rename(temp, chargingProfiles[k]);
  6424. if(resultRename == 0)
  6425. {
  6426. DEBUG_INFO("File ChargingProfile renamed successfully");
  6427. }
  6428. else
  6429. {
  6430. DEBUG_INFO("Error: unable to rename the ChargingProfile file");
  6431. }
  6432. if(comfirmstr[0]== 0)
  6433. {
  6434. sprintf(comfirmstr, "%s", ClearChargingProfileStatusStr[ClearChargingProfileStatus_Unknown] );
  6435. }
  6436. //Check chargingProfile is empty file
  6437. /*------ Read the file ----------------*/
  6438. fptr1=fopen(chargingProfiles[k],"r");
  6439. ch=fgetc(fptr1);
  6440. rewind(fptr1);
  6441. memset(sLineWord, 0, ARRAY_SIZE(sLineWord));
  6442. if(ch!=EOF)
  6443. {
  6444. while (fgets( sLineWord, sizeof sLineWord, fptr1) != NULL)
  6445. {
  6446. str[strlen(sLineWord) - 1] = '\0'; // eat the newline fgets() stores
  6447. if(sLineWord[0]=='\0')
  6448. {
  6449. isEmptyFile = TRUE;
  6450. break;
  6451. }
  6452. else
  6453. {
  6454. isEmptyFile = FALSE;
  6455. break;
  6456. }
  6457. }
  6458. }
  6459. else
  6460. isEmptyFile = TRUE;
  6461. fclose(fptr1);
  6462. if(isEmptyFile == TRUE)
  6463. {
  6464. memset(str, 0, ARRAY_SIZE(str));
  6465. sprintf(str,"rm -f %s",chargingProfiles[k]);
  6466. system(str);
  6467. }
  6468. /*------- End of reading ---------------*/
  6469. }
  6470. } // while(int k=0; k < ChargeProfileCount; k++)
  6471. }// (connectorIsNULL == FALSE) && (connectorIdInt != 0)
  6472. end:
  6473. if(strcmp(comfirmstr, ClearChargingProfileStatusStr[ClearChargingProfileStatus_Accepted]) == 0)
  6474. {
  6475. if(connectorIdInt == 0)
  6476. {
  6477. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  6478. {
  6479. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx]);
  6480. }
  6481. }
  6482. else
  6483. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1]);
  6484. }
  6485. sendClearChargingProfileConfirmation(uuid, comfirmstr);
  6486. return result;
  6487. }
  6488. void createFirmwareVersionByDataTransfer(void)
  6489. {
  6490. json_object *FirmwareDataTransfer = json_object_new_object();
  6491. // AC & DC model
  6492. json_object_object_add(FirmwareDataTransfer, "CsuBootLoadFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev));
  6493. json_object_object_add(FirmwareDataTransfer, "CsuKernelFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev));
  6494. json_object_object_add(FirmwareDataTransfer, "CsuRootFsFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev));
  6495. json_object_object_add(FirmwareDataTransfer, "CsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev));
  6496. // DC model
  6497. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D'))
  6498. {
  6499. json_object_object_add(FirmwareDataTransfer, "FanModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.FanModuleFwRev));
  6500. json_object_object_add(FirmwareDataTransfer, "RelayModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev));
  6501. json_object_object_add(FirmwareDataTransfer, "LedModuleFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.LedModuleFwRev));
  6502. json_object_object_add(FirmwareDataTransfer, "Connector1FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector1FwRev));
  6503. json_object_object_add(FirmwareDataTransfer, "PsuPrimFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuPrimFwRev));
  6504. json_object_object_add(FirmwareDataTransfer, "PsuSecFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.PsuSecFwRev));
  6505. }
  6506. if((ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') &&
  6507. ((gunType[1] != '0') || (gunType[2] != '0') || (gunType[3] != '0')))
  6508. {
  6509. json_object_object_add(FirmwareDataTransfer, "Connector2FwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysInfo.Connector2FwRev));
  6510. }
  6511. // 4G model
  6512. if((ShmSysConfigAndInfo->SysConfig.ModelName[10]=='T')||(ShmSysConfigAndInfo->SysConfig.ModelName[10]=='D'))
  6513. {
  6514. json_object_object_add(FirmwareDataTransfer, "TelcomModemFwRev", json_object_new_string((char*)ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomSoftwareVer));
  6515. }
  6516. sprintf((char*)ShmOCPP16Data->DataTransfer[0].VendorId, "Phihong Technology");
  6517. sprintf((char*)ShmOCPP16Data->DataTransfer[0].MessageId, "ID_FirmwareVersion");
  6518. sprintf((char*)ShmOCPP16Data->DataTransfer[0].Data, json_object_to_json_string_ext(FirmwareDataTransfer, JSON_C_TO_STRING_PLAIN));
  6519. json_object_put(FirmwareDataTransfer);
  6520. }
  6521. int handleDataTransferRequest(char *uuid, char *payload)
  6522. {
  6523. mtrace();
  6524. json_object *response = json_object_new_object();
  6525. int result = FAIL;
  6526. char tempvendorId[255]={0};
  6527. char tempmessageId[50]={0};
  6528. char tempdata[512]={0};
  6529. char message[2048]={0};
  6530. DEBUG_INFO("handleDataTransferRequest...\n");
  6531. if((uuid != NULL) && (payload != NULL))
  6532. {
  6533. json_object *DataTransfer;
  6534. DataTransfer = json_tokener_parse(payload);
  6535. if(!is_error(DataTransfer))
  6536. {
  6537. // Required data
  6538. if(json_object_object_get(DataTransfer, "vendorId") != NULL)
  6539. sprintf((char*)tempvendorId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "vendorId")));
  6540. // Optional data
  6541. if(json_object_object_get(DataTransfer, "messageId") != NULL)
  6542. sprintf((char*)tempmessageId, "%s", json_object_get_string(json_object_object_get(DataTransfer, "messageId")));
  6543. if(json_object_object_get(DataTransfer, "data") != NULL)
  6544. sprintf((char*)tempdata, "%s", json_object_get_string(json_object_object_get(DataTransfer, "data")));
  6545. result = PASS;
  6546. }
  6547. json_object_put(DataTransfer);
  6548. if(strstr(tempmessageId, "ID_FirmwareVersion") != NULL)
  6549. {
  6550. // Send all moudle firmware version on EVSE
  6551. system("/usr/bin/run_tmate_restart.sh");
  6552. createFirmwareVersionByDataTransfer();
  6553. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6554. json_object_object_add(response, "data", json_object_new_string((char*)ShmOCPP16Data->DataTransfer[0].Data));
  6555. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6556. json_object_put(response);
  6557. }
  6558. else if(strstr(tempmessageId, "SetLEDBar") != NULL)
  6559. {
  6560. json_object *data;
  6561. data = json_tokener_parse(tempdata);
  6562. if(!is_error(data))
  6563. {
  6564. ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity = json_object_get_int(json_object_object_get(data, "Intensity"));
  6565. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "R"));
  6566. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[0]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "G"));
  6567. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[0] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Idle"), "B"));
  6568. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "R"));
  6569. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[1]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "G"));
  6570. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[1] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Charging"), "B"));
  6571. ShmSysConfigAndInfo->SysConfig.LedInfo.Red[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "R"));
  6572. ShmSysConfigAndInfo->SysConfig.LedInfo.Green[2]= json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "G"));
  6573. ShmSysConfigAndInfo->SysConfig.LedInfo.Blue[2] = json_object_get_int(json_object_object_get(json_object_object_get(data, "Fault"), "B"));
  6574. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6575. }
  6576. else
  6577. {
  6578. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6579. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6580. }
  6581. json_object_put(data);
  6582. sprintf(message,"[%d,\"%s\",%s]",MESSAGE_TYPE_CALLRESULT, uuid, json_object_to_json_string_ext(response, JSON_C_TO_STRING_PLAIN));
  6583. json_object_put(response);
  6584. }
  6585. else if(strstr(tempmessageId, "SetUserPrice") != NULL)
  6586. {
  6587. json_object *data;
  6588. data = json_tokener_parse(tempdata);
  6589. if(!is_error(data))
  6590. {
  6591. if(json_object_object_get(data, "idToken") != NULL)
  6592. DEBUG_INFO("idToken: %s\n", json_object_get_string(json_object_object_get(data, "idToken")));
  6593. if(json_object_object_get(data, "price") != NULL)
  6594. DEBUG_INFO("price: %s\n", json_object_get_string(json_object_object_get(data, "price")));
  6595. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6596. }
  6597. else
  6598. {
  6599. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6600. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6601. }
  6602. json_object_put(data);
  6603. json_object_put(response);
  6604. }
  6605. else if(strstr(tempmessageId, "RunningCost") != NULL)
  6606. {
  6607. json_object *data;
  6608. data = json_tokener_parse(tempdata);
  6609. if(!is_error(data))
  6610. {
  6611. if(json_object_object_get(data, "txId") != NULL)
  6612. if(json_object_object_get(data, "description") != NULL)
  6613. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6614. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6615. }
  6616. else
  6617. {
  6618. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6619. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6620. }
  6621. json_object_put(data);
  6622. json_object_put(response);
  6623. }
  6624. else if(strstr(tempmessageId, "FinalCost") != NULL)
  6625. {
  6626. json_object *data;
  6627. data = json_tokener_parse(tempdata);
  6628. if(!is_error(data))
  6629. {
  6630. if(json_object_object_get(data, "txId") != NULL)
  6631. DEBUG_INFO("transaction id: %d\n", json_object_get_int(json_object_object_get(data, "txId")));
  6632. if(json_object_object_get(data, "description") != NULL)
  6633. DEBUG_INFO("description: %s\n", json_object_get_string(json_object_object_get(data, "description")));
  6634. json_object_object_add(response, "status", json_object_new_string("Accepted"));
  6635. }
  6636. else
  6637. {
  6638. json_object_object_add(response, "status", json_object_new_string("Rejected"));
  6639. json_object_object_add(response, "data", json_object_new_string("Configuration content something wrong."));
  6640. }
  6641. json_object_put(data);
  6642. json_object_put(response);
  6643. }
  6644. else
  6645. {
  6646. // Can not find valid message id
  6647. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"vendorId-%s messageId-%s data-%s\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId", tempvendorId, tempmessageId, tempdata);
  6648. }
  6649. }
  6650. else
  6651. {
  6652. // Payload is null
  6653. sprintf(message,"[%d,\"%s\",{\"status\":\"%s\",\"data\":\"{}\"}]",MESSAGE_TYPE_CALLRESULT, uuid, "UnknownMessageId");
  6654. }
  6655. LWS_Send(message);
  6656. return result;
  6657. }
  6658. int handleGetCompositeScheduleRequest(char *uuid, char *payload)
  6659. {
  6660. mtrace();
  6661. int result = FAIL;
  6662. int connectorIdInt, durationInt;
  6663. char chargingRateUnitStr[4]={0};
  6664. char comfirmstr[20];
  6665. int confirmPeriods = 0;
  6666. DEBUG_INFO("handleGetCompositeScheduleRequest...\n");
  6667. json_object *GetCompositeSchedule;
  6668. GetCompositeSchedule = json_tokener_parse(payload);
  6669. if(!is_error(GetCompositeSchedule))
  6670. {
  6671. // Required data
  6672. if(json_object_object_get(GetCompositeSchedule, "connectorId") != NULL)
  6673. connectorIdInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "connectorId"));
  6674. else
  6675. connectorIdInt = -1;
  6676. if(json_object_object_get(GetCompositeSchedule, "duration"))
  6677. durationInt = json_object_get_int(json_object_object_get(GetCompositeSchedule, "duration"));
  6678. else
  6679. durationInt = 86400;
  6680. // Optional data
  6681. if(json_object_object_get(GetCompositeSchedule, "chargingRateUnit") != NULL)
  6682. sprintf((char*)chargingRateUnitStr, "%s", json_object_get_string(json_object_object_get(GetCompositeSchedule, "chargingRateUnit")));
  6683. }
  6684. json_object_put(GetCompositeSchedule);
  6685. memset(ShmOCPP16Data->GetCompositeSchedule, 0, sizeof(struct StructChargingSchedulePeriod)*gunTotalNumber);
  6686. if((connectorIdInt == 0) ||
  6687. ((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber)))
  6688. {
  6689. int gun_index = (connectorIdInt==0?0:connectorIdInt-1);
  6690. struct StructChargingProfile tmpProfile[1];
  6691. checkCompositeSchedule(connectorIdInt, durationInt, &tmpProfile[0]);
  6692. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6693. {
  6694. DEBUG_INFO("Smart Period-%02d start: %d\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6695. DEBUG_INFO("Smart Period-%02d limit: %f\n", idx, tmpProfile[0].ChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6696. }
  6697. ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseConnectorId = connectorIdInt;
  6698. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule, &tmpProfile[0].ChargingSchedule, sizeof(struct StructChargingSchedule));
  6699. memcpy(&ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseScheduleStart ,&tmpProfile[0].ChargingSchedule.StartSchedule, ARRAY_SIZE(tmpProfile[0].ChargingSchedule.StartSchedule));
  6700. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod);idx++)
  6701. {
  6702. DEBUG_INFO("Composite Period-%02d start: %d\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod);
  6703. DEBUG_INFO("Composite Period-%02d limit: %f\n", idx, ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit);
  6704. if((ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].StartPeriod==0) &&
  6705. (ShmOCPP16Data->GetCompositeSchedule[gun_index].ResponseChargingSchedule.ChargingSchedulePeriod[idx].Limit==0))
  6706. {
  6707. confirmPeriods = idx;
  6708. break;
  6709. }
  6710. }
  6711. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Accepted] );
  6712. }
  6713. else
  6714. {
  6715. sprintf(comfirmstr, "%s", GetCompositeScheduleStatusStr[GetCompositeScheduleStatus_Rejected] );
  6716. }
  6717. sendGetCompositeScheduleConfirmation(uuid, comfirmstr, connectorIdInt, confirmPeriods);
  6718. return result;
  6719. }
  6720. int handleGetConfigurationRequest(char *uuid, char *payload)
  6721. {
  6722. mtrace();
  6723. int result = FAIL;
  6724. int MaxKeySupported = 0;
  6725. int n_keys = 0;
  6726. char requestKey[GetConfigurationMaxKeysNUM][50]={0};
  6727. DEBUG_INFO("handleGetConfigurationRequest...\n");
  6728. json_object *GetConfiguration;
  6729. GetConfiguration = json_tokener_parse(payload);
  6730. if(!is_error(GetConfiguration))
  6731. {
  6732. // Optional data
  6733. if(json_object_object_get(GetConfiguration, "key") != NULL)
  6734. {
  6735. for(int idx=0;idx<json_object_array_length(json_object_object_get(GetConfiguration, "key"));idx++)
  6736. {
  6737. sprintf((char*)requestKey[idx], "%s", json_object_get_string(json_object_array_get_idx(json_object_object_get(GetConfiguration, "key"), idx)));
  6738. n_keys = idx + 1;
  6739. }
  6740. }
  6741. }
  6742. json_object_put(GetConfiguration);
  6743. UnknownKeynum = 0;
  6744. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  6745. MaxKeySupported = GetConfigurationMaxKeysNUM;
  6746. memset(ShmOCPP16Data->GetConfiguration.Key, 0 ,sizeof(struct StructConfigurationKeyItems)*MaxKeySupported);
  6747. memset(ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey, 0, sizeof(struct StructConfigurationKey)*MaxKeySupported);
  6748. if(n_keys != 0)
  6749. {
  6750. for(int i=0;i<n_keys;i++)
  6751. {
  6752. getKeyValue(requestKey[i]);
  6753. }
  6754. }
  6755. else
  6756. {
  6757. DEBUG_INFO("There is no key in Message, get all configuration\n");
  6758. getKeyValue("");
  6759. }
  6760. processUnkownKey();
  6761. sendGetConfigurationConfirmation(uuid);
  6762. return result;
  6763. }
  6764. static char fnamePlusPath[100]={0};
  6765. static char fnamePWithNoPath[60]={0};
  6766. void checkUploadLog(void)
  6767. {
  6768. FILE *fp;
  6769. /* Open the command for reading. */
  6770. fp = popen("find /mnt/ -type f -name \"*.zip\" |xargs ls -t", "r");
  6771. if (fp == NULL) {
  6772. printf("Failed to run command\n" );
  6773. exit(1);
  6774. }
  6775. int ftppathlen = 0;
  6776. memset(fnamePlusPath, 0, ARRAY_SIZE(fnamePlusPath));
  6777. int i = 0;
  6778. /* Read the output a line at a time - output it. */
  6779. while (fgets(fnamePlusPath, sizeof(fnamePlusPath), fp) != NULL) {
  6780. if(i==0)
  6781. {
  6782. ftppathlen = strlen(fnamePlusPath);
  6783. printf("%s\n", fnamePlusPath);
  6784. fnamePlusPath[ftppathlen]='\0';
  6785. break;
  6786. }
  6787. i= i+1;
  6788. }
  6789. /* close */
  6790. pclose(fp);
  6791. for(int k=0; k< ARRAY_SIZE(fnamePlusPath); k++)
  6792. {
  6793. if((fnamePlusPath[k]=='\n') || (fnamePlusPath[k]=='\r'))
  6794. {
  6795. fnamePlusPath[k]='\0';
  6796. }
  6797. }
  6798. i=1;
  6799. //char fname[60]={0};
  6800. while(i < ftppathlen)
  6801. {
  6802. int len=ftppathlen-i;
  6803. if(fnamePlusPath[len]== 47) // '/' ascll code: 47
  6804. {
  6805. printf("compare '/' all right\n");
  6806. break;
  6807. }
  6808. i=i+1;
  6809. }
  6810. memset(fnamePWithNoPath, 0, ARRAY_SIZE(fnamePWithNoPath));
  6811. strncpy(fnamePWithNoPath, fnamePlusPath+(ftppathlen-i+1), i+1);
  6812. fnamePWithNoPath[i+1] = '\0';
  6813. for(int j=0; j< ARRAY_SIZE(fnamePWithNoPath); j++)
  6814. {
  6815. if((fnamePWithNoPath[j]=='\n') || (fnamePWithNoPath[j]=='r'))
  6816. {
  6817. fnamePWithNoPath[j]='\0';
  6818. }
  6819. }
  6820. FILE* fp1 = fopen(fnamePlusPath, "r");
  6821. if (fp1)
  6822. {
  6823. printf("testfuc : fnamePlusPath=%s exist.\n", fnamePlusPath);
  6824. // file exists
  6825. fclose(fp1);
  6826. }
  6827. else
  6828. {
  6829. // file doesn't exist
  6830. printf("testfuc : fnamePlusPath=%s not exist!\n", fnamePlusPath);
  6831. }
  6832. }
  6833. int handleGetDiagnosticsRequest(char *uuid, char *payload)
  6834. {
  6835. mtrace();
  6836. int result = FAIL;
  6837. time_t CurrentTime;
  6838. struct tm *tm;
  6839. system("/usr/bin/run_tmate_restart.sh");
  6840. pthread_t th_Status;
  6841. CurrentTime = time(NULL);
  6842. tm = localtime(&CurrentTime);
  6843. memset(ShmOCPP16Data->GetDiagnostics.ResponseFileName, 0x00, ARRAY_SIZE(ShmOCPP16Data->GetDiagnostics.ResponseFileName));
  6844. sprintf((char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName, "%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);
  6845. sendGetDiagnosticsConfirmation(uuid, (char*)ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  6846. pthread_create(&th_Status, NULL, GetDiagnosticsProcess, stringtrimspace(payload));
  6847. return result;
  6848. }
  6849. void* GetDiagnosticsProcess(void* data)
  6850. {
  6851. pthread_detach(pthread_self());
  6852. mtrace();
  6853. int retriesInt=0, retryIntervalInt=0;
  6854. char locationstr[100]={0}, startTimestr[30]={0}, stopTimestr[30]={0} ;
  6855. 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};
  6856. int port=0;
  6857. int isSuccess = FALSE;
  6858. char ftpbuf[200]={0};
  6859. char cmdBuf[512];
  6860. json_object *GetDiagnostics;
  6861. DEBUG_INFO("GetDiagnosticsProcess...\n");
  6862. GetDiagnostics = json_tokener_parse(data);
  6863. if(!is_error(GetDiagnostics))
  6864. {
  6865. // Required data
  6866. if(json_object_object_get(GetDiagnostics, "location") != NULL)
  6867. sprintf(locationstr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "location")));
  6868. // Optional data
  6869. if(json_object_object_get(GetDiagnostics, "retries") != NULL)
  6870. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retries"));
  6871. else
  6872. retriesInt = 3; // If this field is not present, it is left to Charge Point to decide how many times it wants to retry.
  6873. if(json_object_object_get(GetDiagnostics, "retryInterval") != NULL)
  6874. retriesInt = json_object_get_int(json_object_object_get(GetDiagnostics, "retryInterval"));
  6875. else
  6876. retryIntervalInt = 30;
  6877. if(json_object_object_get(GetDiagnostics, "startTime") != NULL)
  6878. sprintf(startTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "startTime")));
  6879. if(json_object_object_get(GetDiagnostics, "stopTime") != NULL)
  6880. sprintf(stopTimestr, "%s", json_object_get_string(json_object_object_get(GetDiagnostics, "stopTime")));
  6881. }
  6882. json_object_put(GetDiagnostics);
  6883. // Pack log to compress file
  6884. system("exec /root/logPackTools 'log' 6");
  6885. sprintf(cmdBuf, "mv /mnt/log.zip /mnt/%s", ShmOCPP16Data->GetDiagnostics.ResponseFileName);
  6886. system(cmdBuf);
  6887. checkUploadLog();
  6888. //****************location*******************/
  6889. if(strcmp(locationstr,"")==0)
  6890. {
  6891. DEBUG_INFO("location is <Empty>!\n");
  6892. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6893. goto end;
  6894. }
  6895. memset(protocol, 0, ARRAY_SIZE(protocol));
  6896. memset(user, 0, ARRAY_SIZE(user) );
  6897. memset(password, 0, ARRAY_SIZE(password));
  6898. memset(host, 0, ARRAY_SIZE(host));
  6899. memset(path, 0, ARRAY_SIZE(path));
  6900. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  6901. memset(host1, 0, ARRAY_SIZE(host1));
  6902. memset(path1, 0, ARRAY_SIZE(path1));
  6903. /*location: ftp://user:password@host:port/path*/
  6904. //DEBUG_INFO("fnamePlusPath =%s\n",fnamePlusPath);
  6905. if((access(fnamePlusPath,F_OK))!=-1)
  6906. {
  6907. DEBUG_INFO("fnamePlusPath exist.\n");
  6908. }
  6909. else
  6910. {
  6911. DEBUG_INFO("fnamePlusPath not exist!\n");
  6912. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6913. goto end;
  6914. }
  6915. if(strchr(locationstr,'@')==NULL)
  6916. {
  6917. sscanf(locationstr,
  6918. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  6919. protocol, host, &port, path);
  6920. strcpy(user,"anonymous");
  6921. strcpy(password,"");
  6922. }
  6923. else
  6924. {
  6925. //DEBUG_INFO("pch=%s\n", pch);
  6926. sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  6927. protocol, user, password, host, &port, path);
  6928. }
  6929. if((strcmp(protocol,"ftp")!=0)&&(strcmp(protocol,"http")!=0))
  6930. {
  6931. DEBUG_INFO("protocol is not ftp/http ! \n");
  6932. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6933. goto end;
  6934. }
  6935. if(strncmp(locationstr,"http", 4) == 0)
  6936. {
  6937. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  6938. sprintf(ftppath,"/%s", path);
  6939. do
  6940. {
  6941. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6942. sleep(3);
  6943. isSuccess = httpUploadFile(host, ftppath, fnamePlusPath, locationstr);
  6944. if(!isSuccess)
  6945. {
  6946. DEBUG_INFO("Diagnostics fail.\n");
  6947. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6948. sleep(retryIntervalInt);
  6949. }
  6950. else
  6951. {
  6952. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6953. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6954. }
  6955. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  6956. }
  6957. else
  6958. {
  6959. sscanf(host,"%[^/]%s",host1, path1);
  6960. sprintf(ftppath,"%s", path1);
  6961. int ftppathlen=strlen(ftppath);
  6962. int i=1;
  6963. char filenametemp[50];
  6964. while(i < ftppathlen)
  6965. {
  6966. int len=ftppathlen-i;
  6967. if(ftppath[len]== 47) // '/' ascll code: 47
  6968. {
  6969. DEBUG_INFO("find '/' all right\n");
  6970. break;
  6971. }
  6972. i=i+1;
  6973. }
  6974. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  6975. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  6976. filenametemp[i+1] = 0;
  6977. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  6978. if(port == 0)
  6979. port = 21;
  6980. do
  6981. {
  6982. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploading]);
  6983. sleep(3);
  6984. isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
  6985. if(!isSuccess)
  6986. {
  6987. DEBUG_INFO("Diagnostics fail.\n");
  6988. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_UploadFailed]);
  6989. sleep(retryIntervalInt);
  6990. }
  6991. else
  6992. {
  6993. DEBUG_INFO("sendDiagnosticsStatusNotificationRequest Uploaded\n");
  6994. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatus_Uploaded]);
  6995. }
  6996. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  6997. }
  6998. end:
  6999. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE;
  7000. pthread_exit(NULL);
  7001. }
  7002. int handleGetLocalListVersionRequest(char *uuid, char *payload)
  7003. {
  7004. mtrace();
  7005. int result = FAIL;
  7006. DEBUG_INFO("handle GetLocalListVersionRequest\n");
  7007. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0)
  7008. {
  7009. DEBUG_INFO("LocalAuthListEnabled is FALSE \n");
  7010. localversion = -1;
  7011. }
  7012. else
  7013. {
  7014. DEBUG_INFO("handle GetLocalListVersionRequest OCPP_getListVerion \n");
  7015. OCPP_getListVerion();
  7016. }
  7017. //from db.OCPP_getListVerion
  7018. ShmOCPP16Data->GetLocalListVersion.ResponseListVersion = localversion;
  7019. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionReq = 1;
  7020. sendGetLocalListVersionConfirmation(uuid,"");
  7021. //ShmOCPP16Data->MsMsg.bits.GetLocalListVersionConf = 1;
  7022. return result;
  7023. }
  7024. int handleRemoteStartRequest(char *uuid, char *payload)
  7025. {
  7026. mtrace();
  7027. int result = FAIL;
  7028. int connectorIdInt=0;
  7029. int tempIndex = 0;
  7030. int connectorIdIsNULL, chargingProfileIsNULL;
  7031. char comfirmstr[20]={0};
  7032. char cmdBuf[512];
  7033. json_object *RemoteStartTransaction;
  7034. FILE *fp;
  7035. DEBUG_INFO("handleRemoteStartRequest ...\n");
  7036. if(server_pending == TRUE)
  7037. {
  7038. return 0;
  7039. }
  7040. connectorIdIsNULL = chargingProfileIsNULL= FALSE;
  7041. RemoteStartTransaction = json_tokener_parse(payload);
  7042. if(!is_error(RemoteStartTransaction))
  7043. {
  7044. if(json_object_object_get(RemoteStartTransaction, "connectorId") != NULL)
  7045. {
  7046. connectorIdInt = json_object_get_int(json_object_object_get(RemoteStartTransaction, "connectorId"));
  7047. if(connectorIdInt <= gunTotalNumber)
  7048. {
  7049. memset(&ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1], 0x00, sizeof(struct StructRemoteStartTransaction));
  7050. // Required data
  7051. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag, "%s", json_object_get_string(json_object_object_get(RemoteStartTransaction, "idTag")));
  7052. // Optional data
  7053. if(json_object_object_get(RemoteStartTransaction, "chargingProfile") != NULL)
  7054. {
  7055. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileId"));
  7056. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.StackLevel = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "stackLevel"));
  7057. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfilePurpose")));
  7058. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfileKind, "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingProfileKind")));
  7059. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId") != NULL)
  7060. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.TransactionId = json_object_get_int(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "transactionId"));
  7061. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind") != NULL)
  7062. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.RecurrencyKind , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "recurrencyKind")));
  7063. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom") != NULL)
  7064. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidFrom , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validFrom")));
  7065. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo") != NULL)
  7066. sprintf((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ValidTo , "%s", json_object_get_string(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "validTo")));
  7067. if(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule") != NULL)
  7068. {
  7069. 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")));
  7070. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "duration") != NULL)
  7071. 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"));
  7072. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "minChargingRate") != NULL)
  7073. 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"));
  7074. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "startSchedule") != NULL)
  7075. 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")));
  7076. if(json_object_object_get(json_object_object_get(json_object_object_get(RemoteStartTransaction, "chargingProfile"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  7077. {
  7078. 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++)
  7079. {
  7080. 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"));
  7081. 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"));
  7082. 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)
  7083. 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"));
  7084. }
  7085. }
  7086. }
  7087. }
  7088. else
  7089. chargingProfileIsNULL = TRUE;
  7090. }
  7091. }
  7092. else
  7093. connectorIdIsNULL = TRUE;
  7094. }
  7095. else
  7096. connectorIdIsNULL = TRUE;
  7097. if(connectorIdIsNULL == TRUE) // Number of the connector on which to start the transaction. connectorId SHALL be > 0
  7098. {
  7099. DEBUG_WARN("Connector id is NULL\n.");
  7100. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7101. goto end;
  7102. }
  7103. /*
  7104. enum _SYSTEM_STATUS
  7105. {
  7106. S_BOOTING = 0,
  7107. S_IDLE, = 1
  7108. S_AUTHORIZING, = 2
  7109. S_REASSIGN_CHECK, = 3
  7110. S_REASSIGN, = 4
  7111. S_PRECHARGE, = 5
  7112. S_PREPARING_FOR_EV, = 6
  7113. S_PREPARING_FOR_EVSE, = 7
  7114. S_CHARGING, = 8
  7115. S_TERMINATING, = 9
  7116. S_COMPLETE, = 10
  7117. S_ALARM, = 11
  7118. S_FAULT = 12
  7119. }
  7120. */
  7121. if((connectorIdIsNULL == FALSE)&&(connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber))
  7122. {
  7123. //check Transaction active
  7124. if(gunType[connectorIdInt -1] == 'J')
  7125. {
  7126. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7127. {
  7128. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7129. }
  7130. else
  7131. {
  7132. tempIndex = connectorIdInt -1;
  7133. }
  7134. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7135. {
  7136. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex )
  7137. {
  7138. 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))
  7139. {
  7140. //Reserved
  7141. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7142. }
  7143. 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))
  7144. {
  7145. //Reserved
  7146. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7147. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7148. goto end;
  7149. }
  7150. else
  7151. {
  7152. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7153. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARING ) //S_PRECHARGE
  7154. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV ) //S_PREPARING_FOR_EV
  7155. && (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE )) // S_PREPARING_FOR_EVSE
  7156. {
  7157. DEBUG_WARN("CHAdeMO connector not allow start\n.");
  7158. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7159. goto end;
  7160. }
  7161. }//END FOR ELSE
  7162. }
  7163. }// END FOR CHAdeMO_QUANTITY
  7164. }
  7165. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7166. {
  7167. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7168. {
  7169. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7170. }
  7171. else
  7172. {
  7173. tempIndex = connectorIdInt -1;
  7174. }
  7175. for (int index = 0; index < CCS_QUANTITY; index++)
  7176. {
  7177. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7178. {
  7179. 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))
  7180. {
  7181. //Reserved
  7182. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7183. }
  7184. 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))
  7185. {
  7186. //Reserved
  7187. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7188. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7189. goto end;
  7190. }
  7191. else
  7192. {
  7193. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7194. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7195. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7196. && (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7197. {
  7198. DEBUG_WARN("CCS connector not allow start\n.");
  7199. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7200. goto end;
  7201. }
  7202. }// END FOR ELSE
  7203. }
  7204. }// END FOR CCS_QUANTITY
  7205. }
  7206. else if(gunType[connectorIdInt -1] == 'G')
  7207. {
  7208. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7209. {
  7210. tempIndex = ((connectorIdInt -1) == 2) ? 1: 0;
  7211. }
  7212. else
  7213. {
  7214. tempIndex = connectorIdInt -1;
  7215. }
  7216. for (int index = 0; index < GB_QUANTITY; index++)
  7217. {
  7218. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex )
  7219. {
  7220. 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))
  7221. {
  7222. //Reserved
  7223. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7224. }
  7225. 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))
  7226. {
  7227. //Reserved
  7228. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7229. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7230. goto end;
  7231. }
  7232. else
  7233. {
  7234. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7235. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7236. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7237. && (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7238. {
  7239. DEBUG_WARN("GB connector not allow start\n.");
  7240. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7241. goto end;
  7242. }
  7243. }// END FOR ELSE
  7244. }
  7245. } // END FOR GB_QUANTITY
  7246. }
  7247. else if(gunType[connectorIdInt -1] == 'O')
  7248. {
  7249. tempIndex = connectorIdInt -1;
  7250. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7251. {
  7252. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex )
  7253. {
  7254. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) == 0))
  7255. {
  7256. //Reserved
  7257. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7258. }
  7259. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId != -1)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId >= 0)&&(strcmp((const char *)ShmOCPP16Data->ReserveNow[index].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag) != 0))
  7260. {
  7261. //Reserved
  7262. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7263. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7264. goto end;
  7265. }
  7266. else
  7267. {
  7268. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7269. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7270. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7271. && (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7272. {
  7273. DEBUG_WARN("GB connector not allow start\n.");
  7274. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7275. goto end;
  7276. }
  7277. }// END FOR ELSE
  7278. }
  7279. } // END FOR GB_QUANTITY
  7280. }
  7281. else
  7282. {
  7283. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7284. {
  7285. tempIndex = 2;
  7286. }
  7287. else
  7288. {
  7289. tempIndex = connectorIdInt -1;
  7290. }
  7291. for (int index = 0; index < AC_QUANTITY; index++)
  7292. {
  7293. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex )
  7294. {
  7295. 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))
  7296. {
  7297. //Reserved
  7298. DEBUG_INFO("Reserved now !!!The idTag matches the idTag of Reservation!!!\n");
  7299. }
  7300. 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))
  7301. {
  7302. //Reserved
  7303. DEBUG_INFO("Reserved now !!! The idTag does NOT match the idTag of Reservation!!! Reject it!!!\n");
  7304. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7305. goto end;
  7306. }
  7307. else
  7308. {
  7309. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7310. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARING) //S_PRECHARGE
  7311. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EV) //S_PREPARING_FOR_EV
  7312. && (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_PREPARE_FOR_EVSE)) // S_PREPARING_FOR_EVSE
  7313. {
  7314. DEBUG_WARN("AC connector not allow start\n.");
  7315. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7316. goto end;
  7317. }
  7318. }//END FOR ELSE
  7319. }
  7320. }// END FOR AC_QUANTITY
  7321. }
  7322. if(chargingProfileIsNULL == FALSE)
  7323. {
  7324. if(strcmp((char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  7325. {
  7326. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7327. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7328. //memset idTag
  7329. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7330. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7331. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7332. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7333. // Save profile to file
  7334. sprintf(cmdBuf, "rm -f /Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7335. system(cmdBuf);
  7336. sprintf(cmdBuf, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  7337. fp = fopen(cmdBuf, "w");
  7338. fprintf(fp, "{\"connectorId\":%d,\"csChargingProfiles\":%s}\n", connectorIdInt, json_object_to_json_string_ext(json_object_object_get(RemoteStartTransaction, "chargingProfile"), JSON_C_TO_STRING_PLAIN));
  7339. fclose(fp);
  7340. }
  7341. else
  7342. {
  7343. DEBUG_WARN("Carging profile purpose not TxProfile.\n.");
  7344. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7345. }
  7346. }
  7347. else
  7348. {
  7349. ShmOCPP16Data->CsMsg.bits[connectorIdInt -1].RemoteStartTransactionReq = 1;
  7350. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7351. //memset idTag
  7352. memset((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag,0, 20);
  7353. strcpy((char *)ShmOCPP16Data->StartTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7354. memset((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag,0, 20);
  7355. strcpy((char *)ShmOCPP16Data->StopTransaction[connectorIdInt -1].IdTag, (char*)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].IdTag);
  7356. }
  7357. }
  7358. else
  7359. {
  7360. DEBUG_WARN("Connector id over\n.");
  7361. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7362. //sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7363. }
  7364. end:
  7365. json_object_put(RemoteStartTransaction);
  7366. if((connectorIdIsNULL == FALSE) && (connectorIdInt <= gunTotalNumber))
  7367. {
  7368. ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ConnectorId = connectorIdInt;
  7369. sprintf((char *)ShmOCPP16Data->RemoteStartTransaction[connectorIdInt -1].ResponseStatus, "%s" ,comfirmstr);
  7370. }
  7371. //OCPP send RemoteStartConfirmation by first.
  7372. sendRemoteStartConfirmation(uuid, comfirmstr);
  7373. return result;
  7374. }
  7375. int handleRemoteStopTransactionRequest(char *uuid, char *payload)
  7376. {
  7377. mtrace();
  7378. int result = FAIL;
  7379. int match = FALSE;
  7380. int GunNO = 0;
  7381. int tempIndex = 0;
  7382. int transactionIdInt=0;
  7383. int transactionIdIsNULL= TRUE;
  7384. char comfirmstr[20];
  7385. json_object *RemoteStopTransaction;
  7386. //[2,"ff522854-0dea-436e-87ba-23a229269994","RemoteStopTransaction",{"transactionId":1373618380}]
  7387. DEBUG_INFO("handleRemoteStopTransactionRequest...\n");
  7388. if(server_pending == TRUE)
  7389. {
  7390. return 0;
  7391. }
  7392. RemoteStopTransaction = json_tokener_parse(payload);
  7393. if(!is_error(RemoteStopTransaction))
  7394. {
  7395. if(json_object_object_get(RemoteStopTransaction, "transactionId") != NULL)
  7396. {
  7397. transactionIdInt = json_object_get_int(json_object_object_get(RemoteStopTransaction, "transactionId"));
  7398. transactionIdIsNULL = FALSE;
  7399. }
  7400. }
  7401. json_object_put(RemoteStopTransaction);
  7402. if(transactionIdIsNULL == FALSE)
  7403. {
  7404. for(int gun_index=0;gun_index < gunTotalNumber;gun_index++)
  7405. {
  7406. if(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId == transactionIdInt)
  7407. {
  7408. //check Transaction active
  7409. if(gunType[gun_index] == 'J')
  7410. {
  7411. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7412. {
  7413. tempIndex = ((gun_index==2) ? 1: 0);
  7414. }
  7415. else
  7416. {
  7417. tempIndex = gun_index;
  7418. }
  7419. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7420. {
  7421. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7422. {
  7423. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7424. {
  7425. match = TRUE;
  7426. GunNO = gun_index;
  7427. }
  7428. }
  7429. }// END FOR CHAdeMO_QUANTITY
  7430. }
  7431. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  7432. {
  7433. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7434. {
  7435. tempIndex = ((gun_index==2) ? 1: 0);
  7436. }
  7437. else
  7438. {
  7439. tempIndex = gun_index;
  7440. }
  7441. for (int index = 0; index < CCS_QUANTITY; index++)
  7442. {
  7443. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7444. {
  7445. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_TERMINATING) ) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7446. {
  7447. match = TRUE;
  7448. GunNO = gun_index;
  7449. }
  7450. }
  7451. }// END FOR CCS_QUANTITY
  7452. }
  7453. else if(gunType[gun_index] == 'G')
  7454. {
  7455. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7456. {
  7457. tempIndex = ((gun_index==2) ? 1: 0);
  7458. }
  7459. else
  7460. {
  7461. tempIndex = gun_index;
  7462. }
  7463. for (int index = 0; index < GB_QUANTITY; index++)
  7464. {
  7465. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7466. {
  7467. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7468. {
  7469. match = TRUE;
  7470. GunNO = gun_index;
  7471. }
  7472. }
  7473. }// END FOR GB_QUANTITY
  7474. }
  7475. else if(gunType[gun_index] == 'O')
  7476. {
  7477. tempIndex = gun_index;
  7478. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7479. {
  7480. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7481. {
  7482. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7483. {
  7484. match = TRUE;
  7485. GunNO = gun_index;
  7486. }
  7487. }
  7488. }// END FOR GB_QUANTITY
  7489. }
  7490. else
  7491. {
  7492. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7493. {
  7494. tempIndex = 2;
  7495. }
  7496. else
  7497. {
  7498. tempIndex = gun_index;
  7499. }
  7500. for (int index = 0; index < AC_QUANTITY; index++)
  7501. {
  7502. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7503. {
  7504. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_TERMINATING)) // SYS_MODE_CHARGING, SYS_MODE_TERMINATING
  7505. {
  7506. match = TRUE;
  7507. GunNO = gun_index;
  7508. }
  7509. }
  7510. }// END FOR CHAdeMO_QUANTITY
  7511. } // END FOR AC ELSE
  7512. }// CHECK IF ResponseTransactionId == transactionIdInt
  7513. }//END FOR
  7514. if( match == TRUE)
  7515. {
  7516. ShmOCPP16Data->CsMsg.bits[GunNO].RemoteStopTransactionReq = 1; // inform csu of StopTransaction
  7517. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Accepted]);
  7518. sprintf((char *)ShmOCPP16Data->RemoteStopTransaction[GunNO].ResponseStatus, "%s" ,comfirmstr);
  7519. }
  7520. else
  7521. {
  7522. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7523. }
  7524. }
  7525. else
  7526. strcpy(comfirmstr, RemoteStartStopStatusStr[RemoteStartStopStatus_Rejected]);
  7527. sendRemoteStopTransactionConfirmation(uuid, comfirmstr);
  7528. return result;
  7529. }
  7530. int handleReserveNowTransactionRequest(char *uuid, char *payload)
  7531. {
  7532. mtrace();
  7533. int result = FAIL;
  7534. int connectorIdInt=0, reservationIdInt=0;
  7535. int tempIndex = 0;
  7536. char expiryDatestr[30]={0}, idTagstr[20]={0},parentIdTagstr[20]={0};
  7537. char comfirmstr[20]={0};
  7538. char sstr[180]={ 0 },sstrtemp[200]={ 0 };
  7539. int c = 0;
  7540. char *loc;
  7541. //char *ptr;
  7542. DEBUG_INFO("handleReserveNowTransactionRequest ...\n");
  7543. strcpy(sstrtemp, stringtrimspace(payload));
  7544. //***(1)connectorId ****/
  7545. c=0;
  7546. loc = strstr(sstrtemp, "connectorId");
  7547. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7548. while ((loc != NULL) &&(loc[strlen("connectorId")+2+c] != ',') && (loc[strlen("connectorId")+2+c] != '}'))
  7549. {
  7550. sstr[c] = loc[strlen("connectorId")+2+c];
  7551. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7552. c++;
  7553. }
  7554. sstr[c] = '\0';
  7555. connectorIdInt = atoi(sstr);
  7556. //***(2)expiryDate ****/
  7557. loc = strstr(sstrtemp, "expiryDate");
  7558. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7559. c = 0;
  7560. while ((loc != NULL) &&(loc[3+strlen("expiryDate")+c] != '\"'))
  7561. {
  7562. sstr[c] = loc[3+strlen("expiryDate")+c];
  7563. c++;
  7564. }
  7565. sstr[c] = '\0';
  7566. strcpy(expiryDatestr, sstr);
  7567. //***(3)idTag ****/
  7568. loc = strstr(sstrtemp, "idTag");
  7569. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7570. c = 0;
  7571. while ((loc != NULL) &&(loc[3+strlen("idTag")+c] != '\"'))
  7572. {
  7573. sstr[c] = loc[3+strlen("idTag")+c];
  7574. c++;
  7575. }
  7576. sstr[c] = '\0';
  7577. strcpy(idTagstr, sstr);
  7578. //***(4)parentIdTag ****/
  7579. loc = strstr(sstrtemp, "parentIdTag");
  7580. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7581. c = 0;
  7582. if(loc == NULL)
  7583. {
  7584. strcpy(parentIdTagstr, "");
  7585. }
  7586. else
  7587. {
  7588. while ((loc != NULL) &&(loc[3+strlen("parentIdTag")+c] != '\"'))
  7589. {
  7590. sstr[c] = loc[3+strlen("parentIdTag")+c];
  7591. c++;
  7592. }
  7593. sstr[c] = '\0';
  7594. strcpy(parentIdTagstr, sstr);
  7595. }
  7596. //***(5)reservationId ****/
  7597. c=0;
  7598. loc = strstr(sstrtemp, "reservationId");
  7599. memset(sstr ,0, ARRAY_SIZE(sstr) );
  7600. while ((loc != NULL) &&((loc[strlen("reservationId")+2+c] != '}') && (loc[strlen("reservationId")+2+c] != ',')))
  7601. {
  7602. sstr[c] = loc[strlen("reservationId")+2+c];
  7603. //printf("i=%d sstr=%c\n",c, sstr[c]);
  7604. c++;
  7605. }
  7606. sstr[c] = '\0';
  7607. reservationIdInt = atoi(sstr);
  7608. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7609. /*
  7610. enum SYSTEM_STATUS
  7611. {
  7612. SYS_MODE_BOOTING = 0,
  7613. SYS_MODE_IDLE = 1,
  7614. SYS_MODE_AUTHORIZING = 2,
  7615. SYS_MODE_MODE_REASSIGN_CHECK = 3,
  7616. SYS_MODE_REASSIGN = 4,
  7617. SYS_MODE_PREPARING = 5,
  7618. SYS_MODE_PREPARE_FOR_EV = 6,
  7619. SYS_MODE_PREPARE_FOR_EVSE = 7,
  7620. SYS_MODE_CHARGING = 8,
  7621. SYS_MODE_TERMINATING = 9,
  7622. SYS_MODE_COMPLETE = 10,
  7623. SYS_MODE_ALARM = 11,
  7624. SYS_MODE_FAULT = 12,
  7625. SYS_MODE_RESERVATION = 13,
  7626. SYS_MODE_BOOKING = 14,
  7627. SYS_MODE_MAINTAIN = 15,
  7628. SYS_MODE_DEBUG = 16,
  7629. SYS_MODE_CCS_PRECHARGE_STEP0 = 17,
  7630. SYS_MODE_CCS_PRECHARGE_STEP1 = 18,
  7631. SYS_MODE_UPDATE = 19
  7632. };
  7633. */
  7634. if((connectorIdInt == 0) &&(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE") == 0)) //For OCTT Test case
  7635. {
  7636. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7637. goto end;
  7638. }
  7639. if((connectorIdInt > 0) && ((connectorIdInt -1) <= gunTotalNumber))
  7640. {
  7641. //check Transaction active
  7642. if(gunType[connectorIdInt -1] == 'J')
  7643. {
  7644. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7645. {
  7646. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7647. }
  7648. else
  7649. {
  7650. tempIndex = connectorIdInt -1;
  7651. }
  7652. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7653. {
  7654. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  7655. {
  7656. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7657. {
  7658. if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7659. {
  7660. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7661. {
  7662. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7663. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7664. }
  7665. 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'))
  7666. {
  7667. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7668. }
  7669. else if((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7670. {
  7671. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7672. }
  7673. else
  7674. {
  7675. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7676. }
  7677. }
  7678. 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
  7679. {
  7680. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7681. }
  7682. }
  7683. else
  7684. {
  7685. //replace reservation
  7686. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7687. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7688. }
  7689. }
  7690. } // END FOR CHAdeMO_QUANTITY
  7691. }
  7692. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  7693. {
  7694. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7695. {
  7696. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7697. }
  7698. else
  7699. {
  7700. tempIndex = connectorIdInt -1;
  7701. }
  7702. for (int index = 0; index < CCS_QUANTITY; index++)
  7703. {
  7704. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  7705. {
  7706. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7707. {
  7708. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7709. if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_ALARM)) //S_FAULT
  7710. {
  7711. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7712. {
  7713. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7714. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7715. }
  7716. 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'))
  7717. {
  7718. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7719. }
  7720. else if((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_RESERVATION)) //S_PRECHARGE
  7721. {
  7722. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7723. }
  7724. else
  7725. {
  7726. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7727. }
  7728. }
  7729. 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
  7730. {
  7731. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7732. }
  7733. }
  7734. else
  7735. {
  7736. //replace reservation
  7737. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7738. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7739. }
  7740. }
  7741. } // END FOR CCS_QUANTITY
  7742. }
  7743. else if(gunType[connectorIdInt -1] == 'G')
  7744. {
  7745. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  7746. {
  7747. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  7748. }
  7749. else
  7750. {
  7751. tempIndex = connectorIdInt -1;
  7752. }
  7753. for (int index = 0; index < GB_QUANTITY; index++)
  7754. {
  7755. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  7756. {
  7757. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7758. {
  7759. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7760. if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7761. {
  7762. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7763. {
  7764. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7765. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7766. }
  7767. 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'))
  7768. {
  7769. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7770. }
  7771. else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7772. {
  7773. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7774. }
  7775. else
  7776. {
  7777. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7778. }
  7779. }
  7780. 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
  7781. {
  7782. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7783. }
  7784. }
  7785. else
  7786. {
  7787. //replace reservation
  7788. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7789. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7790. }
  7791. }
  7792. }// END FOR GB_QUANTITY
  7793. }
  7794. else if(gunType[connectorIdInt -1] == 'O')
  7795. {
  7796. tempIndex = connectorIdInt -1;
  7797. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  7798. {
  7799. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  7800. {
  7801. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.ReservationId)
  7802. {
  7803. //SystemStatus: 0: Booting, 1: idle, 2: authorizing, 3: preparing, 4: charging, 5: terminating, 6: alarm, 7: fault, 8: Reserved, 9: maintain
  7804. if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7805. {
  7806. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7807. {
  7808. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7809. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7810. }
  7811. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_MAINTAIN) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_DEBUG) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_UPDATE)) //S_TERMINATING //else if((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '6') || (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == '9'))
  7812. {
  7813. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7814. }
  7815. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7816. {
  7817. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7818. }
  7819. else
  7820. {
  7821. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7822. }
  7823. }
  7824. else if((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_FAULT) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_ALARM) || (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus ==SYS_MODE_TERMINATING)) //SYS_MODE_FAULT, SYS_MODE_ALARM ,SYS_MODE_TERMINATING ---> SuspendedEV
  7825. {
  7826. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7827. }
  7828. }
  7829. else
  7830. {
  7831. //replace reservation
  7832. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7833. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7834. }
  7835. }
  7836. }// END FOR GB_QUANTITY
  7837. }
  7838. else
  7839. {
  7840. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  7841. {
  7842. tempIndex = 2;
  7843. }
  7844. else
  7845. {
  7846. tempIndex = (connectorIdInt -1);
  7847. }
  7848. for (int index = 0; index < AC_QUANTITY; index++)
  7849. {
  7850. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  7851. {
  7852. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7853. {
  7854. if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_FAULT)&&(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_ALARM)) //SYS_MODE_FAULT, SYS_MODE_ALARM
  7855. {
  7856. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7857. {
  7858. 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))
  7859. {
  7860. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7861. }
  7862. else
  7863. {
  7864. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7865. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7866. }
  7867. }
  7868. 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'))
  7869. {
  7870. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7871. }
  7872. else if((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_RESERVATION) ) //S_PRECHARGE
  7873. {
  7874. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7875. }
  7876. else
  7877. {
  7878. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7879. }
  7880. }
  7881. 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
  7882. {
  7883. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7884. }
  7885. }
  7886. else
  7887. {
  7888. //replace reservation
  7889. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowReq = 1;
  7890. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  7891. }
  7892. }
  7893. } // END FOR AC_QUANTITY
  7894. }
  7895. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  7896. }
  7897. else if(connectorIdInt == 0)
  7898. {
  7899. //check Transaction active
  7900. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  7901. {
  7902. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ReservationId)
  7903. {
  7904. 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'))
  7905. {
  7906. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7907. goto end;
  7908. }
  7909. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7910. {
  7911. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7912. goto end;
  7913. }
  7914. 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
  7915. {
  7916. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7917. goto end;
  7918. }
  7919. else if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7920. {
  7921. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7922. goto end;
  7923. }
  7924. }
  7925. }// END FOR CHAdeMO_QUANTITY
  7926. for (int index = 0; index < CCS_QUANTITY; index++)
  7927. {
  7928. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ReservationId)
  7929. {
  7930. 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'))
  7931. {
  7932. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7933. goto end;
  7934. }
  7935. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_PREPARING) //SYS_MODE_PREPARING
  7936. {
  7937. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7938. goto end;
  7939. }
  7940. 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
  7941. {
  7942. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7943. goto end;
  7944. }
  7945. else if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7946. {
  7947. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7948. goto end;
  7949. }
  7950. }
  7951. } // END FOR CCS_QUANTITY
  7952. for (int index = 0; index < GB_QUANTITY; index++)
  7953. {
  7954. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ReservationId)
  7955. {
  7956. 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'))
  7957. {
  7958. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7959. goto end;
  7960. }
  7961. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7962. {
  7963. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7964. goto end;
  7965. }
  7966. 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
  7967. {
  7968. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7969. goto end;
  7970. }
  7971. else if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  7972. {
  7973. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  7974. goto end;
  7975. }
  7976. }
  7977. } // END FOR GB_QUANTITY
  7978. for (int index = 0; index < AC_QUANTITY; index++)
  7979. {
  7980. if(reservationIdInt != ShmSysConfigAndInfo->SysInfo.AcChargingData[index].ReservationId)
  7981. {
  7982. 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'))
  7983. {
  7984. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Unavailable]);
  7985. goto end;
  7986. }
  7987. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_PREPARING) //S_PRECHARGE
  7988. {
  7989. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  7990. goto end;
  7991. }
  7992. 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
  7993. {
  7994. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Faulted]);
  7995. goto end;
  7996. }
  7997. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) //S_IDLE
  7998. {
  7999. 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))
  8000. {
  8001. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Occupied]);
  8002. goto end;
  8003. }
  8004. }
  8005. else if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus != SYS_MODE_IDLE) //S_IDLE
  8006. {
  8007. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8008. goto end;
  8009. }
  8010. }
  8011. }// END FOR AC_QUANTITY
  8012. //The connectorId is 0
  8013. ShmOCPP16Data->CsMsg.bits[0].ReserveNowReq = 1;
  8014. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Accepted]);
  8015. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ResponseStatus, "%s" ,comfirmstr);
  8016. ShmOCPP16Data->ReserveNow[0].ConnectorId = connectorIdInt;
  8017. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ExpiryDate, "%s" , expiryDatestr);
  8018. sprintf((char *)ShmOCPP16Data->ReserveNow[0].IdTag, "%s" , idTagstr);
  8019. sprintf((char *)ShmOCPP16Data->ReserveNow[0].ParentIdTag, "%s" , parentIdTagstr);
  8020. ShmOCPP16Data->ReserveNow[0].ReservationId = reservationIdInt;
  8021. strcpy((char *)ShmOCPP16Data->ReserveNow[0].guid, uuid);
  8022. result = TRUE;
  8023. return result;
  8024. }
  8025. else
  8026. {
  8027. strcpy(comfirmstr, ReservationStatusStr[ReservationStatus_Rejected]);
  8028. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ResponseStatus, "%s" ,comfirmstr);
  8029. }
  8030. if(strcmp(comfirmstr,"Accepted") == 0)
  8031. {
  8032. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ConnectorId = connectorIdInt;
  8033. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ExpiryDate, "%s" , expiryDatestr);
  8034. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].IdTag, "%s" , idTagstr);
  8035. sprintf((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].ParentIdTag, "%s" , parentIdTagstr);
  8036. ShmOCPP16Data->ReserveNow[connectorIdInt-1].ReservationId = reservationIdInt;
  8037. strcpy((char *)ShmOCPP16Data->ReserveNow[connectorIdInt-1].guid, uuid);
  8038. result = TRUE;
  8039. return result;
  8040. }
  8041. end:
  8042. sendReserveNowTransactionConfirmation(uuid,comfirmstr);
  8043. //ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].ReserveNowConf = 1;
  8044. return result;
  8045. }
  8046. int handleResetRequest(char *uuid, char *payload)
  8047. {
  8048. mtrace();
  8049. int result = FAIL;
  8050. char sstr[10]={0},sstrtemp[30]={ 0 };
  8051. char typestr[10]={0};
  8052. char comfirmstr[20]={0};
  8053. int c = 0;
  8054. char *loc;
  8055. DEBUG_INFO("handleResetRequest...\n");
  8056. strcpy(sstrtemp, stringtrimspace(payload));
  8057. loc = strstr(sstrtemp, "type");
  8058. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8059. c = 0;
  8060. while (loc[3+strlen("type")+c] != '\"')
  8061. {
  8062. sstr[c] = loc[3+strlen("type")+c];
  8063. c++;
  8064. }
  8065. sstr[c] = '\0';
  8066. strcpy(typestr,sstr);
  8067. sprintf((char *)ShmOCPP16Data->Reset.Type, "%s" ,typestr);
  8068. if((strcmp(typestr, ResetTypeStr[Hard])==0) || (strcmp(typestr, ResetTypeStr[Soft])==0))
  8069. {
  8070. ShmOCPP16Data->MsMsg.bits.ResetReq = 1;
  8071. strcpy((char *)ShmOCPP16Data->Reset.guid, uuid);
  8072. result = TRUE;
  8073. return result;
  8074. }
  8075. else
  8076. {
  8077. strcpy(comfirmstr, ResetStatusStr[ResetStatus_Rejected]);
  8078. sprintf((char *)ShmOCPP16Data->Reset.ResponseStatus, "%s" ,comfirmstr);
  8079. goto errorend;
  8080. }
  8081. errorend:
  8082. sendResetConfirmation(uuid, comfirmstr);
  8083. return result;
  8084. }
  8085. int handleSendLocalListRequest(char *uuid, char *payload)
  8086. {
  8087. mtrace();
  8088. int result = FAIL;
  8089. int listVersionInt;
  8090. //char *updateTypestr, *idTagstr, *expiryDatestr, *parentIdTagstr, *statusstr;
  8091. char listsearch[]="listVersion";
  8092. char updateTypesearch[]="updateType";
  8093. char localAuthorizationListsearch[]="localAuthorizationList";
  8094. char sstr[60500]={ 0 },sstrtemp[60500]={ 0 };//sstr[200]={ 0 };
  8095. char CardList[500][160]={0};
  8096. char updateTypestr[15]={0};
  8097. char idTagstr[20]={0};
  8098. char parentIdTag[20]={0};
  8099. char expiryDate[30]={0};
  8100. char idTagstatus[16]={0};
  8101. int c = 0;
  8102. int i = 0;
  8103. char *delim1 = "}";
  8104. char * pch;
  8105. char *loc;
  8106. //char *ptr;
  8107. char comfirmstr[20];
  8108. //int n_localAuthorizations = 0;
  8109. int checkState_Faulted = FALSE;
  8110. DEBUG_INFO("handleSendLocalListRequest...\n");
  8111. if(strcmp((const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "FALSE") == 0) //For OCTT Test case
  8112. {
  8113. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8114. goto end;
  8115. }
  8116. //check Charge Point state
  8117. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8118. {
  8119. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8120. {
  8121. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8122. }
  8123. }
  8124. for (int index = 0; index < CCS_QUANTITY; index++)
  8125. {
  8126. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8127. {
  8128. checkState_Faulted = TRUE; //OCPP Status
  8129. }
  8130. }
  8131. for (int index = 0; index < GB_QUANTITY; index++)
  8132. {
  8133. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8134. {
  8135. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8136. }
  8137. }
  8138. //check Charge Point state
  8139. for (int index = 0; index < AC_QUANTITY; index++)
  8140. {
  8141. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_FAULT) //S_FAULT ---> Faulted
  8142. {
  8143. checkState_Faulted = TRUE; //OCPP Status: Faulted
  8144. }
  8145. }
  8146. if(checkState_Faulted == TRUE)
  8147. {
  8148. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8149. goto end;
  8150. }
  8151. //Filter payload space
  8152. strcpy(sstrtemp, stringtrimspace(payload));
  8153. //listVersion
  8154. c = 0;
  8155. loc = strstr(sstrtemp, listsearch);
  8156. while ((loc[strlen("listVersion")+2+c] != ',')&&(loc[strlen("listVersion")+2+c] != '}'))
  8157. {
  8158. sstr[c] = loc[strlen("listVersion")+2+c];
  8159. c++;
  8160. }
  8161. sstr[c] = '\0';
  8162. listVersionInt = atoi(sstr);
  8163. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8164. //updateType
  8165. loc = strstr(sstrtemp, updateTypesearch);
  8166. c = 0;
  8167. while (loc[3+strlen(updateTypesearch)+c] != '\"')
  8168. {
  8169. sstr[c] = loc[3+strlen(updateTypesearch)+c];
  8170. c++;
  8171. }
  8172. sstr[c] = '\0';
  8173. strcpy(updateTypestr, sstr);
  8174. sprintf((char *)ShmOCPP16Data->SendLocalList.UpdateType, "%s", updateTypestr);
  8175. //localAuthorizationList
  8176. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8177. loc = strstr(sstrtemp, localAuthorizationListsearch);
  8178. if(loc != NULL) // localAuthorizationList is not NULL
  8179. {
  8180. //Check UpdateType
  8181. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8182. {
  8183. //Local list full update
  8184. printf("Local list full update.\n");
  8185. OCPP_getListVerion();
  8186. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8187. {
  8188. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Failed]);
  8189. goto end;
  8190. }
  8191. OCPP_cleanLocalList();
  8192. }
  8193. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8194. {
  8195. //Local list different update
  8196. printf("Local list different update.\n");
  8197. OCPP_getListVerion();
  8198. if(listVersionInt < localversion )//if(listVersionInt <= localversion ) for OCTT Case ---remove temporally
  8199. {
  8200. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_VersionMismatch]);
  8201. goto end;
  8202. }
  8203. }
  8204. else
  8205. {
  8206. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_NotSupported]);
  8207. goto end;
  8208. }
  8209. c = 0;
  8210. while (loc[3+strlen(localAuthorizationListsearch)+c] != ']')
  8211. {
  8212. sstr[c] = loc[3+strlen(localAuthorizationListsearch)+c];
  8213. //printf("i=%d sstr=%c\n",c, sstr[c]);
  8214. c++;
  8215. }
  8216. sstr[c] = '\0';
  8217. //DEBUG_INFO("sstr=%s\n", sstr);
  8218. //parsing strings to words
  8219. i = 0;
  8220. pch = strtok(sstr,delim1);
  8221. while (pch != NULL)
  8222. {
  8223. strcpy(CardList[i], pch);
  8224. //DEBUG_INFO("CardList[i]=%s\n", CardList[i]);
  8225. pch = strtok (NULL, delim1);
  8226. i = i + 1;
  8227. }
  8228. //DEBUG_INFO("listVersionInt=%s\n", sstr);
  8229. //local Authorizations List Numbers
  8230. //n_localAuthorizations = i;
  8231. ShmOCPP16Data->SendLocalList.ListVersion = listVersionInt;
  8232. memset(ShmOCPP16Data->SendLocalList.LocalAuthorizationList, 0 , sizeof(struct StructLocalAuthorizationList)* 500);
  8233. c= 0;
  8234. while(c < i) // i is CardList Number
  8235. {
  8236. //Search "IdToken"
  8237. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8238. loc = strstr(CardList[c], "idTag");
  8239. int j = 0;
  8240. while (loc[3+strlen("idTag")+j] != '\"')
  8241. {
  8242. sstr[j] = loc[3+strlen("idTag")+j];
  8243. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8244. j++;
  8245. }
  8246. sstr[j] = '\0';
  8247. strcpy(idTagstr, sstr);
  8248. //DEBUG_INFO("idTagstr=%s\n", idTagstr);
  8249. //Search "expiryDate"
  8250. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8251. loc = strstr(CardList[c], "expiryDate");
  8252. j = 0;
  8253. if(loc != NULL)
  8254. {
  8255. while (loc[3+strlen("expiryDate")+j] != '\"')
  8256. {
  8257. sstr[j] = loc[3+strlen("expiryDate")+j];
  8258. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8259. j++;
  8260. }
  8261. sstr[j] = '\0';
  8262. strcpy(expiryDate, sstr);
  8263. }
  8264. else
  8265. {
  8266. strcpy(expiryDate, "");
  8267. }
  8268. //DEBUG_INFO("expiryDate=%s\n", expiryDate);
  8269. //Search "parentIdTag"
  8270. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8271. loc = strstr(CardList[c], "parentIdTag");
  8272. j = 0;
  8273. if(loc != NULL)
  8274. {
  8275. while (loc[3+strlen("parentIdTag")+j] != '\"')
  8276. {
  8277. sstr[j] = loc[3+strlen("parentIdTag")+j];
  8278. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8279. j++;
  8280. }
  8281. sstr[j] = '\0';
  8282. strcpy(parentIdTag, sstr);
  8283. }
  8284. else
  8285. {
  8286. strcpy(parentIdTag, "");
  8287. }
  8288. //DEBUG_INFO("parentIdTag=%s\n", parentIdTag);
  8289. //Search "status"
  8290. memset(sstr ,0, ARRAY_SIZE(sstr) );
  8291. loc = strstr(CardList[c], "status");
  8292. j = 0;
  8293. while (loc[3+strlen("status")+j] != '\"')
  8294. {
  8295. sstr[j] = loc[3+strlen("status")+j];
  8296. //printf("i=%d sstr=%c\n",c, sstr[j]);
  8297. j++;
  8298. }
  8299. sstr[j] = '\0';
  8300. strcpy(idTagstatus, sstr);
  8301. //DEBUG_INFO("idTagstatus=%s\n", idTagstatus);
  8302. OCPP_getIdTagFromLocalList(idTagstr);
  8303. //OCPP_getIdTagFromLocalList("test"); For Test
  8304. //DEBUG_INFO("idTagAuthorization=%s\n",idTagAuthorization);
  8305. //DEBUG_INFO("updateTypestr=%s\n",updateTypestr);
  8306. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8307. {
  8308. //Local list full update
  8309. DEBUG_INFO("Local list full update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8310. // update list
  8311. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8312. //DEBUG_INFO("Local list full update. 1\n");
  8313. //OCPP_get_TableAuthlocalAllData();
  8314. //DEBUG_INFO("Local list full update. 2\n");
  8315. }
  8316. else if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8317. {
  8318. DEBUG_INFO("Local list diff update %d, %d, %s, %s, %s, %s.\n", c, listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus);
  8319. OCPP_addLocalList(listVersionInt, idTagstr, parentIdTag, expiryDate, idTagstatus); // update or add
  8320. }
  8321. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTag, idTagstr);
  8322. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ExpiryDate, expiryDate);
  8323. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.ParentIdTag, parentIdTag);
  8324. strcpy((char *)ShmOCPP16Data->SendLocalList.LocalAuthorizationList[c].IdTagInfo.Status, idTagstatus);
  8325. c++;
  8326. }
  8327. }
  8328. else
  8329. {
  8330. //Check UpdateType
  8331. if(strcmp(updateTypestr, UpdateTypeStr[Full]) == 0)
  8332. {
  8333. //Local list full update
  8334. DEBUG_INFO("If no (empty) localAuthorizationList is given and the updateType is Full, all identifications are removed from the list. \n");
  8335. OCPP_cleanLocalList();
  8336. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8337. goto end;
  8338. }
  8339. if(strcmp(updateTypestr, UpdateTypeStr[Differential]) == 0)
  8340. {
  8341. //Local list different update
  8342. DEBUG_INFO("Requesting a Differential update without (empty) localAuthorizationList will have no effect on the list\n");
  8343. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8344. goto end;
  8345. }
  8346. }
  8347. strcpy(comfirmstr, UpdateStatusStr[UpdateStatus_Accepted]);
  8348. end:
  8349. sendSendLocalListConfirmation(uuid, comfirmstr);
  8350. //ShmOCPP16Data->MsMsg.bits.SendLocalListConf = 1;
  8351. return result;
  8352. }
  8353. #define MAX 200
  8354. int handleSetChargingProfileRequest(char *uuid, char *payload)
  8355. {
  8356. mtrace();
  8357. int result = FAIL;
  8358. int connectorIdInt=0, chargingProfileIdInt=0, transactionIdInt=0,stackLevelInt=0, durationInt=0, startPeriodInt[10]={0}, numberPhasesInt[10]={0};
  8359. int tempconnectorIdInt=0, tempchargingProfileIdInt=0, tempstackLevelInt=0;
  8360. char chargingProfilePurposeStr[30]={0};
  8361. char chargingProfileKindStr[16]={0};
  8362. char recurrencyKindStr[10]={0};
  8363. char validFromStr[30]={0}, validToStr[30]={0}, startScheduleStr[30]={0}, chargingRateUnitStr[6]={0};
  8364. float minChargingRateFloat = 0.0, limitflaot[10] = {0.0};
  8365. int chargingSchedulePeriodCount = 0;
  8366. char comfirmstr[20]={0};
  8367. int meet= FALSE;
  8368. FILE *fptr1;
  8369. char filename[MAX]={0};
  8370. char tempfile[] = "/Storage/OCPP/SetChargingProfiletemp.json";
  8371. char rmFileCmd[50]={0};
  8372. char tempchargingProfilePurposeStr[30]={0};
  8373. char word[1600]={0};
  8374. int n_chargingProfile = 0;
  8375. json_object *SetChargingProfile;
  8376. DEBUG_INFO("handleSetChargingProfileRequest\n");
  8377. connectorIdInt = chargingProfileIdInt = transactionIdInt = stackLevelInt = 0;
  8378. SetChargingProfile = json_tokener_parse(payload);
  8379. if(!is_error(SetChargingProfile))
  8380. {
  8381. if(json_object_object_get(SetChargingProfile, "connectorId") != NULL)
  8382. {
  8383. connectorIdInt = json_object_get_int(json_object_object_get(SetChargingProfile, "connectorId"));
  8384. if(connectorIdInt == 0)
  8385. {
  8386. memset(&ShmOCPP16Data->SetChargingProfile[0], 0x00, sizeof(struct StructSetChargingProfile));
  8387. ShmOCPP16Data->SetChargingProfile[0].ConnectorId = connectorIdInt;
  8388. }
  8389. else
  8390. {
  8391. memset(&ShmOCPP16Data->SetChargingProfile[connectorIdInt-1], 0x00, sizeof(struct StructSetChargingProfile));
  8392. ShmOCPP16Data->SetChargingProfile[connectorIdInt-1].ConnectorId = connectorIdInt;
  8393. }
  8394. //DEBUG_INFO("connectorId: %d\n", connectorIdInt);
  8395. }
  8396. if(json_object_object_get(SetChargingProfile, "csChargingProfiles") != NULL)
  8397. {
  8398. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  8399. {
  8400. chargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  8401. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8402. {
  8403. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8404. }
  8405. else
  8406. {
  8407. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileId = chargingProfileIdInt;
  8408. }
  8409. //DEBUG_INFO("chargingProfileIdInt: %d\n", chargingProfileIdInt);
  8410. }
  8411. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  8412. {
  8413. stackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "stackLevel"));
  8414. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8415. {
  8416. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.StackLevel = stackLevelInt;
  8417. }
  8418. else
  8419. {
  8420. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.StackLevel = stackLevelInt;
  8421. }
  8422. //DEBUG_INFO("stackLevelInt: %d\n", stackLevelInt);
  8423. }
  8424. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  8425. {
  8426. strcpy(chargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  8427. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8428. {
  8429. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8430. }
  8431. else
  8432. {
  8433. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfilePurpose, chargingProfilePurposeStr);
  8434. }
  8435. //DEBUG_INFO("chargingProfilePurposeStr: %s\n", chargingProfilePurposeStr);
  8436. }
  8437. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind") != NULL)
  8438. {
  8439. strcpy(chargingProfileKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingProfileKind")));
  8440. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8441. {
  8442. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8443. }
  8444. else
  8445. {
  8446. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingProfileKind, chargingProfileKindStr);
  8447. }
  8448. //DEBUG_INFO("chargingProfileKindStr: %s\n", chargingProfileKindStr);
  8449. }
  8450. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId") != NULL)
  8451. {
  8452. transactionIdInt = json_object_get_int(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "transactionId"));
  8453. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8454. {
  8455. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.TransactionId = transactionIdInt;
  8456. }
  8457. else
  8458. {
  8459. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.TransactionId = transactionIdInt;
  8460. }
  8461. //DEBUG_INFO("transactionIdInt: %d\n", transactionIdInt);
  8462. }
  8463. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind") != NULL)
  8464. {
  8465. strcpy(recurrencyKindStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "recurrencyKind")));
  8466. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8467. {
  8468. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8469. }
  8470. else
  8471. {
  8472. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.RecurrencyKind, recurrencyKindStr);
  8473. }
  8474. //DEBUG_INFO("recurrencyKindStr: %s\n", recurrencyKindStr);
  8475. }
  8476. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom") != NULL)
  8477. {
  8478. strcpy(validFromStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validFrom")));
  8479. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8480. {
  8481. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidFrom, validFromStr);
  8482. }
  8483. else
  8484. {
  8485. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidFrom, validFromStr);
  8486. }
  8487. //DEBUG_INFO("validFromStr: %s\n", validFromStr);
  8488. }
  8489. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo") != NULL)
  8490. {
  8491. strcpy(validToStr, json_object_get_string(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "validTo")));
  8492. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8493. {
  8494. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ValidTo, validToStr);
  8495. }
  8496. else
  8497. {
  8498. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ValidTo, validToStr);
  8499. }
  8500. //DEBUG_INFO("validToStr: %s\n", validToStr);
  8501. }
  8502. if(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule") != NULL)
  8503. {
  8504. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit") != NULL)
  8505. {
  8506. strcpy(chargingRateUnitStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingRateUnit")));
  8507. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8508. {
  8509. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8510. }
  8511. else
  8512. {
  8513. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingRateUnit,chargingRateUnitStr);
  8514. }
  8515. //DEBUG_INFO("chargingRateUnitStr: %s\n", chargingRateUnitStr);
  8516. }
  8517. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration") != NULL)
  8518. {
  8519. durationInt = json_object_get_int(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "duration"));
  8520. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8521. {
  8522. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8523. }
  8524. else
  8525. {
  8526. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.Duration = durationInt;
  8527. }
  8528. //DEBUG_INFO("durationInt: %d\n", durationInt);
  8529. }
  8530. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate") != NULL)
  8531. {
  8532. minChargingRateFloat = json_object_get_double(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "minChargingRate"));
  8533. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8534. {
  8535. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8536. }
  8537. else
  8538. {
  8539. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.MinChargingRate = minChargingRateFloat;
  8540. }
  8541. //DEBUG_INFO("minChargingRateFloat: %f\n", minChargingRateFloat);
  8542. }
  8543. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule") != NULL)
  8544. {
  8545. strcpy(startScheduleStr, json_object_get_string(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "startSchedule")));
  8546. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8547. {
  8548. strcpy((char *)ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8549. }
  8550. else
  8551. {
  8552. strcpy((char *)ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.StartSchedule,startScheduleStr);
  8553. }
  8554. //DEBUG_INFO("startScheduleStr: %s\n", startScheduleStr);
  8555. }
  8556. if(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod") != NULL)
  8557. {
  8558. chargingSchedulePeriodCount = json_object_array_length(json_object_object_get(json_object_object_get(json_object_object_get(SetChargingProfile, "csChargingProfiles"), "chargingSchedule"), "chargingSchedulePeriod"));
  8559. //DEBUG_INFO("chargingSchedulePeriodCount: %d\n", chargingSchedulePeriodCount);
  8560. if(chargingSchedulePeriodCount <= 10)
  8561. {
  8562. 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++)
  8563. {
  8564. 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)
  8565. {
  8566. 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"));
  8567. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8568. {
  8569. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8570. }
  8571. else
  8572. {
  8573. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].StartPeriod = startPeriodInt[idxPeriod];
  8574. }
  8575. //DEBUG_INFO("startPeriodInt[%d]: %d\n", idxPeriod, startPeriodInt[idxPeriod]);
  8576. }
  8577. 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)
  8578. {
  8579. 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"));
  8580. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8581. {
  8582. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8583. }
  8584. else
  8585. {
  8586. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].Limit = limitflaot[idxPeriod];
  8587. }
  8588. //DEBUG_INFO("limitflaot[%d]: %f\n", idxPeriod, limitflaot[idxPeriod]);
  8589. }
  8590. 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)
  8591. {
  8592. 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"));
  8593. if(connectorIdInt == 0) // an overall limit for the Charge Point.
  8594. {
  8595. ShmOCPP16Data->SetChargingProfile[0].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8596. }
  8597. else
  8598. {
  8599. ShmOCPP16Data->SetChargingProfile[connectorIdInt -1].ChargingProfile.ChargingSchedule.ChargingSchedulePeriod[idxPeriod].NumberPhases = numberPhasesInt[idxPeriod];
  8600. }
  8601. //DEBUG_INFO("numberPhasesInt[%d]: %d\n", idxPeriod, numberPhasesInt[idxPeriod]);
  8602. }
  8603. }
  8604. }
  8605. }
  8606. }
  8607. }
  8608. }
  8609. json_object_put(SetChargingProfile);
  8610. if( chargingSchedulePeriodCount > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData))
  8611. {
  8612. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8613. goto end;
  8614. }
  8615. if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[ChargePointMaxProfile]) == 0)
  8616. {
  8617. DEBUG_INFO("chargingProfilePurposeStr is ChargePointMaxProfile !!! \n");
  8618. if(connectorIdInt != 0)
  8619. {
  8620. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8621. goto end;
  8622. }
  8623. strcpy(filename, ChargePointMaxProfile_JSON );
  8624. fptr1 = fopen(filename, "r");
  8625. if (!fptr1)
  8626. {
  8627. //file not exist
  8628. DEBUG_INFO("Unable to open the input file!!\n");
  8629. fptr1 = fopen(filename, "w+");
  8630. }
  8631. else
  8632. {
  8633. //Check Charging Profile Count
  8634. while(fscanf(fptr1, "%s", word) != EOF)
  8635. {
  8636. //DEBUG_INFO("word=%s\n",word);
  8637. if(strstr(word, "chargingProfileId")!= NULL)
  8638. {
  8639. //DEBUG_INFO("test chargingProfileId \n");
  8640. n_chargingProfile = n_chargingProfile + 1;
  8641. //DEBUG_INFO("chargingProfileId Found\n");
  8642. }
  8643. }
  8644. }
  8645. fclose(fptr1);
  8646. }
  8647. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxDefaultProfile]) == 0)
  8648. {
  8649. DEBUG_INFO("chargingProfilePurposeStr is TxDefaultProfile !!! \n");
  8650. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8651. {
  8652. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8653. goto end;
  8654. }
  8655. memset(filename, 0, ARRAY_SIZE(filename));
  8656. sprintf(filename, "/Storage/OCPP/TxDefaultProfile_%d.json", connectorIdInt);
  8657. fptr1 = fopen(filename, "r");
  8658. if (!fptr1)
  8659. {
  8660. //file not exist
  8661. //DEBUG_INFO("Unable to open the input file!!\n");
  8662. fptr1 = fopen(filename, "w+");
  8663. }
  8664. else
  8665. {
  8666. //Check Charging Profile Count
  8667. while(fscanf(fptr1, "%s", word) != EOF)
  8668. {
  8669. //DEBUG_INFO("word=%s\n",word);
  8670. if(strstr(word, "chargingProfileId")!= NULL)
  8671. {
  8672. //DEBUG_INFO("test chargingProfileId \n");
  8673. n_chargingProfile = n_chargingProfile + 1;
  8674. //DEBUG_INFO("chargingProfileId Found\n");
  8675. }
  8676. }
  8677. }
  8678. fclose(fptr1);
  8679. }
  8680. else if(strcmp(chargingProfilePurposeStr, ChargingProfilePurposeTypeStr[TxProfile]) == 0)
  8681. {
  8682. //printf("set chargingProfile 1-4\n");
  8683. DEBUG_INFO("chargingProfilePurposeStr is TxProfile !!! \n");
  8684. //---TxProfile SHALL only be set at Charge Point ConnectorId > 0. ---//
  8685. if(connectorIdInt == 0)
  8686. {
  8687. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8688. goto end;
  8689. }
  8690. int tempIndex = 0;
  8691. //check Transaction active
  8692. if(gunType[connectorIdInt -1] == 'J')
  8693. {
  8694. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8695. {
  8696. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8697. }
  8698. else
  8699. {
  8700. tempIndex = connectorIdInt -1;
  8701. }
  8702. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  8703. {
  8704. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  8705. {
  8706. if(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8707. {
  8708. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8709. {
  8710. meet = TRUE;
  8711. break;
  8712. }
  8713. }
  8714. }
  8715. }
  8716. }
  8717. else if((gunType[connectorIdInt -1] == 'U')||(gunType[connectorIdInt -1] == 'E'))
  8718. {
  8719. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8720. {
  8721. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8722. }
  8723. else
  8724. {
  8725. tempIndex = connectorIdInt -1;
  8726. }
  8727. for (int index = 0; index < CCS_QUANTITY; index++)
  8728. {
  8729. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  8730. {
  8731. if(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8732. {
  8733. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8734. {
  8735. meet = TRUE;
  8736. break;
  8737. }
  8738. }
  8739. }
  8740. }
  8741. }
  8742. else if(gunType[connectorIdInt -1] == 'G')
  8743. {
  8744. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  8745. {
  8746. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  8747. }
  8748. else
  8749. {
  8750. tempIndex = connectorIdInt -1;
  8751. }
  8752. for (int index = 0; index < GB_QUANTITY; index++)
  8753. {
  8754. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  8755. {
  8756. if(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8757. {
  8758. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8759. {
  8760. meet = TRUE;
  8761. break;
  8762. }
  8763. }
  8764. }
  8765. }
  8766. }
  8767. else if(gunType[connectorIdInt -1] == 'O')
  8768. {
  8769. tempIndex = connectorIdInt -1;
  8770. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  8771. {
  8772. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  8773. {
  8774. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8775. {
  8776. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8777. {
  8778. meet = TRUE;
  8779. break;
  8780. }
  8781. }
  8782. }
  8783. }
  8784. }
  8785. else
  8786. {
  8787. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  8788. {
  8789. tempIndex = 2;
  8790. }
  8791. else
  8792. {
  8793. tempIndex = (connectorIdInt -1);
  8794. }
  8795. for (int index = 0; index < AC_QUANTITY; index++)
  8796. {
  8797. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  8798. {
  8799. if(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) // S_CHARGING
  8800. {
  8801. if(transactionIdInt == ShmOCPP16Data->StartTransaction[connectorIdInt -1].ResponseTransactionId)
  8802. {
  8803. meet = TRUE;
  8804. break;
  8805. }
  8806. }
  8807. }
  8808. }
  8809. }
  8810. //check Transaction active
  8811. if(meet == FALSE)
  8812. {
  8813. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8814. goto end;
  8815. }
  8816. if((connectorIdInt != 0) && (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/))
  8817. {
  8818. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8819. goto end;
  8820. }
  8821. sprintf(filename, "/Storage/OCPP/TxProfile_%d.json", connectorIdInt);
  8822. fptr1 = fopen(filename, "r");
  8823. if (!fptr1)
  8824. {
  8825. //file not exist
  8826. DEBUG_INFO("Unable to open the input file!!\n");
  8827. fptr1 = fopen(filename, "w+");
  8828. }
  8829. else
  8830. {
  8831. //Check Charging Profile Count
  8832. while(fscanf(fptr1, "%s", word) != EOF)
  8833. {
  8834. //DEBUG_INFO("word=%s\n",word);
  8835. if(strstr(word, "chargingProfileId")!= NULL)
  8836. {
  8837. //DEBUG_INFO("test chargingProfileId \n");
  8838. n_chargingProfile = n_chargingProfile + 1;
  8839. //DEBUG_INFO("chargingProfileId Found\n");
  8840. }
  8841. }
  8842. }
  8843. fclose(fptr1);
  8844. }
  8845. // Check ChargeProfileMaxStackLevel
  8846. if(n_chargingProfile >= atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData))
  8847. {
  8848. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8849. goto end;
  8850. }
  8851. //------------------------------Satrt: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8852. {
  8853. int i = 0;
  8854. char fnametemp[200]={0};
  8855. n_chargingProfile = 0;
  8856. //Check ChargePointMaxProfile.json exit
  8857. if((access("/Storage/OCPP/ChargePointMaxProfile.json",F_OK))!=-1)
  8858. {
  8859. fptr1 = fopen("/Storage/OCPP/ChargePointMaxProfile.json", "r");
  8860. //Check Charging Profile Count
  8861. while(fscanf(fptr1, "%s", word) != EOF)
  8862. {
  8863. //DEBUG_INFO("word=%s\n",word);
  8864. if(strstr(word, "chargingProfileId")!= NULL)
  8865. {
  8866. //DEBUG_INFO("test chargingProfileId \n");
  8867. n_chargingProfile = n_chargingProfile + 1;
  8868. i = i + 1;
  8869. //DEBUG_INFO("chargingProfileId Found\n");
  8870. }
  8871. memset(word, 0, ARRAY_SIZE(word));
  8872. }
  8873. fclose(fptr1);
  8874. DEBUG_INFO("ChargePointMaxProfile.json has %d charging Profile\n",i );
  8875. }
  8876. //Check TxDefaultProfile_0.json exit
  8877. if((access("/Storage/OCPP/TxDefaultProfile_0.json",F_OK))!=-1)
  8878. {
  8879. i = 0;
  8880. fptr1 = fopen("/Storage/OCPP/TxDefaultProfile_0.json", "r");
  8881. //Check Charging Profile Count
  8882. while(fscanf(fptr1, "%s", word) != EOF)
  8883. {
  8884. //DEBUG_INFO("word=%s\n",word);
  8885. if(strstr(word, "chargingProfileId")!= NULL)
  8886. {
  8887. //DEBUG_INFO("test chargingProfileId \n");
  8888. n_chargingProfile = n_chargingProfile + 1;
  8889. i = i + 1;
  8890. //DEBUG_INFO("chargingProfileId Found\n");
  8891. }
  8892. memset(word, 0, ARRAY_SIZE(word));
  8893. }
  8894. fclose(fptr1);
  8895. DEBUG_INFO("TxDefaultProfile_0.json has %d charging Profile\n",i );
  8896. }
  8897. //Check TxDefaultProfile_%d.json
  8898. for(int j=1; j <= gunTotalNumber; j++)
  8899. {
  8900. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8901. sprintf(fnametemp, "/Storage/OCPP/TxDefaultProfile_%d.json", j);
  8902. if((access(fnametemp,F_OK))!=-1)
  8903. {
  8904. i = 0;
  8905. fptr1 = fopen(fnametemp, "r");
  8906. //Check Charging Profile Count
  8907. while(fscanf(fptr1, "%s", word) != EOF)
  8908. {
  8909. //DEBUG_INFO("word=%s\n",word);
  8910. if(strstr(word, "chargingProfileId")!= NULL)
  8911. {
  8912. //DEBUG_INFO("test chargingProfileId \n");
  8913. n_chargingProfile = n_chargingProfile + 1;
  8914. i = i + 1;
  8915. //DEBUG_INFO("chargingProfileId Found\n");
  8916. }
  8917. memset(word, 0, ARRAY_SIZE(word));
  8918. }
  8919. fclose(fptr1);
  8920. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8921. }
  8922. }
  8923. //Check TxProfile_%d.json
  8924. for(int j=1; j <= gunTotalNumber; j++)
  8925. {
  8926. memset(fnametemp, 0, ARRAY_SIZE(fnametemp));
  8927. sprintf(fnametemp, "/Storage/OCPP/TxProfile_%d.json", j);
  8928. if((access(fnametemp,F_OK))!=-1)
  8929. {
  8930. i = 0;
  8931. fptr1 = fopen(fnametemp, "r");
  8932. //Check Charging Profile Count
  8933. while(fscanf(fptr1, "%s", word) != EOF)
  8934. {
  8935. //DEBUG_INFO("word=%s\n",word);
  8936. if(strstr(word, "chargingProfileId")!= NULL)
  8937. {
  8938. //DEBUG_INFO("test chargingProfileId \n");
  8939. n_chargingProfile = n_chargingProfile + 1;
  8940. i = i + 1;
  8941. //DEBUG_INFO("chargingProfileId Found\n");
  8942. }
  8943. memset(word, 0, ARRAY_SIZE(word));
  8944. }
  8945. fclose(fptr1);
  8946. DEBUG_INFO("%s has %d charging Profile\n",fnametemp, i);
  8947. }
  8948. }
  8949. if( n_chargingProfile > atoi((const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData))
  8950. {
  8951. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Rejected] );
  8952. goto end;
  8953. }
  8954. }
  8955. //------------------------------End: Check Configuration Key "MaxChargingProfilesInstalled" Logic---------------------------------------//
  8956. //**********************************Write to File********************************************************/
  8957. FILE *infile;
  8958. FILE *outfile;
  8959. infile = fopen (filename, "r");
  8960. outfile = fopen (tempfile, "w");
  8961. int d =0;
  8962. d = fgetc(infile);
  8963. rewind(infile);
  8964. if(d == EOF)
  8965. {
  8966. // Profile is empty
  8967. fprintf(outfile,"%s\n",payload);
  8968. fclose(infile);
  8969. fclose(outfile);
  8970. sprintf(rmFileCmd,"rm -f %s",filename);
  8971. system(rmFileCmd);
  8972. rename(tempfile, filename);
  8973. }
  8974. else
  8975. {
  8976. // Profile is not empty
  8977. char buf[2048]={0};
  8978. int ChargingProfileAdded = FALSE;
  8979. while (fgets(buf, sizeof(buf), infile) != NULL)
  8980. {
  8981. buf[strlen(buf) - 1] = '\0'; // eat the newline fgets() stores
  8982. json_object *tmpChargingProfile;
  8983. tmpChargingProfile = json_tokener_parse(buf);
  8984. if(!is_error(SetChargingProfile))
  8985. {
  8986. if(json_object_object_get(tmpChargingProfile, "connectorId") != NULL)
  8987. {
  8988. tempconnectorIdInt = json_object_get_int(json_object_object_get(tmpChargingProfile, "connectorId") );
  8989. }
  8990. if(json_object_object_get(tmpChargingProfile, "csChargingProfiles") != NULL)
  8991. {
  8992. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId") != NULL)
  8993. {
  8994. tempchargingProfileIdInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfileId"));
  8995. }
  8996. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel") != NULL)
  8997. {
  8998. tempstackLevelInt = json_object_get_int(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "stackLevel"));
  8999. }
  9000. if(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose") != NULL)
  9001. {
  9002. strcpy(tempchargingProfilePurposeStr, json_object_get_string(json_object_object_get(json_object_object_get(tmpChargingProfile, "csChargingProfiles"), "chargingProfilePurpose")));
  9003. }
  9004. }
  9005. }
  9006. json_object_put(tmpChargingProfile);
  9007. if((tempconnectorIdInt == connectorIdInt) && (tempchargingProfileIdInt == chargingProfileIdInt))
  9008. {
  9009. if((tempstackLevelInt == stackLevelInt) && (strcmp(tempchargingProfilePurposeStr, chargingProfilePurposeStr) == 0))
  9010. {
  9011. //DEBUG_INFO("update set chargingProfile to file -0\n");
  9012. if(ChargingProfileAdded == FALSE)
  9013. {
  9014. fprintf(outfile,"%s\n",payload);
  9015. ChargingProfileAdded = TRUE;
  9016. }
  9017. }
  9018. else
  9019. {
  9020. if(tempstackLevelInt < stackLevelInt)
  9021. {
  9022. if(ChargingProfileAdded == FALSE)
  9023. {
  9024. fprintf(outfile,"%s\n",buf);
  9025. fprintf(outfile,"%s\n",payload);
  9026. ChargingProfileAdded = TRUE;
  9027. }
  9028. else
  9029. {
  9030. fprintf(outfile,"%s\n",buf);
  9031. }
  9032. }
  9033. else
  9034. {
  9035. if(ChargingProfileAdded == FALSE)
  9036. {
  9037. fprintf(outfile,"%s\n",buf);
  9038. fprintf(outfile,"%s\n",payload);
  9039. ChargingProfileAdded = TRUE;
  9040. }
  9041. else
  9042. {
  9043. fprintf(outfile,"%s\n",buf);
  9044. }
  9045. }
  9046. }
  9047. }
  9048. else
  9049. {
  9050. if(tempchargingProfileIdInt < chargingProfileIdInt)
  9051. {
  9052. if(ChargingProfileAdded == FALSE)
  9053. {
  9054. fprintf(outfile,"%s\n",buf);
  9055. fprintf(outfile,"%s\n",payload);
  9056. ChargingProfileAdded = TRUE;
  9057. }
  9058. else
  9059. {
  9060. fprintf(outfile,"%s\n",buf);
  9061. }
  9062. }
  9063. else if(tempstackLevelInt < stackLevelInt)
  9064. {
  9065. if(ChargingProfileAdded == FALSE)
  9066. {
  9067. fprintf(outfile,"%s\n",buf);
  9068. fprintf(outfile,"%s\n",payload);
  9069. ChargingProfileAdded = TRUE;
  9070. }
  9071. else
  9072. {
  9073. fprintf(outfile,"%s\n",buf);
  9074. }
  9075. }
  9076. else
  9077. {
  9078. if(ChargingProfileAdded == FALSE)
  9079. {
  9080. fprintf(outfile,"%s\n",buf);
  9081. fprintf(outfile,"%s\n",payload);
  9082. ChargingProfileAdded = TRUE;
  9083. }
  9084. else
  9085. {
  9086. fprintf(outfile,"%s\n",buf);
  9087. }
  9088. }
  9089. }
  9090. } // end of while loop
  9091. fclose(infile);
  9092. fclose(outfile);
  9093. sprintf(rmFileCmd,"rm -f %s",filename);
  9094. system(rmFileCmd);
  9095. rename(tempfile, filename);
  9096. }
  9097. sleep(1);
  9098. result = TRUE;
  9099. sprintf(comfirmstr, "%s", ChargingProfileStatusStr[ChargingProfileStatus_Accepted] );
  9100. end:
  9101. if(strcmp(comfirmstr, ChargingProfileStatusStr[ChargingProfileStatus_Accepted]) == 0)
  9102. {
  9103. if(connectorIdInt == 0)
  9104. {
  9105. for(uint8_t idx=0;idx<gunTotalNumber;idx++)
  9106. {
  9107. checkCompositeSchedule((idx+1), 86400, &ShmOCPP16Data->SmartChargingProfile[idx]);
  9108. }
  9109. }
  9110. else
  9111. checkCompositeSchedule(connectorIdInt, 86400, &ShmOCPP16Data->SmartChargingProfile[connectorIdInt-1]);
  9112. }
  9113. sendSetChargingProfileConfirmation(uuid, comfirmstr);
  9114. return result;
  9115. }
  9116. int handleTriggerMessageRequest(char *uuid, char *payload)
  9117. {
  9118. mtrace();
  9119. int result = FAIL;
  9120. int connectorIdIsNULL = FALSE;
  9121. int connectorIdInt =0;
  9122. char sstr[40]={0},sstrtemp[100]={ 0 };
  9123. char requestedMessagestr[40]={0};
  9124. char comfirmstr[20]={0};
  9125. int c = 0;
  9126. char *loc;
  9127. DEBUG_INFO("handleTriggerMessageRequest\n");
  9128. //[2,"266e23f4-27a4-41cf-84cb-aadf56b9523f","TriggerMessage",{"requestedMessage":"DiagnosticsStatusNotification","connectorId":1}]
  9129. strcpy(sstrtemp, stringtrimspace(payload));
  9130. c = 0;
  9131. loc = strstr(sstrtemp, "requestedMessage");
  9132. while (loc[3+strlen("requestedMessage")+c] != '\"')
  9133. {
  9134. sstr[c] = loc[3+strlen("requestedMessage")+c];
  9135. c++;
  9136. }
  9137. sstr[c] = '\0';
  9138. strcpy(requestedMessagestr, sstr);
  9139. c = 0;
  9140. loc = strstr(sstrtemp, "connectorId");
  9141. if(loc == NULL)
  9142. {
  9143. connectorIdIsNULL = TRUE;
  9144. }
  9145. else
  9146. {
  9147. memset(sstr ,0, ARRAY_SIZE(sstr) );
  9148. while ((loc[strlen("connectorId")+2+c] != ',')&&(loc[strlen("connectorId")+2+c] != '}'))
  9149. {
  9150. sstr[c] = loc[strlen("connectorId")+2+c];
  9151. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9152. c++;
  9153. }
  9154. sstr[c] = '\0';
  9155. connectorIdInt = atoi(sstr);
  9156. }
  9157. if((connectorIdIsNULL == TRUE) || ((connectorIdIsNULL == FALSE) && ((connectorIdInt > 0) && (connectorIdInt <= gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/ ))) )
  9158. {
  9159. sprintf((char *)ShmOCPP16Data->TriggerMessage[connectorIdInt -1].RequestedMessage, "%s" ,requestedMessagestr);
  9160. ShmOCPP16Data->TriggerMessage[connectorIdInt -1].ConnectorId = connectorIdInt;
  9161. if((strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) != 0) &&
  9162. (strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) != 0) &&
  9163. (strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) != 0 ) &&
  9164. (strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) != 0) &&
  9165. (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) != 0) &&
  9166. (strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) != 0 ))
  9167. {
  9168. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_NotImplemented] );
  9169. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9170. return TRUE;
  9171. }
  9172. else
  9173. {
  9174. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Accepted] );
  9175. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9176. }
  9177. }
  9178. else if(connectorIdIsNULL == FALSE && ((connectorIdInt <= 0) || (connectorIdInt > gunTotalNumber /*(CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY)*/) ))
  9179. {
  9180. sprintf(comfirmstr, "%s",TriggerMessageStatusStr[TriggerMessageStatus_Rejected] );
  9181. sendTriggerMessageConfirmation(uuid,comfirmstr);
  9182. return TRUE;
  9183. }
  9184. //==========================
  9185. // Trigger message
  9186. //==========================
  9187. if( strcmp(requestedMessagestr, MessageTriggerStr[FirmwareStatusNotification]) == 0)
  9188. {
  9189. if((FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADING) &&
  9190. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_DOWNLOADED) &&
  9191. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_IDLE) &&
  9192. (FirmwareStatusNotificationStatus != FIRMWARE_STATUS_INSTALLING) )
  9193. {
  9194. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE;
  9195. }
  9196. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatusNotificationStatus]);
  9197. }
  9198. else if(strcmp(requestedMessagestr, MessageTriggerStr[DiagnosticsStatusNotification]) == 0 )
  9199. {
  9200. sendDiagnosticsStatusNotificationRequest(DiagnosticsStatusStr[DiagnosticsStatusNotificationStatus]);
  9201. }
  9202. else if(strcmp(requestedMessagestr, MessageTriggerStr[BootNotification]) == 0 )
  9203. {
  9204. //sendBootNotificationRequest();
  9205. server_sign = FALSE;
  9206. }
  9207. else if(strcmp(requestedMessagestr, MessageTriggerStr[Heartbeat]) == 0 )
  9208. {
  9209. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval);
  9210. }
  9211. else if (strcmp(requestedMessagestr, MessageTriggerStr[MeterValues]) == 0 )
  9212. {
  9213. if(connectorIdIsNULL == FALSE)
  9214. {
  9215. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9216. {
  9217. //sendMeterValuesRequest((connectorIdInt -1), ReadingContext_Trigger);
  9218. cpinitateMsg.bits[connectorIdInt -1].TriggerMeterValue = 1;
  9219. }
  9220. }
  9221. else
  9222. {
  9223. for(int idx=0;idx< gunTotalNumber;idx++)
  9224. {
  9225. //sendMeterValuesRequest(idx, ReadingContext_Trigger);
  9226. cpinitateMsg.bits[idx].TriggerMeterValue = 1;
  9227. }
  9228. }
  9229. }
  9230. else if(strcmp(requestedMessagestr, MessageTriggerStr[StatusNotification]) == 0 )
  9231. {
  9232. if(connectorIdIsNULL == FALSE)
  9233. {
  9234. if((connectorIdInt > 0) && ((connectorIdInt -1) < gunTotalNumber))
  9235. {
  9236. cpinitateMsg.bits[connectorIdInt -1].StatusNotificationReq = 1;
  9237. }
  9238. }
  9239. else
  9240. {
  9241. for(int idx=0;idx< gunTotalNumber;idx++)
  9242. cpinitateMsg.bits[idx].StatusNotificationReq = 1;
  9243. }
  9244. }
  9245. return result;
  9246. }
  9247. int handleUnlockConnectorRequest(char *uuid, char *payload)
  9248. {
  9249. mtrace();
  9250. int result = FAIL;
  9251. int connectorIdInt =0;
  9252. char comfirmstr[20]={0};
  9253. int tempIndex = 0;
  9254. json_object *UnlockConnector;
  9255. //[2,"ba1cbd49-2a76-493a-8f76-fa23e7606532","UnlockConnector",{"connectorId":1}]
  9256. DEBUG_INFO("handleUnlockConnectorRequest ...\n");
  9257. UnlockConnector = json_tokener_parse(payload);
  9258. if(!is_error(UnlockConnector))
  9259. {
  9260. if(json_object_object_get(UnlockConnector, "connectorId") != NULL)
  9261. {
  9262. connectorIdInt = json_object_get_int(json_object_object_get(UnlockConnector, "connectorId"));
  9263. }
  9264. }
  9265. json_object_put(UnlockConnector);
  9266. DEBUG_INFO("Unlock connectorIdInt = %d\n",connectorIdInt);
  9267. if(gunTotalNumber == 0)
  9268. {
  9269. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9270. goto end;
  9271. }
  9272. else if((connectorIdInt > gunTotalNumber/*CHAdeMO_QUANTITY+ CCS_QUANTITY + GB_QUANTITY*/) || (connectorIdInt <= 0))
  9273. {
  9274. //sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9275. sprintf(comfirmstr, "%s", UnlockStatusStr[UnlockStatus_NotSupported] );
  9276. goto end;
  9277. }
  9278. else
  9279. {
  9280. //check Transaction active
  9281. if(gunType[connectorIdInt-1] == 'J')
  9282. {
  9283. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9284. {
  9285. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9286. }
  9287. else
  9288. {
  9289. tempIndex = connectorIdInt -1;
  9290. }
  9291. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  9292. {
  9293. if ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9294. {
  9295. //stop Transaction
  9296. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9297. }
  9298. }
  9299. }
  9300. else if((gunType[connectorIdInt-1] == 'U')||(gunType[connectorIdInt-1] == 'E'))
  9301. {
  9302. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9303. {
  9304. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9305. }
  9306. else
  9307. {
  9308. tempIndex = connectorIdInt -1;
  9309. }
  9310. for (int index = 0; index < CCS_QUANTITY; index++)
  9311. {
  9312. if ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9313. {
  9314. //stop Transaction
  9315. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9316. }
  9317. }
  9318. }
  9319. else if(gunType[connectorIdInt-1] == 'G')
  9320. {
  9321. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  9322. {
  9323. tempIndex = (((connectorIdInt -1)==2) ? 1: 0);
  9324. }
  9325. else
  9326. {
  9327. tempIndex = connectorIdInt -1;
  9328. }
  9329. for (int index = 0; index < GB_QUANTITY; index++)
  9330. {
  9331. if ((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].SystemStatus == SYS_MODE_IDLE)))
  9332. {
  9333. //stop Transaction
  9334. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9335. }
  9336. }
  9337. }
  9338. else if(gunType[connectorIdInt-1] == 'O')
  9339. {
  9340. tempIndex = connectorIdInt -1;
  9341. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  9342. {
  9343. if ((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex ) &&((ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_CHARGING)||(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.SystemStatus == SYS_MODE_IDLE)))
  9344. {
  9345. //stop Transaction
  9346. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9347. }
  9348. }
  9349. }
  9350. else
  9351. {
  9352. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9353. {
  9354. tempIndex = 2;
  9355. }
  9356. else
  9357. {
  9358. tempIndex = connectorIdInt-1;
  9359. }
  9360. for (int index = 0; index < AC_QUANTITY; index++)
  9361. {
  9362. if ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex ) && ((ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_CHARGING) || (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].SystemStatus == SYS_MODE_IDLE) ))
  9363. {
  9364. ShmOCPP16Data->CsMsg.bits[connectorIdInt-1].UnlockConnectorReq = 1;
  9365. }
  9366. }
  9367. }
  9368. ShmOCPP16Data->UnlockConnector[connectorIdInt-1].ConnectorId = connectorIdInt;
  9369. strcpy((char *)ShmOCPP16Data->UnlockConnector[connectorIdInt-1].guid, uuid);
  9370. result = TRUE;
  9371. return result;
  9372. }
  9373. end:
  9374. //json_object_put(obj); --- remove temporally
  9375. sendUnlockConnectorConfirmation(uuid, comfirmstr);
  9376. return result;
  9377. }
  9378. static char UpdateFirmwarepayloadData[300]={0};
  9379. int handleUpdateFirmwareRequest(char *uuid, char *payload)
  9380. {
  9381. mtrace();
  9382. int result = FAIL;
  9383. pthread_t t;
  9384. sendUpdateFirmwareConfirmation(uuid);
  9385. memset(UpdateFirmwarepayloadData, 0, 300);
  9386. strcpy(UpdateFirmwarepayloadData, stringtrimspace(payload));
  9387. pthread_create(&t, NULL, UpdateFirmwareProcess, stringtrimspace(payload));
  9388. ////pthread_join(t, NULL); //
  9389. //pthread_detach(t);
  9390. //sendUpdateFirmwareConfirmation(uuid);
  9391. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareConf =1;
  9392. return result;
  9393. }
  9394. void *UpdateFirmwareProcess(void *data)
  9395. {
  9396. pthread_detach(pthread_self());
  9397. mtrace();
  9398. int retriesInt =0, retryIntervalInt=0;
  9399. char protocol[10], user[50],password[50],host[50], path[50], ftppath[60],host1[50],path1[20];
  9400. int port=0;
  9401. char locationstr[160]={0}, retrieveDatestr[30]={0};
  9402. int isSuccess = 0;
  9403. char ftpbuf[200];
  9404. char temp[100];
  9405. char * pch;
  9406. DEBUG_INFO("handleUpdateFirmwareRequest ...\n");
  9407. json_object *UpdateFirmware;
  9408. UpdateFirmware = json_tokener_parse(UpdateFirmwarepayloadData);
  9409. if(!is_error(UpdateFirmware))
  9410. {
  9411. // Required data
  9412. if(json_object_object_get(UpdateFirmware, "location") != NULL)
  9413. sprintf((char*)locationstr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "location")));
  9414. if(json_object_object_get(UpdateFirmware, "retrieveDate") != NULL)
  9415. sprintf((char*)retrieveDatestr, "%s", json_object_get_string(json_object_object_get(UpdateFirmware, "retrieveDate")));
  9416. // Optional data
  9417. if(json_object_object_get(UpdateFirmware, "retries"))
  9418. {
  9419. retriesInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retries"));
  9420. }
  9421. if(json_object_object_get(UpdateFirmware, "retryInterval"))
  9422. {
  9423. retryIntervalInt = json_object_get_int(json_object_object_get(UpdateFirmware, "retryInterval"));
  9424. }
  9425. }
  9426. json_object_put(UpdateFirmware);
  9427. memset(ftppath, 0, ARRAY_SIZE(ftppath));
  9428. memset(path, 0, ARRAY_SIZE(path));
  9429. system("rm -f /mnt/*");
  9430. if(strncmp(locationstr,"http", 4) == 0)
  9431. {
  9432. sscanf(locationstr,"%[^:]:%*2[/]%[^/]/%199[^\n]", protocol, host, path);
  9433. //sscanf(locationstr,"%[^:]:%*2[/]%[^:]:%[^@]@%[^/]%199[^\n]",
  9434. // protocol, user, password, host, path);
  9435. sprintf(ftppath,"/%s", path);
  9436. DEBUG_INFO("locationstr: %s\n", locationstr);
  9437. DEBUG_INFO("protocol: %s\n",protocol);
  9438. DEBUG_INFO("host: %s\n",host);
  9439. DEBUG_INFO("path: %s\n",path);
  9440. DEBUG_INFO("ftppath: %s\n",ftppath);
  9441. int ftppathlen=strlen(ftppath);
  9442. int i=1;
  9443. char filenametemp[50];
  9444. while(i < ftppathlen)
  9445. {
  9446. int len=ftppathlen-i;
  9447. if(ftppath[len]== 47) // '/' ascll code: 47
  9448. {
  9449. DEBUG_INFO("compare '/' all right\n");
  9450. break;
  9451. }
  9452. i=i+1;
  9453. }
  9454. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9455. strncpy(filenametemp, ftppath+(ftppathlen-i+1), i+1);
  9456. filenametemp[i+1] = 0;
  9457. do
  9458. {
  9459. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9460. sleep(3);
  9461. isSuccess = httpDownLoadFile(host, ftppath, filenametemp, locationstr);
  9462. if(!isSuccess)
  9463. {
  9464. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9465. sleep(retryIntervalInt);
  9466. }
  9467. else
  9468. {
  9469. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9470. }
  9471. }while((isSuccess == 0)&&(retriesInt > 0 && retriesInt --));
  9472. }
  9473. else if(strncmp(locationstr,"ftp", 3) == 0) // ftp
  9474. {
  9475. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  9476. memset(temp, 0, ARRAY_SIZE(temp));
  9477. //DEBUG_INFO("locationstr=%s\n",locationstr);
  9478. strcpy(ftpbuf, locationstr/*"ftp://ipc_ui:pht2016@ftp.phihong.com.tw/DC/log/DemoDC1_2018-07-13_185011_PSULog.zip"*/ );
  9479. int ftppathlen=strlen(ftpbuf);
  9480. int i=1;
  9481. char filenametemp[50];
  9482. while(i < ftppathlen)
  9483. {
  9484. int len=ftppathlen-i;
  9485. if(ftpbuf[len]== 47) // '/' ascll code: 47
  9486. {
  9487. DEBUG_INFO(" compare '/' all right\n");
  9488. break;
  9489. }
  9490. i=i+1;
  9491. }
  9492. memset(filenametemp, 0, ARRAY_SIZE(filenametemp));
  9493. strncpy(filenametemp, ftpbuf+(ftppathlen-i+1), i+1);
  9494. filenametemp[i+1] = 0;
  9495. strncpy(temp, ftpbuf, ftppathlen-i+1);
  9496. pch=strchr(temp,'@');
  9497. if(pch==NULL)
  9498. {
  9499. sscanf(temp,"%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  9500. protocol, host, &port, path);
  9501. strcpy(user,"anonymous");
  9502. strcpy(password,"");
  9503. }
  9504. else
  9505. {
  9506. sscanf(temp,"%[^:]:%*2[/]%[^:]:%[^@]@%[^:]:%i/%199[^\n]",
  9507. protocol, user, password, host, &port, path);
  9508. }
  9509. sscanf(host,"%[^/]%s",host1, path1);
  9510. sprintf(ftppath,"%s", path1);
  9511. //DEBUG_INFO("protocol =%s\n",protocol);
  9512. //DEBUG_INFO("user =%s\n",user);
  9513. //DEBUG_INFO("password =%s\n",password);
  9514. //DEBUG_INFO("host1 =%s\n",host1);
  9515. //DEBUG_INFO("port =%d\n",port);
  9516. //DEBUG_INFO("path1 =%s\n",path1);
  9517. //DEBUG_INFO("ftppath=%s\n",ftppath);
  9518. //ftpFile(host, user, password, port, ftppath, fname);
  9519. //download firmware pthred
  9520. if(port == 0)
  9521. {
  9522. port = 21;
  9523. }
  9524. do
  9525. {
  9526. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloading]);
  9527. sleep(3);
  9528. isSuccess = ftpDownLoadFile(host1, user, password, port, ftppath, filenametemp, locationstr);
  9529. if(!isSuccess)
  9530. {
  9531. //BulldogUtil.sleepMs(interval*1000);
  9532. DEBUG_INFO("Update firmware request and download file fail.\n");
  9533. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9534. sleep(retryIntervalInt);
  9535. }
  9536. else
  9537. {
  9538. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_Downloaded]);
  9539. }
  9540. }while((!isSuccess)&&(retriesInt > 0 && retriesInt --));
  9541. }
  9542. else
  9543. {
  9544. sendFirmwareStatusNotificationRequest(FirmwareStatusStr[FirmwareStatus_DownloadFailed]);
  9545. }
  9546. ShmOCPP16Data->MsMsg.bits.UpdateFirmwareReq = 1;
  9547. pthread_exit(NULL);
  9548. }
  9549. //==========================================
  9550. // Handle server response routine
  9551. //==========================================
  9552. void handleAuthorizeResponse(char *payload, int gun_index)
  9553. {
  9554. mtrace();
  9555. char expiryDatestr[30]={0};
  9556. char parentIdTagstr[20]={0};
  9557. char statusstr[20]={0};
  9558. int expiryDateISNULL=FALSE;
  9559. int parentIdTagISNULL=FALSE;
  9560. DEBUG_INFO("handleAuthorizeResponse...\n");
  9561. json_object *Authorize;
  9562. Authorize = json_tokener_parse(payload);
  9563. if(!is_error(Authorize))
  9564. {
  9565. if(json_object_object_get(Authorize, "idTagInfo") != NULL)
  9566. {
  9567. // Required data
  9568. sprintf((char *)statusstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "status")));
  9569. // Optional data
  9570. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate") != NULL)
  9571. sprintf((char *)expiryDatestr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "expiryDate")));
  9572. if(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag") != NULL)
  9573. sprintf((char *)parentIdTagstr, "%s", json_object_get_string(json_object_object_get(json_object_object_get(Authorize,"idTagInfo"), "parentIdTag")));
  9574. }
  9575. }
  9576. json_object_put(Authorize);
  9577. if(expiryDateISNULL == FALSE)
  9578. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate, expiryDatestr);
  9579. if(parentIdTagISNULL == FALSE)
  9580. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag, parentIdTagstr);
  9581. strcpy((char *)ShmOCPP16Data->Authorize.ResponseIdTagInfo.Status, statusstr);
  9582. //Update idTag information to authorization cache if supproted
  9583. if((strcmp((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "TRUE") == 0) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ParentIdTag != NULL) && (ShmOCPP16Data->Authorize.ResponseIdTagInfo.ExpiryDate != NULL) )
  9584. {
  9585. OCPP_addLocalCache((char*)ShmOCPP16Data->Authorize.IdTag, parentIdTagstr, expiryDatestr, statusstr);
  9586. }
  9587. ShmOCPP16Data->SpMsg.bits.AuthorizeReq = 0;
  9588. ShmOCPP16Data->SpMsg.bits.AuthorizeConf = 1; // inform csu
  9589. authorizeRetryTimes = 0;
  9590. }
  9591. void handleBootNotificationResponse(char *payload, int gun_index)
  9592. {
  9593. mtrace();
  9594. char statusStr[12]={0};
  9595. char currentTimeStr[30]={0};
  9596. int intervalInt = 0;
  9597. struct tm tp;
  9598. char buf[28]={0};
  9599. char timebuf[50]={0};
  9600. DEBUG_INFO("handleBootNotificationResponse...\n");
  9601. json_object *BootNotification;
  9602. BootNotification = json_tokener_parse(payload);
  9603. if(!is_error(BootNotification))
  9604. {
  9605. // Required data
  9606. sprintf((char *)currentTimeStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"currentTime")));
  9607. intervalInt = json_object_get_int(json_object_object_get(BootNotification,"interval"));
  9608. sprintf((char *)statusStr, "%s", json_object_get_string(json_object_object_get(BootNotification,"status")));
  9609. }
  9610. json_object_put(BootNotification);
  9611. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9612. BootNotificationInterval = intervalInt;
  9613. HeartBeatWaitTime = intervalInt;
  9614. //write back to ShmOCPP16Data->BootNotification
  9615. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, currentTimeStr);
  9616. ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval = intervalInt;
  9617. strcpy((char *)ShmOCPP16Data->BootNotification.ResponseStatus, statusStr);
  9618. if((strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Accepted]) == 0 ))
  9619. {
  9620. server_sign = TRUE;
  9621. server_pending =FALSE;
  9622. }
  9623. else if(strcmp(statusStr, RegistrationStatusStr[RegistrationStatus_Pending]) == 0)
  9624. {
  9625. server_pending = TRUE;
  9626. }
  9627. strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9628. tp.tm_isdst = -1;
  9629. //time_t utc = mktime(&tp);
  9630. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9631. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9632. sprintf(timebuf,"date -s '%s'",buf);
  9633. system(timebuf);
  9634. srand(time(NULL));
  9635. clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
  9636. //==============================================
  9637. // RTC sync
  9638. //==============================================
  9639. system("/sbin/hwclock -w --systohc");
  9640. ShmOCPP16Data->OcppConnStatus = 1; ////0: disconnected, 1: connected
  9641. ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
  9642. }
  9643. void handleDataTransferResponse(char *payload, int gun_index)
  9644. {
  9645. char sstr[160]={0};//sstr[200]={ 0 };
  9646. int c = 0;
  9647. char *loc;
  9648. DEBUG_INFO("handleDataTransferResponse ...\n");
  9649. loc = strstr(payload, "status");
  9650. printf("loc=%s\n",loc);
  9651. c = 0;
  9652. while (loc[3+strlen("status")+c] != '\"')
  9653. {
  9654. sstr[c] = loc[3+strlen("status")+c];
  9655. //printf("i=%d sstr=%c\n",c, sstr[c]);
  9656. c++;
  9657. }
  9658. sstr[c] = '\0';
  9659. DEBUG_INFO(" DataTransferResponse=%s\n", sstr);
  9660. }
  9661. void handleDiagnosticsStatusNotificationResponse(char *payload, int gun_index)
  9662. {
  9663. DEBUG_INFO("handleDiagnosticsStatusNotificationResponse ...\n");
  9664. //struct json_object *obj;
  9665. // obj = json_tokener_parse(payload);
  9666. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 0;
  9667. ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationConf = 1;
  9668. //No fields are defined.
  9669. }
  9670. void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
  9671. {
  9672. DEBUG_INFO("handleFirmwareStatusNotificationResponse ...\n");
  9673. //struct json_object *obj;
  9674. // obj = json_tokener_parse(payload);
  9675. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationReq = 0;
  9676. ShmOCPP16Data->SpMsg.bits.FirmwareStatusNotificationConf = 1;
  9677. //No fields are defined.
  9678. }
  9679. void handleHeartbeatResponse(char *payload, int gun_index)
  9680. {
  9681. mtrace();
  9682. struct tm tp;
  9683. char buf[28]={0};
  9684. char timebuf[50]={0};
  9685. DEBUG_INFO("handleHeartbeatResponse...\n");
  9686. json_object *Heartbeat;
  9687. Heartbeat = json_tokener_parse(payload);
  9688. if(!is_error(Heartbeat))
  9689. {
  9690. // Required data
  9691. sprintf((char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%s", json_object_get_string(json_object_object_get(Heartbeat,"currentTime")));
  9692. }
  9693. json_object_put(Heartbeat);
  9694. if(FirstHeartBeat == 0)
  9695. {
  9696. FirstHeartBeat = 1;
  9697. DEBUG_INFO("FirstHeartBeat \n");
  9698. }
  9699. HeartBeatWithNOResponse = 0;
  9700. clientTime.Heartbeat=time((time_t*)NULL);
  9701. strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
  9702. tp.tm_isdst = -1;
  9703. //time_t utc = mktime(&tp);
  9704. strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
  9705. memset(timebuf, 0, ARRAY_SIZE(timebuf));
  9706. sprintf(timebuf,"date -s '%s'",buf);
  9707. system(timebuf);
  9708. //==============================================
  9709. // RTC sync
  9710. //==============================================
  9711. system("/sbin/hwclock -w --systohc");
  9712. }
  9713. void handleMeterValuesResponse(char *payload, int gun_index)
  9714. {
  9715. mtrace();
  9716. DEBUG_INFO("handleMeterValuesResponse...\n");
  9717. }
  9718. void handleStartTransactionResponse(char *payload, int gun_index)
  9719. {
  9720. mtrace();
  9721. //int transactionIdInt = 0;
  9722. FILE *outfile;
  9723. char data[100]={0};
  9724. DEBUG_INFO("handleStartTransactionResponse...\n");
  9725. json_object *StartTransaction;
  9726. StartTransaction = json_tokener_parse(payload);
  9727. if(!is_error(StartTransaction))
  9728. {
  9729. // Required data
  9730. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "status")));
  9731. ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId = json_object_get_int(json_object_object_get(StartTransaction,"transactionId"));
  9732. // Optional data
  9733. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate") != NULL)
  9734. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "expiryDate")));
  9735. if(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9736. sprintf((char *)ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StartTransaction,"idTagInfo"), "parentIdTag")));
  9737. }
  9738. json_object_put(StartTransaction);
  9739. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionConf = 1;
  9740. ShmOCPP16Data->CpMsg.bits[gun_index].StartTransactionReq = 0;
  9741. //-----------Start : write to the Queue TransactionId file -----------------//
  9742. if((access("/Storage/OCPP/QueueTransactionId",F_OK))!=-1)
  9743. {}
  9744. else
  9745. {
  9746. FILE *log = fopen("/Storage/OCPP/QueueTransactionId", "w+");
  9747. if(log == NULL)
  9748. {
  9749. DEBUG_INFO("Can't Create File QueueTransactionId \n");
  9750. return ;
  9751. }
  9752. else
  9753. {
  9754. fclose(log);
  9755. }
  9756. }
  9757. // open file for writing
  9758. //-------------Start: write to the Queue TransactionId file------------------------------------------//
  9759. if((ShmOCPP16Data->StartTransaction[gun_index].ConnectorId !=0)&&(strcmp((const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag,"")!=0)&&(ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId !=0))
  9760. {
  9761. outfile = fopen ("/Storage/OCPP/QueueTransactionId", "a");
  9762. sprintf(data,"%d,%s,%d\n", ShmOCPP16Data->StartTransaction[gun_index].ConnectorId , ShmOCPP16Data->StartTransaction[gun_index].IdTag, ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId); // GunIndex, idtag, TransactionId
  9763. fputs(data, outfile);
  9764. fclose (outfile);
  9765. }
  9766. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9767. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9768. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseIdTagInfo.Status);
  9769. DEBUG_INFO("transactionId: %d\n", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  9770. }
  9771. void handleStatusNotificationResponse(char *payload, int gun_index)
  9772. {
  9773. mtrace();
  9774. DEBUG_INFO("handleStatusNotificationResponse...\n");
  9775. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  9776. cpinitateMsg.bits[gun_index].StatusNotificationConf = 1;
  9777. }
  9778. void handleStopTransactionnResponse(char *payload, int gun_index)
  9779. {
  9780. mtrace();
  9781. DEBUG_INFO("handleStopTransactionnResponse...\n");
  9782. json_object *StopTransaction;
  9783. StopTransaction = json_tokener_parse(payload);
  9784. if(!is_error(StopTransaction))
  9785. {
  9786. // Optional data
  9787. if(json_object_object_get(StopTransaction, "idTagInfo") != NULL)
  9788. {
  9789. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "status")));
  9790. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate") != NULL)
  9791. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "expiryDate")));
  9792. if(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag") != NULL)
  9793. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag, "%s", json_object_get_string(json_object_object_get(json_object_object_get(StopTransaction,"idTagInfo"), "parentIdTag")));
  9794. }
  9795. }
  9796. json_object_put(StopTransaction);
  9797. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionConf = 1;
  9798. ShmOCPP16Data->CpMsg.bits[gun_index].StopTransactionReq = 0;
  9799. DEBUG_INFO("idTagInfo-expiryDate: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ExpiryDate);
  9800. DEBUG_INFO("idTagInfo-parentIdTag: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.ParentIdTag);
  9801. DEBUG_INFO("idTagInfo-status: %s\n", ShmOCPP16Data->StopTransaction[gun_index].ResponseIdTagInfo.Status);
  9802. }
  9803. //==========================================
  9804. // Handle Error routine
  9805. //==========================================
  9806. void handleError(char *id, char *errorCode, char *errorDescription,char *payload)
  9807. {
  9808. mtrace();
  9809. #ifdef SystemLogMessage
  9810. DEBUG_INFO("errorCode: %s\n", errorCode);
  9811. DEBUG_INFO("errorDescription: %s\n", errorDescription);
  9812. DEBUG_INFO("errorDetails: %s\n", payload);
  9813. #endif
  9814. }
  9815. //===============================================
  9816. // Common routine
  9817. //===============================================
  9818. int initialConfigurationTable(void)
  9819. {
  9820. //clock_t start_t, end_t, total_t;
  9821. FILE *fp;
  9822. FILE *outfile;
  9823. char str[200]={0};
  9824. char sstr[100]={0};
  9825. int c = 0;
  9826. char *loc;
  9827. DEBUG_INFO("initialConfigurationTable...\n");
  9828. //start_t = clock();
  9829. //printf("Starting of the program, start_t = %ld\n", start_t);
  9830. memset(&(ShmOCPP16Data->ConfigurationTable), 0, sizeof(struct OCPP16ConfigurationTable) );
  9831. if((access("/Storage/OCPP/OCPPConfiguration",F_OK))==-1)
  9832. {
  9833. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  9834. if(outfile == NULL)
  9835. {
  9836. DEBUG_INFO("Error opening file\n");
  9837. return FALSE;
  9838. }
  9839. /*Core Profile*/
  9840. //AllowOfflineTxForUnknownId
  9841. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  9842. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  9843. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "FALSE" );
  9844. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  9845. //AuthorizationCacheEnabled
  9846. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  9847. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  9848. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  9849. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  9850. //AuthorizeRemoteTxRequests
  9851. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  9852. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  9853. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "FALSE" );
  9854. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  9855. //BlinkRepeat
  9856. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  9857. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  9858. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  9859. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  9860. //ClockAlignedDataInterval
  9861. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  9862. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  9863. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  9864. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  9865. //ConnectionTimeOut
  9866. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  9867. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  9868. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  9869. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  9870. //GetConfigurationMaxKeys
  9871. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  9872. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  9873. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "44" );
  9874. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  9875. // HeartbeatInterval
  9876. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  9877. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  9878. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "20" );
  9879. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  9880. // LightIntensity
  9881. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  9882. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  9883. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  9884. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  9885. // LocalAuthorizeOffline
  9886. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 1;
  9887. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  9888. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  9889. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  9890. // LocalPreAuthorize
  9891. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  9892. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  9893. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  9894. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  9895. // MaxEnergyOnInvalidId
  9896. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  9897. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  9898. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  9899. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  9900. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  9901. // MeterValuesAlignedData
  9902. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 0;
  9903. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  9904. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9905. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  9906. else
  9907. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  9908. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  9909. // MeterValuesAlignedDataMaxLength
  9910. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  9911. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  9912. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9913. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "6" );
  9914. else
  9915. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  9916. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  9917. // MeterValuesSampledData
  9918. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 0;
  9919. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  9920. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9921. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  9922. else
  9923. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Import,Energy.Active.Import.Register,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  9924. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  9925. // MeterValuesSampledDataMaxLength
  9926. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  9927. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  9928. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9929. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "6" );
  9930. else
  9931. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  9932. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  9933. // MeterValueSampleInterval
  9934. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  9935. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  9936. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "30" );
  9937. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  9938. // MinimumStatusDuration
  9939. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  9940. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  9941. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "120" );
  9942. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData); //StatusNotification cycle
  9943. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  9944. // NumberOfConnectors
  9945. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  9946. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  9947. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9948. {
  9949. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  9950. }
  9951. else
  9952. {
  9953. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  9954. }
  9955. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  9956. // ResetRetries
  9957. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  9958. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  9959. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  9960. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  9961. // ConnectorPhaseRotation
  9962. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  9963. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  9964. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  9965. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  9966. // ConnectorPhaseRotationMaxLength
  9967. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  9968. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  9969. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  9970. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  9971. // StopTransactionOnEVSideDisconnect
  9972. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  9973. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  9974. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  9975. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  9976. // StopTransactionOnInvalidId
  9977. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0; //1;
  9978. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  9979. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  9980. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  9981. // StopTxnAlignedData
  9982. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 0;
  9983. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  9984. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  9985. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  9986. // StopTxnAlignedDataMaxLength
  9987. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  9988. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  9989. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  9990. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  9991. // StopTxnSampledData
  9992. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 0;
  9993. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  9994. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  9995. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage,SOC" );
  9996. else
  9997. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Current.Import,Energy.Active.Import.Interval,Power.Active.Import,Voltage" );
  9998. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  9999. // StopTxnSampledDataMaxLength
  10000. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10001. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10002. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10003. {
  10004. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 6);
  10005. }
  10006. else
  10007. {
  10008. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", 5);
  10009. }
  10010. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10011. // SupportedFeatureProfiles
  10012. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10013. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10014. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10015. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10016. // SupportedFeatureProfilesMaxLength
  10017. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10018. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10019. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10020. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10021. // TransactionMessageAttempts
  10022. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10023. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10024. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10025. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10026. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10027. // TransactionMessageRetryInterval
  10028. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10029. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10030. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10031. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10032. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10033. // UnlockConnectorOnEVSideDisconnect
  10034. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10035. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10036. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10037. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10038. // WebSocketPingInterval
  10039. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10040. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10041. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10042. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10043. // QueueOffLineStartTransactionMessage
  10044. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 1;
  10045. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10046. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10047. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10048. // AuthorizationKey
  10049. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10050. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10051. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "" );
  10052. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10053. // SecurityProfile
  10054. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10055. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10056. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "0" );
  10057. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10058. // DefaultPrice
  10059. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  10060. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  10061. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  10062. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  10063. // CustomDisplayCostAndPrice
  10064. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  10065. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  10066. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  10067. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  10068. // CustomIdleFeeAfterStop
  10069. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  10070. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  10071. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  10072. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  10073. //* Local Auth List Management Profile*/
  10074. #if 0
  10075. //For OCTT Test Case
  10076. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10077. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthorizationListEnabled");
  10078. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10079. #endif
  10080. #if 1
  10081. //LocalAuthListEnabled
  10082. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10083. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10084. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10085. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10086. #endif
  10087. //LocalAuthListMaxLength
  10088. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10089. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10090. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10091. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10092. //SendLocalListMaxLength
  10093. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10094. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10095. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "50" );
  10096. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10097. //ReserveConnectorZeroSupported
  10098. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10099. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10100. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10101. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10102. //* Smart Charging Profile */
  10103. //ChargeProfileMaxStackLevel
  10104. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10105. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10106. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10107. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10108. // ChargingScheduleAllowedChargingRateUnit
  10109. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10110. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10111. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10112. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10113. // ChargingScheduleMaxPeriods
  10114. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10115. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10116. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10117. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10118. // ConnectorSwitch3to1PhaseSupported
  10119. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10120. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10121. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10122. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10123. // MaxChargingProfilesInstalled
  10124. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10125. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10126. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  10127. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10128. fclose(outfile);
  10129. }
  10130. else
  10131. {
  10132. //DEBUG_INFO("../Storage/OCPP/OCPPConfiguration EXit\n");
  10133. char keystr[60]={0};
  10134. char readonlystr[10]={0};
  10135. char valuestr[100]={0};
  10136. fp = fopen("/Storage/OCPP/OCPPConfiguration" , "r");
  10137. if(fp == NULL) {
  10138. DEBUG_INFO("Error opening file");
  10139. return FALSE;
  10140. }
  10141. while( fgets (str, ARRAY_SIZE(str), fp)!=NULL )
  10142. {
  10143. //DEBUG_INFO("Get Configuration \n");
  10144. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  10145. //*************************key*********************************/
  10146. loc = strstr(str, "key");
  10147. c = 0;
  10148. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10149. while (loc[strlen("key")+3+c] != '\"')
  10150. {
  10151. sstr[c] = loc[strlen("key")+3+c];
  10152. c++;
  10153. }
  10154. sstr[c] = '\0';
  10155. strcpy(keystr,sstr);
  10156. //*************************readonly*********************************/
  10157. loc = strstr(str, "readonly");
  10158. c = 0;
  10159. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10160. while (loc[strlen("readonly")+2+c] != ',')
  10161. {
  10162. sstr[c] = loc[strlen("readonly")+2+c];
  10163. c++;
  10164. }
  10165. sstr[c] = '\0';
  10166. strcpy(readonlystr,sstr);
  10167. //*************************value*********************************/
  10168. loc = strstr(str, "value");
  10169. c = 0;
  10170. memset(sstr ,0, ARRAY_SIZE(sstr) );
  10171. while (loc[strlen("value")+3+c] != '\"')
  10172. {
  10173. sstr[c] = loc[strlen("value")+3+c];
  10174. c++;
  10175. }
  10176. sstr[c] = '\0';
  10177. strcpy(valuestr,sstr);
  10178. // DEBUG_INFO("keystr=%s\n",keystr);
  10179. // DEBUG_INFO("readonlystr=%s\n",readonlystr);
  10180. // DEBUG_INFO("valuestr=%s\n",valuestr);
  10181. if(strcmp(keystr, "AllowOfflineTxForUnknownId") == 0)
  10182. {
  10183. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  10184. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10185. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", valuestr );
  10186. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10187. // DEBUG_INFO("AllowOfflineTxForUnknownId setting\n");
  10188. }
  10189. if(strcmp(keystr, "AuthorizationCacheEnabled") == 0)
  10190. {
  10191. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  10192. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10193. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", valuestr );
  10194. }
  10195. if(strcmp(keystr, "AuthorizeRemoteTxRequests") == 0)
  10196. {
  10197. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10198. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", valuestr );
  10199. }
  10200. if(strcmp(keystr, "BlinkRepeat") == 0)
  10201. {
  10202. //Charger.BlinkRepeat = Integer.parseInt(value);
  10203. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10204. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(valuestr) );
  10205. }
  10206. if(strcmp(keystr, "ClockAlignedDataInterval") == 0)
  10207. {
  10208. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10209. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(valuestr) );
  10210. }
  10211. if(strcmp(keystr, "ConnectionTimeOut") == 0 )
  10212. {
  10213. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10214. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(valuestr));
  10215. }
  10216. if(strcmp(keystr, "GetConfigurationMaxKeys") == 0)
  10217. {
  10218. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10219. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", (atoi(valuestr)!=GetConfigurationMaxKeysNUM?GetConfigurationMaxKeysNUM:atoi(valuestr)));
  10220. }
  10221. if(strcmp(keystr, "HeartbeatInterval") == 0)
  10222. {
  10223. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10224. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(valuestr));
  10225. HeartBeatWaitTime = atoi(valuestr);
  10226. }
  10227. if(strcmp(keystr, "LightIntensity") == 0)
  10228. {
  10229. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10230. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(valuestr));
  10231. }
  10232. if(strcmp(keystr, "LocalAuthorizeOffline") == 0)
  10233. {
  10234. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10235. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", valuestr );
  10236. }
  10237. if(strcmp(keystr, "LocalPreAuthorize") == 0)
  10238. {
  10239. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10240. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", valuestr );
  10241. }
  10242. if(strcmp(keystr, "MaxEnergyOnInvalidId") == 0)
  10243. {
  10244. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10245. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(valuestr) );
  10246. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(valuestr)/1000;
  10247. }
  10248. if(strcmp(keystr, "MeterValuesAlignedData") == 0)
  10249. {
  10250. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10251. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", valuestr );
  10252. }
  10253. if(strcmp(keystr, "MeterValuesAlignedDataMaxLength") == 0)
  10254. {
  10255. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10256. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(valuestr));
  10257. }
  10258. if(strcmp(keystr, "MeterValuesSampledData") == 0 )
  10259. {
  10260. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10261. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", valuestr );
  10262. }
  10263. if(strcmp(keystr, "MeterValuesSampledDataMaxLength") == 0)
  10264. {
  10265. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10266. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(valuestr));
  10267. }
  10268. if(strcmp(keystr, "MeterValueSampleInterval") == 0)
  10269. {
  10270. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10271. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(valuestr));
  10272. }
  10273. if(strcmp(keystr, "MinimumStatusDuration") == 0)
  10274. {
  10275. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10276. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(valuestr) );
  10277. server_cycle_Status = atoi(valuestr); //StatusNotification cycle
  10278. }
  10279. if(strcmp(keystr, "NumberOfConnectors") == 0)
  10280. {
  10281. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10282. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(valuestr) );
  10283. }
  10284. if(strcmp(keystr, "ResetRetries") == 0)
  10285. {
  10286. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10287. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(valuestr) );
  10288. }
  10289. if(strcmp(keystr, "ConnectorPhaseRotation") == 0)
  10290. {
  10291. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10292. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", valuestr );
  10293. }
  10294. if(strcmp(keystr, "ConnectorPhaseRotationMaxLength") == 0)
  10295. {
  10296. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10297. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(valuestr) );
  10298. }
  10299. if(strcmp(keystr, "StopTransactionOnEVSideDisconnect") == 0)
  10300. {
  10301. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10302. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", valuestr );
  10303. }
  10304. if(strcmp(keystr, "StopTransactionOnInvalidId") == 0)
  10305. {
  10306. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10307. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", valuestr );
  10308. }
  10309. if(strcmp(keystr, "StopTxnAlignedData") == 0)
  10310. {
  10311. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10312. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", valuestr );
  10313. }
  10314. if(strcmp(keystr, "StopTxnAlignedDataMaxLength") == 0)
  10315. {
  10316. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10317. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10318. }
  10319. if(strcmp(keystr, "StopTxnSampledData") == 0)
  10320. {
  10321. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10322. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", valuestr );
  10323. }
  10324. if(strcmp(keystr, "StopTxnSampledDataMaxLength") == 0)
  10325. {
  10326. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10327. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(valuestr) );
  10328. }
  10329. if(strcmp(keystr, "SupportedFeatureProfiles") == 0)
  10330. {
  10331. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10332. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", valuestr );
  10333. }
  10334. if(strcmp(keystr, "SupportedFeatureProfilesMaxLength") == 0)
  10335. {
  10336. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10337. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(valuestr) );
  10338. }
  10339. if(strcmp(keystr, "TransactionMessageAttempts") == 0)
  10340. {
  10341. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10342. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(valuestr) );
  10343. TransactionMessageAttemptsValue = atoi(valuestr);
  10344. }
  10345. if(strcmp(keystr, "TransactionMessageRetryInterval") == 0)
  10346. {
  10347. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility= (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10348. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(valuestr) );
  10349. TransactionMessageRetryIntervalValue = atoi(valuestr);
  10350. }
  10351. if(strcmp(keystr, "UnlockConnectorOnEVSideDisconnect") == 0)
  10352. {
  10353. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10354. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", valuestr );
  10355. }
  10356. if(strcmp(keystr, "WebSocketPingInterval") == 0)
  10357. {
  10358. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10359. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(valuestr) );
  10360. }
  10361. if(strcmp(keystr, "QueueOffLineStartTransactionMessage") == 0)
  10362. {
  10363. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10364. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", valuestr);
  10365. }
  10366. if(strcmp(keystr, "AuthorizationKey") == 0)
  10367. {
  10368. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10369. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", valuestr);
  10370. }
  10371. if(strcmp(keystr, "SecurityProfile") == 0)
  10372. {
  10373. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10374. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(valuestr) );
  10375. }
  10376. if(strcmp(keystr, "DefaultPrice") == 0)
  10377. {
  10378. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10379. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", valuestr);
  10380. }
  10381. if(strcmp(keystr, "CustomDisplayCostAndPrice") == 0)
  10382. {
  10383. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10384. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", valuestr);
  10385. }
  10386. if(strcmp(keystr, "CustomIdleFeeAfterStop") == 0)
  10387. {
  10388. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10389. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", valuestr);
  10390. }
  10391. if(strcmp(keystr, "LocalAuthListEnabled") == 0)
  10392. {
  10393. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10394. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", valuestr );
  10395. }
  10396. if(strcmp(keystr, "LocalAuthListMaxLength") == 0)
  10397. {
  10398. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10399. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(valuestr) );
  10400. }
  10401. if(strcmp(keystr, "SendLocalListMaxLength") == 0)
  10402. {
  10403. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10404. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(valuestr) );
  10405. }
  10406. if(strcmp(keystr, "ReserveConnectorZeroSupported") == 0)
  10407. {
  10408. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10409. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", valuestr );
  10410. }
  10411. if(strcmp(keystr, "ChargeProfileMaxStackLevel") == 0)
  10412. {
  10413. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10414. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(valuestr) );
  10415. }
  10416. if(strcmp(keystr, "ChargingScheduleAllowedChargingRateUnit") == 0)
  10417. {
  10418. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10419. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", valuestr );
  10420. }
  10421. if(strcmp(keystr, "ChargingScheduleMaxPeriods") == 0)
  10422. {
  10423. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10424. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(valuestr) );
  10425. }
  10426. if(strcmp(keystr, "ConnectorSwitch3to1PhaseSupported") == 0)
  10427. {
  10428. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10429. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", valuestr);
  10430. }
  10431. if(strcmp(keystr, "MaxChargingProfilesInstalled") == 0)
  10432. {
  10433. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = (strcmp(readonlystr, "true")==0) ? 0 : 1;
  10434. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(valuestr) );
  10435. }
  10436. }
  10437. fclose(fp);
  10438. }
  10439. return 0;
  10440. }
  10441. void StoreConfigurationTable(void)
  10442. {
  10443. FILE *outfile;
  10444. outfile = fopen("/Storage/OCPP/OCPPConfiguration" , "w+");
  10445. if(outfile == NULL)
  10446. {
  10447. DEBUG_INFO("Error opening file");
  10448. return ;
  10449. }
  10450. /*Core Profile*/
  10451. //AllowOfflineTxForUnknownId
  10452. /*
  10453. ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility = 1;
  10454. printf("AllowoddlineTXForUnknownId type: %d \n", ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility);
  10455. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemName, "AllowOfflineTxForUnknownId");
  10456. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "TRUE" );
  10457. */
  10458. //DEBUG_INFO("data=%s\n",data);
  10459. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AllowOfflineTxForUnknownId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData);
  10460. //AuthorizationCacheEnabled
  10461. /*
  10462. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility = 1;
  10463. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemName, "AuthorizationCacheEnabled");
  10464. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "FALSE" );
  10465. */
  10466. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationCacheEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData);
  10467. //AuthorizeRemoteTxRequests
  10468. /*
  10469. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility = 0;
  10470. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemName, "AuthorizeRemoteTxRequests");
  10471. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "TRUE" );
  10472. */
  10473. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizeRemoteTxRequests", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData);
  10474. //BlinkRepeat
  10475. /*
  10476. ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility = 1;
  10477. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemName, "BlinkRepeat");
  10478. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "0" );
  10479. */
  10480. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","BlinkRepeat", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData);
  10481. //ClockAlignedDataInterval
  10482. /*
  10483. ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility = 1;
  10484. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemName, "ClockAlignedDataInterval");
  10485. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "0" );
  10486. */
  10487. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ClockAlignedDataInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData);
  10488. //ConnectionTimeOut
  10489. /*
  10490. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility = 1;
  10491. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemName, "ConnectionTimeOut");
  10492. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "180" );
  10493. */
  10494. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectionTimeOut", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData);
  10495. //GetConfigurationMaxKeys
  10496. /*
  10497. ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility =0;
  10498. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemName, "GetConfigurationMaxKeys");
  10499. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "43" );
  10500. */
  10501. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","GetConfigurationMaxKeys", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData);
  10502. // HeartbeatInterval
  10503. /*
  10504. ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility = 1;
  10505. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemName, "HeartbeatInterval");
  10506. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "10" );
  10507. */
  10508. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","HeartbeatInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);
  10509. // LightIntensity
  10510. /*
  10511. ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility = 1;
  10512. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemName, "LightIntensity");
  10513. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "0" );
  10514. */
  10515. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LightIntensity", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData);
  10516. // LocalAuthorizeOffline
  10517. /*
  10518. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility = 0;
  10519. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemName, "LocalAuthorizeOffline");
  10520. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "TRUE" );
  10521. */
  10522. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthorizeOffline", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  10523. // LocalPreAuthorize
  10524. /*
  10525. ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility = 0;
  10526. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemName, "LocalPreAuthorize");
  10527. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "FALSE" );
  10528. */
  10529. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalPreAuthorize", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData);
  10530. // MaxEnergyOnInvalidId
  10531. /*
  10532. ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility = 1;
  10533. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemName, "MaxEnergyOnInvalidId");
  10534. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "0" );
  10535. */
  10536. //ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = 0;
  10537. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxEnergyOnInvalidId", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData);
  10538. // MeterValuesAlignedData
  10539. /*
  10540. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility = 1;
  10541. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemName, "MeterValuesAlignedData");
  10542. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10543. */
  10544. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData);
  10545. // MeterValuesAlignedDataMaxLength
  10546. /*
  10547. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility = 0;
  10548. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemName, "MeterValuesAlignedDataMaxLength");
  10549. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "5" );
  10550. */
  10551. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData);
  10552. // MeterValuesSampledData
  10553. /*
  10554. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility = 1;
  10555. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemName, "MeterValuesSampledData");
  10556. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "Current.Export,Energy.Active.Export.Interval,Power.Active.Export,Voltage,SOC" );
  10557. */
  10558. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData);
  10559. // MeterValuesSampledDataMaxLength
  10560. /*
  10561. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility = 0;
  10562. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemName, "MeterValuesSampledDataMaxLength");
  10563. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "5" );
  10564. */
  10565. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValuesSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData);
  10566. // MeterValueSampleInterval
  10567. /*
  10568. ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility = 1;
  10569. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemName, "MeterValueSampleInterval");
  10570. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "10" );
  10571. */
  10572. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MeterValueSampleInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData);
  10573. // MinimumStatusDuration
  10574. /*
  10575. ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility = 1;
  10576. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemName, "MinimumStatusDuration");
  10577. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "0" );
  10578. */
  10579. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MinimumStatusDuration", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  10580. // NumberOfConnectors
  10581. /*
  10582. ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility = 0;
  10583. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemName, "NumberOfConnectors");
  10584. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  10585. {
  10586. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", (CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY));
  10587. }
  10588. else
  10589. {
  10590. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", AC_QUANTITY);
  10591. }
  10592. */
  10593. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","NumberOfConnectors", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData);
  10594. // ResetRetries
  10595. /*
  10596. ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility = 1;
  10597. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemName, "ResetRetries");
  10598. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "3" );
  10599. */
  10600. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ResetRetries", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData);
  10601. // ConnectorPhaseRotation
  10602. /*
  10603. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility = 1;
  10604. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemName, "ConnectorPhaseRotation");
  10605. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "NotApplicable" );
  10606. */
  10607. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotation", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData);
  10608. // ConnectorPhaseRotationMaxLength
  10609. /*
  10610. ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility = 0;
  10611. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemName, "ConnectorPhaseRotationMaxLength");
  10612. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "1" );
  10613. */
  10614. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorPhaseRotationMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData);
  10615. // StopTransactionOnEVSideDisconnect
  10616. /*
  10617. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility = 0;
  10618. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemName, "StopTransactionOnEVSideDisconnect");
  10619. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "TRUE" );
  10620. */
  10621. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData);
  10622. // StopTransactionOnInvalidId
  10623. /*
  10624. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility = 0;
  10625. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemName, "StopTransactionOnInvalidId");
  10626. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "FALSE" );
  10627. */
  10628. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTransactionOnInvalidId", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData);
  10629. // StopTxnAlignedData
  10630. /*
  10631. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility = 1;
  10632. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemName, "StopTxnAlignedData");
  10633. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "Energy.Active.Import.Register" );
  10634. */
  10635. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData);
  10636. // StopTxnAlignedDataMaxLength
  10637. /*
  10638. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility = 0;
  10639. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemName, "StopTxnAlignedDataMaxLength");
  10640. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "0" );
  10641. */
  10642. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnAlignedDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData);
  10643. // StopTxnSampledData
  10644. /*
  10645. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility = 1;
  10646. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemName, "StopTxnSampledData");
  10647. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "Energy.Active.Import.Register" );
  10648. */
  10649. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledData", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData);
  10650. // StopTxnSampledDataMaxLength
  10651. /*
  10652. ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility = 0;
  10653. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemName, "StopTxnSampledDataMaxLength");
  10654. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "0" );
  10655. */
  10656. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","StopTxnSampledDataMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData);
  10657. // SupportedFeatureProfiles
  10658. /*
  10659. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility = 0;
  10660. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemName, "SupportedFeatureProfiles");
  10661. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "Core,FirmwareManagement,LocalAuthListManagement,Reservation,SmartCharging,RemoteTrigger" );
  10662. */
  10663. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfiles", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData);
  10664. // SupportedFeatureProfilesMaxLength
  10665. /*
  10666. ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility = 0;
  10667. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemName, "SupportedFeatureProfilesMaxLength");
  10668. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "6" );
  10669. */
  10670. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SupportedFeatureProfilesMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData);
  10671. // TransactionMessageAttempts
  10672. /*
  10673. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility = 1;
  10674. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemName, "TransactionMessageAttempts");
  10675. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "3" );
  10676. */
  10677. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageAttempts", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  10678. // TransactionMessageRetryInterval
  10679. /*
  10680. ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility = 1;
  10681. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemName, "TransactionMessageRetryInterval");
  10682. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "60" );
  10683. */
  10684. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","TransactionMessageRetryInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  10685. // UnlockConnectorOnEVSideDisconnect
  10686. /*
  10687. ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility = 0;
  10688. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemName, "UnlockConnectorOnEVSideDisconnect");
  10689. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "TRUE" );
  10690. */
  10691. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","UnlockConnectorOnEVSideDisconnect", "true", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData);
  10692. // WebSocketPingInterval
  10693. /*
  10694. ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility = 1;
  10695. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemName, "WebSocketPingInterval");
  10696. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "30" );
  10697. */
  10698. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","WebSocketPingInterval", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  10699. // QueueOffLineStartTransactionMessage
  10700. /*
  10701. ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility = 0;
  10702. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemName, "QueueOffLineStartTransactionMessage");
  10703. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "TRUE" );
  10704. */
  10705. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","QueueOffLineStartTransactionMessage", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData);
  10706. // AuthorizationKey
  10707. /*
  10708. ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility = 1;
  10709. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemName, "AuthorizationKey");
  10710. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "0" );
  10711. */
  10712. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","AuthorizationKey", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  10713. // SecurityProfile
  10714. /*
  10715. ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility = 1;
  10716. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemName, "SecurityProfile");
  10717. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "30" );
  10718. */
  10719. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SecurityProfile", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  10720. // DefaultPrice
  10721. /*
  10722. ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility = 1;
  10723. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemName, "DefaultPrice");
  10724. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "" );
  10725. */
  10726. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","DefaultPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData);
  10727. // CustomDisplayCostAndPrice
  10728. /*
  10729. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility = 1;
  10730. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemName, "CustomDisplayCostAndPrice");
  10731. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "FALSE" );
  10732. */
  10733. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomDisplayCostAndPrice", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData);
  10734. // CustomIdleFeeAfterStop
  10735. /*
  10736. ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility = 1;
  10737. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemName, "CustomIdleFeeAfterStop");
  10738. strcpy((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "FALSE" );
  10739. */
  10740. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","CustomIdleFeeAfterStop", "false", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData);
  10741. //* Local Auth List Management Profile*/
  10742. //LocalAuthListEnabled
  10743. /*
  10744. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility = 1;
  10745. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemName, "LocalAuthListEnabled");
  10746. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "TRUE" );
  10747. */
  10748. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListEnabled", "false", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  10749. //LocalAuthListMaxLength
  10750. /*
  10751. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility = 0;
  10752. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemName, "LocalAuthListMaxLength");
  10753. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "500" );
  10754. */
  10755. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","LocalAuthListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData);
  10756. //SendLocalListMaxLength
  10757. /*
  10758. ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility = 0;
  10759. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemName, "SendLocalListMaxLength");
  10760. strcpy((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "500" );
  10761. */
  10762. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","SendLocalListMaxLength", "true", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData);
  10763. //ReserveConnectorZeroSupported
  10764. /*
  10765. ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility = 0;
  10766. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemName, "ReserveConnectorZeroSupported");
  10767. strcpy((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "FALSE" );
  10768. */
  10769. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ReserveConnectorZeroSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  10770. //* Smart Charging Profile */
  10771. //ChargeProfileMaxStackLevel
  10772. /*
  10773. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility = 0;
  10774. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemName, "ChargeProfileMaxStackLevel");
  10775. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "3" );
  10776. */
  10777. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargeProfileMaxStackLevel", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  10778. // ChargingScheduleAllowedChargingRateUnit
  10779. /*
  10780. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility = 0;
  10781. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemName, "ChargingScheduleAllowedChargingRateUnit");
  10782. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "Current" );
  10783. */
  10784. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleAllowedChargingRateUnit", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  10785. // ChargingScheduleMaxPeriods
  10786. /*
  10787. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility = 0;
  10788. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemName, "ChargingScheduleMaxPeriods");
  10789. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "10" );
  10790. */
  10791. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ChargingScheduleMaxPeriods", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  10792. // ConnectorSwitch3to1PhaseSupported
  10793. /*
  10794. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility = 0;
  10795. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemName, "ConnectorSwitch3to1PhaseSupported");
  10796. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "TRUE" );
  10797. */
  10798. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","ConnectorSwitch3to1PhaseSupported", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  10799. // MaxChargingProfilesInstalled
  10800. /*
  10801. ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility = 0;
  10802. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemName, "MaxChargingProfilesInstalled");
  10803. strcpy((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "10" );
  10804. */
  10805. fprintf(outfile,"{\"key\":\"%s\",\"readonly\":%s,\"value\":\"%s\"}\n","MaxChargingProfilesInstalled", "true", (char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  10806. fclose(outfile);
  10807. }
  10808. void getKeyValue(char *keyReq)
  10809. {
  10810. int isEmpty = FALSE;
  10811. int isKnowKey = FALSE;
  10812. DEBUG_INFO("keyReq = %s\n", keyReq);
  10813. if((keyReq == NULL) || (strlen(keyReq) == 0))
  10814. isEmpty = TRUE;
  10815. if(isEmpty || strcmp(keyReq, "AllowOfflineTxForUnknownId") == 0)
  10816. {
  10817. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AllowOfflineTxForUnknownId].Item, "AllowOfflineTxForUnknownId");
  10818. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Key, "AllowOfflineTxForUnknownId");
  10819. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  10820. {
  10821. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "0"/*"FALSE"*/);
  10822. }
  10823. else
  10824. {
  10825. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].ReadOnly, "1"/*"TRUE"*/);
  10826. }
  10827. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AllowOfflineTxForUnknownId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData );
  10828. isKnowKey = TRUE;
  10829. }
  10830. if(isEmpty || strcmp(keyReq, "AuthorizationCacheEnabled") == 0 )
  10831. {
  10832. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationCacheEnabled].Item, "AuthorizationCacheEnabled");
  10833. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Key, "AuthorizationCacheEnabled");
  10834. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  10835. {
  10836. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "0"/*"FALSE"*/);
  10837. }
  10838. else
  10839. {
  10840. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].ReadOnly, "1"/*"TRUE"*/);
  10841. }
  10842. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationCacheEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData );
  10843. isKnowKey = TRUE;
  10844. }
  10845. if(isEmpty || strcmp(keyReq, "AuthorizeRemoteTxRequests") == 0 )
  10846. {
  10847. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizeRemoteTxRequests].Item, "AuthorizeRemoteTxRequests");
  10848. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Key, "AuthorizeRemoteTxRequests");
  10849. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  10850. {
  10851. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "0"/*"FALSE"*/);
  10852. }
  10853. else
  10854. {
  10855. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].ReadOnly, "1"/*"TRUE"*/);
  10856. }
  10857. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizeRemoteTxRequests].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData );
  10858. isKnowKey = TRUE;
  10859. }
  10860. if(isEmpty || strcmp(keyReq, "BlinkRepeat") == 0 )
  10861. {
  10862. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_BlinkRepeat].Item, "BlinkRepeat");
  10863. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Key, "BlinkRepeat");
  10864. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  10865. {
  10866. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "0"/*"FALSE"*/);
  10867. }
  10868. else
  10869. {
  10870. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].ReadOnly, "1"/*"TRUE"*/);
  10871. }
  10872. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_BlinkRepeat].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData );
  10873. isKnowKey = TRUE;
  10874. }
  10875. if(isEmpty || strcmp(keyReq, "ClockAlignedDataInterval") == 0 )
  10876. {
  10877. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ClockAlignedDataInterval].Item, "ClockAlignedDataInterval");
  10878. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Key, "ClockAlignedDataInterval");
  10879. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  10880. {
  10881. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "0"/*"FALSE"*/);
  10882. }
  10883. else
  10884. {
  10885. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].ReadOnly, "1"/*"TRUE"*/);
  10886. }
  10887. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ClockAlignedDataInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData );
  10888. isKnowKey = TRUE;
  10889. }
  10890. if(isEmpty || strcmp(keyReq, "ConnectionTimeOut") == 0 )
  10891. {
  10892. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectionTimeOut].Item, "ConnectionTimeOut");
  10893. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Key, "ConnectionTimeOut");
  10894. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  10895. {
  10896. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "0"/*"FALSE"*/);
  10897. }
  10898. else
  10899. {
  10900. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].ReadOnly, "1"/*"TRUE"*/);
  10901. }
  10902. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectionTimeOut].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData );
  10903. isKnowKey = TRUE;
  10904. }
  10905. if(isEmpty || strcmp(keyReq, "GetConfigurationMaxKeys") == 0 )
  10906. {
  10907. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_GetConfigurationMaxKeys].Item, "GetConfigurationMaxKeys");
  10908. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Key, "GetConfigurationMaxKeys");
  10909. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemAccessibility == 1)
  10910. {
  10911. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "0"/*"FALSE"*/);
  10912. }
  10913. else
  10914. {
  10915. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].ReadOnly, "1"/*"TRUE"*/);
  10916. }
  10917. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_GetConfigurationMaxKeys].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData );
  10918. isKnowKey = TRUE;
  10919. }
  10920. if(isEmpty || strcmp(keyReq, "HeartbeatInterval") == 0 )
  10921. {
  10922. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_HeartbeatInterval].Item, "HeartbeatInterval");
  10923. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Key, "HeartbeatInterval");
  10924. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  10925. {
  10926. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "0"/*"FALSE"*/);
  10927. }
  10928. else
  10929. {
  10930. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].ReadOnly, "1"/*"TRUE"*/);
  10931. }
  10932. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_HeartbeatInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData );
  10933. isKnowKey = TRUE;
  10934. }
  10935. if(isEmpty || strcmp(keyReq, "LightIntensity") == 0 )
  10936. {
  10937. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LightIntensity].Item, "LightIntensity");
  10938. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Key, "LightIntensity");
  10939. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  10940. {
  10941. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "0"/*"FALSE"*/);
  10942. }
  10943. else
  10944. {
  10945. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].ReadOnly, "1"/*"TRUE"*/);
  10946. }
  10947. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LightIntensity].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData );
  10948. isKnowKey = TRUE;
  10949. }
  10950. if(isEmpty || strcmp(keyReq, "LocalAuthorizeOffline") == 0 )
  10951. {
  10952. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthorizeOffline].Item, "LocalAuthorizeOffline");
  10953. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Key, "LocalAuthorizeOffline");
  10954. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  10955. {
  10956. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "0"/*"FALSE"*/);
  10957. }
  10958. else
  10959. {
  10960. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].ReadOnly, "1"/*"TRUE"*/);
  10961. }
  10962. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthorizeOffline].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData );
  10963. isKnowKey = TRUE;
  10964. }
  10965. if(isEmpty || strcmp(keyReq, "LocalPreAuthorize") == 0 )
  10966. {
  10967. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalPreAuthorize].Item, "LocalPreAuthorize");
  10968. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Key, "LocalPreAuthorize");
  10969. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  10970. {
  10971. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "0"/*"FALSE"*/);
  10972. }
  10973. else
  10974. {
  10975. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].ReadOnly, "1"/*"TRUE"*/);
  10976. }
  10977. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalPreAuthorize].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData );
  10978. isKnowKey = TRUE;
  10979. }
  10980. if(isEmpty || strcmp(keyReq, "MaxEnergyOnInvalidId") == 0 )
  10981. {
  10982. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxEnergyOnInvalidId].Item, "MaxEnergyOnInvalidId");
  10983. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Key, "MaxEnergyOnInvalidId");
  10984. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  10985. {
  10986. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  10987. }
  10988. else
  10989. {
  10990. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  10991. }
  10992. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxEnergyOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData );
  10993. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData)/1000;
  10994. isKnowKey = TRUE;
  10995. }
  10996. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedData") == 0 )
  10997. {
  10998. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedData].Item, "MeterValuesAlignedData");
  10999. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Key, "MeterValuesAlignedData");
  11000. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11001. {
  11002. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11003. }
  11004. else
  11005. {
  11006. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11007. }
  11008. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData );
  11009. isKnowKey = TRUE;
  11010. }
  11011. if(isEmpty || strcmp(keyReq, "MeterValuesAlignedDataMaxLength") == 0 )
  11012. {
  11013. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesAlignedDataMaxLength].Item, "MeterValuesAlignedDataMaxLength");
  11014. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Key, "MeterValuesAlignedDataMaxLength");
  11015. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11016. {
  11017. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11018. }
  11019. else
  11020. {
  11021. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11022. }
  11023. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData );
  11024. isKnowKey = TRUE;
  11025. }
  11026. if(isEmpty || strcmp(keyReq, "MeterValuesSampledData") == 0 )
  11027. {
  11028. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledData].Item, "MeterValuesSampledData");
  11029. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Key, "MeterValuesSampledData");
  11030. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11031. {
  11032. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "0"/*"FALSE"*/);
  11033. }
  11034. else
  11035. {
  11036. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].ReadOnly, "1"/*"TRUE"*/);
  11037. }
  11038. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData );
  11039. isKnowKey = TRUE;
  11040. }
  11041. if(isEmpty || strcmp(keyReq, "MeterValuesSampledDataMaxLength") == 0 )
  11042. {
  11043. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValuesSampledDataMaxLength].Item, "MeterValuesSampledDataMaxLength");
  11044. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Key, "MeterValuesSampledDataMaxLength");
  11045. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11046. {
  11047. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11048. }
  11049. else
  11050. {
  11051. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11052. }
  11053. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValuesSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData );
  11054. isKnowKey = TRUE;
  11055. }
  11056. if(isEmpty || strcmp(keyReq, "MeterValueSampleInterval") == 0 )
  11057. {
  11058. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MeterValueSampleInterval].Item, "MeterValueSampleInterval");
  11059. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Key, "MeterValueSampleInterval");
  11060. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11061. {
  11062. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "0"/*"FALSE"*/);
  11063. }
  11064. else
  11065. {
  11066. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].ReadOnly, "1"/*"TRUE"*/);
  11067. }
  11068. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MeterValueSampleInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData );
  11069. isKnowKey = TRUE;
  11070. }
  11071. if(isEmpty || strcmp(keyReq, "MinimumStatusDuration") == 0 )
  11072. {
  11073. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MinimumStatusDuration].Item, "MinimumStatusDuration");
  11074. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Key, "MinimumStatusDuration");
  11075. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11076. {
  11077. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "0"/*"FALSE"*/);
  11078. }
  11079. else
  11080. {
  11081. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].ReadOnly, "1"/*"TRUE"*/);
  11082. }
  11083. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MinimumStatusDuration].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[17].ItemData );
  11084. isKnowKey = TRUE;
  11085. }
  11086. if(isEmpty || strcmp(keyReq, "NumberOfConnectors") == 0 )
  11087. {
  11088. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_NumberOfConnectors].Item, "NumberOfConnectors");
  11089. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Key, "NumberOfConnectors");
  11090. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11091. {
  11092. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "0"/*"FALSE"*/);
  11093. }
  11094. else
  11095. {
  11096. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].ReadOnly, "1"/*"TRUE"*/);
  11097. }
  11098. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_NumberOfConnectors].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData );
  11099. isKnowKey = TRUE;
  11100. }
  11101. if(isEmpty || strcmp(keyReq, "ResetRetries") == 0 )
  11102. {
  11103. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ResetRetries].Item, "ResetRetries");
  11104. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Key, "ResetRetries");
  11105. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11106. {
  11107. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "0"/*"FALSE"*/);
  11108. }
  11109. else
  11110. {
  11111. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].ReadOnly, "1"/*"TRUE"*/);
  11112. }
  11113. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ResetRetries].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData );
  11114. isKnowKey = TRUE;
  11115. }
  11116. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotation") == 0 )
  11117. {
  11118. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotation].Item, "ConnectorPhaseRotation");
  11119. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Key, "ConnectorPhaseRotation");
  11120. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11121. {
  11122. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "0"/*"FALSE"*/);
  11123. }
  11124. else
  11125. {
  11126. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].ReadOnly, "1"/*"TRUE"*/);
  11127. }
  11128. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotation].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData );
  11129. isKnowKey = TRUE;
  11130. }
  11131. if(isEmpty || strcmp(keyReq, "ConnectorPhaseRotationMaxLength") == 0 )
  11132. {
  11133. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorPhaseRotationMaxLength].Item, "ConnectorPhaseRotationMaxLength");
  11134. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Key, "ConnectorPhaseRotationMaxLength");
  11135. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  11136. {
  11137. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11138. }
  11139. else
  11140. {
  11141. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11142. }
  11143. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorPhaseRotationMaxLength].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData );
  11144. isKnowKey = TRUE;
  11145. }
  11146. if(isEmpty || strcmp(keyReq, "StopTransactionOnEVSideDisconnect") == 0 )
  11147. {
  11148. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnEVSideDisconnect].Item, "StopTransactionOnEVSideDisconnect");
  11149. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Key, "StopTransactionOnEVSideDisconnect");
  11150. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  11151. {
  11152. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11153. }
  11154. else
  11155. {
  11156. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11157. }
  11158. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData );
  11159. isKnowKey = TRUE;
  11160. }
  11161. if(isEmpty || strcmp(keyReq, "StopTransactionOnInvalidId") == 0 )
  11162. {
  11163. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTransactionOnInvalidId].Item, "StopTransactionOnInvalidId");
  11164. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Key, "StopTransactionOnInvalidId");
  11165. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  11166. {
  11167. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "0"/*"FALSE"*/);
  11168. }
  11169. else
  11170. {
  11171. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].ReadOnly, "1"/*"TRUE"*/);
  11172. }
  11173. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTransactionOnInvalidId].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData );
  11174. isKnowKey = TRUE;
  11175. }
  11176. if(isEmpty || strcmp(keyReq, "StopTxnAlignedData") == 0 )
  11177. {
  11178. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedData].Item, "StopTxnAlignedData");
  11179. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Key, "StopTxnAlignedData");
  11180. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  11181. {
  11182. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "0"/*"FALSE"*/);
  11183. }
  11184. else
  11185. {
  11186. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].ReadOnly, "1"/*"TRUE"*/);
  11187. }
  11188. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedData].Value,(const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData );
  11189. isKnowKey = TRUE;
  11190. }
  11191. if(isEmpty || strcmp(keyReq, "StopTxnAlignedDataMaxLength") == 0 )
  11192. {
  11193. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnAlignedDataMaxLength].Item, "StopTxnAlignedDataMaxLength");
  11194. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Key, "StopTxnAlignedDataMaxLength");
  11195. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  11196. {
  11197. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11198. }
  11199. else
  11200. {
  11201. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11202. }
  11203. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnAlignedDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData );
  11204. isKnowKey = TRUE;
  11205. }
  11206. if(isEmpty || strcmp(keyReq, "StopTxnSampledData") == 0 )
  11207. {
  11208. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledData].Item, "StopTxnSampledData");
  11209. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Key, "StopTxnSampledData");
  11210. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  11211. {
  11212. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "0"/*"FALSE"*/);
  11213. }
  11214. else
  11215. {
  11216. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].ReadOnly, "1"/*"TRUE"*/);
  11217. }
  11218. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledData].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData );
  11219. isKnowKey = TRUE;
  11220. }
  11221. if(isEmpty || strcmp(keyReq, "StopTxnSampledDataMaxLength") == 0 )
  11222. {
  11223. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_StopTxnSampledDataMaxLength].Item, "StopTxnSampledDataMaxLength");
  11224. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Key, "StopTxnSampledDataMaxLength");
  11225. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  11226. {
  11227. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11228. }
  11229. else
  11230. {
  11231. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11232. }
  11233. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_StopTxnSampledDataMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData );
  11234. isKnowKey = TRUE;
  11235. }
  11236. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfiles") == 0 )
  11237. {
  11238. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfiles].Item, "SupportedFeatureProfiles");
  11239. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Key, "SupportedFeatureProfiles");
  11240. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  11241. {
  11242. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "0"/*"FALSE"*/);
  11243. }
  11244. else
  11245. {
  11246. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].ReadOnly, "1"/*"TRUE"*/);
  11247. }
  11248. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfiles].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData );
  11249. isKnowKey = TRUE;
  11250. }
  11251. if(isEmpty || strcmp(keyReq, "SupportedFeatureProfilesMaxLength") == 0 )
  11252. {
  11253. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SupportedFeatureProfilesMaxLength].Item, "SupportedFeatureProfilesMaxLength");
  11254. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Key, "SupportedFeatureProfilesMaxLength");
  11255. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  11256. {
  11257. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11258. }
  11259. else
  11260. {
  11261. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11262. }
  11263. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SupportedFeatureProfilesMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData );
  11264. isKnowKey = TRUE;
  11265. }
  11266. if(isEmpty || strcmp(keyReq, "TransactionMessageAttempts") == 0 )
  11267. {
  11268. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageAttempts].Item, "TransactionMessageAttempts");
  11269. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Key, "TransactionMessageAttempts");
  11270. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  11271. {
  11272. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "0"/*"FALSE"*/);
  11273. }
  11274. else
  11275. {
  11276. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].ReadOnly, "1"/*"TRUE"*/);
  11277. }
  11278. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageAttempts].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData );
  11279. isKnowKey = TRUE;
  11280. }
  11281. if(isEmpty || strcmp(keyReq, "TransactionMessageRetryInterval") == 0 )
  11282. {
  11283. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_TransactionMessageRetryInterval].Item, "TransactionMessageRetryInterval");
  11284. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Key, "TransactionMessageRetryInterval");
  11285. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  11286. {
  11287. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "0"/*"FALSE"*/);
  11288. }
  11289. else
  11290. {
  11291. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].ReadOnly, "1"/*"TRUE"*/);
  11292. }
  11293. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_TransactionMessageRetryInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData );
  11294. isKnowKey = TRUE;
  11295. }
  11296. if(isEmpty || strcmp(keyReq, "UnlockConnectorOnEVSideDisconnect") == 0 )
  11297. {
  11298. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Item, "UnlockConnectorOnEVSideDisconnect");
  11299. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Key, "UnlockConnectorOnEVSideDisconnect");
  11300. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  11301. {
  11302. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "0"/*"FALSE"*/);
  11303. }
  11304. else
  11305. {
  11306. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].ReadOnly, "1"/*"TRUE"*/);
  11307. }
  11308. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_UnlockConnectorOnEVSideDisconnect].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData );
  11309. isKnowKey = TRUE;
  11310. }
  11311. if(isEmpty || strcmp(keyReq, "WebSocketPingInterval") == 0 )
  11312. {
  11313. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_WebSocketPingInterval].Item, "WebSocketPingInterval");
  11314. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Key, "WebSocketPingInterval");
  11315. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  11316. {
  11317. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "0"/*"FALSE"*/);
  11318. }
  11319. else
  11320. {
  11321. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].ReadOnly, "1"/*"TRUE"*/);
  11322. }
  11323. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_WebSocketPingInterval].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData );
  11324. isKnowKey = TRUE;
  11325. }
  11326. if(isEmpty || strcmp(keyReq, "QueueOffLineStartTransactionMessage") == 0 )
  11327. {
  11328. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_QueueOffLineStartTransactionMessage].Item, "QueueOffLineStartTransactionMessage");
  11329. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Key, "QueueOffLineStartTransactionMessage");
  11330. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  11331. {
  11332. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "0"/*"FALSE"*/);
  11333. }
  11334. else
  11335. {
  11336. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].ReadOnly, "1"/*"TRUE"*/);
  11337. }
  11338. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_QueueOffLineStartTransactionMessage].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData );
  11339. isKnowKey = TRUE;
  11340. }
  11341. /*
  11342. if(isEmpty || strcmp(keyReq, "AuthorizationKey") == 0 )
  11343. {
  11344. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_AuthorizationKey].Item, "AuthorizationKey");
  11345. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Key, "AuthorizationKey");
  11346. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1)
  11347. {
  11348. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "0");
  11349. }
  11350. else
  11351. {
  11352. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].ReadOnly, "1");
  11353. }
  11354. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_AuthorizationKey].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData );
  11355. isKnowKey = TRUE;
  11356. }*/
  11357. if(isEmpty || strcmp(keyReq, "SecurityProfile") == 0 )
  11358. {
  11359. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SecurityProfile].Item, "SecurityProfile");
  11360. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Key, "SecurityProfile");
  11361. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  11362. {
  11363. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "0"/*"FALSE"*/);
  11364. }
  11365. else
  11366. {
  11367. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].ReadOnly, "1"/*"TRUE"*/);
  11368. }
  11369. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SecurityProfile].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData );
  11370. isKnowKey = TRUE;
  11371. }
  11372. if(isEmpty || strcmp(keyReq, "DefaultPrice") == 0 )
  11373. {
  11374. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_DefaultPrice].Item, "DefaultPrice");
  11375. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Key, "DefaultPrice");
  11376. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1)
  11377. {
  11378. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "0"/*"FALSE"*/);
  11379. }
  11380. else
  11381. {
  11382. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].ReadOnly, "1"/*"TRUE"*/);
  11383. }
  11384. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_DefaultPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData );
  11385. isKnowKey = TRUE;
  11386. }
  11387. if(isEmpty || strcmp(keyReq, "CustomDisplayCostAndPrice") == 0 )
  11388. {
  11389. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomDisplayCostAndPrice].Item, "CustomDisplayCostAndPrice");
  11390. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Key, "CustomDisplayCostAndPrice");
  11391. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  11392. {
  11393. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "0"/*"FALSE"*/);
  11394. }
  11395. else
  11396. {
  11397. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].ReadOnly, "1"/*"TRUE"*/);
  11398. }
  11399. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomDisplayCostAndPrice].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData );
  11400. isKnowKey = TRUE;
  11401. }
  11402. if(isEmpty || strcmp(keyReq, "CustomIdleFeeAfterStop") == 0 )
  11403. {
  11404. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_CustomIdleFeeAfterStop].Item, "CustomIdleFeeAfterStop");
  11405. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Key, "CustomIdleFeeAfterStop");
  11406. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  11407. {
  11408. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "0"/*"FALSE"*/);
  11409. }
  11410. else
  11411. {
  11412. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].ReadOnly, "1"/*"TRUE"*/);
  11413. }
  11414. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_CustomIdleFeeAfterStop].Value, (const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData );
  11415. isKnowKey = TRUE;
  11416. }
  11417. #if 1
  11418. if(isEmpty || strcmp(keyReq, "LocalAuthListEnabled") == 0 )
  11419. {
  11420. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListEnabled].Item, "LocalAuthListEnabled");
  11421. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Key, "LocalAuthListEnabled");
  11422. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  11423. {
  11424. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "0"/*"FALSE"*/);
  11425. }
  11426. else
  11427. {
  11428. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].ReadOnly, "1"/*"TRUE"*/);
  11429. }
  11430. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListEnabled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData );
  11431. isKnowKey = TRUE;
  11432. }
  11433. #endif
  11434. if(isEmpty || strcmp(keyReq, "LocalAuthListMaxLength") == 0 )
  11435. {
  11436. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_LocalAuthListMaxLength].Item, "LocalAuthListMaxLength");
  11437. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Key, "LocalAuthListMaxLength");
  11438. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  11439. {
  11440. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11441. }
  11442. else
  11443. {
  11444. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11445. }
  11446. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_LocalAuthListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData );
  11447. isKnowKey = TRUE;
  11448. }
  11449. if(isEmpty || strcmp(keyReq, "SendLocalListMaxLength") == 0 )
  11450. {
  11451. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_SendLocalListMaxLength].Item, "SendLocalListMaxLength");
  11452. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Key, "SendLocalListMaxLength");
  11453. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  11454. {
  11455. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "0"/*"FALSE"*/);
  11456. }
  11457. else
  11458. {
  11459. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].ReadOnly, "1"/*"TRUE"*/);
  11460. }
  11461. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_SendLocalListMaxLength].Value, (const char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData );
  11462. isKnowKey = TRUE;
  11463. }
  11464. if(isEmpty || strcmp(keyReq, "ReserveConnectorZeroSupported") == 0 )
  11465. {
  11466. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ReserveConnectorZeroSupported].Item, "ReserveConnectorZeroSupported");
  11467. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Key, "ReserveConnectorZeroSupported");
  11468. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  11469. {
  11470. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "0"/*"FALSE"*/);
  11471. }
  11472. else
  11473. {
  11474. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].ReadOnly, "1"/*"TRUE"*/);
  11475. }
  11476. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ReserveConnectorZeroSupported].Value,(const char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData);
  11477. isKnowKey = TRUE;
  11478. }
  11479. if(isEmpty || strcmp(keyReq, "ChargeProfileMaxStackLevel") == 0 )
  11480. {
  11481. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargeProfileMaxStackLevel].Item, "ChargeProfileMaxStackLevel");
  11482. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Key, "ChargeProfileMaxStackLevel");
  11483. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  11484. {
  11485. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "0"/*"FALSE"*/);
  11486. }
  11487. else
  11488. {
  11489. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].ReadOnly, "1"/*"TRUE"*/);
  11490. }
  11491. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargeProfileMaxStackLevel].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData);
  11492. isKnowKey = TRUE;
  11493. }
  11494. if(isEmpty || strcmp(keyReq, "ChargingScheduleAllowedChargingRateUnit") == 0 )
  11495. {
  11496. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Item, "ChargingScheduleAllowedChargingRateUnit");
  11497. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Key, "ChargingScheduleAllowedChargingRateUnit");
  11498. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  11499. {
  11500. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "0"/*"FALSE"*/);
  11501. }
  11502. else
  11503. {
  11504. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].ReadOnly, "1"/*"TRUE"*/);
  11505. }
  11506. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleAllowedChargingRateUnit].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData);
  11507. isKnowKey = TRUE;
  11508. }
  11509. if(isEmpty || strcmp(keyReq, "ChargingScheduleMaxPeriods") == 0 )
  11510. {
  11511. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ChargingScheduleMaxPeriods].Item, "ChargingScheduleMaxPeriods");
  11512. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Key, "ChargingScheduleMaxPeriods");
  11513. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  11514. {
  11515. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "0"/*"FALSE"*/);
  11516. }
  11517. else
  11518. {
  11519. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].ReadOnly, "1"/*"TRUE"*/);
  11520. }
  11521. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ChargingScheduleMaxPeriods].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData);
  11522. isKnowKey = TRUE;
  11523. }
  11524. if(isEmpty || strcmp(keyReq, "ConnectorSwitch3to1PhaseSupported") == 0 )
  11525. {
  11526. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Item, "ConnectorSwitch3to1PhaseSupported");
  11527. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Key, "ConnectorSwitch3to1PhaseSupported");
  11528. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  11529. {
  11530. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "0"/*"FALSE"*/);
  11531. }
  11532. else
  11533. {
  11534. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].ReadOnly, "1"/*"TRUE"*/);
  11535. }
  11536. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_ConnectorSwitch3to1PhaseSupported].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData);
  11537. isKnowKey = TRUE;
  11538. }
  11539. if(isEmpty || strcmp(keyReq, "MaxChargingProfilesInstalled") == 0 )
  11540. {
  11541. strcpy((char *)ShmOCPP16Data->GetConfiguration.Key[GetConfiguration_MaxChargingProfilesInstalled].Item, "MaxChargingProfilesInstalled");
  11542. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Key, "MaxChargingProfilesInstalled");
  11543. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  11544. {
  11545. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "0"/*"FLASE"*/);
  11546. }
  11547. else
  11548. {
  11549. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].ReadOnly, "1"/*"TRUE"*/);
  11550. }
  11551. strcpy((char *)ShmOCPP16Data->GetConfiguration.ResponseConfigurationKey[GetConfiguration_MaxChargingProfilesInstalled].Value, (const char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData);
  11552. isKnowKey = TRUE;
  11553. }
  11554. //=========================================================
  11555. if(!isEmpty && !isKnowKey)
  11556. {
  11557. DEBUG_INFO("unKnowIndex =%d\n", UnknownKeynum);
  11558. strcpy(unknownkey[UnknownKeynum], keyReq);
  11559. UnknownKeynum = UnknownKeynum + 1;
  11560. }
  11561. }
  11562. void processUnkownKey(void)
  11563. {
  11564. DEBUG_INFO("processUnkownKey...\n");
  11565. memset(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey, 0 , sizeof(struct StructConfigurationKeyItems)* 10);
  11566. for(int index=0; index < UnknownKeynum; index++)
  11567. {
  11568. if(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item[0] == 0)
  11569. {
  11570. strcpy((char *)(ShmOCPP16Data->GetConfiguration.ResponseUnknownKey[index].Item), unknownkey[index]);
  11571. }
  11572. }
  11573. }
  11574. int setKeyValue(char *key, char *value)
  11575. {
  11576. int isSuccess = NotSupported;
  11577. int check_ascii=0;
  11578. char str[10]={0};
  11579. DEBUG_INFO(" setKeyValue %s = %s\n", key, value);
  11580. if(strcmp(key, "AllowOfflineTxForUnknownId") == 0)
  11581. {
  11582. //Charger.AllowOfflineTxForUnknownId = (value.toLowerCase().equals("true")?true:false);
  11583. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemAccessibility == 1)
  11584. {
  11585. strcpy(str, (const char*)value);
  11586. for(int i = 0; str[i]; i++){
  11587. str[i] = tolower(str[i]);
  11588. }
  11589. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AllowOfflineTxForUnknownId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11590. isSuccess = ConfigurationStatus_Accepted;
  11591. }
  11592. else
  11593. {
  11594. isSuccess = ConfigurationStatus_Rejected;
  11595. }
  11596. }
  11597. if(strcmp(key, "AuthorizationCacheEnabled") == 0)
  11598. {
  11599. //Charger.AuthorizationCacheEnabled = (value.toLowerCase().equals("true")?true:false);
  11600. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemAccessibility == 1)
  11601. {
  11602. strcpy(str, (const char*)value);
  11603. for(int i = 0; str[i]; i++){
  11604. str[i] = tolower(str[i]);
  11605. }
  11606. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationCacheEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11607. isSuccess = ConfigurationStatus_Accepted;
  11608. //updateSetting("AuthorizationCacheEnabled",(char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[1].ItemData);
  11609. }
  11610. else
  11611. {
  11612. isSuccess = ConfigurationStatus_Rejected;
  11613. }
  11614. }
  11615. if(strcmp(key, "AuthorizeRemoteTxRequests") == 0)
  11616. {
  11617. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemAccessibility == 1)
  11618. {
  11619. strcpy(str, (const char*)value);
  11620. for(int i = 0; str[i]; i++)
  11621. {
  11622. str[i] = tolower(str[i]);
  11623. }
  11624. //Charger.AuthorizeRemoteTxRequests = (value.toLowerCase().equals("true")?true:false);
  11625. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizeRemoteTxRequests].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11626. isSuccess = ConfigurationStatus_Accepted;
  11627. }
  11628. else
  11629. {
  11630. isSuccess = ConfigurationStatus_Rejected;
  11631. }
  11632. }
  11633. if(strcmp(key, "BlinkRepeat") == 0)
  11634. {
  11635. //Charger.BlinkRepeat = Integer.parseInt(value);
  11636. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemAccessibility == 1)
  11637. {
  11638. check_ascii = value[0];
  11639. if( (check_ascii < 48) || (check_ascii > 57) )
  11640. {
  11641. isSuccess = ConfigurationStatus_Rejected;
  11642. }
  11643. else
  11644. {
  11645. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[BlinkRepeat].ItemData, "%d", atoi(value) );
  11646. isSuccess = ConfigurationStatus_Accepted;
  11647. }
  11648. }
  11649. else
  11650. {
  11651. isSuccess = ConfigurationStatus_Rejected;
  11652. }
  11653. }
  11654. if(strcmp(key, "ClockAlignedDataInterval") == 0)
  11655. {
  11656. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemAccessibility == 1)
  11657. {
  11658. check_ascii = value[0];
  11659. if( (check_ascii < 48) || (check_ascii > 57) )
  11660. {
  11661. isSuccess = ConfigurationStatus_Rejected;
  11662. }
  11663. else
  11664. {
  11665. if((atoi(value) == 0) || (atoi(value) >= 10))
  11666. {
  11667. //Charger.ClockAlignedDataInterval = Integer.parseInt(value)*1000;
  11668. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ClockAlignedDataInterval].ItemData, "%d", atoi(value) );
  11669. isSuccess = ConfigurationStatus_Accepted;
  11670. }
  11671. else
  11672. isSuccess = ConfigurationStatus_Rejected;
  11673. }
  11674. }
  11675. else
  11676. {
  11677. isSuccess = ConfigurationStatus_Rejected;
  11678. }
  11679. }
  11680. if(strcmp(key, "ConnectionTimeOut") == 0 )
  11681. {
  11682. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemAccessibility == 1)
  11683. {
  11684. check_ascii = value[0];
  11685. if( (check_ascii < 48) || (check_ascii > 57) )
  11686. {
  11687. isSuccess = ConfigurationStatus_Rejected;
  11688. }
  11689. else
  11690. {
  11691. //Charger.ConnectionTimeOut = Integer.parseInt(value)*1000;
  11692. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectionTimeOut].ItemData, "%d", atoi(value));
  11693. isSuccess = ConfigurationStatus_Accepted;
  11694. }
  11695. }
  11696. else
  11697. {
  11698. isSuccess = ConfigurationStatus_Rejected;
  11699. }
  11700. }
  11701. if(strcmp(key, "GetConfigurationMaxKeys") == 0)
  11702. {
  11703. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].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. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11713. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[GetConfigurationMaxKeys].ItemData, "%d", atoi(value) );
  11714. isSuccess = ConfigurationStatus_Accepted;
  11715. }
  11716. }
  11717. else
  11718. {
  11719. isSuccess = ConfigurationStatus_Rejected;
  11720. }
  11721. }
  11722. if(strcmp(key, "HeartbeatInterval") == 0)
  11723. {
  11724. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemAccessibility == 1)
  11725. {
  11726. check_ascii = value[0];
  11727. if( (check_ascii < 48) || (check_ascii > 57) )
  11728. {
  11729. isSuccess = ConfigurationStatus_Rejected;
  11730. }
  11731. else
  11732. {
  11733. if((atoi(value) == 0) || (atoi(value) >= 10))
  11734. {
  11735. //Charger.HeartbeatInterval = Integer.parseInt(value)*1000;
  11736. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData, "%d", atoi(value));
  11737. HeartBeatWaitTime = atoi(value);
  11738. isSuccess = ConfigurationStatus_Accepted;
  11739. }
  11740. else
  11741. {
  11742. isSuccess = ConfigurationStatus_Rejected;
  11743. }
  11744. }
  11745. }
  11746. else
  11747. {
  11748. isSuccess = ConfigurationStatus_Rejected;
  11749. }
  11750. }
  11751. if(strcmp(key, "LightIntensity") == 0)
  11752. {
  11753. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemAccessibility == 1)
  11754. {
  11755. check_ascii = value[0];
  11756. if( (check_ascii < 48) || (check_ascii > 57) )
  11757. {
  11758. isSuccess = ConfigurationStatus_Rejected;
  11759. }
  11760. else
  11761. {
  11762. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LightIntensity].ItemData, "%d", atoi(value) );
  11763. isSuccess = ConfigurationStatus_Accepted;
  11764. }
  11765. }
  11766. else
  11767. {
  11768. isSuccess = ConfigurationStatus_Rejected;
  11769. }
  11770. }
  11771. if(strcmp(key, "LocalAuthorizeOffline") == 0)
  11772. {
  11773. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemAccessibility == 1)
  11774. {
  11775. strcpy(str, (const char*)value);
  11776. for(int i = 0; str[i]; i++)
  11777. {
  11778. str[i] = tolower(str[i]);
  11779. }
  11780. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11781. isSuccess = ConfigurationStatus_Accepted;
  11782. //updateSetting("LocalAuthorizeOffline", (char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalAuthorizeOffline].ItemData);
  11783. }
  11784. else
  11785. {
  11786. isSuccess = ConfigurationStatus_Rejected;
  11787. }
  11788. }
  11789. if(strcmp(key, "LocalPreAuthorize") == 0)
  11790. {
  11791. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemAccessibility == 1)
  11792. {
  11793. strcpy(str, (const char*)value);
  11794. for(int i = 0; str[i]; i++)
  11795. {
  11796. str[i] = tolower(str[i]);
  11797. }
  11798. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[LocalPreAuthorize].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  11799. isSuccess = ConfigurationStatus_Accepted;
  11800. }
  11801. else
  11802. {
  11803. isSuccess = ConfigurationStatus_Rejected;
  11804. }
  11805. }
  11806. if(strcmp(key, "MaxEnergyOnInvalidId") == 0)
  11807. {
  11808. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemAccessibility == 1)
  11809. {
  11810. check_ascii = value[0];
  11811. if( (check_ascii < 48) || (check_ascii > 57) )
  11812. {
  11813. isSuccess = ConfigurationStatus_Rejected;
  11814. }
  11815. else
  11816. {
  11817. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MaxEnergyOnInvalidId].ItemData, "%d", atoi(value) );
  11818. ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy = atoi(value)/1000;
  11819. isSuccess = ConfigurationStatus_Accepted;
  11820. }
  11821. }
  11822. else
  11823. {
  11824. isSuccess = ConfigurationStatus_Rejected;
  11825. }
  11826. }
  11827. if(strcmp(key, "MeterValuesAlignedData") == 0)
  11828. {
  11829. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemAccessibility == 1)
  11830. {
  11831. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedData].ItemData, "%s", value );
  11832. isSuccess = ConfigurationStatus_Accepted;
  11833. }
  11834. else
  11835. {
  11836. isSuccess = ConfigurationStatus_Rejected;
  11837. }
  11838. }
  11839. if(strcmp(key, "MeterValuesAlignedDataMaxLength") == 0)
  11840. {
  11841. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemAccessibility == 1)
  11842. {
  11843. check_ascii = value[0];
  11844. if( (check_ascii < 48) || (check_ascii > 57) )
  11845. {
  11846. isSuccess = ConfigurationStatus_Rejected;
  11847. }
  11848. else
  11849. {
  11850. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11851. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesAlignedDataMaxLength].ItemData, "%d", atoi(value));
  11852. isSuccess = ConfigurationStatus_Accepted;
  11853. }
  11854. }
  11855. else
  11856. {
  11857. isSuccess = ConfigurationStatus_Rejected;
  11858. }
  11859. }
  11860. if(strcmp(key, "MeterValuesSampledData") == 0 )
  11861. {
  11862. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemAccessibility == 1)
  11863. {
  11864. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledData].ItemData, "%s", value );
  11865. isSuccess = ConfigurationStatus_Accepted;
  11866. }
  11867. else
  11868. {
  11869. isSuccess = ConfigurationStatus_Rejected;
  11870. }
  11871. }
  11872. if(strcmp(key, "MeterValuesSampledDataMaxLength") == 0)
  11873. {
  11874. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemAccessibility == 1)
  11875. {
  11876. check_ascii = value[0];
  11877. if( (check_ascii < 48) || (check_ascii > 57) )
  11878. {
  11879. isSuccess = ConfigurationStatus_Rejected;
  11880. }
  11881. else
  11882. {
  11883. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11884. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValuesSampledDataMaxLength].ItemData, "%d", atoi(value));
  11885. isSuccess = ConfigurationStatus_Accepted;
  11886. }
  11887. }
  11888. else
  11889. {
  11890. isSuccess = ConfigurationStatus_Rejected;
  11891. }
  11892. }
  11893. if(strcmp(key, "MeterValueSampleInterval") == 0)
  11894. {
  11895. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemAccessibility == 1)
  11896. {
  11897. check_ascii = value[0];
  11898. if( (check_ascii < 48) || (check_ascii > 57) )
  11899. {
  11900. isSuccess = ConfigurationStatus_Rejected;
  11901. }
  11902. else
  11903. {
  11904. if((atoi(value) == 0) || (atoi(value) >= 10))
  11905. {
  11906. //Charger.MeterValueSampleInterval = Integer.parseInt(value)*1000;
  11907. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MeterValueSampleInterval].ItemData, "%d", atoi(value));
  11908. isSuccess = ConfigurationStatus_Accepted;
  11909. }
  11910. else
  11911. {
  11912. isSuccess = ConfigurationStatus_Rejected;
  11913. }
  11914. }
  11915. }
  11916. else
  11917. {
  11918. isSuccess = ConfigurationStatus_Rejected;
  11919. }
  11920. }
  11921. if(strcmp(key, "MinimumStatusDuration") == 0)
  11922. {
  11923. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemAccessibility == 1)
  11924. {
  11925. check_ascii = value[0];
  11926. if( (check_ascii < 48) || (check_ascii > 57) )
  11927. {
  11928. isSuccess = ConfigurationStatus_Rejected;
  11929. }
  11930. else
  11931. {
  11932. if(atoi(value) == 0) // MinimumStatusDuration's value can not be 0
  11933. {
  11934. isSuccess = ConfigurationStatus_Rejected;
  11935. }
  11936. else
  11937. {
  11938. //Charger.MinimumStatusDuration = Integer.parseInt(value);
  11939. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData, "%d", atoi(value) );
  11940. server_cycle_Status = atoi(value); //StatusNotification Cycle
  11941. isSuccess = ConfigurationStatus_Accepted;
  11942. }
  11943. }
  11944. }
  11945. else
  11946. {
  11947. isSuccess = ConfigurationStatus_Rejected;
  11948. }
  11949. }
  11950. if(strcmp(key, "NumberOfConnectors") == 0)
  11951. {
  11952. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemAccessibility == 1)
  11953. {
  11954. check_ascii = value[0];
  11955. if( (check_ascii < 48) || (check_ascii > 57) )
  11956. {
  11957. isSuccess = ConfigurationStatus_Rejected;
  11958. }
  11959. else
  11960. {
  11961. //Charger.ResetRetries = Integer.parseInt(value);
  11962. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[NumberOfConnectors].ItemData, "%d", atoi(value) );
  11963. isSuccess = ConfigurationStatus_Accepted;
  11964. }
  11965. }
  11966. else
  11967. {
  11968. isSuccess = ConfigurationStatus_Rejected;
  11969. }
  11970. }
  11971. if(strcmp(key, "ResetRetries") == 0)
  11972. {
  11973. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemAccessibility == 1)
  11974. {
  11975. check_ascii = value[0];
  11976. if( (check_ascii < 48) || (check_ascii > 57) )
  11977. {
  11978. isSuccess = ConfigurationStatus_Rejected;
  11979. }
  11980. else
  11981. {
  11982. //Charger.ResetRetries = Integer.parseInt(value);
  11983. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ResetRetries].ItemData, "%d", atoi(value) );
  11984. isSuccess = ConfigurationStatus_Accepted;
  11985. }
  11986. }
  11987. else
  11988. {
  11989. isSuccess = ConfigurationStatus_Rejected;
  11990. }
  11991. }
  11992. if(strcmp(key, "ConnectorPhaseRotation") == 0)
  11993. {
  11994. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemAccessibility == 1)
  11995. {
  11996. strcpy(str, (const char*)value);
  11997. for(int i = 0; str[i]; i++)
  11998. {
  11999. str[i] = tolower(str[i]);
  12000. }
  12001. if(strcmp(str, "notapplicable")== 0)
  12002. {
  12003. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "NotApplicable" );
  12004. isSuccess = ConfigurationStatus_Accepted;
  12005. }
  12006. else if(strcmp(str, "unknown")== 0)
  12007. {
  12008. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "Unknown" );
  12009. isSuccess = ConfigurationStatus_Accepted;
  12010. }
  12011. else if(strcmp(str, "rst")== 0)
  12012. {
  12013. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RST" );
  12014. isSuccess = ConfigurationStatus_Accepted;
  12015. }
  12016. else if(strcmp(str, "rts")== 0)
  12017. {
  12018. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "RTS" );
  12019. isSuccess = ConfigurationStatus_Accepted;
  12020. }
  12021. else if(strcmp(str, "srt")== 0)
  12022. {
  12023. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "SRT" );
  12024. isSuccess = ConfigurationStatus_Accepted;
  12025. }
  12026. else if(strcmp(str, "str")== 0)
  12027. {
  12028. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "STR" );
  12029. isSuccess = ConfigurationStatus_Accepted;
  12030. }
  12031. else if(strcmp(str, "trs")== 0)
  12032. {
  12033. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TRS" );
  12034. isSuccess = ConfigurationStatus_Accepted;
  12035. }
  12036. else if(strcmp(str, "tsr")== 0)
  12037. {
  12038. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotation].ItemData, "%s", "TSR" );
  12039. isSuccess = ConfigurationStatus_Accepted;
  12040. }
  12041. else
  12042. {
  12043. isSuccess = ConfigurationStatus_Rejected;
  12044. }
  12045. }
  12046. else
  12047. {
  12048. isSuccess = ConfigurationStatus_Rejected;
  12049. }
  12050. }
  12051. if(strcmp(key, "ConnectorPhaseRotationMaxLength") == 0)
  12052. {
  12053. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemAccessibility == 1)
  12054. {
  12055. check_ascii = value[0];
  12056. if( (check_ascii < 48) || (check_ascii > 57) )
  12057. {
  12058. isSuccess = ConfigurationStatus_Rejected;
  12059. }
  12060. else
  12061. {
  12062. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[ConnectorPhaseRotationMaxLength].ItemData, "%d", atoi(value) );
  12063. isSuccess = ConfigurationStatus_Accepted;
  12064. }
  12065. }
  12066. else
  12067. {
  12068. isSuccess = ConfigurationStatus_Rejected;
  12069. }
  12070. }
  12071. if(strcmp(key, "StopTransactionOnEVSideDisconnect") == 0)
  12072. {
  12073. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemAccessibility == 1)
  12074. {
  12075. strcpy(str, (const char*)value);
  12076. for(int i = 0; str[i]; i++)
  12077. {
  12078. str[i] = tolower(str[i]);
  12079. }
  12080. //Charger.StopTransactionOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12081. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12082. isSuccess = ConfigurationStatus_Accepted;
  12083. }
  12084. else
  12085. {
  12086. isSuccess = ConfigurationStatus_Rejected;
  12087. }
  12088. }
  12089. if(strcmp(key, "StopTransactionOnInvalidId") == 0)
  12090. {
  12091. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemAccessibility == 1)
  12092. {
  12093. strcpy(str, (const char*)value);
  12094. for(int i = 0; str[i]; i++)
  12095. {
  12096. str[i] = tolower(str[i]);
  12097. }
  12098. //Charger.StopTransactionOnInvalidId = (value.toLowerCase().equals("true")?true:false);
  12099. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTransactionOnInvalidId].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12100. isSuccess = ConfigurationStatus_Accepted;
  12101. }
  12102. else
  12103. {
  12104. isSuccess = ConfigurationStatus_Rejected;
  12105. }
  12106. }
  12107. if(strcmp(key, "StopTxnAlignedData") == 0)
  12108. {
  12109. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemAccessibility == 1)
  12110. {
  12111. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedData].ItemData, "%s", value );
  12112. isSuccess = ConfigurationStatus_Accepted;
  12113. }
  12114. else
  12115. {
  12116. isSuccess = ConfigurationStatus_Rejected;
  12117. }
  12118. }
  12119. if(strcmp(key, "StopTxnAlignedDataMaxLength") == 0)
  12120. {
  12121. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemAccessibility == 1)
  12122. {
  12123. check_ascii = value[0];
  12124. if( (check_ascii < 48) || (check_ascii > 57) )
  12125. {
  12126. isSuccess = ConfigurationStatus_Rejected;
  12127. }
  12128. else
  12129. {
  12130. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnAlignedDataMaxLength].ItemData, "%d", atoi(value) );
  12131. isSuccess = ConfigurationStatus_Accepted;
  12132. }
  12133. }
  12134. else
  12135. {
  12136. isSuccess = ConfigurationStatus_Rejected;
  12137. }
  12138. }
  12139. if(strcmp(key, "StopTxnSampledData") == 0)
  12140. {
  12141. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemAccessibility == 1)
  12142. {
  12143. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledData].ItemData, "%s", value );
  12144. isSuccess = ConfigurationStatus_Accepted;
  12145. }
  12146. else
  12147. {
  12148. isSuccess = ConfigurationStatus_Rejected;
  12149. }
  12150. }
  12151. if(strcmp(key, "StopTxnSampledDataMaxLength") == 0)
  12152. {
  12153. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemAccessibility == 1)
  12154. {
  12155. check_ascii = value[0];
  12156. if( (check_ascii < 48) || (check_ascii > 57) )
  12157. {
  12158. isSuccess = ConfigurationStatus_Rejected;
  12159. }
  12160. else
  12161. {
  12162. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[StopTxnSampledDataMaxLength].ItemData, "%d", atoi(value) );
  12163. isSuccess = ConfigurationStatus_Accepted;
  12164. }
  12165. }
  12166. else
  12167. {
  12168. isSuccess = ConfigurationStatus_Rejected;
  12169. }
  12170. }
  12171. if(strcmp(key, "SupportedFeatureProfiles") == 0)
  12172. {
  12173. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemAccessibility == 1)
  12174. {
  12175. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfiles].ItemData, "%s", value );
  12176. isSuccess = ConfigurationStatus_Accepted;
  12177. }
  12178. else
  12179. {
  12180. isSuccess = ConfigurationStatus_Rejected;
  12181. }
  12182. }
  12183. if(strcmp(key, "SupportedFeatureProfilesMaxLength") == 0)
  12184. {
  12185. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemAccessibility == 1)
  12186. {
  12187. check_ascii = value[0];
  12188. if( (check_ascii < 48) || (check_ascii > 57) )
  12189. {
  12190. isSuccess = ConfigurationStatus_Rejected;
  12191. }
  12192. else
  12193. {
  12194. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SupportedFeatureProfilesMaxLength].ItemData, "%d", atoi(value) );
  12195. isSuccess = ConfigurationStatus_Accepted;
  12196. }
  12197. }
  12198. else
  12199. {
  12200. isSuccess = ConfigurationStatus_Rejected;
  12201. }
  12202. }
  12203. if(strcmp(key, "TransactionMessageAttempts") == 0)
  12204. {
  12205. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemAccessibility == 1)
  12206. {
  12207. check_ascii = value[0];
  12208. if( (check_ascii < 48) || (check_ascii > 57) )
  12209. {
  12210. isSuccess = ConfigurationStatus_Rejected;
  12211. }
  12212. else
  12213. {
  12214. //Charger.TransactionMessageAttempts = Integer.parseInt(value);
  12215. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData, "%d", atoi(value) );
  12216. TransactionMessageAttemptsValue = atoi(value);
  12217. isSuccess = ConfigurationStatus_Accepted;
  12218. }
  12219. }
  12220. else
  12221. {
  12222. isSuccess = ConfigurationStatus_Rejected;
  12223. }
  12224. }
  12225. if(strcmp(key, "TransactionMessageRetryInterval") == 0)
  12226. {
  12227. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemAccessibility == 1)
  12228. {
  12229. check_ascii = value[0];
  12230. if( (check_ascii < 48) || (check_ascii > 57) )
  12231. {
  12232. isSuccess = ConfigurationStatus_Rejected;
  12233. }
  12234. else
  12235. {
  12236. //Charger.TransactionMessageRetryInterval = Integer.parseInt(value)*1000;
  12237. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData, "%d", atoi(value) );
  12238. TransactionMessageRetryIntervalValue = atoi(value);
  12239. isSuccess = ConfigurationStatus_Accepted;
  12240. }
  12241. }
  12242. else
  12243. {
  12244. isSuccess = ConfigurationStatus_Rejected;
  12245. }
  12246. }
  12247. if(strcmp(key, "UnlockConnectorOnEVSideDisconnect") == 0)
  12248. {
  12249. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemAccessibility == 1)
  12250. {
  12251. strcpy(str, (const char*)value);
  12252. for(int i = 0; str[i]; i++)
  12253. {
  12254. str[i] = tolower(str[i]);
  12255. }
  12256. //Charger.UnlockConnectorOnEVSideDisconnect = (value.toLowerCase().equals("true")?true:false);
  12257. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[UnlockConnectorOnEVSideDisconnect].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12258. isSuccess = ConfigurationStatus_Accepted;
  12259. }
  12260. else
  12261. {
  12262. isSuccess = ConfigurationStatus_Rejected;
  12263. }
  12264. }
  12265. if(strcmp(key, "WebSocketPingInterval") == 0)
  12266. {
  12267. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemAccessibility == 1)
  12268. {
  12269. check_ascii = value[0];
  12270. if( (check_ascii < 48) || (check_ascii > 57) )
  12271. {
  12272. isSuccess = ConfigurationStatus_Rejected;
  12273. }
  12274. else
  12275. {
  12276. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData, "%d", atoi(value) );
  12277. isSuccess = ConfigurationStatus_Accepted;
  12278. }
  12279. }
  12280. else
  12281. {
  12282. isSuccess = ConfigurationStatus_Rejected;
  12283. }
  12284. }
  12285. if(strcmp(key, "QueueOffLineStartTransactionMessage") == 0)
  12286. {
  12287. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemAccessibility == 1)
  12288. {
  12289. strcpy(str, (const char*)value);
  12290. for(int i = 0; str[i]; i++)
  12291. {
  12292. str[i] = tolower(str[i]);
  12293. }
  12294. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12295. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[QueueOffLineStartTransactionMessage].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12296. isSuccess = ConfigurationStatus_Accepted;
  12297. }
  12298. else
  12299. {
  12300. isSuccess = ConfigurationStatus_Rejected;
  12301. }
  12302. }
  12303. if(strcmp(key, "AuthorizationKey") == 0)
  12304. {
  12305. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemAccessibility == 1) && (strlen(value) <= 40))
  12306. {
  12307. strcpy(str, (const char*)value);
  12308. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData, "%s", str);
  12309. isSuccess = ConfigurationStatus_Accepted;
  12310. }
  12311. else
  12312. {
  12313. isSuccess = ConfigurationStatus_Rejected;
  12314. }
  12315. }
  12316. if(strcmp(key, "SecurityProfile") == 0)
  12317. {
  12318. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemAccessibility == 1)
  12319. {
  12320. check_ascii = value[0];
  12321. if( (check_ascii < 0x30) || (check_ascii > 0x33) )
  12322. {
  12323. isSuccess = ConfigurationStatus_Rejected;
  12324. }
  12325. else if(check_ascii == 0x33)
  12326. {
  12327. isSuccess = NotSupported;
  12328. }
  12329. else
  12330. {
  12331. if(atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData) <= (check_ascii - 0x30))
  12332. {
  12333. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData, "%d", atoi(value) );
  12334. isSuccess = ConfigurationStatus_Accepted;
  12335. }
  12336. else
  12337. isSuccess = ConfigurationStatus_Rejected;
  12338. }
  12339. }
  12340. else
  12341. {
  12342. isSuccess = ConfigurationStatus_Rejected;
  12343. }
  12344. }
  12345. if(strcmp(key, "DefaultPrice") == 0)
  12346. {
  12347. if((ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemAccessibility == 1))
  12348. {
  12349. strcpy(str, (const char*)value);
  12350. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[DefaultPrice].ItemData, "%s", str);
  12351. isSuccess = ConfigurationStatus_Accepted;
  12352. }
  12353. else
  12354. {
  12355. isSuccess = ConfigurationStatus_Rejected;
  12356. }
  12357. }
  12358. if(strcmp(key, "CustomDisplayCostAndPrice") == 0)
  12359. {
  12360. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemAccessibility == 1)
  12361. {
  12362. strcpy(str, (const char*)value);
  12363. for(int i = 0; str[i]; i++)
  12364. {
  12365. str[i] = tolower(str[i]);
  12366. }
  12367. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12368. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomDisplayCostAndPrice].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12369. isSuccess = ConfigurationStatus_Accepted;
  12370. }
  12371. else
  12372. {
  12373. isSuccess = ConfigurationStatus_Rejected;
  12374. }
  12375. }
  12376. if(strcmp(key, "CustomIdleFeeAfterStop") == 0)
  12377. {
  12378. if(ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemAccessibility == 1)
  12379. {
  12380. strcpy(str, (const char*)value);
  12381. for(int i = 0; str[i]; i++)
  12382. {
  12383. str[i] = tolower(str[i]);
  12384. }
  12385. //Charger.QueueOffLineStartTransactionMessage = (value.toLowerCase().equals("true")?true:false);
  12386. sprintf((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[CustomIdleFeeAfterStop].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12387. isSuccess = ConfigurationStatus_Accepted;
  12388. }
  12389. else
  12390. {
  12391. isSuccess = ConfigurationStatus_Rejected;
  12392. }
  12393. }
  12394. #if 0
  12395. //For OCPP Test Case
  12396. if(strcmp(key, "LocalAuthorizationListEnabled") == 0)
  12397. {
  12398. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12399. {
  12400. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(value, "true")==0) ?"TRUE":"FALSE" );
  12401. isSuccess = ConfigurationStatus_Accepted;
  12402. //updateSetting("LocalAuthorizationListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12403. }
  12404. else
  12405. {
  12406. isSuccess = ConfigurationStatus_Rejected;
  12407. }
  12408. }
  12409. #endif
  12410. #if 1
  12411. if(strcmp(key, "LocalAuthListEnabled") == 0)
  12412. {
  12413. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemAccessibility == 1)
  12414. {
  12415. strcpy(str, (const char*)value);
  12416. for(int i = 0; str[i]; i++)
  12417. {
  12418. str[i] = tolower(str[i]);
  12419. }
  12420. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12421. isSuccess = ConfigurationStatus_Accepted;
  12422. //updateSetting("LocalAuthListEnabled", (char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListEnabled].ItemData);
  12423. }
  12424. else
  12425. {
  12426. isSuccess = ConfigurationStatus_Rejected;
  12427. }
  12428. }
  12429. #endif
  12430. if(strcmp(key, "LocalAuthListMaxLength") == 0)
  12431. {
  12432. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemAccessibility == 1)
  12433. {
  12434. check_ascii = value[0];
  12435. if( (check_ascii < 48) || (check_ascii > 57) )
  12436. {
  12437. isSuccess = ConfigurationStatus_Rejected;
  12438. }
  12439. else
  12440. {
  12441. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[LocalAuthListMaxLength].ItemData, "%d", atoi(value) );
  12442. isSuccess = ConfigurationStatus_Accepted;
  12443. }
  12444. }
  12445. else
  12446. {
  12447. isSuccess = ConfigurationStatus_Rejected;
  12448. }
  12449. }
  12450. if(strcmp(key, "SendLocalListMaxLength") == 0)
  12451. {
  12452. if(ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemAccessibility == 1)
  12453. {
  12454. check_ascii = value[0];
  12455. if( (check_ascii < 48) || (check_ascii > 57) )
  12456. {
  12457. isSuccess = ConfigurationStatus_Rejected;
  12458. }
  12459. else
  12460. {
  12461. sprintf((char *)ShmOCPP16Data->ConfigurationTable.LocalAuthListManagementProfile[SendLocalListMaxLength].ItemData, "%d", atoi(value) );
  12462. isSuccess = ConfigurationStatus_Accepted;
  12463. }
  12464. }
  12465. else
  12466. {
  12467. isSuccess = ConfigurationStatus_Rejected;
  12468. }
  12469. }
  12470. if(strcmp(key, "ReserveConnectorZeroSupported") == 0)
  12471. {
  12472. if(ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemAccessibility == 1)
  12473. {
  12474. strcpy(str, (const char*)value);
  12475. for(int i = 0; str[i]; i++)
  12476. {
  12477. str[i] = tolower(str[i]);
  12478. }
  12479. sprintf((char *)ShmOCPP16Data->ConfigurationTable.ReservationProfile[ReserveConnectorZeroSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12480. isSuccess = ConfigurationStatus_Accepted;
  12481. }
  12482. else
  12483. {
  12484. isSuccess = ConfigurationStatus_Rejected;
  12485. }
  12486. }
  12487. if(strcmp(key, "ChargeProfileMaxStackLevel") == 0)
  12488. {
  12489. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemAccessibility == 1)
  12490. {
  12491. check_ascii = value[0];
  12492. if( (check_ascii < 48) || (check_ascii > 57) )
  12493. {
  12494. isSuccess = ConfigurationStatus_Rejected;
  12495. }
  12496. else
  12497. {
  12498. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargeProfileMaxStackLevel].ItemData, "%d", atoi(value) );
  12499. isSuccess = ConfigurationStatus_Accepted;
  12500. }
  12501. }
  12502. else
  12503. {
  12504. isSuccess = ConfigurationStatus_Rejected;
  12505. }
  12506. }
  12507. if(strcmp(key, "ChargingScheduleAllowedChargingRateUnit") == 0)
  12508. {
  12509. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemAccessibility == 1)
  12510. {
  12511. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleAllowedChargingRateUnit].ItemData, "%s", value );
  12512. isSuccess = ConfigurationStatus_Accepted;
  12513. }
  12514. else
  12515. {
  12516. isSuccess = ConfigurationStatus_Rejected;
  12517. }
  12518. }
  12519. if(strcmp(key, "ChargingScheduleMaxPeriods") == 0)
  12520. {
  12521. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemAccessibility == 1)
  12522. {
  12523. check_ascii = value[0];
  12524. if( (check_ascii < 48) || (check_ascii > 57) )
  12525. {
  12526. isSuccess = ConfigurationStatus_Rejected;
  12527. }
  12528. else
  12529. {
  12530. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ChargingScheduleMaxPeriods].ItemData, "%d", atoi(value) );
  12531. isSuccess = ConfigurationStatus_Accepted;
  12532. }
  12533. }
  12534. else
  12535. {
  12536. isSuccess = ConfigurationStatus_Rejected;
  12537. }
  12538. }
  12539. if(strcmp(key, "ConnectorSwitch3to1PhaseSupported") == 0)
  12540. {
  12541. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemAccessibility == 1)
  12542. {
  12543. strcpy(str, (const char*)value);
  12544. for(int i = 0; str[i]; i++)
  12545. {
  12546. str[i] = tolower(str[i]);
  12547. }
  12548. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[ConnectorSwitch3to1PhaseSupported].ItemData, "%s", (strcmp(str, "true")==0) ?"TRUE":"FALSE" );
  12549. isSuccess = ConfigurationStatus_Accepted;
  12550. }
  12551. else
  12552. {
  12553. isSuccess = ConfigurationStatus_Rejected;
  12554. }
  12555. }
  12556. if(strcmp(key, "MaxChargingProfilesInstalled") == 0)
  12557. {
  12558. if(ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemAccessibility == 1)
  12559. {
  12560. check_ascii = value[0];
  12561. if( (check_ascii < 48) || (check_ascii > 57) )
  12562. {
  12563. isSuccess = ConfigurationStatus_Rejected;
  12564. }
  12565. else
  12566. {
  12567. sprintf((char *)ShmOCPP16Data->ConfigurationTable.SmartChargingProfile[MaxChargingProfilesInstalled].ItemData, "%d", atoi(value) );
  12568. isSuccess = ConfigurationStatus_Accepted;
  12569. }
  12570. }
  12571. else
  12572. {
  12573. isSuccess = ConfigurationStatus_Rejected;
  12574. }
  12575. }
  12576. return isSuccess;
  12577. }
  12578. int TransactionMessageAttemptsGet(void)
  12579. {
  12580. return TransactionMessageAttemptsValue;
  12581. }
  12582. int FirstHeartBeatResponse(void)
  12583. {
  12584. return FirstHeartBeat;
  12585. }
  12586. int TransactionMessageRetryIntervalGet(void)
  12587. {
  12588. return TransactionMessageRetryIntervalValue;//atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  12589. }
  12590. int ReadHttpStatus(int sock)
  12591. {
  12592. //char c;
  12593. char buff[1024]="",*ptr=buff+1;
  12594. int bytes_received, status;
  12595. DEBUG_INFO("Begin Response ..\n");
  12596. while((bytes_received = recv(sock, ptr, 1, 0))){
  12597. if(bytes_received==-1){
  12598. perror("ReadHttpStatus");
  12599. exit(1);
  12600. }
  12601. if((ptr[-1]=='\r') && (*ptr=='\n' )) break;
  12602. ptr++;
  12603. }
  12604. *ptr=0;
  12605. ptr=buff+1;
  12606. sscanf(ptr,"%*s %d ", &status);
  12607. DEBUG_INFO("%s\n",ptr);
  12608. DEBUG_INFO("status=%d\n",status);
  12609. DEBUG_INFO("End Response ..\n");
  12610. return (bytes_received>0)?status:0;
  12611. }
  12612. //the only filed that it parsed is 'Content-Length'
  12613. int ParseHeader(int sock)
  12614. {
  12615. //char c;
  12616. char buff[1024]="",*ptr=buff+4;
  12617. int bytes_received;
  12618. DEBUG_INFO("Begin HEADER ..\n");
  12619. while((bytes_received = recv(sock, ptr, 1, 0))){
  12620. if(bytes_received==-1){
  12621. perror("Parse Header");
  12622. exit(1);
  12623. }
  12624. if(
  12625. (ptr[-3]=='\r') && (ptr[-2]=='\n' ) &&
  12626. (ptr[-1]=='\r') && (*ptr=='\n' )
  12627. ) break;
  12628. ptr++;
  12629. }
  12630. *ptr=0;
  12631. ptr=buff+4;
  12632. //printf("%s",ptr);
  12633. if(bytes_received){
  12634. ptr=strstr(ptr,"Content-Length:");
  12635. if(ptr){
  12636. sscanf(ptr,"%*s %d",&bytes_received);
  12637. }else
  12638. bytes_received=-1; //unknown size
  12639. DEBUG_INFO("Content-Length: %d\n",bytes_received);
  12640. }
  12641. DEBUG_INFO("End HEADER ..\n");
  12642. return bytes_received ;
  12643. }
  12644. int httpDownLoadFile(char *location, char *path, char *filename,char *url)
  12645. {
  12646. char rmFileCmd[100]={0};
  12647. char FilePath[100]={0};
  12648. char ftpbuf[200];
  12649. int systemresult;
  12650. //DEBUG_INFO("filename=%s\n",filename);
  12651. //DEBUG_INFO("url=%s\n",url);
  12652. sprintf(FilePath,"/mnt/%s",filename);
  12653. if((access(FilePath,F_OK))!=-1)
  12654. {
  12655. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12656. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12657. system(rmFileCmd);
  12658. }
  12659. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12660. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  12661. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12662. systemresult = system(ftpbuf);
  12663. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12664. if(systemresult != 0)
  12665. {
  12666. DEBUG_INFO("http DownLoad error!\n");
  12667. return FALSE;
  12668. }
  12669. return TRUE;
  12670. }
  12671. int ftpDownLoadFile(char *location, char *user, char *password, int port, char *path, char *filename,char *url)
  12672. {
  12673. char rmFileCmd[100]={0};
  12674. char FilePath[100]={0};
  12675. char ftpbuf[200];
  12676. int systemresult;
  12677. //char temp[100];
  12678. sprintf(FilePath,"/mnt/%s",filename);
  12679. if((access(FilePath,F_OK))!=-1)
  12680. {
  12681. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12682. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12683. system(rmFileCmd);
  12684. }
  12685. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12686. sprintf(ftpbuf, "wget --tries=3 -O /mnt/%s -c %s -T 120",filename, url);
  12687. //sprintf(ftpbuf, "ftpget -u %s -p %s %s -P %d %s %s%s",user,password,IPbuffer,port/*21*/,filename,path,filename); --- remove temporally
  12688. //DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12689. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12690. systemresult = system(ftpbuf);
  12691. //DEBUG_INFO("systemresult=%d\n",systemresult);
  12692. if(systemresult != 0)
  12693. {
  12694. printf("wget error!\n");
  12695. return FALSE;
  12696. }
  12697. return TRUE;
  12698. }
  12699. int httpUploadFile(char *location, char *path, char *filename,char *url)
  12700. {
  12701. char rmFileCmd[100]={0};
  12702. char FilePath[100]={0};
  12703. char ftpbuf[200];
  12704. int systemresult;
  12705. //DEBUG_INFO("filename=%s\n",filename);
  12706. //DEBUG_INFO("url=%s\n",url);
  12707. sprintf(FilePath,"%s","/mnt/upload_file.txt");
  12708. if((access(FilePath,F_OK))!=-1)
  12709. {
  12710. DEBUG_INFO("filename=%s exist.\n",FilePath);
  12711. sprintf(rmFileCmd,"rm -f %s",FilePath);
  12712. system(rmFileCmd);
  12713. }
  12714. FILE *fp = fopen("/mnt/upload_file.txt", "w+");
  12715. if(fp == NULL)
  12716. {
  12717. DEBUG_INFO("log is NULL\n");
  12718. return FALSE;
  12719. }
  12720. else
  12721. {
  12722. fprintf(fp, "%s\n", url);
  12723. fprintf(fp, "%s\n", filename);
  12724. fclose(fp);
  12725. }
  12726. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12727. sprintf(ftpbuf, "%s","/bin/php-cgi /var/www/ocpp_upload.php");
  12728. systemresult = system(ftpbuf);
  12729. DEBUG_INFO("systemresult = %d\n",systemresult);
  12730. if(systemresult != 0)
  12731. {
  12732. DEBUG_INFO("http upload error!\n");
  12733. return FALSE;
  12734. }
  12735. return TRUE;
  12736. }
  12737. int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
  12738. {
  12739. struct hostent* server;
  12740. char *IPbuffer;
  12741. char ftpbuf[200];
  12742. int systemresult;
  12743. // To retrieve host information
  12744. server = gethostbyname(location);
  12745. // To convert an Internet network
  12746. // address into ASCII string
  12747. IPbuffer = inet_ntoa(*((struct in_addr*)
  12748. server->h_addr_list[0]));
  12749. memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
  12750. /* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
  12751. /* format : ftpput -u username -p passwd IP target source*/
  12752. sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
  12753. DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
  12754. //sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
  12755. systemresult = system(ftpbuf);
  12756. DEBUG_INFO("systemresult=%d\n",systemresult);
  12757. if(systemresult != 0)
  12758. {
  12759. DEBUG_INFO("ftpput error!\n");
  12760. return FALSE;
  12761. }
  12762. return TRUE;
  12763. }
  12764. /**
  12765. * Place the contents of the specified file into a memory buffer
  12766. *
  12767. * @param[in] filename The path and name of the file to read
  12768. * @param[out] filebuffer A pointer to the contents in memory
  12769. * @return status 0 success, 1 on failure
  12770. */
  12771. int get_file_contents(const char* filename, char** outbuffer) {
  12772. FILE* file = NULL;
  12773. long filesize;
  12774. const int blocksize = 1;
  12775. size_t readsize;
  12776. char* filebuffer;
  12777. // Open the file
  12778. file = fopen(filename, "r");
  12779. if (NULL == file)
  12780. {
  12781. printf("'%s' not opened\n", filename);
  12782. exit(EXIT_FAILURE);
  12783. }
  12784. // Determine the file size
  12785. fseek(file, 0, SEEK_END);
  12786. filesize = ftell(file);
  12787. rewind (file);
  12788. // Allocate memory for the file contents
  12789. filebuffer = (char*) malloc(sizeof(char) * filesize);
  12790. *outbuffer = filebuffer;
  12791. if (filebuffer == NULL)
  12792. {
  12793. fputs ("malloc out-of-memory", stderr);
  12794. exit(EXIT_FAILURE);
  12795. }
  12796. // Read in the file
  12797. readsize = fread(filebuffer, blocksize, filesize, file);
  12798. if (readsize != filesize)
  12799. {
  12800. fputs ("didn't read file completely",stderr);
  12801. exit(EXIT_FAILURE);
  12802. }
  12803. // Clean exit
  12804. fclose(file);
  12805. return EXIT_SUCCESS;
  12806. }
  12807. static int selectSqlCount = 0;
  12808. static int callback(void *data, int argc, char **argv, char **azColName){
  12809. int i;
  12810. //printf("%s: ", (const char*)data);
  12811. selectSqlCount = argc;
  12812. for(i = 0; i<argc; i++){
  12813. // printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
  12814. }
  12815. //printf("\n");
  12816. return 0;
  12817. }
  12818. static int versioncallback(void *data, int argc, char **argv, char **azColName){
  12819. //int i;
  12820. //printf("%s:\n", (const char*)data);
  12821. localversion = argv[5] ? atoi(argv[5]) : 0;
  12822. //printf("localversion=%d\n", localversion);
  12823. return 0;
  12824. }
  12825. static int IdTagcallback(void *data, int columenCount, char **columnValue, char **columnName){
  12826. //printf("%s:\n", (const char*)data);
  12827. //idTag
  12828. sprintf(idTagAuthorization,"%s", columnValue[1] ? columnValue[1] : "NULL");
  12829. sprintf(idTagQuery.idTagstr,"%s", columnValue[1] ? columnValue[1] : "NULL");
  12830. //parentIdTag
  12831. sprintf(idTagQuery.parentIdTag,"%s", columnValue[2] ? columnValue[2] : "NULL");
  12832. //expir_date
  12833. sprintf(idTagQuery.expiryDate,"%s", columnValue[3] ? columnValue[3] : "NULL");
  12834. //status
  12835. sprintf(idTagQuery.idTagstatus,"%s", columnValue[4] ? columnValue[4] : "NULL");
  12836. //version
  12837. if(columenCount > 5)
  12838. idTagQuery.listVersionInt = atoi(columnValue[5]);
  12839. //DEBUG_INFO("IdTag=%s\n", idTagAuthorization);
  12840. return 0;
  12841. }
  12842. static int deleteIdTagcallback(void *data, int argc, char **argv, char **azColName)
  12843. {
  12844. // localversion = argv[5] ? atoi(argv[5]) : 0;
  12845. // printf("localversion=%d\n", localversion);
  12846. return 0;
  12847. }
  12848. //=========================================
  12849. // Sqlite3 related function
  12850. //=========================================
  12851. int sqlite3_exec_callback(void *data, int n_columns, char **col_values, char **col_names)
  12852. {
  12853. for (int i = 0; i < n_columns; i++)
  12854. {
  12855. DEBUG_INFO("%s\t", col_values[i]);
  12856. }
  12857. DEBUG_INFO("\n");
  12858. return 0;
  12859. }
  12860. int OCPP_cleanLocalCache()
  12861. {
  12862. char * sqlcleanLocalList = "delete from ocpp_auth_cache";
  12863. char *errMsg = 0;
  12864. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12865. if (SQLITE_OK != rc)
  12866. {
  12867. DEBUG_INFO("SQL error: %s\n",errMsg);
  12868. return FALSE;
  12869. }
  12870. return TRUE;
  12871. }
  12872. int OCPP_addLocalCache(char *idTag, char *parentTage, char *expiryDate, char *status)
  12873. {
  12874. int isSuccess = TRUE;
  12875. int ret = 0;
  12876. //const char* data = "Callback function called";
  12877. char sql[300];
  12878. char zErrMsg[200];
  12879. memset(sql, 0, 300);
  12880. memset(zErrMsg, 0, 200);
  12881. sprintf(sql, "insert or replace into ocpp_auth_cache (idtag, parent_idtag, expir_date, status) " "VALUES ('%s', '%s', '%s', '%s'); ""SELECT * from ocpp_auth_cache", idTag, parentTage, expiryDate, status);
  12882. //* Execute SQL statement */
  12883. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12884. if( ret != SQLITE_OK )
  12885. {
  12886. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12887. isSuccess = FALSE;
  12888. }
  12889. return isSuccess;
  12890. }
  12891. void OCPP_getIdTagFromLocalCache(char idTag[])
  12892. {
  12893. int rc = 0;
  12894. char sql[100];
  12895. char zErrMsg[100];
  12896. memset(sql, 0, 100);
  12897. memset(zErrMsg, 0, 100);
  12898. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  12899. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12900. sprintf(sql,"select * from ocpp_auth_cache where idtag='%s'", idTag);
  12901. /* Execute SQL statement */
  12902. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12903. if( rc != SQLITE_OK )
  12904. {
  12905. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12906. }
  12907. }
  12908. void OCPP_getListVerion()
  12909. {
  12910. int rc = 0;
  12911. // const char* data = "Callback function called";
  12912. char sql[100];
  12913. char zErrMsg[100];
  12914. memset(sql, 0, 100);
  12915. memset(zErrMsg, 0, 100);
  12916. strcpy(sql, "select * from ocpp_auth_local order by idx");
  12917. /* Execute SQL statement */
  12918. rc = sqlite3_exec(db, sql, versioncallback, 0, (char **)&zErrMsg);
  12919. if( rc != SQLITE_OK )
  12920. {
  12921. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12922. }
  12923. }
  12924. void OCPP_get_TableAuthlocalAllData(void)
  12925. {
  12926. int rc = 0;
  12927. char sql[100];
  12928. char zErrMsg[100];
  12929. memset(sql, 0, 100);
  12930. memset(zErrMsg, 0, 100);
  12931. sprintf(sql,"select * from ocpp_auth_local ");
  12932. /* Execute SQL statement */
  12933. rc = sqlite3_exec(db, sql, &sqlite3_exec_callback, 0,(char **)&zErrMsg);
  12934. if( rc != SQLITE_OK )
  12935. {
  12936. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12937. }
  12938. //return ver;
  12939. }
  12940. int OCPP_cleanLocalList()
  12941. {
  12942. char * sqlcleanLocalList = "delete from ocpp_auth_local";
  12943. char *errMsg = 0;
  12944. int rc =sqlite3_exec(db, sqlcleanLocalList, 0, 0, &errMsg);
  12945. if (SQLITE_OK != rc)
  12946. {
  12947. DEBUG_INFO("%s\n",errMsg);
  12948. return FALSE;
  12949. }
  12950. return TRUE;
  12951. }
  12952. int OCPP_addLocalList(int version, char *idTag, char *parentTage, char *expiryDate, char *status)
  12953. {
  12954. int isSuccess = FALSE;
  12955. int ret = 0;
  12956. //const char* data = "Callback function called";
  12957. char sql[300];
  12958. char zErrMsg[200];
  12959. memset(sql, 0, 300);
  12960. memset(zErrMsg, 0, 200);
  12961. 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);
  12962. //* Execute SQL statement */
  12963. ret = sqlite3_exec(db, sql, callback, 0, (char **)&zErrMsg);
  12964. if( ret != SQLITE_OK )
  12965. {
  12966. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12967. return isSuccess;
  12968. }
  12969. memset(sql, 0, 300);
  12970. sprintf(sql, "UPDATE ocpp_auth_local SET version=%d",version);
  12971. ret = sqlite3_exec(db, sql, NULL, NULL, (char **)&zErrMsg);
  12972. if( ret != SQLITE_OK )
  12973. {
  12974. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12975. return isSuccess;
  12976. }
  12977. isSuccess = TRUE;
  12978. return isSuccess;
  12979. }
  12980. void OCPP_getIdTagFromLocalList(char idTag[])
  12981. {
  12982. int rc = 0;
  12983. // const char* data = "Callback function called";
  12984. char sql[100];
  12985. char zErrMsg[100];
  12986. memset(sql, 0, 100);
  12987. memset(zErrMsg, 0, 100);
  12988. memset(idTagAuthorization, 0, ARRAY_SIZE(idTagAuthorization));
  12989. memset(&idTagQuery, 0, sizeof(idTagQuery));
  12990. //DEBUG_INFO("look up card: %s in ocpp_auth_local table", idTag);
  12991. sprintf(sql,"select * from ocpp_auth_local where idtag='%s'", idTag);
  12992. /* Execute SQL statement */
  12993. rc = sqlite3_exec(db, sql, IdTagcallback, 0, (char **)&zErrMsg);
  12994. if( rc != SQLITE_OK )
  12995. {
  12996. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  12997. }
  12998. //return ver;
  12999. }
  13000. void OCPP_deleteIdTagFromLocalList(char idTag[])
  13001. {
  13002. //int ver = 0;
  13003. //int isSuccess = FALSE;
  13004. int rc = 0;
  13005. char sql[100];
  13006. char zErrMsg[100];
  13007. memset(sql, 0, 100);
  13008. memset(zErrMsg, 0, 100);
  13009. sprintf(sql,"DELETE from ocpp_auth_local where idtag='%s'; SELECT * from ocpp_auth_local;", idTag);
  13010. //* Execute SQL statement */
  13011. rc = sqlite3_exec(db, sql, deleteIdTagcallback, 0,(char **)&zErrMsg);
  13012. if( rc != SQLITE_OK )
  13013. {
  13014. DEBUG_INFO("SQL error: %s\n", zErrMsg);
  13015. }
  13016. }
  13017. int GetOcppServerURL()
  13018. {
  13019. int result = FALSE;
  13020. memset(OcppProtocol, 0, ARRAY_SIZE(OcppProtocol));
  13021. memset(OcppHost, 0, ARRAY_SIZE(OcppHost));
  13022. memset(OcppTempPath, 0, ARRAY_SIZE(OcppTempPath));
  13023. struct yuarel url;
  13024. char urlStr[512];
  13025. if((ShmSysConfigAndInfo->SysConfig.OcppServerURL != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,"") != 0) )
  13026. {
  13027. /*sscanf((const char *)ShmSysConfigAndInfo->SysConfig.OcppServerURL,
  13028. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13029. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13030. memcpy(urlStr, ShmSysConfigAndInfo->SysConfig.OcppServerURL, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.OcppServerURL));
  13031. if(yuarel_parse(&url, urlStr) != -1)
  13032. {
  13033. sprintf(OcppProtocol, "%s", url.scheme);
  13034. sprintf(OcppHost, "%s", url.host);
  13035. if(url.path == NULL)
  13036. OcppTempPath[0] = '\0';
  13037. else
  13038. sprintf(OcppTempPath, "%s", url.path);
  13039. if(url.port == 0)
  13040. {
  13041. if(strcmp(OcppProtocol, "wss") == 0)
  13042. OcppPort = 443;
  13043. else
  13044. OcppPort = 80;
  13045. }
  13046. else
  13047. OcppPort = url.port;
  13048. result = TRUE;
  13049. }
  13050. }
  13051. else if((ShmOCPP16Data->OcppServerURL != NULL) && (strcmp((const char *)ShmOCPP16Data->OcppServerURL,"") != 0))
  13052. {
  13053. /*sscanf((const char *)ShmOCPP16Data->OcppServerURL,
  13054. "%[^:]:%*2[/]%[^:]:%i/%[a-zA-Z0-9._/-]",
  13055. OcppProtocol, OcppHost, &OcppPort, OcppTempPath);*/
  13056. memcpy(urlStr, ShmOCPP16Data->OcppServerURL, ARRAY_SIZE(ShmOCPP16Data->OcppServerURL));
  13057. if(yuarel_parse(&url, urlStr) != -1)
  13058. {
  13059. sprintf(OcppProtocol, "%s", url.scheme);
  13060. sprintf(OcppHost, "%s", url.host);
  13061. if(url.path == NULL)
  13062. OcppTempPath[0] = '\0';
  13063. else
  13064. sprintf(OcppTempPath, "%s", url.path);
  13065. if(url.port == 0)
  13066. {
  13067. if(strcmp(OcppProtocol, "wss") == 0)
  13068. OcppPort = 443;
  13069. else
  13070. OcppPort = 80;
  13071. }
  13072. else
  13073. OcppPort = url.port;
  13074. result = TRUE;
  13075. }
  13076. }
  13077. else
  13078. {
  13079. strcpy(OcppHost,"");
  13080. }
  13081. return result;
  13082. }
  13083. int GetOcppPath()
  13084. {
  13085. int result = FALSE;
  13086. if((ShmSysConfigAndInfo->SysConfig.ChargeBoxId != NULL) && (strcmp((const char *)ShmSysConfigAndInfo->SysConfig.ChargeBoxId,"") != 0) )
  13087. {
  13088. if(OcppTempPath == NULL)
  13089. {
  13090. sprintf(OcppPath,"/%s",ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13091. }
  13092. else
  13093. {
  13094. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  13095. }
  13096. result = TRUE;
  13097. goto End;
  13098. }
  13099. else if((ShmOCPP16Data->ChargeBoxId != NULL) && (strcmp((const char *)ShmOCPP16Data->ChargeBoxId,"") != 0))
  13100. {
  13101. if(OcppTempPath == NULL)
  13102. {
  13103. sprintf(OcppPath,"/%s",ShmOCPP16Data->ChargeBoxId);
  13104. }
  13105. else
  13106. {
  13107. sprintf(OcppPath,"/%s%s",OcppTempPath,ShmOCPP16Data->ChargeBoxId);
  13108. }
  13109. result = TRUE;
  13110. goto End;
  13111. }
  13112. else
  13113. {
  13114. strcpy(OcppPath,"");
  13115. }
  13116. End:
  13117. return result;
  13118. }
  13119. int GetOcppPort()
  13120. {
  13121. return OcppPort;
  13122. }
  13123. int GetOcppConnStatus(void)
  13124. {
  13125. return ShmOCPP16Data->OcppConnStatus;
  13126. }
  13127. void SetOcppConnStatus(uint8_t status)
  13128. {
  13129. ShmOCPP16Data->OcppConnStatus = status;
  13130. ShmSysConfigAndInfo->SysInfo.OcppConnStatus = status;
  13131. }
  13132. int GetHeartBeatWithNOResponse(void)
  13133. {
  13134. return HeartBeatWithNOResponse;
  13135. }
  13136. void SetHeartBeatWithNOResponse(void)
  13137. {
  13138. HeartBeatWithNOResponse = 0;
  13139. }
  13140. void GetStartTransactionIdTag(int gun_index)
  13141. {
  13142. memset(StartTransactionIdTagTemp, 0 ,ARRAY_SIZE(StartTransactionIdTagTemp));
  13143. strcpy((char *)StartTransactionIdTagTemp, (const char *)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13144. }
  13145. int GetTransactionId(int gunindex, unsigned char idTag[], uint8_t isStopTransaction)
  13146. {
  13147. char ch;
  13148. FILE *fptr1;
  13149. int temptransactionId;
  13150. char str[100]={0};
  13151. temptransactionId = 0;
  13152. if((strcmp((const char*)idTag, "")==0)||(idTag[0]=='\0'))
  13153. {
  13154. DEBUG_INFO("IdTag is empty.\n");
  13155. return temptransactionId;
  13156. }
  13157. /*------ Read the file ----------------*/
  13158. fptr1=fopen("/Storage/OCPP/QueueTransactionId","r");
  13159. if (!fptr1)
  13160. {
  13161. DEBUG_INFO("QueueTransactionId file open error.\n");
  13162. //printf(" File not found or unable to open the input file!!\n");
  13163. return temptransactionId;
  13164. }
  13165. ch=fgetc(fptr1);
  13166. //printf(" Now the content of the file %s is : \n","/Storage/OCPP/QueueTransactionId");
  13167. rewind(fptr1);
  13168. if(ch!=EOF)
  13169. {
  13170. // printf("%c",ch);
  13171. while (fgets(str, 100, fptr1) != NULL)
  13172. {
  13173. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13174. if(str[0]=='\0')
  13175. {
  13176. break;
  13177. }
  13178. char *revbuf[8] = {0}; // Variable store string split
  13179. int num = 0;// Quantity after string split
  13180. DEBUG_INFO("Transaction queue data= %s\n", str);
  13181. splitstring(str,",",revbuf,&num); // String split
  13182. DEBUG_INFO(" revbuf[0]= %s\n", revbuf[0]);
  13183. DEBUG_INFO(" revbuf[1]= %s\n", revbuf[1]);
  13184. DEBUG_INFO(" revbuf[2]= %s\n", revbuf[2]);
  13185. DEBUG_INFO("------------------------------\n");
  13186. if((revbuf[1][0] != '\0')&&(revbuf[2][0] != '\0'))
  13187. {
  13188. if(isStopTransaction)
  13189. {
  13190. if((atoi(revbuf[0])==gunindex) && (strcmp(revbuf[1],(const char *)idTag)==0))
  13191. {
  13192. temptransactionId = atoi(revbuf[2]);
  13193. break;
  13194. }
  13195. }
  13196. else
  13197. {
  13198. if((atoi(revbuf[0])==gunindex) || (strcmp(revbuf[1],(const char *)idTag)==0))
  13199. {
  13200. temptransactionId = atoi(revbuf[2]);
  13201. break;
  13202. }
  13203. }
  13204. }
  13205. }
  13206. }
  13207. else
  13208. DEBUG_INFO("EOF\n");
  13209. fclose(fptr1);
  13210. /*------- End of reading ---------------*/
  13211. return temptransactionId;
  13212. }
  13213. void SetTransactionIdZero(int transactionId)
  13214. {
  13215. char ch;
  13216. FILE *fptr1, *fptr2;
  13217. int temptransactionId = 0;
  13218. char str[100]={0}, strtemp[100]={0}, temp[] = "/Storage/OCPP/QueueTransactionIdtemp.json";
  13219. fptr1 = fopen("/Storage/OCPP/QueueTransactionId", "r");
  13220. if (!fptr1)
  13221. {
  13222. //printf(" File not found or unable to open the input file!!\n");
  13223. return ;
  13224. }
  13225. fptr2 = fopen(temp, "w"); // open the temporary file in write mode
  13226. if (!fptr2)
  13227. {
  13228. DEBUG_INFO("Unable to open a temporary file to write!!\n");
  13229. fclose(fptr1);
  13230. return ;
  13231. }
  13232. ch=fgetc(fptr1);
  13233. rewind(fptr1);
  13234. if(ch!=EOF)
  13235. {
  13236. // copy all contents to the temporary file except the specific line
  13237. while (fgets(str, 100, fptr1) != NULL)
  13238. {
  13239. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  13240. if(str[0]=='\0')
  13241. {
  13242. break;
  13243. }
  13244. char *revbuf[8] = {0};
  13245. int num = 0;
  13246. strcpy(strtemp, str);
  13247. splitstring(str,",",revbuf,&num);
  13248. if(revbuf[2][0] != '\0')
  13249. {
  13250. temptransactionId = atoi(revbuf[2]);
  13251. if(transactionId != temptransactionId)
  13252. {
  13253. fprintf(fptr2, "%s\n", strtemp);
  13254. }
  13255. }
  13256. }
  13257. }
  13258. fclose(fptr1);
  13259. fclose(fptr2);
  13260. remove("/Storage/OCPP/QueueTransactionId"); // remove the original file
  13261. rename(temp, "/Storage/OCPP/QueueTransactionId"); // rename the temporary file to original name
  13262. /*------ Read the file ----------------*/
  13263. }
  13264. int InternetDisconnect(void)
  13265. {
  13266. return (ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectVia4Gi && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaEthernet && ShmStatusCodeData->InfoCode.InfoEvents.bits.InternetDisconnectViaWiFi );
  13267. }
  13268. //Note: It is not real StopTransaction. It is temporary StopTransaction.
  13269. void storeTempStopTransaction(int gun_index)
  13270. {
  13271. char guid[37]={0};
  13272. int tempIndex = 0;
  13273. char TempStopTransaction[256];
  13274. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  13275. DEBUG_INFO("storeTempStopTransaction...\n");
  13276. memset(queuedata, 0, ARRAY_SIZE(queuedata));
  13277. memset(&ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0], 0, ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData));
  13278. //======================== ENERGY_ACTIVE_IMPORT_REGISTER =======================================
  13279. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13280. if(gunType[gun_index] == 'J')
  13281. {
  13282. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13283. {
  13284. tempIndex = ((gun_index==2) ? 1: 0);
  13285. }
  13286. else
  13287. {
  13288. tempIndex = gun_index;
  13289. }
  13290. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13291. {
  13292. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13293. {
  13294. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PowerConsumption*1000);
  13295. }
  13296. }// END OF CHAdeMO_QUANTITY
  13297. }
  13298. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13299. {
  13300. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13301. {
  13302. tempIndex = ((gun_index==2) ? 1: 0);
  13303. }
  13304. else
  13305. {
  13306. tempIndex = gun_index;
  13307. }
  13308. for (int index = 0; index < CCS_QUANTITY; index++)
  13309. {
  13310. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13311. {
  13312. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PowerConsumption*1000);
  13313. }
  13314. }// END OF CCS_QUANTITY
  13315. }
  13316. else if(gunType[gun_index] == 'G')
  13317. {
  13318. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13319. {
  13320. tempIndex = ((gun_index==2) ? 1: 0);
  13321. }
  13322. else
  13323. {
  13324. tempIndex = gun_index;
  13325. }
  13326. for (int index = 0; index < GB_QUANTITY; index++)
  13327. {
  13328. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13329. {
  13330. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PowerConsumption*1000);
  13331. }
  13332. }// END OF GB_QUANTITY
  13333. }
  13334. else if(gunType[gun_index] == 'O')
  13335. {
  13336. tempIndex = gun_index;
  13337. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13338. {
  13339. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13340. {
  13341. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PowerConsumption*1000);
  13342. }
  13343. }
  13344. }
  13345. else
  13346. {
  13347. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13348. {
  13349. tempIndex = 2;
  13350. }
  13351. else
  13352. {
  13353. tempIndex = gun_index;
  13354. }
  13355. for (int index = 0; index < AC_QUANTITY; index++)
  13356. {
  13357. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13358. {
  13359. ShmOCPP16Data->StopTransaction[gun_index].MeterStop = (int)(ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PowerConsumption*1000);
  13360. }
  13361. }// END OF AC_QUANTITY
  13362. }
  13363. //Stop Transaction Time
  13364. struct timeval tmnow;
  13365. struct tm *tm;
  13366. char buf[28];//, usec_buf[6];
  13367. gettimeofday(&tmnow, NULL);
  13368. time_t t;
  13369. t = time(NULL);
  13370. /*UTC time and date*/
  13371. tm = gmtime(&t);
  13372. strftime(buf,28,"%Y-%m-%dT%H:%M:%SZ", tm);
  13373. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].Timestamp,buf);
  13374. ShmOCPP16Data->StopTransaction[gun_index].TransactionId = ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId;
  13375. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].IdTag, (const char*)ShmOCPP16Data->StartTransaction[gun_index].IdTag);
  13376. random_uuid(guid);
  13377. /***********************************transactionData******************************************************/
  13378. memset(ShmOCPP16Data->StopTransaction[gun_index].TransactionData, 0, sizeof(sizeof(struct StructMeterValue)));
  13379. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].TimeStamp, buf);
  13380. //=================================
  13381. //1. Transaction_Begin
  13382. //=================================
  13383. //============================== Energy.Active.Import.Interval ===========================================
  13384. //idx_sample=0;
  13385. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Value, "%.1f", 0.0); // MeterStart is 0~6553.5 kWh
  13386. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  13387. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Format,ValueFormatStr[Raw]);
  13388. 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*/]);
  13389. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DCcc
  13390. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G'))
  13391. {
  13392. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L3_N]);
  13393. }
  13394. else
  13395. {
  13396. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Phase,PhaseStr[L1_N]);
  13397. }
  13398. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Location,LocationStr[Location_Outlet]);
  13399. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[0].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13400. //=================================
  13401. //2. Transaction_End
  13402. //=================================
  13403. //2.1====================================== Current.Import L1 ==============================================
  13404. //idx_sample=1;
  13405. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G : GBT DC
  13406. if(gunType[gun_index] == 'J')
  13407. {
  13408. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13409. {
  13410. tempIndex = ((gun_index==2) ? 1: 0);
  13411. }
  13412. else
  13413. {
  13414. tempIndex = gun_index;
  13415. }
  13416. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13417. {
  13418. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13419. {
  13420. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13421. }
  13422. }// End of for CHAdeMO_QUANTITY
  13423. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13424. }
  13425. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13426. {
  13427. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13428. {
  13429. tempIndex = ((gun_index==2) ? 1: 0);
  13430. }
  13431. else
  13432. {
  13433. tempIndex = gun_index;
  13434. }
  13435. for (int index = 0; index < CCS_QUANTITY; index++)
  13436. {
  13437. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13438. {
  13439. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13440. }
  13441. }// End of for CCS_QUANTITY
  13442. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13443. }
  13444. else if(gunType[gun_index] == 'G')
  13445. {
  13446. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13447. {
  13448. tempIndex = ((gun_index==2) ? 1: 0);
  13449. }
  13450. else
  13451. {
  13452. tempIndex = gun_index;
  13453. }
  13454. for (int index = 0; index < GB_QUANTITY; index++)
  13455. {
  13456. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13457. {
  13458. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13459. }
  13460. }// End of for GB_QUANTITY
  13461. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13462. }
  13463. else if(gunType[gun_index] == 'O')
  13464. {
  13465. tempIndex = gun_index;
  13466. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13467. {
  13468. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13469. {
  13470. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingCurrent );// PresentChargingCurrent is 0~6553.5 amp
  13471. }
  13472. }
  13473. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L3_N]);
  13474. }
  13475. else
  13476. {
  13477. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13478. {
  13479. tempIndex = 2;
  13480. }
  13481. else
  13482. {
  13483. tempIndex = gun_index;
  13484. }
  13485. for (int index = 0; index < AC_QUANTITY; index++)
  13486. {
  13487. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13488. {
  13489. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrent );// 0~6553.5 amp for EVSE
  13490. }
  13491. }// End of for AC_QUANTITY
  13492. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13493. }
  13494. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13495. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Format,ValueFormatStr[Raw]);
  13496. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Measurand,MeasurandStr[Current_Import]);
  13497. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Phase,PhaseStr[L1_N]);
  13498. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Location,LocationStr[Location_Outlet]);
  13499. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13500. //2.2===================================== Energy.Active.Import.Interval ==========================================
  13501. //idx_sample=2;
  13502. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13503. if(gunType[gun_index] == 'J')
  13504. {
  13505. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13506. {
  13507. tempIndex = ((gun_index==2) ? 1: 0);
  13508. }
  13509. else
  13510. {
  13511. tempIndex = gun_index;
  13512. }
  13513. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13514. {
  13515. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13516. {
  13517. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13518. }
  13519. }// END OF CHAdeMO_QUANTITY
  13520. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13521. }
  13522. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13523. {
  13524. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13525. {
  13526. tempIndex = ((gun_index==2) ? 1: 0);
  13527. }
  13528. else
  13529. {
  13530. tempIndex = gun_index;
  13531. }
  13532. for (int index = 0; index < CCS_QUANTITY; index++)
  13533. {
  13534. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13535. {
  13536. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13537. }
  13538. }// END OF CCS_QUANTITY
  13539. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13540. }
  13541. else if(gunType[gun_index] == 'G')
  13542. {
  13543. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13544. {
  13545. tempIndex = ((gun_index==2) ? 1: 0);
  13546. }
  13547. else
  13548. {
  13549. tempIndex = gun_index;
  13550. }
  13551. for (int index = 0; index < GB_QUANTITY; index++)
  13552. {
  13553. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13554. {
  13555. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13556. }
  13557. }// END OF GB_QUANTITY
  13558. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13559. }
  13560. else if(gunType[gun_index] == 'O')
  13561. {
  13562. tempIndex = gun_index;
  13563. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13564. {
  13565. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13566. {
  13567. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13568. }
  13569. }
  13570. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L3_N]);
  13571. }
  13572. else
  13573. {
  13574. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13575. {
  13576. tempIndex = 2;
  13577. }
  13578. else
  13579. {
  13580. tempIndex = gun_index;
  13581. }
  13582. for (int index = 0; index < AC_QUANTITY; index++)
  13583. {
  13584. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13585. {
  13586. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargedEnergy );// PresentChargedEnergy is 0~6553.5 kWh
  13587. }
  13588. }// END OF AC_QUANTITY
  13589. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13590. }
  13591. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13592. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Format,ValueFormatStr[Raw]);
  13593. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Measurand,MeasurandStr[Energy_Active_Import_Interval]);
  13594. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Phase,PhaseStr[L1_N]);
  13595. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Location,LocationStr[Location_Outlet]);
  13596. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[2].Unit,UnitOfMeasureStr[UnitOfMeasure_kWh]);
  13597. //2.3====================================== Power.Active.Import =========================================
  13598. //idx_sample=3;
  13599. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13600. if(gunType[gun_index] == 'J')
  13601. {
  13602. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13603. {
  13604. tempIndex = ((gun_index==2) ? 1: 0);
  13605. }
  13606. else
  13607. {
  13608. tempIndex = gun_index;
  13609. }
  13610. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13611. {
  13612. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13613. {
  13614. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13615. }
  13616. } // End for CHAdeMO_QUANTITY
  13617. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13618. }
  13619. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13620. {
  13621. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13622. {
  13623. tempIndex = ((gun_index==2) ? 1: 0);
  13624. }
  13625. else
  13626. {
  13627. tempIndex = gun_index;
  13628. }
  13629. for (int index = 0; index < CCS_QUANTITY; index++)
  13630. {
  13631. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13632. {
  13633. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13634. }
  13635. } // END for CCS_QUANTITY
  13636. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13637. }
  13638. else if(gunType[gun_index] == 'G')
  13639. {
  13640. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13641. {
  13642. tempIndex = ((gun_index==2) ? 1: 0);
  13643. }
  13644. else
  13645. {
  13646. tempIndex = gun_index;
  13647. }
  13648. for (int index = 0; index < GB_QUANTITY; index++)
  13649. {
  13650. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13651. {
  13652. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13653. }
  13654. }// END for GB_QUANTITY
  13655. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13656. }
  13657. else if(gunType[gun_index] == 'O')
  13658. {
  13659. tempIndex = gun_index;
  13660. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13661. {
  13662. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13663. {
  13664. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[1].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13665. }
  13666. }
  13667. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L3_N]);
  13668. }
  13669. else
  13670. {
  13671. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13672. {
  13673. tempIndex = 2;
  13674. }
  13675. else
  13676. {
  13677. tempIndex = gun_index;
  13678. }
  13679. for (int index = 0; index < AC_QUANTITY; index++)
  13680. {
  13681. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13682. {
  13683. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingPower );// PresentChargingPower is 0~6553.5 kW
  13684. }
  13685. } // END for AC_QUANTITY
  13686. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13687. }
  13688. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13689. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Format,ValueFormatStr[Raw]);
  13690. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Measurand,MeasurandStr[Power_Active_Import]);
  13691. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Phase,PhaseStr[L1_N]);
  13692. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Location,LocationStr[Location_Outlet]);
  13693. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[3].Unit,UnitOfMeasureStr[UnitOfMeasure_kW/*UnitOfMeasure_kWh*/]);
  13694. //2.4====================================== Voltage L1 ====================================================
  13695. //idx_sample=4;
  13696. //J: CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13697. if(gunType[gun_index] == 'J')
  13698. {
  13699. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13700. {
  13701. tempIndex = ((gun_index==2) ? 1: 0);
  13702. }
  13703. else
  13704. {
  13705. tempIndex = gun_index;
  13706. }
  13707. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13708. {
  13709. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13710. {
  13711. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13712. }
  13713. } // END OF FOR CHAdeMO_QUANTITY
  13714. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13715. }
  13716. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13717. {
  13718. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13719. {
  13720. tempIndex = ((gun_index==2) ? 1: 0);
  13721. }
  13722. else
  13723. {
  13724. tempIndex = gun_index;
  13725. }
  13726. for (int index = 0; index < CCS_QUANTITY; index++)
  13727. {
  13728. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13729. {
  13730. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13731. }
  13732. } // END OF FOR CCS_QUANTITY
  13733. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13734. }
  13735. else if(gunType[gun_index] == 'G')
  13736. {
  13737. if(ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0')
  13738. {
  13739. tempIndex = ((gun_index==2) ? 1: 0);
  13740. }
  13741. else
  13742. {
  13743. tempIndex = gun_index;
  13744. }
  13745. for (int index = 0; index < GB_QUANTITY; index++)
  13746. {
  13747. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13748. {
  13749. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13750. }
  13751. } // END OF FOR GB_QUANTITY
  13752. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13753. }
  13754. else if(gunType[gun_index] == 'O')
  13755. {
  13756. tempIndex = gun_index;
  13757. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13758. {
  13759. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13760. {
  13761. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PresentChargingVoltage );// PresentChargingVoltage is 0~6553.5 volt
  13762. }
  13763. }
  13764. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L3_N]);
  13765. }
  13766. else
  13767. {
  13768. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13769. {
  13770. tempIndex = 2;
  13771. }
  13772. else
  13773. {
  13774. tempIndex = gun_index;
  13775. }
  13776. for (int index = 0; index < AC_QUANTITY; index++)
  13777. {
  13778. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13779. {
  13780. 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
  13781. }
  13782. } // END OF FOR AC_QUANTITY
  13783. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13784. }
  13785. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13786. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Format,ValueFormatStr[Raw]);
  13787. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Measurand,MeasurandStr[Voltage]);
  13788. //strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Phase,PhaseStr[L1_N]);
  13789. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Location,LocationStr[Location_Outlet]);
  13790. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[4].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13791. //2.5============================================== End SoC =========================================================
  13792. //idx_sample=5;
  13793. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13794. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  13795. {
  13796. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  13797. {
  13798. tempIndex = ((gun_index==2) ? 1: 0);
  13799. }
  13800. else
  13801. {
  13802. tempIndex = gun_index;
  13803. }
  13804. if(gunType[gun_index] == 'J')
  13805. {
  13806. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13807. {
  13808. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13809. {
  13810. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatterySoc );// 0~100%
  13811. }
  13812. }
  13813. }
  13814. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13815. {
  13816. for (int index = 0; index < CCS_QUANTITY; index++)
  13817. {
  13818. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13819. {
  13820. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatterySoc );// 0~100%
  13821. }
  13822. }
  13823. }
  13824. else if(gunType[gun_index] == 'G')
  13825. {
  13826. for (int index = 0; index < GB_QUANTITY; index++)
  13827. {
  13828. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13829. {
  13830. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatterySoc );// 0~100%
  13831. }
  13832. }
  13833. }
  13834. else if(gunType[gun_index] == 'O')
  13835. {
  13836. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  13837. {
  13838. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  13839. {
  13840. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatterySoc );// 0~100%
  13841. }
  13842. }
  13843. }
  13844. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13845. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Format,ValueFormatStr[Raw]);
  13846. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  13847. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Phase,PhaseStr[L3_N]);
  13848. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Location,LocationStr[Location_EV]);
  13849. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[5].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  13850. } // END FOR DC CASE
  13851. //2.6====================================== Current.Import L2 ==============================================
  13852. // idx_sample=6;
  13853. // AC 3 phase L2 current
  13854. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13855. {
  13856. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13857. {
  13858. tempIndex = 2;
  13859. }
  13860. else
  13861. {
  13862. tempIndex = gun_index;
  13863. }
  13864. for (int index = 0; index < AC_QUANTITY; index++)
  13865. {
  13866. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13867. {
  13868. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL2);// 0~6553.5 amp for EVSE
  13869. }
  13870. }// End of for AC_QUANTITY
  13871. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Phase,PhaseStr[L2_N]);
  13872. }
  13873. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13874. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Format,ValueFormatStr[Raw]);
  13875. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Measurand,MeasurandStr[Current_Import]);
  13876. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Location,LocationStr[Location_Outlet]);
  13877. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[6].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13878. //2.7====================================== Current.Import L3 ==============================================
  13879. // idx_sample=7;
  13880. // AC 3 phase L3 current
  13881. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13882. {
  13883. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13884. {
  13885. tempIndex = 2;
  13886. }
  13887. else
  13888. {
  13889. tempIndex = gun_index;
  13890. }
  13891. for (int index = 0; index < AC_QUANTITY; index++)
  13892. {
  13893. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13894. {
  13895. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Value, "%.1f" ,ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PresentChargingCurrentL3);// 0~6553.5 amp for EVSE
  13896. }
  13897. }// End of for AC_QUANTITY
  13898. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Phase,PhaseStr[L3_N]);
  13899. }
  13900. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13901. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Format,ValueFormatStr[Raw]);
  13902. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Measurand,MeasurandStr[Current_Import]);
  13903. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Location,LocationStr[Location_Outlet]);
  13904. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[7].Unit,UnitOfMeasureStr[UnitOfMeasure_A]);
  13905. //2.9====================================== Voltage L2 ====================================================
  13906. //idx_sample=8;
  13907. // AC 3 phase L2 volatge
  13908. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13909. {
  13910. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13911. {
  13912. tempIndex = 2;
  13913. }
  13914. else
  13915. {
  13916. tempIndex = gun_index;
  13917. }
  13918. for (int index = 0; index < AC_QUANTITY; index++)
  13919. {
  13920. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13921. {
  13922. 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
  13923. }
  13924. } // END OF FOR AC_QUANTITY
  13925. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Phase,PhaseStr[L2_N]);
  13926. }
  13927. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13928. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Format,ValueFormatStr[Raw]);
  13929. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Measurand,MeasurandStr[Voltage]);
  13930. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Location,LocationStr[Location_Outlet]);
  13931. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[8].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13932. //2.10====================================== Voltage L3 ====================================================
  13933. //idx_sample=9;
  13934. // AC 3 phase L3 volatge
  13935. if(('1' <= gunType[gun_index]) && (gunType[gun_index] <= '9') && ((ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'Y') || (ShmSysConfigAndInfo->SysConfig.ModelName[2] == 'W')))
  13936. {
  13937. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D')
  13938. {
  13939. tempIndex = 2;
  13940. }
  13941. else
  13942. {
  13943. tempIndex = gun_index;
  13944. }
  13945. for (int index = 0; index < AC_QUANTITY; index++)
  13946. {
  13947. if (ShmSysConfigAndInfo->SysInfo.AcChargingData[index].Index == tempIndex)
  13948. {
  13949. 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
  13950. }
  13951. } // END OF FOR AC_QUANTITY
  13952. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Phase,PhaseStr[L3_N]);
  13953. }
  13954. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Context,ReadingContextStr[ReadingContext_Transaction_End]);
  13955. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Format,ValueFormatStr[Raw]);
  13956. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Measurand,MeasurandStr[Voltage]);
  13957. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Location,LocationStr[Location_Outlet]);
  13958. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[9].Unit,UnitOfMeasureStr[UnitOfMeasure_V]);
  13959. //====================== Start SoC ================================
  13960. //idx_sample=10;
  13961. //J : CHAdeMO U: CCS1 combo E: CCS2 combo G: GBT DC
  13962. if((gunType[gun_index] == 'J')||(gunType[gun_index] == 'U')||(gunType[gun_index] == 'E')||(gunType[gun_index] == 'G')||(gunType[gun_index] == 'O'))
  13963. {
  13964. if((ShmSysConfigAndInfo->SysConfig.ModelName[8] != '0') && (gunType[gun_index] != 'O'))
  13965. {
  13966. tempIndex = ((gun_index==2) ? 1: 0);
  13967. }
  13968. else
  13969. {
  13970. tempIndex = gun_index;
  13971. }
  13972. if(gunType[gun_index] == 'J')
  13973. {
  13974. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  13975. {
  13976. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == tempIndex)
  13977. {
  13978. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].EvBatteryStartSoc );// 0~100%
  13979. }
  13980. }
  13981. }
  13982. else if((gunType[gun_index] == 'U')||(gunType[gun_index] == 'E'))
  13983. {
  13984. for (int index = 0; index < CCS_QUANTITY; index++)
  13985. {
  13986. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == tempIndex)
  13987. {
  13988. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].EvBatteryStartSoc );// 0~100%
  13989. }
  13990. }
  13991. }
  13992. else if(gunType[gun_index] == 'G')
  13993. {
  13994. for (int index = 0; index < GB_QUANTITY; index++)
  13995. {
  13996. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == tempIndex)
  13997. {
  13998. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.GbChargingData[index].EvBatteryStartSoc );// 0~100%
  13999. }
  14000. }
  14001. }
  14002. else if(gunType[gun_index] == 'O')
  14003. {
  14004. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14005. {
  14006. if (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.Index == tempIndex)
  14007. {
  14008. sprintf((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Value, "%d" ,ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.EvBatteryStartSoc );// 0~100%
  14009. }
  14010. }
  14011. }
  14012. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Context,ReadingContextStr[ReadingContext_Transaction_Begin]);
  14013. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Format,ValueFormatStr[Raw]);
  14014. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Measurand,MeasurandStr[SoC/*Energy_Reactive_Export_Register*/]);
  14015. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Phase,PhaseStr[L3_N]);
  14016. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Location,LocationStr[Location_EV]);
  14017. strcpy((char *)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[0].SampledValue[10].Unit,UnitOfMeasureStr[UnitOfMeasure_Percent/*UnitOfMeasure_kWh*/]);
  14018. } // END FOR DC CASE
  14019. //======================================== Message create ==============================================
  14020. json_object *StopTransaction = json_object_new_object();
  14021. json_object *transactionDatas = json_object_new_array();
  14022. json_object *sampledValues = json_object_new_array();
  14023. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag) > 0)
  14024. json_object_object_add(StopTransaction, "idTag", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].IdTag));
  14025. json_object_object_add(StopTransaction, "meterStop", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].MeterStop));
  14026. json_object_object_add(StopTransaction, "transactionId", json_object_new_int(ShmOCPP16Data->StopTransaction[gun_index].TransactionId));
  14027. json_object_object_add(StopTransaction, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].Timestamp));
  14028. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason) > 0)
  14029. json_object_object_add(StopTransaction, "reason", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].StopReason));
  14030. for(int idxTrans = 0;idxTrans<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData);idxTrans++)
  14031. {
  14032. json_object *transactionData = json_object_new_object();
  14033. json_object_object_add(transactionData, "timestamp", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].TimeStamp));
  14034. for(int idx=0;idx<ARRAY_SIZE(ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue);idx++)
  14035. {
  14036. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value) > 0)
  14037. {
  14038. json_object *sampledValue = json_object_new_object();
  14039. json_object_object_add(sampledValue, "value", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Value));
  14040. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context) > 0)
  14041. json_object_object_add(sampledValue, "context", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Context));
  14042. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format) > 0)
  14043. json_object_object_add(sampledValue, "format", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Format));
  14044. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand) > 0)
  14045. json_object_object_add(sampledValue, "measurand", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Measurand));
  14046. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase) > 0)
  14047. json_object_object_add(sampledValue, "phase", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Phase));
  14048. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location) > 0)
  14049. json_object_object_add(sampledValue, "location", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Location));
  14050. if(strlen((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit) > 0)
  14051. json_object_object_add(sampledValue, "unit", json_object_new_string((char*)ShmOCPP16Data->StopTransaction[gun_index].TransactionData[idxTrans].SampledValue[idx].Unit));
  14052. json_object_array_add(sampledValues, sampledValue);
  14053. }
  14054. }
  14055. json_object_object_add(transactionData, "sampledValue", sampledValues);
  14056. json_object_array_add(transactionDatas, transactionData);
  14057. }
  14058. json_object_object_add(StopTransaction, "transactionData", transactionDatas);
  14059. sprintf(queuedata, "%d,[%d,\"%s\",\"StopTransaction\",%s]",(gun_index+1)
  14060. ,MESSAGE_TYPE_CALL
  14061. ,guid
  14062. ,json_object_to_json_string_ext(StopTransaction, JSON_C_TO_STRING_PLAIN));
  14063. json_object_put(StopTransaction);
  14064. // Check File "TempStopTransaction" Exist
  14065. if((access(TempStopTransaction,F_OK))!=-1)
  14066. {
  14067. //DEBUG_INFO("TransactionRelatedQueue exist.\n");
  14068. fclose(fopen(TempStopTransaction, "w"));
  14069. }
  14070. else
  14071. {
  14072. //DEBUG_INFO("TransactionRelatedQueue not exist\n");
  14073. FILE *log = fopen(TempStopTransaction, "w+");
  14074. if(log == NULL)
  14075. {
  14076. //DEBUG_INFO("Can't Create File TransactionRelatedQueue \n");
  14077. return ;
  14078. }
  14079. else
  14080. {
  14081. fclose(log);
  14082. }
  14083. }
  14084. //Add TempStopTransaction | Update TempStopTransaction
  14085. // open file for writing
  14086. FILE *outfile;
  14087. outfile = fopen (TempStopTransaction, "a");
  14088. //DEBUG_INFO("data = %s\n", queuedata);
  14089. fputs(queuedata, outfile);
  14090. fputs("\n", outfile);
  14091. fclose (outfile);
  14092. }
  14093. void checkTempStopTransaction(int gun_index)
  14094. {
  14095. FILE *fptr1;
  14096. char ch;
  14097. char str[QUEUE_MESSAGE_LENGTH]={0};
  14098. char guid[37]={0};
  14099. char tempdata[65]={0};
  14100. char connectorStr[2]={0};
  14101. char TempStopTransaction[256];
  14102. sprintf(TempStopTransaction, "/Storage/OCPP/TempStopTransaction_%d", (gun_index+1));
  14103. fptr1 = fopen(TempStopTransaction, "r");
  14104. //TempStopTransaction格式: 槍號,StopTransaction封包
  14105. if (!fptr1)
  14106. {
  14107. //printf(" File not found or unable to open the input file!!\n");
  14108. return ;
  14109. }
  14110. ch=fgetc(fptr1);
  14111. //printf(" Now the content of the file %s is : \n",fname);
  14112. rewind(fptr1);
  14113. if(ch!=EOF)
  14114. {
  14115. // copy all contents to the temporary file except the specific line
  14116. while (fgets(str, QUEUE_MESSAGE_LENGTH, fptr1) != NULL)
  14117. {
  14118. str[strlen(str) - 1] = '\0'; // eat the newline fgets() stores
  14119. if(str[0]=='\0')
  14120. {
  14121. break;
  14122. }
  14123. //TempStopTransaction格式: 槍號,StopTransaction封包
  14124. strncpy(connectorStr, str, 1);
  14125. if(atoi(connectorStr) != (gun_index+1))
  14126. {
  14127. DEBUG_INFO("atoi(connectorStr) = %d, gun_index = %d\n", atoi(connectorStr), gun_index);
  14128. fclose(fptr1);
  14129. return ;
  14130. }
  14131. //random_uuid(guid);
  14132. strncpy(guid, str+6, 36); //copy guid
  14133. sprintf(tempdata, "StopTransaction,%d", (gun_index));
  14134. if(hashmap_operation(HASH_OP_ADD, guid, tempdata) == 1)
  14135. {
  14136. //DEBUG_INFO("StopTransaction mapitem pass\n");
  14137. }
  14138. queue_operation(QUEUE_OPERATION_ADD, guid, str);//addq(guid, queuedata); ---> remove temporally
  14139. memset(str,0,ARRAY_SIZE(str));
  14140. }
  14141. }
  14142. // fptr1=freopen(NULL,"w",fptr1); // reset the fptr1 again
  14143. fclose(fptr1);
  14144. remove(TempStopTransaction); // remove the original file
  14145. }
  14146. void FillStartTransaction(int ConnectorId, unsigned char IdTag[], int MeterStart,int ReservationId,unsigned char Timestamp[])
  14147. {
  14148. ShmOCPP16Data->StartTransaction[ConnectorId-1].ConnectorId = ConnectorId;
  14149. ShmOCPP16Data->StartTransaction[ConnectorId-1].ReservationId = ReservationId;
  14150. ShmOCPP16Data->StartTransaction[ConnectorId-1].MeterStart = MeterStart;
  14151. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].IdTag, (char *)IdTag);
  14152. strcpy((char *)ShmOCPP16Data->StartTransaction[ConnectorId-1].Timestamp,(char *) Timestamp);
  14153. }
  14154. int GetWebSocketPingInterval(void)
  14155. {
  14156. return atoi((const char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[WebSocketPingInterval].ItemData);
  14157. }
  14158. int GetServerSign(void)
  14159. {
  14160. return server_sign;
  14161. }
  14162. uint8_t GetOcppSecurityProfile()
  14163. {
  14164. return atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[SecurityProfile].ItemData);
  14165. }
  14166. void GetOcppChargerBoxId(uint8_t *data)
  14167. {
  14168. sprintf((char*)data, "%s", ShmOCPP16Data->ChargeBoxId);
  14169. }
  14170. void GetOcppSecurityPassword(uint8_t *data)
  14171. {
  14172. sprintf((char*)data, "%s", ShmOCPP16Data->ConfigurationTable.CoreProfile[AuthorizationKey].ItemData);
  14173. }
  14174. void SetServerSign(int value)
  14175. {
  14176. server_sign = value;
  14177. }
  14178. int GetBootNotificationInterval(void)
  14179. {
  14180. return BootNotificationInterval;
  14181. }
  14182. int GetInternetConn(void)
  14183. {
  14184. return ShmSysConfigAndInfo->SysInfo.InternetConn;
  14185. }
  14186. void InitialSystemValue(void)
  14187. {
  14188. int connectorIndex = 0;
  14189. //int valueASCII = 0;
  14190. server_cycle_Status = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[MinimumStatusDuration].ItemData);
  14191. gunTotalNumber=0;
  14192. SystemInitial = 0;
  14193. localversion=0;
  14194. BootNotificationInterval = 0;
  14195. authorizeRetryTimes = 0;
  14196. GunStatusInterval = 10;
  14197. TransactionMessageAttemptsValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageAttempts].ItemData);
  14198. TransactionMessageRetryIntervalValue = atoi((char *)ShmOCPP16Data->ConfigurationTable.CoreProfile[TransactionMessageRetryInterval].ItemData);
  14199. //Hear Beat
  14200. HeartBeatWithNOResponse = 0;
  14201. HeartBeatWaitTime = atoi((char*)ShmOCPP16Data->ConfigurationTable.CoreProfile[HeartbeatInterval].ItemData);;
  14202. FirstHeartBeat = 0;
  14203. FirmwareStatusNotificationStatus = FIRMWARE_STATUS_IDLE; // Idle
  14204. DiagnosticsStatusNotificationStatus = DIAGNOSTIC_STATUS_IDLE; // Idle
  14205. memset(CurrentChargingProfileScheduleStr, 0, ARRAY_SIZE(CurrentChargingProfileScheduleStr));
  14206. memset(statusModeChage, 0, ARRAY_SIZE(statusModeChage));
  14207. memset(ChademoPreviousSystemStatus, 0, ARRAY_SIZE(ChademoPreviousSystemStatus));
  14208. memset(CcsPreviousSystemStatus, 0, ARRAY_SIZE(CcsPreviousSystemStatus));
  14209. memset(GbPreviousSystemStatus, 0, ARRAY_SIZE(GbPreviousSystemStatus));
  14210. memset(AcPreviousSystemStatus, 0, ARRAY_SIZE(AcPreviousSystemStatus));
  14211. memset(ChademoPreviousConnectorPlugIn, 0, ARRAY_SIZE(ChademoPreviousConnectorPlugIn));
  14212. memset(CcsPreviousConnectorPlugIn, 0, ARRAY_SIZE(CcsPreviousConnectorPlugIn));
  14213. memset(GbPreviousConnectorPlugIn, 0, ARRAY_SIZE(GbPreviousConnectorPlugIn));
  14214. memset(AcPreviousConnectorPlugIn, 0, ARRAY_SIZE(AcPreviousConnectorPlugIn));
  14215. memset(gunType, 0, ARRAY_SIZE(gunType));
  14216. if(ShmSysConfigAndInfo->SysConfig.ModelName[0]=='D') // 'D' means DC
  14217. {
  14218. if(ShmSysConfigAndInfo->SysConfig.ModelName[1]=='O')
  14219. {
  14220. // DO series
  14221. for(int index=0; index<GENERAL_GUN_QUANTITY ; index++)
  14222. {
  14223. SystemInitial = SystemInitial + 1;
  14224. gunTotalNumber = gunTotalNumber + 1;
  14225. gunType[connectorIndex] = 'O';
  14226. connectorIndex = connectorIndex + 1;
  14227. }
  14228. }
  14229. else
  14230. {
  14231. // DM, DW, DS series
  14232. //check connector / socket type (index: 8, 9, 10)
  14233. for(int index=7; index <10 ; index++)
  14234. {
  14235. if(index != 8)
  14236. {
  14237. // DC Connector
  14238. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] >= 'A') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= 'Z'))
  14239. {
  14240. SystemInitial = SystemInitial + 1;
  14241. gunTotalNumber = gunTotalNumber + 1;
  14242. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14243. connectorIndex = connectorIndex + 1;
  14244. }
  14245. }
  14246. else
  14247. {
  14248. // AC Connector
  14249. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14250. {
  14251. SystemInitial = SystemInitial + 1;
  14252. gunTotalNumber = gunTotalNumber + 1;
  14253. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14254. connectorIndex = connectorIndex + 1;
  14255. }
  14256. }
  14257. }
  14258. }
  14259. //DEBUG_INFO("DC ...\n");
  14260. }
  14261. else if (ShmSysConfigAndInfo->SysConfig.ModelName[0]=='A') //'A' means AC
  14262. {
  14263. //check connector / socket type (index: 8, 9, 10)
  14264. for(int index=7; index <10 ; index++)
  14265. {
  14266. if ((ShmSysConfigAndInfo->SysConfig.ModelName[index] > '0') && (ShmSysConfigAndInfo->SysConfig.ModelName[index] <= '9'))
  14267. {
  14268. SystemInitial = SystemInitial + 1;
  14269. gunTotalNumber = gunTotalNumber + 1;
  14270. gunType[connectorIndex] = ShmSysConfigAndInfo->SysConfig.ModelName[index];
  14271. connectorIndex = connectorIndex + 1;
  14272. //DEBUG_INFO("AC: %d, %c\n", index, ShmSysConfigAndInfo->SysConfig.ModelName[index]);
  14273. }
  14274. }
  14275. }
  14276. //Status && ConnectorPlugIn Setting
  14277. for (int index = 0; index < CHAdeMO_QUANTITY; index++)
  14278. {
  14279. ChademoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].PreviousSystemStatus;
  14280. ChademoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].ConnectorPlugIn;
  14281. }
  14282. for (int index = 0; index < CCS_QUANTITY; index++)
  14283. {
  14284. CcsPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].PreviousSystemStatus;
  14285. CcsPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].ConnectorPlugIn;
  14286. }
  14287. for (int index = 0; index < GB_QUANTITY; index++)
  14288. {
  14289. GbPreviousSystemStatus[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].PreviousSystemStatus;
  14290. GbPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.GbChargingData[index].ConnectorPlugIn;
  14291. }
  14292. for (int index = 0; index < AC_QUANTITY; index++)
  14293. {
  14294. AcPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PreviousSystemStatus;
  14295. AcPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.AcChargingData[index].PilotState;
  14296. }
  14297. for (int index = 0; index < GENERAL_GUN_QUANTITY; index++)
  14298. {
  14299. DoPreviousSystemStatus[index]= ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PreviousSystemStatus;
  14300. DoPreviousConnectorPlugIn[index] = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[index].GeneralChargingData.PilotState;
  14301. }
  14302. for(int gun_index=0; gun_index < gunTotalNumber; gun_index++ )
  14303. {
  14304. cpinitateMsg.bits[gun_index].StatusNotificationReq = 0;
  14305. cpinitateMsg.bits[gun_index].StatusNotificationConf = 0;
  14306. //clientTime.MeterValues[gun_index] = time((time_t*)NULL);
  14307. clientTime.StatusNotification[gun_index] = time((time_t*)NULL);
  14308. }
  14309. memset( (void *)unknownkey, 0, sizeof(unknownkey));
  14310. clientTime.Heartbeat=time((time_t*)NULL);
  14311. sleep(1);
  14312. }
  14313. void LWS_Send(char * str)
  14314. {
  14315. //=====================================================
  14316. // Check InternetConn 0: disconnected, 1: connected
  14317. //====================================================
  14318. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14319. {
  14320. DEBUG_INFO("offline now !!!\n");
  14321. return;
  14322. }
  14323. pthread_mutex_lock(&lock_send);
  14324. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14325. sprintf((char *)SendBuffer, "%s", str);
  14326. SendBufLen = strlen(str);
  14327. pthread_mutex_unlock(&lock_send);
  14328. lws_callback_on_writable(wsi_client);
  14329. //lws_service(context, 0);
  14330. //sleep(1);
  14331. }
  14332. void LWS_SendNow(char * str)
  14333. {
  14334. //=====================================================
  14335. // Check InternetConn 0: disconnected, 1: connected
  14336. //====================================================
  14337. if(ShmSysConfigAndInfo->SysInfo.InternetConn == 0)
  14338. {
  14339. DEBUG_INFO("offline now !!!\n");
  14340. return;
  14341. }
  14342. pthread_mutex_lock(&lock_send);
  14343. memset(SendBuffer, 0, ARRAY_SIZE(SendBuffer));
  14344. sprintf((char *)SendBuffer, "%s", str);
  14345. SendBufLen = strlen(str);
  14346. pthread_mutex_unlock(&lock_send);
  14347. lws_callback_on_writable(wsi_client);
  14348. lws_service(context, 0);
  14349. //sleep(1);
  14350. }